Makefile支持多种体系结构/配置

时间:2011-06-07 18:24:06

标签: makefile build-automation

为多种体系结构和配置提供makefile支持的最简单方法是什么?例如,发布配置可能使用比调试配置更多的优化。是否应将更改选项定义为makefile中的变量,并依赖用户根据需要更新它们?

# Change to -O2 for release.
COMPILER_OPTIONS := -arch x86_64 -O0

或者应该在规则中处理这类事情吗?

*_Release.a:
    # Recipe for building a release library, i.e., with optimization.
    # Unsure how to integrate this with different architectures.

或者两者的组合?

2 个答案:

答案 0 :(得分:5)

架构和配置是一种正交;他们呼吁采用不同的方法。用户应该能够在构建时选择配置,最简洁的方法是使用不同的目标。但是我认为尝试在另一个架构上构建一个架构没有任何意义,因此应该自动处理架构的选择。细节会根据您的需要而有所不同,但您的makefile最终可能会看起来像这样:

# Determine whatever we need to know about architecture with "uname" or its
# equivalent (I think it's "ver" on Windows).

MACHINE = $(shell "uname -m") 

ifeq ($(MACHINE), i386)
SOME_VAR = 386
foo:
    make a foo the i386 way  
else
SOME_VAR = something else
foo:
    make a foo some other way
endif


# Choice of configuration is up to the user

release: COMPILER_OPTIONS += -O0
debug: CCFLAGS += -g -Wall

debug release:
    whatever...

答案 1 :(得分:0)

最简单的方法是不同的目标。概括地说:

RELFLAGS := -O2 
DBGFLAGS := -g

release: 
    $(COMMAND) $(RELFLAGS) $(FILES)

debug:
    $(COMMAND) $(DBGFLAGS) $(FILES)

与不同的架构相同,虽然我自己不做任何交叉编译。

相关问题