如何修改Makefile以支持交叉编译? [英] How to modify Makefile to support cross compilation?

查看:1133
本文介绍了如何修改Makefile以支持交叉编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Makefile:

I have the following Makefile:

CC=g++

top_srcdir=$(SRC_DIR)/cpp/src/

INCLUDES:= -I $(top_srcdir) -I $(top_srcdir)command_classes -I $(top_srcdir)platform -I $(top_srcdir)value_classes
LIBS:= -lopenzwave -lpthread -ludev
LDFLAGS += -L$(SRC_DIR) -Wl,-R$(SRC_DIR) '-Wl,-R$$ORIGIN'

all:    ozw

ozw: Main.cpp
    $(CC) $(INCLUDES) -c Main.cpp -o ozw-power-on-off.o
    $(CC) $(LIBS) $(LDFLAGS) ozw-power-on-off.o -o ozw-power-on-off.out

clean:
    rm -rf *.o *.out

我使用以下命令执行它:

I execute it with the following command:

  make ARCH=$TARGET_ARCH \
       CROSS_COMPILE=$TARGET_PREFIX \
       SRC_DIR=$ROOT/$PKG_BUILD

但它会忽略 ARCH CROSS_COMPILE 值。我试图用 $(MAKE)替换 $(CC)并添加-$( MAKEFLAGS),但它说'Main.cpp'不需要做任何事情。

But it ignores ARCH and CROSS_COMPILE values. I tried to replace $(CC) with $(MAKE) and added -$(MAKEFLAGS), but it was saying Nothing to be done for 'Main.cpp'.

我该如何解决它并添加交叉编译支持?

How can I fix it and add cross compilation support?

推荐答案

以下是我可能尝试的一种示例:在这个简单的示例中,$ ARCH get映射到 arm。我还没有测试过,但是以前做过类似的事情。

A possible example of something I would try is below assuming $ARCH get's mapped to "arm" in this trivial example. I haven't tested it, but have done something similar before.

CC=g++
CC-arm=arm-g++

ozw: Main.cpp
    $(CC-$(ARCH)) $(INCLUDES) -c Main.cpp -o ozw-power-on-off.o
    $(CC-$(ARCH)) $(LIBS) $(LDFLAGS) ozw-power-on-off.o -o ozw-power-on-off.out

编辑:这假定您的路径中存在工具链。
编辑:可能还会对其进行修改,以使CC = $(PREFIX)-g ++完全取决于您传递给它的内容与工具链命名约定的映射。

edit: This assumes that the tool chain exists in your path. edit: Might also modify it such that CC=$(PREFIX)-g++ it all depends on what you how what you pass into it maps against your tool chains naming convention.

这篇关于如何修改Makefile以支持交叉编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆