Makefile:使用规则复制文件 [英] Makefile: Copying files with a rule

查看:1957
本文介绍了Makefile:使用规则复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用我的规则复制文件,但是我的规则没有被触发:

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.xsdconfig.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 copy rule, but I suspect that there's a file called copy confusing the matter. Anyway, [copy] a bad rule.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆