The make process behaves differently (and produces warnings) when CFLAGS are set via the environment versus the command line. e.g.:
$ make NO_PARALLEL_MAKE=1 CFLAGS=-Dfred
make[1]: Entering directory `/home/kelso/wc/builds/OpenBLAS/0.2.17-0/OpenBLAS-0.2.17/interface'
gcc -Dfred -O2 -DMAX_STACK_ALLOC=2048 -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DASMNAME=saxpy -DASMFNAME=saxpy_ -DNAME=saxpy_ -DCNAME=saxpy -DCHAR_NAME=\"saxpy_\" -DCHAR_CNAME=\"saxpy\" -DNO_AFFINITY -I.. -I. -UDOUBLE -UCOMPLEX -c axpy.c -o saxpy.o
gcc -Dfred -O2 -DMAX_STACK_ALLOC=2048 -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DASMNAME=sswap -DASMFNAME=sswap_ -DNAME=sswap_ -DCNAME=sswap -DCHAR_NAME=\"sswap_\" -DCHAR_CNAME=\"sswap\" -DNO_AFFINITY -I.. -I. -UDOUBLE -UCOMPLEX -c swap.c -o sswap.o
gcc -Dfred -O2 -DMAX_STACK_ALLOC=2048 -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DASMNAME=scopy -DASMFNAME=scopy_ -DNAME=scopy_ -DCNAME=scopy -DCHAR_NAME=\"scopy_\" -DCHAR_CNAME=\"scopy\" -DNO_AFFINITY -I.. -I. -UDOUBLE -UCOMPLEX -c copy.c -o scopy.o
^Cmake[1]: *** Deleting file `scopy.o'
make[1]: *** [scopy.o] Interrupt
make: *** [libs] Interrupt
$ make NO_PARALLEL_MAKE=1 CFLAGS=-Dfred clean >/dev/null 2>&1
$ CFLAGS=-Dfred make NO_PARALLEL_MAKE=1
make[1]: Entering directory `/home/kelso/wc/builds/OpenBLAS/0.2.17-0/OpenBLAS-0.2.17/interface'
gcc -Dfred -O2 -DMAX_STACK_ALLOC=2048 -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DASMNAME= -DASMFNAME=_ -DNAME=_ -DCNAME= -DCHAR_NAME=\"_\" -DCHAR_CNAME=\"\" -DNO_AFFINITY -I. -O2 -DMAX_STACK_ALLOC=2048 -Wall -m64 -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DASMNAME=saxpy -DASMFNAME=saxpy_ -DNAME=saxpy_ -DCNAME=saxpy -DCHAR_NAME=\"saxpy_\" -DCHAR_CNAME=\"saxpy\" -DNO_AFFINITY -I.. -I. -UDOUBLE -UCOMPLEX -c axpy.c -o saxpy.o
<command-line>: warning: "ASMNAME" redefined
<command-line>: warning: this is the location of the previous definition
<command-line>: warning: "ASMFNAME" redefined
<command-line>: warning: this is the location of the previous definition
<command-line>: warning: "NAME" redefined
<command-line>: warning: this is the location of the previous definition
<command-line>: warning: "CNAME" redefined
<command-line>: warning: this is the location of the previous definition
<command-line>: warning: "CHAR_NAME" redefined
<command-line>: warning: this is the location of the previous definition
<command-line>: warning: "CHAR_CNAME" redefined
<command-line>: warning: this is the location of the previous definition
gcc -Dfred -O2 ... next file
< extra output deleted>
When running with an environment CFLAGS being used, it sets ASMNAME, ASMFNAME, NAME,CNAME, CHAR_NAME and DCHAR_CNAME to empty strings and then sets them afterwards to the correct values, causing the gcc redefinition warning.
Using gcc 4.4.7 and make 3.81. Also tested and fails with gcc 5.3.0 and make 4.1
Running Linux 2.6.32-504.12.2.el6.x86_64
CFLAGS is made from couple of options in Makefile.rules
And then again for each kernel -DDOUBLE etc are added.
Also it would be just polite to run 'make clean' after interrupted build.
At first glance this looks like a duplicate of #472 (which appears to have been closed without resolution,
probably because the warnings are harmless and rewriting the Makefile hierarchy would be of dubious value). At least the ASMNAME et al. are set by appending to CCOMMON_OPT in Makefile.system, which appears to be traversed twice, with FU etc blank on the first iteration.
I wonder if it would help to move the "INCLUDED=1" guard from the top of Makefile.system to its end
and make the CCOMMON_OPT addition of ASMNAME and other defines in line 908 depend on INCLUDED being set to 1 already (which should then happen only when (re-)invoked through one of the subproject Makefiles). Unfortunately I cannot test this immediately (and the question remains whether it would be worth it just to remove the nuisance warning)
I did as you suggested moved the INCLUDED definition to the end and bracketed the COMMON_OPT definition with 'ifdef INCLUDED' and the warnings no longer appear.
Thanks for the suggestion
Thanks for testing my idea. Unfortunately this appears to remove not only the warning, but actually the declarations of ASMNAME etc. as well, so does not qualify as a solution.
(What does seem to happen though is that this CCOMMON_OPT addition only happens once, but it must be the "override CFLAGS +=..." in line 996 that somehow gets executed twice when CFLAGS were passed via the environment. Making this depend on INCLUDED only breaks things however. Time to find a makefile debugger to understand code flow. Sorry for stealing your time.)
Some limited progress: at the time the empty ASMNAME (...) declarations are output, the active Makefile target ($@) is a subtarget like "libs" rather than a file like saxpy.o (hence "$(*F)", the file component of the target path, is empty). Unfortunately using these "automatic variables" in a conditional does not work. What does appear to work is defining an auxiliary variable "DOIT=1"
before the "include Makefile.system" line in the subordinate Makefiles in interfaces,driver/level2, driver/level3, driver/others, lapack and kernel and testing for that rather than for INCLUDED in Makefile.system. Not sure yet if there is a more elegant solution than changing these six in addition to Makefile.system just to remove a warning.
As a workaround for the time being I have changed my script which calls the make to the following:
CF="${CFLAGS}"
unset CFLAGS
make CFLAGS="${CF}"
Using this, the multiple definition errors do not occur. It's not ideal, but it does get me working without having to 'grep -v' for the rededifinitions.
Your workaround works for me, @skelso068. Though I completely agree with you that this is not ideal.
Most helpful comment
As a workaround for the time being I have changed my script which calls the make to the following:
Using this, the multiple definition errors do not occur. It's not ideal, but it does get me working without having to 'grep -v' for the rededifinitions.