←back to thread

Be Aware of the Makefile Effect

(blog.yossarian.net)
431 points thunderbong | 1 comments | | HN request time: 0.619s | source
Show context
shusaku ◴[] No.42664796[source]
I always write my makefiles from scratch. At some point in the process, I will google “make automatic variables”, because they’re a pain to memorize.
replies(2): >>42664907 #>>42664917 #
kragen ◴[] No.42664907[source]
Yeah, I've always been mystified by the idea that writing a new Makefile is some kind of wizardly mystery. Make has its design flaws, for sure, but how hard is it really to write this?

    CFLAGS = -std=gnu99 -Wall

    all: foo
    clean:
        $(RM) foo *.o

    foo: foo_main.o foolib.o
        $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
(Except with tabs, which HN doesn't allow.)

I haven't tested what I just typed above, but I'm reasonably sure that if I biffed it in a way that makes it nonfunctional, it will be obvious how to correct the problem.

I mean, not that you can't do better than that (I'm pretty sure anyone experienced can see some problems!), or that there aren't tricky and annoying tradeoffs, but it just doesn't seem like a big activation barrier the way people sometimes make it out to be?

Maybe those people just need to spend an afternoon once in their life working through a basic make tutorial? Maybe not the first time they work on a project using make, but, maybe, after the fifth or sixth project when they realize that this somewhat primitive inference engine is going to be something they interact with daily for years? At some point you're getting into "lead a horse to water" or "teach a man to fish" territory. There's a limit to how much you can empower someone who's sabotaging themself.

There's a slightly less minimal example in https://www.gnu.org/software/make/manual/html_node/Simple-Ma... with a full explanation. You can read it in a few minutes, but of course you have to experiment to actually learn it. The whole GNU Make 4.4.1 manual in PDF form is only 229 pages, so you can read it after dinner one night, or on your commute on the train over the course of a few days. And then you'll know the complete rules of the game.

replies(2): >>42664925 #>>42669115 #
pantalaimon ◴[] No.42664925[source]
Auto-generated Makefiles that CMake and Autotools produce really leave a bad impression on how complex Makefiles need to be.
replies(3): >>42665093 #>>42667052 #>>42667753 #
1. kragen ◴[] No.42665093[source]
Yeah, I guess trying to read the output of gcc -O -S would make assembly language seem pretty overwhelming, too.