Pat S
Pat S

Reputation: 490

trying to create a general rule for concatenating files with make

I have two folders that look something like this:

process:

raw:
a_1.x.txt   a_2.x.txt   b_1.x.txt   b_2.x.txt
a_1.x.dat   a_2.x.dat   b_1.x.dat   b_2.x.dat

These txt files are dumps from binary files *.dat that will be created by another rule. I would like to create a make file that will pool the raw/%_#.txt files to create process/%.txt. I can do this with...

process/a.txt : raw/a_1.x.txt raw/a_2.x.txt
    cat $^ > $@

process/b.txt : raw/b_1.x.txt raw/b_2.x.txt
    cat $^ > $@

... when I do make process/a.txt or make process/b.txt. But in my real life problem, I have a, b, c, etc and each has a variable number of files in the raw folder. So, I'd like to create a general rule to do this for me.

I've tried...

.SECONDEXPANSION:
process/%.txt : $$(join $$(join raw/,%),$$(wildcard *.x.txt)))
    cat $^ > $@

But the make command comes back with

make: *** No rule to make target 'process/a.txt'. Stop.

Ditto for:

process/%.txt : $$(patsubst raw,process,$$(patsubst .txt, $$(wildcard *.x.txt),))
    cat $^ > $@`

Any suggestions?

Upvotes: 3

Views: 171

Answers (1)

akond
akond

Reputation: 16060

Maybe this can be of help:

DATA = $(wildcard raw/*.dat)
TEXTS = $(patsubst %.dat,%.txt,$(DATA))
PROCESSED = $(subst raw,process,$(TEXTS))


all: $(PROCESSED)


%.txt: %.dat
    touch $@

process/%.txt: raw/%.txt
    touch $@

Upvotes: 2

Related Questions