如何将特定文件与 makefile 同步
How to sync specific file with makefile
我有一个生成文件,它是根据我拥有的 JSON 文件结构生成的。 IE。用户将在他的项目中提供一些 JSON 文件,并通过执行一些 CLI 工具(我将提供),它将根据 project.json
文件生成一个 makefile。
目前为止一切正常,但棘手的地方来了。如果用户更改 project.json
文件并且 makefile
已经生成,它将不会捕获 project.json
文件的最新更改,有没有办法用 make 文件解决它?我需要它们同步...
更新
这是我的 make 文件 gmake
include gmake
gmake: project.json
rtr init $< $@
DIR := $(shell rtr execute start)
all: app1 app2
.PHONY: app1
App1:
@echo “run app 1"
.PHONY: app2
App2:
@echo "run app2”
Done:
rtr clean $(DIR)
您可以使用顶层和生成的 makefile 进行操作。在顶层makefile
,你可能只有
all: makefile.gen
@$(MAKE) -f $<
.PHONY: all
makefile.gen: project.json
@yourCommand > $@
并且生成的 makefile(此处命名为 makefile.gen
)会在 project.json
更改时构建。确保根据需要更改最后的构建规则,以便 makefile.gen
由命令行工具生成。
如果您使用的是 GNU make,您可以简单地将此生成的 makefile 包含在顶级 makefile 中:
include Makefile.generated
Makefile.generated: project.json
json2makefile $< $@
make 总是尝试重建丢失或过时的 makefile。如果是,它会再次解析 makefile。来自 How Makefiles Are Remade of the GNU make documentation:
To this end, after reading in all makefiles, make will consider each
as a goal target and attempt to update it. If a makefile has a rule
which says how to update it (found either in that very makefile or in
another one) or if an implicit rule applies to it (see Using Implicit
Rules), it will be updated if necessary. After all makefiles have been
checked, if any have actually been changed, make starts with a clean
slate and reads all the makefiles over again. (It will also attempt to
update each of them over again, but normally this will not change them
again, since they are already up to date.)
我有一个生成文件,它是根据我拥有的 JSON 文件结构生成的。 IE。用户将在他的项目中提供一些 JSON 文件,并通过执行一些 CLI 工具(我将提供),它将根据 project.json
文件生成一个 makefile。
目前为止一切正常,但棘手的地方来了。如果用户更改 project.json
文件并且 makefile
已经生成,它将不会捕获 project.json
文件的最新更改,有没有办法用 make 文件解决它?我需要它们同步...
更新
这是我的 make 文件 gmake
include gmake
gmake: project.json
rtr init $< $@
DIR := $(shell rtr execute start)
all: app1 app2
.PHONY: app1
App1:
@echo “run app 1"
.PHONY: app2
App2:
@echo "run app2”
Done:
rtr clean $(DIR)
您可以使用顶层和生成的 makefile 进行操作。在顶层makefile
,你可能只有
all: makefile.gen
@$(MAKE) -f $<
.PHONY: all
makefile.gen: project.json
@yourCommand > $@
并且生成的 makefile(此处命名为 makefile.gen
)会在 project.json
更改时构建。确保根据需要更改最后的构建规则,以便 makefile.gen
由命令行工具生成。
如果您使用的是 GNU make,您可以简单地将此生成的 makefile 包含在顶级 makefile 中:
include Makefile.generated
Makefile.generated: project.json
json2makefile $< $@
make 总是尝试重建丢失或过时的 makefile。如果是,它会再次解析 makefile。来自 How Makefiles Are Remade of the GNU make documentation:
To this end, after reading in all makefiles, make will consider each as a goal target and attempt to update it. If a makefile has a rule which says how to update it (found either in that very makefile or in another one) or if an implicit rule applies to it (see Using Implicit Rules), it will be updated if necessary. After all makefiles have been checked, if any have actually been changed, make starts with a clean slate and reads all the makefiles over again. (It will also attempt to update each of them over again, but normally this will not change them again, since they are already up to date.)