Search code examples
cmakemakefilegnu-makenmake

Learning Makefile: Are the rules universal across all implementations of Make?


I'm interested in learning the art of Makefile projects. However, I have one concern.

For background: On my computer, I have nmake installed, which I'm assuming came with Visual Studio when I installed it. I am possibly thinking of having my C++ projects use the makefile structure using nmake. But what if I wanted to move to other popular versions of make? gmake? This leads me to my main question:

If I learned one implementation of make (nmake, gmake) and moved to another, to what extent can I expect a difference in makefile syntax? In conventions/practices?

If there is a substantial difference between each implementation, I have a followup question (a bit opinionated):

Which implementation of make should I learn first and why?


Solution

  • cmake is not an implementation of make at all. It's a completely different tool: cmake is a tool that creates project build control files, such as makefiles, Visual Studio project files, Xcode project files, Eclipse project files, etc. Cmake syntax has no relationship whatsoever to make syntax.

    nmake is a "sort of" make tool, but it's also different than other versions of make; most other versions of make (GNU make, Solaris make, BSD make, etc.) conform at least to the POSIX specification for make. nmake (as far as I'm aware) doesn't do that. However the basic syntax of nmake for defining rules is similar to other versions of make.

    GNU make is a highly portable version of make that supports POSIX, plus a large number of non-portable extensions. However, GNU make itself is highly portable: in addition to Windows (both native and cygwin) and UNIX (BSD, Linux, Solaris, etc.) systems, it also supports VMS and other operating systems.

    Of the above, nmake is the least portable option; it's available only on Windows. cmake is a good choice if you want to use a variety of development tools, but it is not in any way make-like. If you want to learn make and makefiles and be portable across a wide variety of platforms, your best bet is GNU make.