Makefile:使用规则复制文件 [英] Makefile: Copying files with a rule
问题描述
我正在尝试使用我的规则复制文件,但是我的规则没有被触发:
BUILDDIR = build
COPY_FILES = code/xml/schema/schema.xsd config.txt
all: $(BUILDDIR) $(COPY_FILES) copy
$(BUILDDIR):
mkdir -p $@
$(COPY_FILES):
cp -f $@ $(BUILDDIR)
copy:
cp -f $(COPY_FILES) $(BUILDDIR)
我正在尝试使用$(COPY_FILES),但是没有触发,尽管$(BUILDDIR)和复制被触发了.我不确定我的Makefile有什么问题.如果可能的话,我想让$(COPY_FILES)规则起作用(并删除副本).有人知道吗?
$(COPY_FILES)
规则的问题在于该规则的目标是已经存在的两个文件,即code/xml/schema/schema.xsd
和config.txt
. Make认为没有理由执行规则. 我不确定为什么Make不执行无论如何,[复制]错误的规则.>
copy
规则,但是我怀疑有一个名为copy
的文件使事情变得混乱.
尝试一下:
COPY_FILES = $(BUILD_DIR)/schema.xsd $(BUILD_DIR)/config.txt
all: $(COPY_FILES)
$(BUILD_DIR)/schema.xsd: code/xml/schema/schema.xsd
$(BUILD_DIR)/config.txt: config.txt
$(BUILD_DIR)/%:
cp -f $< $@
I am trying to copy files using a my rule but my rule does not get triggered:
BUILDDIR = build
COPY_FILES = code/xml/schema/schema.xsd config.txt
all: $(BUILDDIR) $(COPY_FILES) copy
$(BUILDDIR):
mkdir -p $@
$(COPY_FILES):
cp -f $@ $(BUILDDIR)
copy:
cp -f $(COPY_FILES) $(BUILDDIR)
I am trying to use $(COPY_FILES) but it is not being triggered, although $(BUILDDIR) and copy are triggered. I am not sure what is wrong with my Makefile. I would like to get the $(COPY_FILES) rule to work if possible please (and remove copy). Does anyone please know?
The problem with the $(COPY_FILES)
rule is that the targets of that rule are two files that already exist, namely code/xml/schema/schema.xsd
and config.txt
. Make sees no reason to execute the rule. I'm not sure why Make doesn't execute the Anyway, [copy] a bad rule.copy
rule, but I suspect that there's a file called copy
confusing the matter.
Try this:
COPY_FILES = $(BUILD_DIR)/schema.xsd $(BUILD_DIR)/config.txt
all: $(COPY_FILES)
$(BUILD_DIR)/schema.xsd: code/xml/schema/schema.xsd
$(BUILD_DIR)/config.txt: config.txt
$(BUILD_DIR)/%:
cp -f $< $@
这篇关于Makefile:使用规则复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!