tags:

views:

44

answers:

1

I'm trying to compile an open source project on windows under mingw/msys.

The makefile contains (among others) this line

@${MAKE} --no-print-directory -C . -f physfs.make

physfs.make contains (among others) these lines:

ifndef CC
  CC = gcc
endif

when I ran make I get the following error:

Creating obj/Debug/physfs
physfs.c
make[1]: cc: Command not found
make[1]: *** [obj/Debug/physfs/physfs.o] Error 127
make: *** [physfs] Error 2

If I comment the ifndef / endif pair leaving CC = gcc intact, the build works. If instead of make I issue this command:

make -e CC=gcc

the build works as well. But when I run the following command in msys:

echo $CC

nothing is displayed.

I think there is something basic about how environment variables work in MSYS and make that I don't understand.

Could please some help me troubleshoot this issue, so I can understand why simple 'make' command complains and why the ifndef block doesn't function as I expect it to function.

+1  A: 

CC is one of several implicit variables automatically defined in a make session, so the line ifndef CC should never evaluate to true.

This explains why you see nothing on the command line for echo $CC. The MSYS environment has no concept of CC.

If you want to see the value of variables from within a make session, you can always use the info function:

$(info $(CC))

This will echo the value of the CC variable to the console at the point when that line in the makefile is evaluated.

e.James
Remark: the correct way to test if `$(CC)` has the default value would be `ifeq (default,$(origin CC))`.
Jack Kelly
@Jack Kelly: The make file is generated by premake utility http://industriousone.com/premake so I can't change what is being generated. On the premake website someone maintained that it's a bug in mingw-make, that CC by default equals to cc. The gnu man that e.James linked seems to suggest otherwise.
zespri
@zespri: The link that I posted agrees: CC is set to cc by default.
e.James
@e.James If I understood your last comment correctly, then this is what I meant too. Someone said (http://industriousone.com/post/how-do-i-echo-full-compile-command-modify-linkcmdcc-various) that mingw-make sets CC to a wrong value, and the link you gave suggests that setting CC to cc by default is how it was intended.
zespri
@zespri: Yes, we are saying the same thing. I had misunderstood your previous comment; I thought you meant that my link stated that the CC variable was *not* supposed to equal cc by default. I realize now that you meant the opposite `:)`
e.James