I have two makefiles, for native and cross compilation. The only difference between them is compiler name:
# makefile CC = g++ ...
# makefile-cc CC = arm-linux-gnueabihf-g++ ...
To make native compilation, I execute make, to make cross-compilation, I execute make -f makefile-cc. I want to have one makefile, which should be executed using make for native compilation, and make cross for cross-compilation. What is correct syntax to do this, something like:
# makefile (C-like pseudo-code)
if cross
CC = arm-linux-gnueabihf-g++
else
CC = g++
You can assign/append variables for specific targets by using the syntax target:assignment on a line. Here is an example:
native: CC=cc
native:
echo $(CC)
cross: CC=arm-linux-gnueabihf-g++
cross:
echo $(CC)
calling
make native
(or just make, here) prints
echo cc
cc
and calling
make cross
prints
echo arm-linux-gnueabihf-g++
arm-linux-gnueabihf-g++
So you can use your usual compilation line with $(CC)
You can pass parameters to make.
e.g. make TARGET=native and make TARGET=cross then use this
ifeq ($(TARGET),cross)
CC = arm-linux-gnueabihf-g++
else
CC = g++
endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With