makefile and multiple executions
I have a big project in C which is built using a make file and accepts multiple command line arguments like make DSP=1 DEBUG=1 LX=1 etc etc
To complete my experiment I need to build this program by passing different arguments. Can I create a file in whic开发者_如何转开发h I can write all these multiple execution statements?
I know there must be some way to do this but I'm new to linux so cnt make out. Executing each make individually would be too hectic.
Just write (or generate automatically) a text file with all your commands one per line. Then to run all the commands in sequence just type
bash <filename>
the normal unix way would be adding a line with #!/bin/bash
at the beginning and then doing a chmod +x
to make the file executable, but just calling bash is easier and allows using the same file also on windows (just name the file "something.bat").
Don't bother with a shell script, do it in make. This way you get the advantages of make: detection on broken compiles; parallel operation; all the stuff in one place, etc.
.PHONY: all
all:
${MAKE} bigcompile DSP=1 DEBUG=1 LX=1
${MAKE} bigcompile DSP=0 DEBUG=1 LX=1
${MAKE} bigcompile DSP=1 DEBUG=0 LX=1
${MAKE} bigcompile DSP=0 DEBUG=0 LX=1
∶
bigcompile:
∶
If you have written your makefile properly, then it should be possible to run several bigcompile
s all at the same time. In this case you need to tell make that it can run more than one bigcompile at once:
.PHONY: all
all: compile1 compile2 compile3 compile4 ; @echo $@ success
.PHONY: compile1 compile2 compile3 compile4
compile1: ; ${MAKE} bigcompile DSP=1 DEBUG=1 LX=1
compile2: ; ${MAKE} bigcompile DSP=0 DEBUG=1 LX=1
compile3: ; ${MAKE} bigcompile DSP=1 DEBUG=0 LX=1
compile4: ; ${MAKE} bigcompile DSP=0 DEBUG=0 LX=1
∶
(There is clear opportunity to shrink this boilerplate text.)
The basic answer was given by @6502.
Another trick you need to know is how to make sure that everything is rebuilt on the rerun. With GNU Make, you can use the -B
(or --always-make
) option. If you are not using GNU Make, you can run your cleanup (make clean
) to remove the built files. If you don't yet have a clean
target, you will need to add one.
精彩评论