Makefile Tutorial by Example
makefiletutorial.com
makefiletutorial.com
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.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...
And then directly jumps into nice a real-world example:
https://www.gnu.org/software/make/manual/html_node/Simple-Ma...
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.
For the first concern, phony is mentioned a bit later, likely did not want to start-off with added complexity for the reader.
For the second point, but then bar.foo and baz.foo are already there and would be up to date, so what's the point in that? Most cases it's not what you want, that note is pointing-out a common gotcha.
So though precisely you are totally correct, it's not what the author was going for.
Some opinion of mine now. I do not like GNU make document linked. It goes into too much detail and then close to the end is just a short warnings about how so much of the above was GNU specific. I prefer the BSD make man page, but obviously that is not a good starting point for someone new to make. I recommend the book "Managing Projects with make" personally.
http://www.sitepoint.com/using-gnu-make-front-end-developmen...
$ echo 'int main() {}' >foo.c
$ make foo2. It regularly breaks compatibility through regressions or feature removal, thus having to pin a specific version of autotools to a project to build it.
3. It doesn't manage dependencies.
4. It's not simple.
3. It does not download the dependencies but it can verify that your system has all it needs to build the project.
I don't have much experience with make and autotools so feel free to disagree with what I said and say why.
I like the look of redo or tup.
I use tup widely across my personal projects and I must say, it has dramatically simplified my dev life.
But since Make is in use in so so many projects having good tutorials and material available is valuably to anyone who ends up needing to contribute to such an (open source) project.
CMake, for example, is less arcane, and can also generate project files for visual studio.
I'd agree that make shouldn't really be the go-to choice for brand new projects. It's limitations can encircle new projects.
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.
$ 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.