Reputation: 2950
I need to process all files with a particular extension, and package up the results into a single archive. Is there a way to have make
do this?
For example suppose I need to take all the .w files and produce a .n file for each one with any vowels turned to periods, then tar
up the results. If I create a Makefile
as follows:
novowels.tar: %.n
tar cf $@ $^
%.n: %.w
sed -e "s/[aeiou]/./g" > $@ < $<
make
(unsurprisingly) returns the following if there are no .n files in the directory:
make: *** No rule to make target '%.n', needed by 'novowels.tar'. Stop.
I can call make the.n
and it'll create the file from the.w (assuming that exists), and if I then call make
it'll get included in the archive.
The question is: how (best) to have make
realise that there are a whole load of .w files that need converting to .n files in the first place?
Upvotes: 1
Views: 44
Reputation: 25613
Take this as an example:
ALLFILES_IN := $(wildcard *.w)
ALLFILES_OUT := $(ALLFILES_IN:.w=.n)
$(info In : $(ALLFILES_IN))
$(info Out: $(ALLFILES_OUT))
%.n: %.w
cat $< > $@
all.tar: $(ALLFILES_OUT)
@echo "Tar:" $^
Maybe you find something like that helpful:
CPP_FILES := $(wildcard src/*.cpp)
OBJ_FILES := $(addprefix obj/,$(notdir $(CPP_FILES:.cpp=.o)))
which was stolen from: Can I compile all .cpp files in src/ to .o's in obj/, then link to binary in ./?
Upvotes: 3