c++ - Writing dependencies in makefile, with makefile -
based on questions -- , further reference found --, i'm trying build makefile able to:
- find, given directories in
$(src),.cppfiles compiled; - compile
.cpp, producing.oobjects; - generate
.soshared objects each.oformerly compiled.
what make file supposed achieve is:
- find, given directories in
$(src),.cppfiles compiled; - build dependency list each
.cppusing-mmcompiler's flag; - annotate/add each dependency using
$(eval ...); - evaluate/solve each dependency found, producing both
.o,.sofiles.
what have far: i've been able quite whole thing, except making work (: error i'm getting states there is, somehow, empty label '' dependency:
$ make make: * no rule make target
', needed/home/rubens/bin/label.o'. stop.
so, here makefile i'm yet not able run:
# directories src := process init bin := $(home)/bin lib := watershed libpath := $(watershed)/lib inc := $(watershed)/include $(xerces)/include # paths mpicpp := mpic++ sources := $(shell find $(src) -name '*.cpp') objects := $(addprefix $(bin)/, $(notdir $(sources:.cpp=.o))) shared := $(objects:.o=.so) # flags cflags := -std=c++0x -o2 -wall -fpic cflags += $(foreach inc, $(inc), -i $(inc)) lflags := lflags += $(foreach lib, $(lib), -l $(lib)) lflags += $(foreach path, $(libpath), -l $(lib)) # rules $(shared): | bindir %.o: @echo $@ -- [$<][$^][$*] @echo $(mpicpp) $(cflags) -c $< -o $@ %.so: %.o @echo $(mpicpp) $(lflags) -shared $< -o $@ bindir: @mkdir -p $(bin) # utilities .phony: clean all: $(shared) clean: @rm -f $(objects) $(shared) # dependencies define dependencies $(addprefix $(bin)/, $(notdir $(1:.cpp=.o))): \ $(shell $(mpicpp) $(cflags) -mm $(1) | sed 's/^.*\.o:[ ]*//') endef $(foreach src, $(sources), $(eval $(call dependencies, $(src)))) where seems error: seems caused dependency generation step, as, when remove empty lines , piping output grep, follows:
define dependencies $(addprefix $(bin)/, $(notdir $(1:.cpp=.o))): \ $(shell $(mpicpp) $(cflags) -mm $(1) | sed 's/^.*\.o:[ ]*//' | \ grep -v ^$) endef the error somehow digivolves empty list of dependencies; i'm able see list empty echo's in rule %.o: -- variables not empty $@ , $*.
/home/rubens/bin/label.o -- [][][/home/rubens/bin/label]
mpic++ -std=c++0x -o2 -wall -fpic -i /home/rubens/libwatershed/include -i /home/rubens/xerces-c-3.1.1/include -c -o /home/rubens/bin/label.o
mpic++ -l watershed -l -shared /home/rubens/bin/label.o -o /home/rubens/bin/label.so
any advice on better ways solve very, welcome; yet, finish writing makefile, before use cmake or scons.
-mm generate dependencies on makefile format simplify generating dependencies each .cpp same file, doing "-include $(deps_file)". that's more maintainable using eval.
Comments
Post a Comment