16

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?

4

2 回答 2

26

该规则的问题$(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 $< $@
于 2013-08-07T00:41:55.027 回答
0

就我而言,我使用一个简单的“for 循环”来 cp 所有这些文件。

例如,将规则编写如下:

RELEASE_DIR = ../rc1
RELEASE_FILES = ai.h main.cc main_async.cc bmp_utils.h bmp_utils.cc
release: $(RELEASE_FILES)
     for u in $(RELEASE_FILES); do echo $$u; cp -f $$u $(RELEASE_DIR); done

然后,

make release
于 2019-12-04T23:58:52.340 回答