From cf88fc04686af2b4a34f9ccebc9f517cd83be491 Mon Sep 17 00:00:00 2001 From: Gert van Valkenhoef Date: Tue, 15 Nov 2011 19:39:55 +0000 Subject: [PATCH] Precompile .ih files and cache dependencies based on .ih files --- Makefile | 42 +++++++++++++++++++++-------------- fold/fold.cc | 3 +-- fold/fold.ih | 2 ++ main/Make.inc | 1 + main/main.ih | 18 +++++++++++++++ odcread.cc => main/odcread.cc | 18 +-------------- reader/Make.inc | 5 +---- store/store.cc | 6 +---- store/store.ih | 5 +++++ textmodel/textmodel.cc | 6 +---- textmodel/textmodel.ih | 5 +++++ typeregister/typeregister.cc | 4 +--- typeregister/typeregister.ih | 3 +++ 13 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 fold/fold.ih create mode 100644 main/Make.inc create mode 100644 main/main.ih rename odcread.cc => main/odcread.cc (90%) create mode 100644 store/store.ih create mode 100644 textmodel/textmodel.ih create mode 100644 typeregister/typeregister.ih diff --git a/Makefile b/Makefile index 656105b..415e325 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,12 @@ # * $(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. +CFLAGS := -I. # Variables for the modules to write to -SRCS := odcread.cc +SRCS := # Include module definitions include $(patsubst %,%/Make.inc,$(MODULES)) @@ -18,28 +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: -# 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. +# TODO: rename all %/%.ih files to %/module.ih for simplicity of matching rules diff --git a/fold/fold.cc b/fold/fold.cc index 7fdf01b..94ed587 100644 --- a/fold/fold.cc +++ b/fold/fold.cc @@ -1,5 +1,4 @@ -#include "fold/fold.h" -#include "reader/reader.h" +#include "fold/fold.ih" namespace odc { diff --git a/fold/fold.ih b/fold/fold.ih new file mode 100644 index 0000000..48ab6b1 --- /dev/null +++ b/fold/fold.ih @@ -0,0 +1,2 @@ +#include "fold/fold.h" +#include "reader/reader.h" diff --git a/main/Make.inc b/main/Make.inc new file mode 100644 index 0000000..ad34496 --- /dev/null +++ b/main/Make.inc @@ -0,0 +1 @@ +SRCS += main/odcread.cc diff --git a/main/main.ih b/main/main.ih new file mode 100644 index 0000000..22b020a --- /dev/null +++ b/main/main.ih @@ -0,0 +1,18 @@ +#include +#include +#include +#include + +#include "oberon.h" +#include "reader/reader.h" +#include "store/store.h" +#include "textmodel/textmodel.h" +#include "visitor/visitor.h" + +// Character encoding conversions +#include // determine the current charset +#include // locale support +#include // charset conversions +#include // error codes +#include // string descriptions of error codes + diff --git a/odcread.cc b/main/odcread.cc similarity index 90% rename from odcread.cc rename to main/odcread.cc index a509ab6..075671f 100644 --- a/odcread.cc +++ b/main/odcread.cc @@ -1,20 +1,4 @@ -#include -#include -#include -#include - -#include "oberon.h" -#include "reader/reader.h" -#include "store/store.h" -#include "textmodel/textmodel.h" -#include "visitor/visitor.h" - -// Character encoding conversions -#include // determine the current charset -#include // locale support -#include // charset conversions -#include // error codes -#include // string descriptions of error codes +#include "main/main.ih" namespace odc { class Context { diff --git a/reader/Make.inc b/reader/Make.inc index 6f5e81a..c61b0f0 100644 --- a/reader/Make.inc +++ b/reader/Make.inc @@ -1,4 +1 @@ -READER_SRC := addPathComponent.cc fixTypeName.cc readAlien.cc reader.cc \ - readLinkStore.cc readNewLinkStore.cc readNilStore.cc readPath.cc \ - readStore.cc readStoreOrElemStore.cc readVersion.cc util.cc -SRCS += $(patsubst %,reader/%,$(READER_SRC)) +SRCS += $(wildcard reader/*.cc) diff --git a/store/store.cc b/store/store.cc index 76f0586..a967518 100644 --- a/store/store.cc +++ b/store/store.cc @@ -1,8 +1,4 @@ -#include "store/store.h" -#include "reader/reader.h" -#include "visitor/visitor.h" - -#include +#include "store/store.ih" namespace odc { diff --git a/store/store.ih b/store/store.ih new file mode 100644 index 0000000..6e2fab4 --- /dev/null +++ b/store/store.ih @@ -0,0 +1,5 @@ +#include "store/store.h" +#include "reader/reader.h" +#include "visitor/visitor.h" + +#include diff --git a/textmodel/textmodel.cc b/textmodel/textmodel.cc index 720654a..aa28193 100644 --- a/textmodel/textmodel.cc +++ b/textmodel/textmodel.cc @@ -1,8 +1,4 @@ -#include "textmodel/textmodel.h" -#include "reader/reader.h" - -#include -#include +#include "textmodel/textmodel.ih" namespace odc { diff --git a/textmodel/textmodel.ih b/textmodel/textmodel.ih new file mode 100644 index 0000000..d3fe086 --- /dev/null +++ b/textmodel/textmodel.ih @@ -0,0 +1,5 @@ +#include "textmodel/textmodel.h" +#include "reader/reader.h" + +#include +#include diff --git a/typeregister/typeregister.cc b/typeregister/typeregister.cc index 91120c6..0093b9a 100644 --- a/typeregister/typeregister.cc +++ b/typeregister/typeregister.cc @@ -1,6 +1,4 @@ -#include "typeregister/typeregister.h" - -#include +#include "typeregister/typeregister.ih" namespace odc { diff --git a/typeregister/typeregister.ih b/typeregister/typeregister.ih new file mode 100644 index 0000000..6de1205 --- /dev/null +++ b/typeregister/typeregister.ih @@ -0,0 +1,3 @@ +#include "typeregister/typeregister.h" + +#include -- 2.29.2