Das Problem scheint unwahrscheinlich, aber das Make-Datei ist, was Sie wollen:
Makefile
VPATH := dirx:diry:dirz
SRCS := a.cc b.cc c.cc
OBJS := $(foreach src,$(SRCS),$(basename $(src))_$(basename $(src)).o)
.PHONY: all clean
.SECONDEXPANSION:
%.o: $$(basename $$(subst _,.,$$*)).cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o [email protected] $<
all: $(OBJS)
clean:
rm -f $(OBJS)
Mit Verzeichnissen und Dateien nach Ihrem Beispiel ein:
$ ls -R
.:
dirx diry dirz Makefile
./dirx:
a.cc
./diry:
b.cc
./dirz:
c.cc
es läuft wie:
$ make
g++ -c -o a_a.o dirx/a.cc
g++ -c -o b_b.o diry/b.cc
g++ -c -o c_c.o dirz/c.cc
Cribs: -
Eine weitere Alternative ist automatisch regenerierten enthalten Makefiles zu verwenden. Für einen vollständigen Satz von Blog-Posts über "Metaprogrammierung" in Makefiles siehe http://make.mad-scientist.net/category/metaprogramming/ – MadScientist