DEADSOFTWARE

Precompile .ih files and cache dependencies based on .ih files
authorGert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
Tue, 15 Nov 2011 19:39:55 +0000 (19:39 +0000)
committerGert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl>
Tue, 15 Nov 2011 20:26:07 +0000 (20:26 +0000)
13 files changed:
Makefile
fold/fold.cc
fold/fold.ih [new file with mode: 0644]
main/Make.inc [new file with mode: 0644]
main/main.ih [new file with mode: 0644]
main/odcread.cc [moved from odcread.cc with 90% similarity]
reader/Make.inc
store/store.cc
store/store.ih [new file with mode: 0644]
textmodel/textmodel.cc
textmodel/textmodel.ih [new file with mode: 0644]
typeregister/typeregister.cc
typeregister/typeregister.ih [new file with mode: 0644]

index 656105b1c1de1d9709988bf77591889dabe78111..415e3250cebaf0cde6ad7c7995e9f02e2ba2c42a 100644 (file)
--- 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
index 7fdf01b6d66d0bfe53a833325576abd0aada23d2..94ed5878f6f00a1831f2f3b671f3285118ac925d 100644 (file)
@@ -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 (file)
index 0000000..48ab6b1
--- /dev/null
@@ -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 (file)
index 0000000..ad34496
--- /dev/null
@@ -0,0 +1 @@
+SRCS += main/odcread.cc
diff --git a/main/main.ih b/main/main.ih
new file mode 100644 (file)
index 0000000..22b020a
--- /dev/null
@@ -0,0 +1,18 @@
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <stack>
+
+#include "oberon.h"
+#include "reader/reader.h"
+#include "store/store.h"
+#include "textmodel/textmodel.h"
+#include "visitor/visitor.h"
+
+// Character encoding conversions
+#include <langinfo.h> // determine the current charset
+#include <locale.h> // locale support
+#include <iconv.h> // charset conversions
+#include <errno.h> // error codes
+#include <string.h> // string descriptions of error codes
+
similarity index 90%
rename from odcread.cc
rename to main/odcread.cc
index a509ab6bc7a72468e72243815aaf794a47057240..075671fadc1c9dddb39c74cc1b81c64f9d8639ed 100644 (file)
@@ -1,20 +1,4 @@
-#include <iostream>
-#include <fstream>
-#include <string>
-#include <stack>
-
-#include "oberon.h"
-#include "reader/reader.h"
-#include "store/store.h"
-#include "textmodel/textmodel.h"
-#include "visitor/visitor.h"
-
-// Character encoding conversions
-#include <langinfo.h> // determine the current charset
-#include <locale.h> // locale support
-#include <iconv.h> // charset conversions
-#include <errno.h> // error codes
-#include <string.h> // string descriptions of error codes
+#include "main/main.ih"
 
 namespace odc {
        class Context {
index 6f5e81a97d9327feabe88724a99cf777d276c321..c61b0f06af8193b8724e5e1d6b51a36b8c14ed52 100644 (file)
@@ -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)
index 76f0586f3fcf6d714114366bfdd4c80bec024d4f..a967518550e594006e06d24ded0ebbe16157605c 100644 (file)
@@ -1,8 +1,4 @@
-#include "store/store.h"
-#include "reader/reader.h"
-#include "visitor/visitor.h"
-
-#include <iostream>
+#include "store/store.ih"
 
 namespace odc {
 
diff --git a/store/store.ih b/store/store.ih
new file mode 100644 (file)
index 0000000..6e2fab4
--- /dev/null
@@ -0,0 +1,5 @@
+#include "store/store.h"
+#include "reader/reader.h"
+#include "visitor/visitor.h"
+
+#include <iostream>
index 720654a1492e4def31ba5da0b330a8e689ed7ca3..aa2819304f10de7203ad066ac47d8983100f85ac 100644 (file)
@@ -1,8 +1,4 @@
-#include "textmodel/textmodel.h"
-#include "reader/reader.h"
-
-#include <vector>
-#include <assert.h>
+#include "textmodel/textmodel.ih"
 
 namespace odc {
 
diff --git a/textmodel/textmodel.ih b/textmodel/textmodel.ih
new file mode 100644 (file)
index 0000000..d3fe086
--- /dev/null
@@ -0,0 +1,5 @@
+#include "textmodel/textmodel.h"
+#include "reader/reader.h"
+
+#include <vector>
+#include <assert.h>
index 91120c6b6c504f116207aebab59cce3a4d5d543a..0093b9a0618b929c9f887cc5cbbdaab7965f1742 100644 (file)
@@ -1,6 +1,4 @@
-#include "typeregister/typeregister.h"
-
-#include <iostream>
+#include "typeregister/typeregister.ih"
 
 namespace odc {
 
diff --git a/typeregister/typeregister.ih b/typeregister/typeregister.ih
new file mode 100644 (file)
index 0000000..6de1205
--- /dev/null
@@ -0,0 +1,3 @@
+#include "typeregister/typeregister.h"
+
+#include <iostream>