7 ms·
Makefile Tutorial by Example
- emsy 11y agoThe 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)
- emmelaich 11y agoHave a look at the discussion at https://news.ycombinator.com/item?id=9945438 https://news.ycombinator.com/item?id=9945438 I like the look of redo or tup.
- halosghost 11y agoI was one of the folks that mentioned tup in that link. Allow me to take a moment and mention my support for it again. It is an incredibly simple build-system with a ton of advantages over make et al. I use tup widely across my personal projects and I must say, it has dramatically simplified my dev life.
- mzs 11y agoOh man I wish I could love tup. That syntax is great, it cleans all by itself, and figures-out dependencies all by it self - even the source file often! But it was a total no-go when I tried on FreeBSD. Basically it does those awesome things by leveraging FUSE and makes all sorts of assumptions about how FUSE operates which are not true on FreeBSD. More over those assumptions would need to change as some of them are bugs and others are honest to goodness differences for good reason. So it boils down to, tup is just too clever sadly.
- halosghost 11y agoThat's such a bummer! I'm sorry to hear that it doesn't work for FreeBSD! You should consider opening a bug about it; the devs seem pretty open and responsive. Maybe they'll get it fixed for you!
- daenney 11y agoBetter is very much in the eye of the beholder. I dislike most build tools, SCons included. I've found them all to be of varying degrees of meh to terrible. 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.
- emsy 11y agoI understand that people need resources to understand the Makefiles of existing projects, but I fear that tutorials might encourage people to use Make in new projects. Yes, I really want to extinguish Make. Other build tools are also "bad" but Make deserves a special place in hell.
- fit2rule 11y agoBeen using Make for decades, I don't see the problem. It works sufficiently well to be in use in a lot of my projects as a comfortable and productive environment. As with all 'tool X must die' conversations, one must always end with the only relevant conclusion that should be made: ymmv.
- Sir_Substance 11y agoIn this case, there are genuinly better options. 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.
- TorKlingberg 11y agoCMake generates makefiles, at least as I have used it, so you need to understand makefiles to debug any build problems.
- Sir_Substance 11y ago
- pubby 11y agoWhat are your specific complaints about make, and how does SCons fix them?
- amelius 11y agoIt is still better to have one kind-of-bad build tool, than hundreds of build tools that are slightly better. Every time you have to install new software and something goes wrong, you'd have to learn a new build tool!
- jschwartzi 11y agoPeople 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 11y agoIn 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.
- digital-rubber 11y agoThat's a nice clean overview, but you don't think nowadays cmake is a more convenient way?
- jgrahamc 11y agoA 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 11y agoYeah, RTFM! :)
- vog 11y agoNot 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-Introduction.html 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-Makefile.html 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.
- agumonkey 11y agoAnother case of "there's so much more than it appear". People should really RThisFM.
- mweibel 11y agoI usually use this tutorial as a help if I write Makefiles: http://www.ploxiln.net/make.html http://www.ploxiln.net/make.html
- DarkTree 11y agoAs an alternative to Grunt and Gulp for Frontend Developers: http://www.sitepoint.com/using-gnu-make-front-end-development-build-tool/ http://www.sitepoint.com/using-gnu-make-front-end-developmen...
- steaminghacker 11y agoThis 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.
- sidarape 11y agoWhat I'm really looking for is a tutorial about autoconf, automake, and friends.
- thameera 11y agoI've found this thoughtbot article very helpful to grasp autotools: https://robots.thoughtbot.com/the-magic-behind-configure-make-make-install https://robots.thoughtbot.com/the-magic-behind-configure-mak...
- sidarape 11y agoThis seems nice, thank you. I'll read it later.
- nwmcsween 11y agoDon't, it's not needed, just use shell scripts.
- sidarape 11y agoWhy? It's standardized the project (thus facilitate use by others), manage dependencies, and provide a simple way to manage a project. Also, many other languages have already something that does that (gem, python package, jar) and not C.
- nwmcsween 11y ago1. It's not standardized in any way. 2. 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.
- sidarape 11y ago1. For someone that installed Linux From Scratch, I can say that it's really nice that most of softwares use that. It's maybe not standardized like POSIX or other systems, but it's some kind of standardized by default. 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.
- GFK_of_xmaspast 11y agoThis is 2015, there's no reason to manually write a makefile like an animal.
- oso2k 11y agoThings 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
- ibiza 11y agoMissed 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