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++
not exactly what you wanted but you can read
CC
as an environment variable. consider the followingMakefile
:and you can call it with
CC=g++ make
which gives you:or call it with
CC=arm-linux-gnueabihf-g++ make
which gives you:and the best part is you can put these in your
~/.bashrc
asexport CC=g++
andexport CC=arm-linux-gnueabihf-g++
respectively and do the calling with onlymake
.Another way to do it which is more portable than the gnu make
ifeq
way is this one:CROSS
contains eitherarm-linux-gnueabihf-
or is empty.CC will contain the expansion result.
You can assign/append variables for specific targets by using the syntax target:assignment on a line. Here is an example:
calling
(or just
make
, here) printsand calling
prints
So you can use your usual compilation line with $(CC)
You can pass parameters to make.
e.g.
make TARGET=native
andmake TARGET=cross
then use this