X-Git-Url: https://deadsoftware.ru/gitweb?p=odcread.git;a=blobdiff_plain;f=Makefile;h=415e3250cebaf0cde6ad7c7995e9f02e2ba2c42a;hp=260da917104710eaf8c5c5f7a0f6dca5c2015ed2;hb=cf88fc04686af2b4a34f9ccebc9f517cd83be491;hpb=067f77e22bace6d17204e3f1f677dd6a5ca6f563 diff --git a/Makefile b/Makefile index 260da91..415e325 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,15 @@ -MODULES := reader store alien typeregister textmodel fold typepath +# Modules, each containing: +# * $(MODULE)/Make.inc -- makefile include +# * $(MODULE)/$(MODULE).h -- minimal "interface" header file +# * $(MODULE)/$(MODULE).ih -- internal/implementation header file +# (only to be included by sources within the module) +# * $(MODULE)/*.cc -- module source files +MODULES := main reader store alien typeregister textmodel fold typepath -# Add module directories to the include path -CFLAGS += -I. +CFLAGS := -I. # Variables for the modules to write to -SRCS := odcread.cc +SRCS := # Include module definitions include $(patsubst %,%/Make.inc,$(MODULES)) @@ -13,22 +18,36 @@ include $(patsubst %,%/Make.inc,$(MODULES)) odcread: $(SRCS:.cc=.o) g++ -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. +%.o: %.cc + g++ $(CFLAGS) $< -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 + g++ $(CFLAGS) -x c++-header $< -MM -MF $(dir $@)module.d -MP -MT $@ + g++ $(CFLAGS) -x c++-header $< -o $@ + +# This rule build an object (.o) from a source (.cc). +# 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))$(patsubst %/,%,$(dir $(1))).ih.gch +endef +$(foreach src,$(SRCS),$(eval $(call depend_on_compiled_header,$(src)))) clean: - rm -f odcread *.d *.o */*.o */*.d + rm -f odcread *.o */*.o */*.d */*.ih.gch # Include the generated dependency files (if they exist) --include $(SRCS:.cc=.d) +-include $(patsubst %,%/module.d,$(MODULES)) + +# TODO: rename all %/%.ih files to %/module.ih for simplicity of matching rules