25

How similar/different are gnu make, microsoft nmake and posix standard make?

Obviously there's things like "which OS?", "which compiler?" and "which linker?", but I'm referring specifically to the syntax, semantics and command-line options of the makefiles themselves.

If I write makefiles based on manuals for gnu make, what are the most important portability issues that I need to be aware of?

  • Related: [Restricting GNU‑Make to POSIX Make behaviour @ Unix.SE](http://unix.stackexchange.com/q/144424/50602) Sadly there seems to be no way of achieving that, you can just use `.POSIX` special target which still leaves many extensions enabled. – Palec Oct 17 '14 at 23:37

1 Answers1

11

GNU Make and POSIX Make share a common core so that GNU Make understands makefiles intended for POSIX Make and interprets them the same way - with very few exceptions. However, many GNU Makefiles use features that are only available in GNU Make. Sometimes this is deliberate and conscious; sometimes it isn't (and "sometimes isn't" is a problem). I'm less familiar with Microsoft nmake; I believe it is likely to hew close to the POSIX Make semantics at its core, but it will have its own divergent set of extensions.

Generally speaking, what the programs like autoconf produce are close to portable Makefiles.

The main things to be beware of using GNU Make are all the extended function notations for mapping file names (macros) into useful values. While they are undoubtedly useful, they are also a trap for portability.

The '%.x' notations for suffix rules are not defined by the POSIX specification for make — they are recognized as a common extension:

The interpretation of targets containing the characters '%' and '"' is implementation-defined.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • I have run into aix make program couple times. Yuck. It is strictly POSIX or is it something else standard-wise? – Anycorn Feb 17 '10 at 03:50
  • @unknown: it is fairly close to POSIX Make - somewhere between that and one of the System V make programs. POSIX Make is pretty much a common subset of the various make variants. – Jonathan Leffler Feb 17 '10 at 06:01
  • 3
    Also command line options (relevant to `MAKEFLAGS` variable), special targets (uppercase, starting with dot) and built-in rules vary wildly. But e.g. `.PHONY` special target seems to be supported even outside Gnu Make world. I think the only safe way is to test your makefiles. If you want to play it safe, adhere to POSIX even though it defines a very limited make. – Palec Oct 17 '14 at 23:24
  • i tried searching for an official POSIX make's documentation, and couldn't find it, nor what is its latest version. the [gnu make's page](https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-simply-expanded-variables) doesn't list when it was updated, or w.r.t. which POSIX version they are mentioning against. – user8395964 Aug 25 '22 at 03:22
  • Did you follow the [POSIX](http://www.opengroup.org/onlinepubs/9699919799/utilities/make.html) link in the previous edition of the answer? It actually leads to the POSIX specification of `make`. I've revised the text to make that clearer. – Jonathan Leffler Aug 25 '22 at 03:24