进行“切换”的好方法 在 Makefile 中

发布于 2024-07-08 07:38:53 字数 560 浏览 6 评论 0 原文

我正在工作中尝试更新的构建系统; 目前,我正在尝试找到一种设置编译器和编译器的好方法。 标志取决于目标平台。

我想做的是

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

咋地 2024-07-15 07:38:54

怎么样:

CFLAGS_Linux_x86_release        = -O3
CFLAGS_Linux_x86_debug          = -O0 -g


CFLAGS  = ${CFLAGS_${PLATFORM}_${BUILD}}

How about:

CFLAGS_Linux_x86_release        = -O3
CFLAGS_Linux_x86_debug          = -O0 -g


CFLAGS  = ${CFLAGS_${PLATFORM}_${BUILD}}
花伊自在美 2024-07-15 07:38:54

配置此类参数将是配置脚本的任务。

话虽这么说,您可以查看 条件 的语法和条件函数。 例如,您可以尝试以下操作:

ifeq ($(PLATFORM)_$(BUILD_TYPE),Linux_x86_release)
    CFLAGS = -O3
endif
ifeq ($(PLATFORM)_$(BUILD_TYPE),Linux_x86_debug)
    CFLAGS = -O0 -g
endif

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:

ifeq ($(PLATFORM)_$(BUILD_TYPE),Linux_x86_release)
    CFLAGS = -O3
endif
ifeq ($(PLATFORM)_$(BUILD_TYPE),Linux_x86_debug)
    CFLAGS = -O0 -g
endif
美煞众生 2024-07-15 07:38:54

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.

尛丟丟 2024-07-15 07:38:54

切换到为您执行此操作的系统(automake/autoconf)可能会更简单......

Switching to a system which does it for you (automake/autoconf) may be simpler...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文