生成文件中的预构建步骤 [英] Pre-build step in makefile

查看:238
本文介绍了生成文件中的预构建步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何运行必须在所有其他makefile命令之前执行的脚本?如果没有要构建的脚本,则不执行脚本会很好(但不是强制性的).

How can I run a script, which must execute before all other makefile commands? And it will be nice (but not mandatory) to the script is not executed if there is nothing to build.

我已经搜索过SO和Google,但找不到任何内容.

I've searched SO and Google, but can't find anything.

我有此解决方法:

# myscript.bat output is empty
CHEAT_ARGUMENT = (shell myscript.bat)
CFLAGS += -DCHEAT_ARGUMENT=$(CHEAT_ARGUMENT)
AFLAGS += -DCHEAT_ARGUMENT=$(CHEAT_ARGUMENT)

但这非常丑陋.还有其他方法可以在 makefile 中运行"预构建步骤"吗?

But it's very ugly. Is there other way to run "pre-build step" in makefile?

推荐答案

我提出了两种解决方案.第一个模仿NetBeans IDE生成的内容:

I propose two solutions. The first mimics what NetBeans IDE generates:

CC=gcc

.PHONY: all clean

all: post-build

pre-build:
    @echo PRE

post-build: main-build
    @echo POST

main-build: pre-build
    @$(MAKE) --no-print-directory target

target: $(OBJS)
    $(CC) -o $@ $(OBJS)

clean:
    rm -f $(OBJS) target

第二个是Eclipse IDE生成的内容:

The second one is inpired by what Eclipse IDE generates:

CC=gcc

.PHONY: all clean
.SECONDARY: main-build

all: pre-build main-build

pre-build:
    @echo PRE

post-build:
    @echo POST

main-build: target

target: $(OBJS)
    $(CC) -o $@ $(OBJS)
    @$(MAKE) --no-print-directory post-build

clean:
    rm -f $(OBJS) target

请注意,在第一个构建中,无论是否确定主构建是最新的,始终都会调用前构建和后构建.

Note that in the first one, pre and post builds are always called regardless of whether the main build is determined to be up to date or not.

在第二个步骤中,如果主构建的状态为最新,则不执行构建后步骤.虽然预构建步骤总是在这两个步骤中执行.

In the second one, the post-build step is not executed if the state of the main build is up to date. While the pre-build step is always executed in both.

这篇关于生成文件中的预构建步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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