Live data from Hacker News

Practical Makefiles, by example

nuclear.mutantstargoat.com

1–10 of 29 posts

Re: Practical Makefiles, by example

#2
To anyone implementing the automatic dependency generation mentioned in this article, you can actually make things even simpler by combining the compiling and dependency steps.

This works because if you add a new dependency to a file, that information will only be needed for the next build - the current file will already be considered out of date seeing as it was edited to add the #include.

  gcc -MD -MP foo.c -o foo.o
Will compile foo.c into foo.o, and also generate foo.d (-MD). Foo.d will contains make style dependencies, and also a phony target for every dependency (-MP). This allows you to delete dependant files, as make considers the target of a rule that has no perquisites or commands to be up to date if said target does not exist.

Re: Practical Makefiles, by example

#3
I disagree with this. I don't find CMake any less easy to use than make in the simple case, but it is far better than Autotools in the complex case. Just learn CMake and be done with it. As a bonus, it saves you some typing making your program cross-platform, although that is a pain no matter what tool you're using.

Re: Practical Makefiles, by example

#5
One other dependency often forgotten is on the Makefile itself. This way if the Makefile changes, everything gets rebuilt:

    DEPS = Makefile
    %.o: %.c $(DEPS)
        $(CC) $(CCFLAGS) -o $@ -c $

Re: Practical Makefiles, by example

#6
post #4

Great idea. But awful theme. And no longer really relevant. CMake is now all the rage. Like krapht said, just learn CMake and be done with it.

CMake generates Makefiles (and other build system files on other systems). If something doesn't work, you can either fiddle with it without understanding what you're doing, or you can look at the Makefile and see what went wrong...

I prefer to just use plain Makefiles, they're easier to fix and "make correct" than anything else. For me, I guess. make is weird, but more minimal than cmake. (cmake is HUGE. autotools are a lot weirder than make. considering the alternatives, I actually like make...)

Re: Practical Makefiles, by example

#7
post #4

Great idea. But awful theme. And no longer really relevant. CMake is now all the rage. Like krapht said, just learn CMake and be done with it.

ugh. CMake is atrocious. It covers maybe .1% of the cases that autotools handles while having some of the worst documentation known to man. Not to mention yet another language to learn. It's not more "modern" than autotools and it's in no way shape or form "newer" than autotools, seeing that automake/autoconf have been in active development since inception.

Re: Practical Makefiles, by example

#8
Getting into JavaScript there's grunt. I know it's not really comparable to make as it doesn't check dependencies but ... it really seems like it would be cool for a "new" build system that took plugins the way grunt does. Maybe they'd wouldn't fit most people's use cases enough?

Re: Practical Makefiles, by example

#9
post #7
post #4

Great idea. But awful theme. And no longer really relevant. CMake is now all the rage. Like krapht said, just learn CMake and be done with it.

ugh. CMake is atrocious. It covers maybe .1% of the cases that autotools handles while having some of the worst documentation known to man. Not to mention yet another language to learn. It's not more "modern" than autotools and it's in no way shape or form "newer" than autotools, seeing that automake/autoconf have been in active development since inception.

It does let you avoid shell, which makes cross platform stuff less fraught.

This should not be interpreted as an endorsement of CMakes miserable, quarter-assed BASIC-in-almost-s-exprs language.

Re: Practical Makefiles, by example

#10
This is nice introduction for someone just beginning gcc like compilers. For example I would use this back then when I started to use avr-gcc. It doesn't have to be cross-platform or need any other super complex fancy things. It just needs few extra rules and some basic stuffs. Make is great choice for this kind of things.
Post reply on HN