刷新 makefile 解释过程中

huangapple go评论51阅读模式
英文:

Refreshing makefile midway through interpretation

问题

I'm working with a c++ project that someone else wrote, and the makefile is quite convoluted. The only way that I can get a certain dependency to build is by having it build and then using sed to change a portion of the makefile. However, this means running the make command twice. This honestly is the only way to solve the issue and I've been tearing my hair out over it.

Is there any way that I can have make refresh the makefile so that it sees the updated makefile before continuing interpretation?

Example of what needs doing:

.PHONY: target1 target2

target1:
        @sed -i 's/Brian/World/' Makefile
        # At this point, make needs to refresh the contents of the makefile to see the changes made

target2: target1
        @echo "Hello Brian!"
        # After the makefile has been refreshed, this will print "Hello World!"
英文:

I'm working with a c++ project that someone else wrote, and the makefile is quite convoluted. The only way that I can get a certain dependency to build is by having it build and then using sed to change a portion of the makefile. However, this means running the make command twice. This honestly is the only way to solve the issue and I've been tearing my hair out over it.

Is there any way that I can have make refresh the makefile so that it sees the updated makefile before continuing interpretation?

Example of what needs doing:

.PHONY: target1 target2

target1:
        @sed -i 's/Brian/World/' Makefile
        # At this point, make needs to refresh the contents of the makefile to see the changes made

target2: target1
        @echo "Hello Brian!"
        # After the makefile has been refreshed, this will print "Hello World!"

答案1

得分: 2

我会使用一个单独的临时复制文件来编写这个:

Makefile.world: Makefile
    @sed 's/Brian/World/' $< >$@

target1: Makefile.world
    $(MAKE) -f $<

但如果修改永远不会改变(像这样),那么没有必要将它设置为临时的。除非您经常编辑Makefile并希望确保Makefile.world保持最新。

英文:

I would write this with a separate temporary copy of the makefile:

Makefile.world: Makefile
        @sed &#39;s/Brian/World/&#39; $&lt; &gt;$@

target1: Makefile.world
        $(MAKE) -f $&lt;

but if the modification never changes (like this), there's little reason to make it a temporary. Unless you're frequently editing Makefile and want to make sure Makefile.world stays up to date.

huangapple
  • 本文由 发表于 2023年2月10日 05:49:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404773.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定