Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

GNU Make Help

Name: Anonymous 2012-11-07 6:46

I want to take all .foo files in source/ and compile them to .bar files in target/

I can use the following to successfully compile .foo files to .bar files in the *same* source/ directory, but *not* to the target/ directory


SOURCES=$(wildcard source/*.foo)
TARGETS=$(patsubst %.foo,%.bar,$(SOURCES))

less: $(TARGETS)

%.foo: %.bar
    foobar $< > $@



The ``foobar'' is just an example and it's not a C compiler. I tried tweaking patsubst but to no avail. Ideas?

Any help is greatly appreciated. Thanks for the help :)

Name: Anonymous 2012-11-07 7:21

Ok, so here's my revised Makefile, that works, but not recursively:


SOURCES=$(wildcard source/*.foo)
TARGETS=$(patsubst source%.foo,target%.bar,$(SOURCES))

all: $(TARGETS)

source/%.foo: target/%.bar
    foobar $< > $@


How can I change the above Makefile so that it will compile all and every *.foo files found in source/ recursively and compile it to target/ and mirror the directory, e.g., source/a/b/c.foo will be compiled to target/a/b/c.bar

Name: Anonymous 2012-11-07 7:31

OK, so after a little bit of hair pulling and reflecting in disbelief how people put up with Make's shitty syntax and semantics, I am now quite happy with the following:


SOURCES=$(shell find source -type f -name '*.foo')
TARGETS=$(patsubst source%.foo,target%.bar,$(SOURCES))

all: $(TARGETS)

source/%.foo: target/%.bar
    mkdir -p "$(@D)"
    foobar $< > $@



Thanks guys :) not really

Name: Anonymous 2012-11-07 8:42

You're welcome.

Don't change these.
Name: Email:
Entire Thread Thread List