英文:
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 's/Brian/World/' $< >$@
target1: Makefile.world
$(MAKE) -f $<
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论