
Makefile Tutorial by Example - luu
http://makefiletutorial.com/
======
jgrahamc
A far better way to learn about GNU make would be to read the actual manual.

[https://www.gnu.org/software/make/manual/](https://www.gnu.org/software/make/manual/)

This doesn't seem like a well thought out introduction. There's quite a lot of
randomness. For example, the first makefile says:

    
    
        This makefile will always run. The default target is some_binary,    
        because it is first.
    
        some_binary:
    	echo "nothing"
    

Actually, it's not true that that will always echo nothing because some_binary
isn't declared as phony and so if some_binary exists on the CWD echo "nothing"
will not happen.

Also, the language here is weird. The tutorial talks about makefiles running
and targets calling targets.

4.8 states:

    
    
        1) We do not use *.o, because that is just the string *.o, 
        which might be useful in the commands, but is only one 
        target and does not expand."
    

That's not true. Consider the following

    
    
        *.foo: ; @echo $@
    

If there are any files in the CWD that match *.foo then it is expanded and
rules created for each file.

~~~
CharlesFinley
Yeah, RTFM! :)

~~~
vog
Not sure if your comment was meant to be sarcasm, but I do find the GNU Make
Manual very clear and well written.

For example, it starts with a rough description of what a Makefile is composed
of:

[https://www.gnu.org/software/make/manual/html_node/Rule-
Intr...](https://www.gnu.org/software/make/manual/html_node/Rule-
Introduction.html)

And then directly jumps into nice a real-world example:

[https://www.gnu.org/software/make/manual/html_node/Simple-
Ma...](https://www.gnu.org/software/make/manual/html_node/Simple-
Makefile.html)

This is a good compromise between abstract and concrete knowledge.

Most manuals either cover only some special cases and leave you alone to find
out what's more. Then they cover only the whole syntax as BNF, or a whole API
doc, or something. But nothing in between, drawing the connection between
practical usage and abstract description of what's all possible.

------
mweibel
I usually use this tutorial as a help if I write Makefiles:
[http://www.ploxiln.net/make.html](http://www.ploxiln.net/make.html)

~~~
DarkTree
As an alternative to Grunt and Gulp for Frontend Developers:

[http://www.sitepoint.com/using-gnu-make-front-end-
developmen...](http://www.sitepoint.com/using-gnu-make-front-end-development-
build-tool/)

------
ibiza
Missed an opportunity to demonstrate that since make already knows how to make
quite a lot of things, you can start w/ no Makefile at all, e.g.:

    
    
        $ echo 'int main() {}' >foo.c
        $ make foo

------
sidarape
What I'm really looking for is a tutorial about autoconf, automake, and
friends.

~~~
thameera
I've found this thoughtbot article very helpful to grasp autotools:
[https://robots.thoughtbot.com/the-magic-behind-configure-
mak...](https://robots.thoughtbot.com/the-magic-behind-configure-make-make-
install)

~~~
sidarape
This seems nice, thank you. I'll read it later.

------
steaminghacker
This is great. i wish a lot more things were like this. ie by example. it's
also good for jogging one's memory on details.

------
oso2k
Things like this are good for a basis of understanding. But if you need help
figuring how to tie stuff all together, the suckless[0] guys are masters of
brevity.

[0]
[http://git.suckless.org/dwm/tree/Makefile](http://git.suckless.org/dwm/tree/Makefile)

------
emsy
The tutorial is allright but I would prefer for it not to exist (or not need
to exist) because Make is so arcane and touchy that it should've been replaced
a long long time ago. I really hate Make. There are better alternatives out
there (e.g. SCons)

~~~
jschwartzi
People hate Make because it doesn't define any conventions for its use. You
can use it to do anything, but it does very little by default. This gives you
a tremendous amount of freedom to declare exactly what it means to "build" an
arbitrary component, but it also means you have to declare it yourself.

Many of the modern build tools move away from that. CMake, for instance, drops
the ability to build arbitrary assemblages of files and focuses almost
exclusively on giving you a nicely-constrained language for defining
compilation targets and allowing you to support many different compilers.

Maven, Ivy, and it's ilk focus on declaring run-time dependencies and on some
concept of a "build l lifecycle."

Having used all these systems, I find that there are things I need to do when
running a build that I can easily do in Make, but which are encumbered
significantly by other tools.

Make's syntax sucks, and it expects you to know a bunch of arcane stuff about
how your project is built, but in exchange you get the ability to build
literally anything.

~~~
mzs
In fact there is a lot of convention typically installed by default:

    
    
      $ make -pf /dev/null | wc -l
           359
    

Those suffix rules are enough for many projects, and a great example to follow
if you need something different.

------
GFK_of_xmaspast
This is 2015, there's no reason to manually write a makefile like an animal.

