Live data from Hacker News

One line you should add to every makefile

blog.jgc.org

91–99 of 99 posts

Re: One line you should add to every makefile

#91
post #3

I firmly believe that there is only one production-quality makefile that has ever been written from scratch. Every other makefile has been copied from an earlier makefile, dating back to the one Ur-makefile, and modified to suit the author's purpose.

The simplest Makefile is ... no Makefile at all!

e.g. if you create C program your-program.c with a main(), all you have to do is invoke

    make your-program
and it is done.

Not exactly production quality (no clean target) but can't beat it for simplicity :-)

Re: One line you should add to every makefile

#93
post #50

Earlier quoted context omitted.

I wrote a god-awful Perl script to gen (and update) Makefiles for me: https://github.com/wspeirs/makemake

It seems every competent programmer makes that mistake at least once in their carreer :)

Hey, I wrote my own build system, and then used it to build a 300kloc compiler. (It's at http://primemover.sourceforge.net/ should anyone care.) It was an astonishingly good learning experience and I'm never doing it again because it sucked.

The main thing I learn was that build systems are really, really hard. Simply coming up with an intuitive way of letting the user write down what problem they're trying to solve is painfully hard, let alone actually solving the problem. I have yet to see a build system that wasn't horrible.

GNU make is a hideous pile of recursive terribleness, but it is at least a ubiquitous hideous pile of recursive terribleness. That doesn't make it any less pleasant to use but it does at least make it more likely that people will be able to use the result. But for any non-trivial project make requires you to implement a build system in make, and as there are no debugging tools and the language is cryptic and inconsistent beyond words, the results are always buggy and hard to understand.

I dunno. I think what I'd really like is a reinvented GNU make that doesn't have all the many, many bad design decisions from the past in it. ninja, maybe? I've yet to actually try to use that...

Re: One line you should add to every makefile

#94
post #28

You can avoid editing the Makefile to add the rule with GNU make 3.81 or older, which does not support --eval. Create a new file in your home named ~/Makefile.debug with the contents: print-%: ; @echo $*=$($*) include Makefile Now you can use it the following way from any source directory: $ make -f ~/Makefile.debug print-SOURCE_FILES

You're missing the final tail call which includes Makefile.debug again. With this, we can make a REPL: $ cat Makefile FOO := bar target: Next: $ cat Makefile.debug ifeq ($(MAKEFILE_INCLUDED),) -include Makefile MAKEFILE_INCLUDED := y endif REPL_COMMAND := $(shell read line; printf "%s\n" $$line) $(eval $(REPL_COMMAND)) -include Makefile.debug Now, here we go: $ make -f Makefile.debug $(warning $(FOO)) :)

This is the kind of idea for which the phrase 'genius crazy' was invented.

I might actually use this some time, god help me. I won't thank you, but I will remember you and curse a little every time I do.

Re: One line you should add to every makefile

#96
post #36
post #14

Earlier quoted context omitted.

That misses the point; you can already echo a variable wherever you want in a makefile similarly. This gives you a way to do it without editing the makefile, without knowing before hand you want to see that variable.

Echo and p aren't exactly the same, there's a difference during debugging between: 1 2 3 4 (echo) and ["1", "2 3", "4"] (p)

that's a strawman though. what about

  printf ' "%s"' $(numbers)
to output

  "1" "2 3" "4"

Re: One line you should add to every makefile

#97
post #3

I firmly believe that there is only one production-quality makefile that has ever been written from scratch. Every other makefile has been copied from an earlier makefile, dating back to the one Ur-makefile, and modified to suit the author's purpose.

No, make files are quite often written from scratch.

But the linker script for ARM Cortex and the GNU linker is usually copied verbatim. You can find it everywhere. Open source projects, commercial development. Everywhere. Because STM ships it with their standard peripheral library.

Nobody cares that this linker script is (c) Atollic and only licensed for use with their IDE:

http://hackaday.com/2012/06/19/stm32-demo-code-carries-extra...

Re: One line you should add to every makefile

#99
post #87
post #81

never use makefiles. its not 1975 and we have learned a lot since then

examples?

(not to mention the shameful use of timestamps to detect modifcation in make - leading to years and years of wasted time as people get confused by it when working with others)
Post reply on HN