-1

I am looking for some basic information regarding makefile structure. Any pointers will be highly appreciated. Thanks.

Brian Neal
  • 31,821
  • 7
  • 55
  • 59
stranger
  • 39
  • 1
  • 2
  • CMake is better than Make. If you are looking to create your own project, you may be interested in my C++ project template which uses the CMake build system and takes care of issues such as the build system for you: http://code.google.com/p/cpp-project-template/ – Michael Aaron Safyan May 26 '10 at 23:00
  • 1
    That said, if you want a Makefile tutorial, here is one: http://sites.google.com/site/michaelsafyan/coding/resources/how-to-guides/how-to-write-a-makefile – Michael Aaron Safyan May 26 '10 at 23:01

5 Answers5

11

Official NMAKE documentation.

There are several other types of build systems that use "makefiles". Several of the other answers here are pointing you to these other systems. They all implement the same basic ideas, but the capabilities and syntax vary, sometimes in subtle ways. If you need to learn how to use NMAKE (which is the one you mentioned in the title), and you read GNU make documentation, you're likely to get confused.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Adrian McCarthy
  • 45,555
  • 16
  • 123
  • 175
7

The best help I think I can give anyone desiring to learn how to write their own makefiles is:

DON'T DO IT!!!

Use a makefile generator. There's a lot out there. One of the best I've seen is CMake but there's also automake/autoconf/all that.

You can also use a totally different build system like Ant (but that's by far the only option in this category).

Make actually kind of sucks. I haven't touched one in 10 years. Put your development effort where it will do the most good, in your code.

Edward Strange
  • 40,307
  • 7
  • 73
  • 125
  • Well, before Cmake it is usefull just to get acquaintance with makefiles, to understand how it evolved historically. – Max May 26 '10 at 22:51
  • Ant is the same as make. It is just as complex and basically defines its own language within XML. – Martin York May 26 '10 at 22:53
  • +1 for advocating CMake over Make. – Michael Aaron Safyan May 26 '10 at 22:56
  • @Martin, yeah, Ant is not the way to go; for Java, one should use Maven. I actually think Make is easier to understand than Ant, and for C and C++, the CMake build system is definitely the best. – Michael Aaron Safyan May 26 '10 at 22:59
  • Yeah, I've never used Ant or Maven. I looked at them briefly but never tried them. I wasn't advocating them, only indicating them as an alternative. I've used CMake before and liked it a lot. Currently I mostly just use the build system in the IDE I'm using. – Edward Strange May 26 '10 at 23:09
  • @Max - I wouldn't worry about it. CMake abstracts away the Make garbage fairly effectively. If you were using automake and friends then it might be likely you'd eventually have to resort to Make syntax to make the right macros. I don't see that as likely when using CMake. One partial reason at least may be that CMake can generate things like VS solutions in addition to makefiles of varying syntax and birthright. – Edward Strange May 26 '10 at 23:12
  • @Noah Roberts. Yes, you are absolutely right. btw, I also use CMake, but it is just interesting how it works, I mean, CMake produces makefiles (or, as you said VS solutions), and what is inside makefiles, what does make with them, etc. – Max May 27 '10 at 00:03
4

For very quick start (if you haven't yet tried) - read this, very simple.

If you want start writing makefiles in couple hours - this one.

To be a monster in makefiles use official, commonly you need this as reference book.

Max
  • 4,792
  • 4
  • 29
  • 32
1

You may want to have a look at the Autobook

nico
  • 50,859
  • 17
  • 87
  • 112
1

I agree with most earlier responders: don't continue to be dependent on NMake, use newer tools. Ant, MSBuild, Maven, Scons, GNU/autotools, etc. But, if you really want to learn more about NMake, check out the Microsoft Rotor (SSCLI) source distro, it includes the source to NMake, at least a hacked-up snapshot needed to bootstrap Rotor's build. And for better examples of Nmakefiles, look in early Win32 SDKs, and later OS/2 SDKs, that was the heydey of complex Nmakefiles.

Lee Fisher
  • 36
  • 2