g++ - how to set up cross-directory dependencies in gnu make -


i've got common set of make rules being used in multiple directories. each make simple:

basedir:=../.. target:=thetarget include makefile.include 

unless overridden, have default value source code:

src:= $(wildcard *.cpp) 

we want build object files in directory (not sources), so:

objdir:= ../obj bare:= $(foreach f,$(src),$(notdir $(f) ) obj:= $(foreach o,$(bare),$(objdir)/$(o).o ) 

so have .o files, need each 1 fire rule based on .cpp long directory known, easy:

$(objdir)/%.o: %.cpp 

but in of directories, there arbitrarily grouped files in subdirectories. temporarily got around hardcoding of them in central makefile:

$(objdir)/%.o: a/%.cpp     build... $(objdir)/%.o: b/%.cpp     build... 

but i'd able specify build directories in variable if possible. there way set dependencies

$(objdir)/x.o: a/x.cpp $(objdir)/y.o: a/y.cpp 

and

$(objdir)/z.o: b/z.cpp 

without manually having list out dependencies?

for matter, have dependency files (.d)

$(depdir)/%.d: $(src) 

i want set dependencies based on whatever in source. example: .deps/x.d: a/x.cpp g++ -mm -mt$(objdir)/$(notdir $@) $< -o $(depdir)/$(notdir $@ )

is there easy way generate these rules without writing them each directory?

here's got information on generating .d files in first place: http://mad-scientist.net/make/autodep.html#advanced

the goal in end include .d files , have dependence tree auto-generated files. last part. don't know how use .d files. include them all?

include $(depdir)/%.d 

doesn't work.

i can cat them in rule: cat $(dep) >$(depdir)/deps.inc

and then

include deps.inc 

first, cope source directories:

vpath %.cpp b  $(objdir)/%.o: %.cpp     build... 

then if want can generate dependency files this:

# might use depdir, rather "deps"  $(depdir)/%.d: %.cpp      g++ -mm ...  # note wildcard. , '-' @ beginning means # "don't panic if there aren't any".  -include $(depdir)/*.d 

but there better way described in source cite. don't make rule .d files, build them in same rule builds object files. way don't build them unless need them.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -