open-power / hostboot

System initialization firmware for Power systems
Apache License 2.0
75 stars 97 forks source link

make infrastructure can't handle custom CFLAGS #7

Open jk-ozlabs opened 9 years ago

jk-ozlabs commented 9 years ago

I'm trying to compile hostboot with -mbig-endian, by providing a custom CFLAGS:

CROSS_PREFIX=/home/jk/IBM/openpower/op-build/output.tmp/host/usr/bin/powerpc64-buildroot-linux-gnu- CONFIG_FILE=/home/jk/IBM/openpower/op-build/openpower/configs/hostboot/palmetto.config HOST_BINUTILS_DIR=/home/jk/IBM/openpower/op-build/output/build/host-binutils-2.24/ HOST_PREFIX="" OPENPOWER_BUILD=1 BUILD_VERBOSE=1 CFLAGS=-mbig-endian make

but it looks like specifying CFLAGS= in the environment causes the make infrastructure to construct an invalid compiler command:

/home/jk/IBM/openpower/op-build/output.tmp/host/usr/bin/powerpc64-buildroot-linux-gnu-g++ -c  -mbig-endian -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -D__HOSTBOOT_MODULE=trace -fPIC -Bsymbolic -Bsymbolic-functions -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -D__HOSTBOOT_MODULE=trace -fPIC -Bsymbolic -Bsymbolic-functions -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -D__HOSTBOOT_MODULE=tracedaemon -fPIC -Bsymbolic -Bsymbolic-functions -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -D__HOSTBOOT_MODULE=tracedaemon -fPIC -Bsymbolic -Bsymbolic-functions -O3 -nostdlib -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec -Wall -Werror -mtraceback=no -pipe -ffunction-sections -fdata-sections -ffreestanding -nostdinc++ -fno-rtti -fno-exceptions -Wall -fuse-cxa-atexit daemon.C \
                -o ../../../../obj/modules/tracedaemon/daemon.o.trace -I../../../../src/include/usr -I../../../../src/include/ -I../../../../obj/genfiles -iquote .
<command-line>:0:0: error: "__HOSTBOOT_MODULE" redefined [-Werror]
<command-line>:0:0: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
scprek commented 9 years ago

Hi,

Finally got around to focusing on this again, was on the back burner for a while. Here are my findings:

GNU standards

Sourced: https://www.gnu.org/prep/standards/html_node/Command-Variables.html "If there are C compiler options that must be used for proper compilation of certain files, do not include them in CFLAGS. Users expect to be able to specify CFLAGS freely themselves. Instead, arrange to pass the necessary options to the C compiler independently of CFLAGS, by writing them explicitly in the compilation commands or by defining an implicit rule, like this:"

CFLAGS = -g
ALL_CFLAGS = -I. $(CFLAGS)
.c.o:
        $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<

My initial approach

I switched all 'CFLAGS' variables to 'LOCAL_CFLAGS' and the following compiles

CFLAGS=-mbig-endian make -j8

Sourced: http://stackoverflow.com/questions/9052792/how-to-pass-macro-definition-from-make-command-line-arguments-d-to-c-source

"You cannot use "CFLAGS = $(CFLAGS) -Wall"; this would be a recursive definition and make does not allow this. You could use "CFLAGS := $(CFLAGS) -Wall", or "CFLAGS += -Wall", but those won't work either because an assignment on the command line has a higher precedence. You could use "override CFLAGS += -Wall", but generally we recommend you just choose different variables internally. The GNU Coding Standards require CFLAGS etc. be left for the user, and makefiles choose another variable, like "local_CFLAGS = $(CFLAGS) -Wall"."