如何显式运行“make clean”?不同目标之间?

发布于 2024-12-28 00:05:54 字数 391 浏览 0 评论 0原文

我正在寻找以下行为:

# make debug (project is rebuilt. this works fine.)
# make debug (project is not rebuilt because no changes have been made.)
# make release (this is a different target than the currently-built one. I want 'make clean' to run before the release target is built)
# make release (project is not rebuilt because no changes have been made.)

谢谢。

I'm looking for the following behavior:

# make debug (project is rebuilt. this works fine.)
# make debug (project is not rebuilt because no changes have been made.)
# make release (this is a different target than the currently-built one. I want 'make clean' to run before the release target is built)
# make release (project is not rebuilt because no changes have been made.)

Thank you.

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

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

发布评论

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

评论(4

邮友 2025-01-04 00:05:54

有趣的问题。我能想到的唯一方法是从外部记录最近的目标(例如将其回显到文件),然后检查它是否与当前目标相同或不同。如果相同,则运行常规构建过程;如果它们不同,请首先运行 make clean

我对此进行了第一次尝试,以说明该过程(未经测试)。

debug release:
ifneq ($(MAKECMDGOALS),$(shell cat last_target.txt))
    $(MAKE) clean
endif
    @echo $@ > last_target.txt
    [regular build commands]

这假设两个目标具有相同的配方(某些变量具有不同的设置)。如果它们有不同的配方,则条件部分和 echo 命令显然必须插入到两个配方中。

Interesting problem. The only way I can come up with to do this, is to externally record the most recent target (e.g. echo it to a file), and then check to see if it is the same or different as the current one. If they are the same, just run the regular build process; if they differ, first run make clean.

I made a first attempt at this, to illustrate the process (untested).

debug release:
ifneq ($(MAKECMDGOALS),$(shell cat last_target.txt))
    $(MAKE) clean
endif
    @echo $@ > last_target.txt
    [regular build commands]

This assumes both targets have the same recipe (with different settings for certain variables). If they have distinct recipes, the conditional part and the echo command obviously have to be inserted in both recipes.

西瓜 2025-01-04 00:05:54

您可能已经有或应该有单独的 DEBUG 和 RELEASE 目录。它们应该是分开的,因为所有中介和可执行文件都是不同的。然后,在每个目录中拥有单独的 make 目标/上下文,并使用“全局”目标/上下文来选择正确的 make 文件并从那里继续,这将是微不足道的。

You probably already have, or should have, separate directories for DEBUG and RELEASE. They should be separate because all intermediaries and executables are different. Then it would be trivial to have separate make targets/context in each directory, with a 'global' one to select the proper make file and continue from there.

音盲 2025-01-04 00:05:54

为了详细说明我的评论,我认为最好的设置是为不同的构建选项集设置不同的输出目录。在您的情况下,将有一个用于 debug 的输出目录和一个用于 release 的输出目录。这个想法是,构建期间生成的所有文件(目标文件、库、可执行文件等)都被放置到特定于目标的目录中。

这将使 make releasemake debug 完全解耦,并消除部分构建混合的可能性。

To elaborate on my comment, I think the best setup is to have different output directories for different sets of build options. In your case, there'd be an output directory for debug and an output directory for release. The idea is that all files produced during the build (object files, libraries, executables etc) are placed into the target-specific directory.

This would completely decouple make release from make debug, and would eleminate the possibility of partial builds getting mixed up.

厌倦 2025-01-04 00:05:54

据推测,debugrelease 目标构建相同的文件,但具有不同的标志。有一篇 Make 先生的文章,名为当 CPPFLAGS 更改时进行重建< /a> 它描述了如何让 gmake 做你需要的事情。

或者,您可以切换到 ElectricMake,这是一个与 gmake 兼容的 make 实现,具有许多功能对标准 gmake 的改进,包括 ledger 功能,该功能允许在最新检查中考虑命令行参数/编译器标志,因此您只需启用即可获得您所描述的行为该功能:

emake --emake-ledger=command debug   ;# builds everything with debug flags
emake --emake-ledger=command debug   ;# does nothing
emake --emake-ledger=command release ;# rebuilds everything with release flags
emake --emake-ledger=command release ;# does nothing

(免责声明:我是 ElectricMake 的架构师)

Presumably the debug and release targets build the same files, but with different flags. There's a Mr. Make article called Rebuilding when CPPFLAGS changes which describes how to get gmake to do what you need.

Alternatively you could switch to ElectricMake, a gmake-compatible make implementation with many improvements over standard gmake, including a the ledger feature which allows the consideration of command-line arguments/compiler flags in the up-to-date check, so you get the behavior you're describing just be enabling that feature:

emake --emake-ledger=command debug   ;# builds everything with debug flags
emake --emake-ledger=command debug   ;# does nothing
emake --emake-ledger=command release ;# rebuilds everything with release flags
emake --emake-ledger=command release ;# does nothing

(disclaimer: I'm the architect of ElectricMake)

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