生成文件中的预构建步骤

编程入门 行业动态 更新时间:2024-10-08 05:22:29
本文介绍了生成文件中的预构建步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何运行必须在所有其他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.

更多推荐

生成文件中的预构建步骤

本文发布于:2023-11-12 14:22:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:步骤   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!