Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile: Copying files with a rule

Tags:

makefile

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?

like image 837
user1777907 Avatar asked Aug 06 '13 22:08

user1777907


1 Answers

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 $< $@
like image 195
Beta Avatar answered Oct 13 '22 16:10

Beta