我在这里的GNUmakefile能够构建它们.虽然如果我更新文件夹,则不会跟踪依赖项.我显然不想依赖于干净的目标,所以如何跟踪每个文件夹的内容?
WGTS := $(shell find -name 'config.xml' | while read wgtdir; do echo `dirname $$wgtdir`.wgt; done )
all: $(WGTS)
%.wgt:
@cd $* && zip -q -r ../$(shell basename $*).wgt .
@echo Created $@
clean:
rm -f $(WGTS)
Run Code Online (Sandbox Code Playgroud)
我希望这样的事情:
%.wgt: $(shell find $* -type f)
Run Code Online (Sandbox Code Playgroud)
会工作,但事实并非如此.帮助.
将Beta 的想法与我的想法结合起来:
WGTS := $(shell find -name config.xml)
WGTS := $(WGTS:/config.xml=.wgt)
WGTS_d := $(WGTS:.wgt=.wgt.d)
全部:$(WGTS)
干净的:
rm -f $(WGTS) $(WGTS_d)
-包括$(WGTS_d)
定义 WGT_RULE
$(1): $(shell 查找 $(1:.wgt=))
$(1:.wgt=)/%:
@
恩德夫
$(foreach targ,$(WGTS),$(eval $(call WGT_RULE,$(targ))))
%.wgt:
@echo 创建$@
@(echo -n "$@: "; find $* -type f | tr '\n' ' ') > $@.d
@cd $* && zip -q -r ../$(shell 基本名称 $*).wgt 。
例子:
$ mkdir -p foo bar/嵌套
$ touch {foo,bar/nested}/config.xml
$ 制作
创建 bar/nested.wgt
创建 foo.wgt
$ 制作
make:无需为“全部”执行任何操作。
$ 触摸 foo/a
$ 制作
创建 foo.wgt
$ rm foo/a
$ 制作
创建 foo.wgt
$ 制作
make:无需为“全部”执行任何操作。
这里唯一的潜在问题是虚拟规则,它让 make 忽略它不知道如何构建嵌套在目录中的目标。(在我的示例中为 foo/a。)如果这些是 make 需要知道如何构建的真实目标,则重复的配方定义可能会成为问题。