You can use a shell script that takes some cues by how its called and invokes make
after setting CFLAGS
appropriately for the occasional one-off build.
Lets say you have /usr/bin/compile
, which is a shell script that looks at $0
to see what name actually invoked it. You then make symbolic links to it named pedantic
, fullwarn
, etc.
In the shell script itself, something like:
OLDCFLAGS=$CFLAGS
WHATAMI=$(basename $0)
case "$WHATAMI" in
pedantic)
export CFLAGS="-Wall -pedantic -ansi"
make $@
exit $?
;;
c99)
export CFLAGS="-std=c99 ... ... ..."
....
Then, to compile foo.c with the extra naggy flags:
pedantic foo
This is handy, as I said for one-off builds, e.g trying to compile code that someone posted in a question, or working out how to use a new library, etc.
For anything else, just use a makefile, as others have said.