3 ms·
Even if you’re always rebuilding everything, where makefiles win over a flat script is being able to group things, e.g. CFLAGS = -g -O2 all: foo foo: ;
by mananaysiempre 4y ago
Even if you’re always rebuilding everything, where makefiles win over a flat script is being able to group things, e.g.
CFLAGS = -g -O2
all: foo
foo: ; # how to build foo
install: install-foo
install-foo: ; # how to install foo
clean: clean-foo
clean-foo: ; # how to clean foo
all: bar
# etc.
This is somewhat similar to AWK’s “pattern-action” structure and perhaps literate programming, but otherwise I struggle to describe how it fits into the world of programming languages.
The ability to override variables from the command line is also pretty sweet: e.g. with the above you can get a non-optimized build with `make CFLAGS=-O0 clean all`. But I guess by using ${CFLAGS=...} you could get `CFLAGS=-O0 ./build.sh` to work as well.
- xdennis 4y agoPersonally I use this pattern to make subcommands: main() { if [[ $1 ]]; then cmd_"$@" return fi cmd_all "$@" } cmd_all() { cmd_something "$@" cmd_some-other-thing } cmd_something() { ... } cmd_some-other-thing() { ... } main "$@" I find it much easier to understand when you execute things in a predictable order and you can have a `set -x` to follow everything through. If it's too slow, then only the show bits should be parallelized. At work, on the other hand, every project uses something like this in the Makefile: -include $(shell 'pwd')/makefile-modules/*/*Makefile* That, and wildcard job names makes it quite difficult to follow the flow when things break.