我正在工作中尝试更新的构建系统; 目前,我正在尝试找到一种设置编译器和编译器的好方法。 标志取决于目标平台。
我想做的是
switch $(PLATFORM)_$(BUILD_TYPE)
case "Linux_x86_release"
CFLAGS = -O3
case "Linux_x86_debug"
CFLAGS = -O0 -g
case "ARM_release"
CC = armcc
AR = armlink
CFLAGS = -O2 -fx
...
GNU Make 不支持的事情。 现在,我的第一个想法是这样做
-include $(PLATFORM)_$(BUILD_TYPE)
,这是一个相当不错的解决方案,但是,它使得很难了解文件之间的差异,更不用说我期待着编写和编写文件。 维护好 60-80 个文件,每个文件包含一组变量定义。
有谁知道更好的方法来实现这一目标吗? 即根据另一个变量设置一组标志和其他选项?
I'm experimenting with an updated build system at work; currently, I'm trying to find a good way to set compiler & flags depending on the target platform.
What I would like to do is something like
switch $(PLATFORM)_$(BUILD_TYPE)
case "Linux_x86_release"
CFLAGS = -O3
case "Linux_x86_debug"
CFLAGS = -O0 -g
case "ARM_release"
CC = armcc
AR = armlink
CFLAGS = -O2 -fx
...
which is not supported by GNU Make. Now, my first thought was to just do
-include $(PLATFORM)_$(BUILD_TYPE)
which is a pretty decent solution, however, it makes it hard to get an overview of what differs between files, not to mention that I'm looking forward to writing & maintaining a good 60-80 files, each containing a set of variable definitions.
Does anyone happen to know a better way to accomplish this? I.e. setting a set of flags and other options based on another variable?
发布评论
评论(4)
怎么样:
How about:
配置此类参数将是配置脚本的任务。
话虽这么说,您可以查看 条件 的语法和条件函数。 例如,您可以尝试以下操作:
Configuring such parameters would be the task of a
configure
script.That being said, you can look into the syntax for conditionals and conditional functions. For example, you could try the following:
Makefile .com" rel="nofollow noreferrer">git 是 Makefile 的一个很好的示例,它在 Makefile 本身中执行重要的配置任务(例如切换主机类型)。 它实际上非常可读并且使用起来相当简单。
The Makefile used by git is a good example of a Makefile which does non-trivial configuration tasks in the Makefile itself (such as switching on the host type). It's actually quite readable and reasonably simple to use.
切换到为您执行此操作的系统(automake/autoconf)可能会更简单......
Switching to a system which does it for you (automake/autoconf) may be simpler...