一个供两个编译器使用的makefile [英] One makefile for two compilers
问题描述
我有两个makefile,用于本机和交叉编译。它们之间的唯一区别是编译器名称:
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++
...
要进行本机编译,我要执行 make
进行交叉编译,我执行 make -f makefile-cc
。我想拥有一个 makefile
,应使用 make
进行本机编译,并使用进行交叉
进行交叉编译。正确的语法是什么,例如:
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++
推荐答案
您可以为特定目标分配/附加变量通过在一行上使用语法 target:assignment 来实现。下面是一个示例:
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)
通话
make native
(或仅 make
,在这里)打印
echo cc
cc
呼叫
make cross
打印
echo arm-linux-gnueabihf-g++
arm-linux-gnueabihf-g++
因此,您可以将常规编译行与$(CC)一起使用
So you can use your usual compilation line with $(CC)
这篇关于一个供两个编译器使用的makefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!