3 ms·
Using a plethora of disconnected, non-build targets in a Makefile to provide a "make <command>" language sometimes seems like such an anti-pattern. Those comman
by kazinator 7y ago
Using a plethora of disconnected, non-build targets in a Makefile to provide a "make <command>" language sometimes seems like such an anti-pattern. Those commands just want to be simple scripts, right?
Why does that pattern persist? I believe it is for these psycho-technical reasons.
1. The current directory "." is usually not in PATH for security reasons. But make ignores that; it reads a Makefile from the current directory.
The psychological hypothesis here is that people somehow like typing
make bundle
make yarn
make db-reset
compared to the no-Makefile alternative scripts:
./bundle
./yarn
./db-reset
Something always feels off about running a program as ./name.
2. If there are any shared make variables between the non-build utility steps like "make bundle" and actual build steps, then it's easier for those utility steps to be in the Makefile so they can interpolate the make variables. The scripted alternative would be to have shell variables in some "vars.sh" file that is sourced by all the commands. But then somehow the Makefile would have to pick those up also in some clean way, probably requiring a ./make wrapper:
#!/bin/sh
. ./vars.sh
# propagated needed subset of vars to make
make FOO="$FOO" BAR="$BAR" "$@"
So I think these are some of the main sources of the "pressure" for various project-related automated tasks to go into the Makefile.
Another source of the pressure is that the "<command> <subcommand>" pattern is present elsewhere, like in version control tools "quilt push", "git blame", ...
It has the technical advantage of namespacing. If you have a make target called "ls", then "make ls" doesn't clash in any way with /bin/ls.