On 07/27/2015 12:59 PM, Paul Smith wrote: > On Mon, 2015-07-27 at 12:47 -0500, Larry Evans wrote: >> How should the which command within the for loop script be >> modified to produce the same output as the which command >> before the for loop script? > > The recipe is run by the shell, not by make. Make simply expands the > make variables and functions one time before the shell is started, then > sends the results to the shell to be run, then waits for the exit code > to see if it worked. The shell, being a separate shell process, cannot > access make's database of variables. So, you cannot write a _shell_ > loop that uses _make_ computed variables. > > If you want to use make variables, you have to use a make loop via > $(foreach ...) or similar. > > compiles: > make -version > @echo "COMPILE.gcc=" $(COMPILE.gcc) > which $(COMPILE.gcc) > for HOW_CXX in $(foreach C,gcc,$(COMPILE.$C)) ; do \ > which $$HOW_CXX ; \ > done ; > Thanks Paul. It works; however, what I really want is to use the compiler to compile a source file to and object file.
When I tried to modify the Makefile as shown in 1st attachment, I get the output shown in 2nd attachment. Apparently, it's not globbing the gcc and the -c together. Instead, it's using gcc to produce the a.out file, which is not what I want and during the 2nd loop, it's trying to use -c is a shell command. How should I modify this 2nd version of the Makefile to make it compile to produce the .o and not the a.out file? BTW, I'd rather not hardcode the -c into compile command because the actual args to the compile command depend on the compiler. Also, I'd like the output object file name to be $(MAIN).gcc.o instead of just $(MAIN).o. TIA. -Larry
COMPILE.gcc=g++ -c COMPILE.clang=clang -c MAIN=test compiles: @echo "COMPILE.gcc=" $(COMPILE.gcc) for HOW_CXX in $(foreach C,gcc,$(COMPILE.$C)) ; do \ echo "HOW_CXX=" $$HOW_CXX ; \ rm -f a.out $(MAIN).o ; \ date ; \ $$HOW_CXX $(MAIN).cpp ; \ ls -l a.out $(MAIN).o ; \ done ;
Compilation started at Mon Jul 27 13:46:17 make COMPILE.gcc= g++ -c for HOW_CXX in g++ -c ; do \ echo "HOW_CXX=" $HOW_CXX ; \ rm -f a.out test.o ; \ date ; \ $HOW_CXX test.cpp ; \ ls -l a.out test.o ; \ done ; HOW_CXX= g++ Mon Jul 27 13:46:17 CDT 2015 ls: cannot access test.o: No such file or directory -rwxrwxr-x 1 evansl evansl 6654 Jul 27 13:46 a.out HOW_CXX= -c Mon Jul 27 13:46:17 CDT 2015 /bin/sh: 5: -c: not found ls: cannot access a.out: No such file or directory ls: cannot access test.o: No such file or directory make: *** [compiles] Error 2 Compilation exited abnormally with code 2 at Mon Jul 27 13:46:17
_______________________________________________ Help-make mailing list Help-make@gnu.org https://lists.gnu.org/mailman/listinfo/help-make