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), .cpp files compiled;
  • compile .cpp, producing .o objects;
  • generate .so shared objects each .o formerly compiled.

what make file supposed achieve is:

  • find, given directories in $(src), .cpp files compiled;
  • build dependency list each .cpp using -mm compiler's flag;
  • annotate/add each dependency using $(eval ...);
  • evaluate/solve each dependency found, producing both .o , .so files.

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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -