Makefile Tutorial
makefiletutorial.com
makefiletutorial.com
Makefile Tutorial by Example - https://news.ycombinator.com/item?id=9979865 - July 2015 (33 comments)
# 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.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.
Also note that ninja exists as an alternative.
Idk about you but every shell syntax on a unix-like OS is wonky to me
Unix’s philosophy that everything is a file, and everything is stream of bytes is Good™. Dumb pipes and smart ends are future proof. The smarter the pipe, the more likely you’re going to run into things just not being possible.
Shell scripts should not live long enough to require being future proof. If you need to rely long term on some code, write it in an actual programming language
I don’t think you understand what I’m talking about. Powershell isn’t just a shell with some rudimentary flow control, like every Unix shell since thr 1960s. Powershell can hook together apps with a rich IPC objects, not just the old stream of bytes that kicked off this thread. In fact, I specifically mentioned its rich IPC as its nifty feature, and a feature that I did not understand how it worked, especially since it works in a backwards compatible fashion. THAT’S the thing that moves it beyond a stream of random bytes, to something with semantics. Maybe you didn’t know that, but it does. In fact, when it came out that was its marquee feature. That’s why I’m talking about IPC, and and the fucking programs. No one give a shit about a janky ass .sh file. It’s the thing that go in it. If the programs being connected together don’t understand the rich IPC channel, you’re stuck in the 1960s, like every other shell and scripting language, and so Powershell’s benefits are nonexistent.
This thread went from interesting to absolutely infuriating because you keep smuggly chiming in about things you apparently don’t understand.
This statement:
> The PROGRAMS. Who wants to rewrite everything because you can no longer pipe or redirect?
Is almost unintelligible, aside from the fact that I guess it qualifies as a nearly-correct statement in English
A world where every program talks via the same IPC is utopia. Claiming that pwsh benefits are nonexistent because of that, is absurd.
Besides, there are ways to mitigate this problem. As an example, many tools now accept and return json output, which means they can be easily hooked to pwsh via ConvertTo/From-Json without any parsing whatsoever.
There is no such a thing as serious programming vs baby shell programming. There are just tools, that are means to an end, simple as that. If the tool sufficiently and efficiently does the job, there is no need to replace it with an 'actual' programming language.
Csh and Tcsh might be improvements, but I don't know how to use them and none of my coworkers do either.
Powershell is an option at my particular company, but it has a handful of other problems (some of which are gradually being fixed in newer versions) and it's not "portable" to other organizations.
And I personally use Zsh, which I think is an improvement over Bash, but again, none of my coworkers know how to use it, even though it's the default of everyone's Mac.
People have similar complaints about SQL. It's kind of bad, but nothing has replaced it because it's just too hard to accumulate the critical mass of adoption for any one replacement.
Make is great. Even has a debugger: https://remake.readthedocs.io/en/latest/debugger.html
mk is generally available in modern systems' package repositories through plan9port¹ or 9base².
0. https://9p.io/sys/doc/mk.html
Looks like a version of make optimized for running commands instead of builds.
Lacking a good way to do this was the #1 reason I moved off of Make:
make test-foo TESTOPTS='-a -b -c'
Yuck.My team now just adds a "run" script to all of our projects and it works well enough, no extra dependencies and no fussing around with the unfamiliarity of Make macros. Simple example of how this looks:
#!/usr/bin/env bash
set -eu
venv=.venv
test-coverage() {
"${venv}"/bin/pytest --cov=src
}
coverage-report() {
"${venv}"/bin/coverage combine || true
"${venv}"/bin/coverage report
}
_run() {
source "${venv}"/bin/activate
"$@"
}
_run "$@"/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.)
one of the best pieces of technical writing i've ever read
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.
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.
If your code only ever runs with gcc on Linux though, Make works pretty well..
I’ve written a small Makefile to learn the basic and backgrounds. Make itself is fine. But the next higher level would have been Autotools. Which is an intimidating and weird set of tools. Most new stuff written in C/C++ use now Meson and it feels sane.
Make is simple and good-enough for most cases. I use this: https://github.com/dkogan/mrbuild
But it's not special and there are lots like it. And they are all infinitely better than cmake
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.