I have a Makefile that has two identical targets, one for mkdir
and the other for cp
.
The Makefile creates dir when it does not exist, and then copy files. I wonder how it works. As I know, Makefile does not execute recipes line by line, from top to bottom.
Can someone explain how it works?
# Makefile
SRCDIR := ../../../src
SUBDIR := include
HEADERS := a.hpp \
b.hpp
HEADERS := $(addprefix $(SUBDIR)/, $(HEADERS))
# Copy headers in SRCDIR to SUBDIR
prebuild: $(HEADERS)
$(HEADERS): | $(SUBDIR)
$(SUBDIR):
mkdir $@
$(HEADERS): %: $(SRCDIR)/%
cp $< $@
ADDED
@cryptarch What I am doing is
$ make prebuild
What this Makefile should do is
copy ../../../src/include/*
to ./include/
make
, so we can't just take your example Makefile and try it out to see what you mean. – cryptarch Feb 4 at 18:38make
. – schily Feb 4 at 20:16$(HEADERS)
. – Stephen Kitt Feb 4 at 21:55