X-Git-Url: https://deadsoftware.ru/gitweb?p=odcread.git;a=blobdiff_plain;f=Makefile;h=b1fac089f138b1ae207a0a16fec379fe5e6e6f2c;hp=656105b1c1de1d9709988bf77591889dabe78111;hb=HEAD;hpb=0c3c99510dbda9c562787b5d08f69b68a969f561 diff --git a/Makefile b/Makefile index 656105b..b1fac08 100644 --- a/Makefile +++ b/Makefile @@ -4,42 +4,51 @@ # * $(MODULE)/$(MODULE).ih -- internal/implementation header file # (only to be included by sources within the module) # * $(MODULE)/*.cc -- module source files -MODULES := reader store alien typeregister textmodel fold typepath +MODULES := main reader store alien typeregister textmodel fold typepath -CFLAGS += -I. +CXXFLAGS = -I. +CXX = g++ # Variables for the modules to write to -SRCS := odcread.cc +SRCS := # Include module definitions include $(patsubst %,%/Make.inc,$(MODULES)) # This rule just links the object files together odcread: $(SRCS:.cc=.o) - g++ -o $@ $^ + $(CXX) -liconv -o $@ $^ -# This rule build an object (.o) from a source (.cc). It first builds a -# dependency (.d) file which will ensure that the .o is rebuilt whenever the -# header files included by the .cc are updated. +# This rule build an object (.o) from a source (.cc). +%.o: %.cc + $(CXX) $(CXXFLAGS) $< -c -o $@ + +# For each implementation header (.ih) generate a dependency (.d) file which +# will ensure that the compiled header (.ih.gch) is rebuilt whenever the header +# files included by the .ih are updated. # The options given to GCC for this are as follows: # -MM : calculate dependencies, but exclude system headers # -MF : output dependencies to the given file # -MP : generate "header.h:" rules to avoid errors on deletion of headers # -MT : the main rule has the given target (to handle subdirs correctly) # The .d file is not an explicit target because it will need to be (re-)built -# if and only if the .o needs to be rebuilt. -%.o: %.cc - g++ $(CFLAGS) $< -MM -MF $*.d -MP -MT $@ - g++ $(CFLAGS) $< -c -o $@ +# if and only if the .ih.gch needs to be rebuilt. +%.ih.gch: %.ih + $(CXX) $(CXXFLAGS) -x c++-header $< -MM -MF $*.d -MP -MT $@ + $(CXX) $(CXXFLAGS) -x c++-header $< -o $@ + +# Each module has a .ih file that should be *the only* include from the .cc +# files. These .ih files are pre-compiled to .ih.gch, and dependency caching +# is based on the .ih files, not the .cc files. +define depend_on_compiled_header +$(patsubst %.cc,%.o,$(1)) : $(dir $(1))module.ih.gch +endef +$(foreach src,$(SRCS),$(eval $(call depend_on_compiled_header,$(src)))) clean: - rm -f odcread *.d *.o */*.o */*.d + rm -f */*.o */module.d */module.ih.gch +dist-clean: clean + rm -f odcread # Include the generated dependency files (if they exist) --include $(SRCS:.cc=.d) - - -# TODO: -# Each module has a .ih file that should be *the only* include from the .cc -# files. These .ih files should be pre-compiled, and dependency caching should -# be based on the .ih files, not the .cc files. +-include $(patsubst %,%/module.d,$(MODULES))