14 ms·
Makefile Tutorial
- iosono88 3y ago[dead]
- kstrauser 3y agoA bit off-topic, but I think still relevant: I've fallen in love with justfiles for all the non-build-related things I'd have used Makefiles for. Make is incredibly powerful. Sometimes that power makes the simple things a little harder to express. In those cases, Just warms my jaded heart. In short, I use make when I'm building a C project and want to model build dependencies as a DAG. I use just when I want to write a bunch of convenient entry points for a project like `just build` (e.g. calling `cargo build`), `just test` (running all the tests no matter what language I'm using), and so on.
- CableNinja 3y agoI use makefiles for my automation. I built some bootstrap functions that reach for a separate git repo (no submodules for ease of update in certain cases), and then in that repo is the real meat, built in an easily extensible way. I have generic targets like `build`, but that build call actually executes all *_build` targets. And its all auto documented help via comments and grepping. Bit over engineered but i love usin and modifying it
- tnorthcutt 3y agoDropping a link here for convenience: https://github.com/casey/just https://github.com/casey/just
- kitd 3y agoThank you. It's not a search-friendly name
- silverwind 3y agoUnfortunately, Just is a stupid task runner. It has no dependency tracking, which is the real power of Make.
- kstrauser 3y agoThat’s what makes it beautiful: it’s optimized for running tasks, with options to show all the “recipes” (with docs), accept arguments, etc.
- 9Ljdg6p8ZSzejt 3y agoLearn Makefiles with the Tastiest Examples - https://news.ycombinator.com/item?id=35936665 https://news.ycombinator.com/item?id=35936665 - May 2023 (95 comments) Makefile Tutorial by Example - https://news.ycombinator.com/item?id=9979865 https://news.ycombinator.com/item?id=9979865 - July 2015 (33 comments)
- spc476 3y agoScanning through this, it's actually a tutorial for GNU make.
- zabzonk 3y agognu make manual - https://www.gnu.org/software/make/manual/make.html https://www.gnu.org/software/make/manual/make.html one of the best pieces of technical writing i've ever read
- nerdponx 3y agoIt's pretty good, but I think it's hard to figure out which piece of information is on which page and it's insufficiently anchored/crosslinked. However the concept index is excellent and should help you find everything you need: https://www.gnu.org/software/make/manual/make.html#Concept-Index https://www.gnu.org/software/make/manual/make.html#Concept-I...
- tkiolp4 3y agoHonest question: why don’t we see a new version of Make tailored to more modern use cases, and that is available immediately/automatically in the most used Linux distributions (e.g., Ubuntu, Debian, etc.)? I’ve seen dozens of new libraries, frameworks and prog. languages appeared in the last 20 years… but no one is interested in improving Make? I’m not talking about creating an alternative (e.g., Task), I’m talking about Make 2.0 Same goes for Bash.
- UncleOxidant 3y agoIt seems like most of the effort goes into creating Make replacements (Bezel, etc). I suspect the problem could be that a Make tailored to more modern use cases may end up being incompatible with current Make - or it could be that preserving compatibility with classic Make would make using the proposed added modern features awkward.
- jjice 3y agoI think it comes down to user segmentation and legacy. There are a few tools that I feel could fit into this space but Make has serious legacy that would making moving projects, people, and build systems over a real pain. Same idea with Bash as well. Maybe we'll see it but I don't have a ton of faith.
- stabbles 3y agoGNU Make is still being developed. What features are you talking about? IMHO GNU Make is pretty complete, and it shouldn't change drastically. Also note that ninja exists as an alternative.
- tkiolp4 3y agoI see teams using Make to execute commands (e.g., transpile this, rename that, etc.), as a replacement (or enhancement) of npm (in the node world), for compiling Golang binaries, and even for running stuff in the pipeline. Make is quite versatile, indeed, but it feels like modern teams are using it in a way Make was never intended to be used. That’s the reason why alternatives to Make have appeared. My take is: wouldn’t it be possible to update Make so that it fits more modern use cases more naturally? The problems with Make alternatives is that: they are many and they don’t come preinstalled with your usual Linux distribution. Make has that special place to be a greater tool than what it is right now.
- jimbob45 3y agoWhat alternatives are there to Make? Popular C/C++ alternative build systems are SCons, CMake, Bazel, and Ninja. IMHO just bite the bullet and start with CMake. Make is such a pain to learn and is instantly useless once you realize you're going to need CMake at some point in your career anyway.
- dventimi 3y agoI've used Make routinely in my 25 year career as a backend software engineer and data scientist working mostly in Java, C#, Fortran, Python, SQL, and on the command line. So far I've never experienced the need for CMake. Perhaps I just need a few more years under my belt.
- xboxnolifes 3y agoThe comment is explicitly targeted toward those working with C or C++.
- stabbles 3y agoThe issue is that Make isn't particularly well suited to figure out properties of C / C++ compilers, or how to locate and link dependencies. That's the main reason Autotools and CMake exist.
- cozzyd 3y agoyeah, CMake helps if not everyone is running the same compiler/environment as you. If your code only ever runs with gcc on Linux though, Make works pretty well..
- dventimi 3y agoThat's fair. I see now that the parent did in fact make reference to C/C++. I was reacting to the mistaken impression that the parent was making a blanket statement that went beyond C/C++.
- deleted 3y ago[deleted]
- stabbles 3y agoThis tutorial is out of date: # Search for the "-i" flag. MAKEFLAGS is just a list of single characters, one per flag. So look for "i" in this case. ifneq (,$(findstring i, $(MAKEFLAGS))) echo "i was passed to MAKEFLAGS" endif As of GNU Make 4.4 (Oct 2022) it gives false positives; from the release notes: * WARNING: Backward-incompatibility! Previously only simple (one-letter) options were added to the MAKEFLAGS variable that was visible while parsing makefiles. Now, all options are available in MAKEFLAGS. If you want to check MAKEFLAGS for a one-letter option, expanding "$(firstword -$(MAKEFLAGS))" is a reliable way to return the set of one-letter options which can be examined via findstring, etc.
- TOGoS 3y agoBut I don't like tabs and don't understand dependencies so I'm going to invent an ad-hoc DSL full of footguns where everything's driven by magical, opaque 'plugins', call it "modern", and tell everyone to use that, instead. /s (I'm all for replacing Make with a tool that's more cross-platform, less dependent on the shell, and has nicer syntax for writing functions, etc, but somehow every 'Make replacement' that crashes through here seems to completely completely miss the point of Make, and instead just provides, at best, a badly-defined scripting language with language-specific package management. There's a reason Make keeps going.)
- getrealyall 3y agoIt's because web developers actually just want a command runner, and not a tool originally designed specifically for selectively recompiling parts of C programs. Make still works for what make is good at, and that's not simply running `npm start`.
- israrkhan 3y agomake is not very well suited for extremely large projects (Android or some other OS distribution for example). Bazel works best in such scenarios. it is not just for C++, it has support for other languages too, and in IMO it works better than other complex build systems such as Yocto for large projects. CMake is not a competitor to make, it is just a tool to generate makefiles with cross platform support. More suited for opensource C++ libraries.
- bch 3y ago<the BSDs have entered the chat>