DEADSOFTWARE

Precompile .ih files and cache dependencies based on .ih files
[odcread.git] / Makefile
1 # Modules, each containing:
2 # * $(MODULE)/Make.inc -- makefile include
3 # * $(MODULE)/$(MODULE).h -- minimal "interface" header file
4 # * $(MODULE)/$(MODULE).ih -- internal/implementation header file
5 # (only to be included by sources within the module)
6 # * $(MODULE)/*.cc -- module source files
7 MODULES := main reader store alien typeregister textmodel fold typepath
9 CFLAGS := -I.
11 # Variables for the modules to write to
12 SRCS :=
14 # Include module definitions
15 include $(patsubst %,%/Make.inc,$(MODULES))
17 # This rule just links the object files together
18 odcread: $(SRCS:.cc=.o)
19 g++ -o $@ $^
21 %.o: %.cc
22 g++ $(CFLAGS) $< -c -o $@
24 # For each implementation header (.ih) generate a dependency (.d) file which
25 # will ensure that the compiled header (.ih.gch) is rebuilt whenever the header
26 # files included by the .ih are updated.
27 # The options given to GCC for this are as follows:
28 # -MM : calculate dependencies, but exclude system headers
29 # -MF : output dependencies to the given file
30 # -MP : generate "header.h:" rules to avoid errors on deletion of headers
31 # -MT : the main rule has the given target (to handle subdirs correctly)
32 # The .d file is not an explicit target because it will need to be (re-)built
33 # if and only if the .ih.gch needs to be rebuilt.
34 %.ih.gch: %.ih
35 g++ $(CFLAGS) -x c++-header $< -MM -MF $(dir $@)module.d -MP -MT $@
36 g++ $(CFLAGS) -x c++-header $< -o $@
38 # This rule build an object (.o) from a source (.cc).
39 # Each module has a .ih file that should be *the only* include from the .cc
40 # files. These .ih files are pre-compiled to .ih.gch, and dependency caching
41 # is based on the .ih files, not the .cc files.
42 define depend_on_compiled_header
43 $(patsubst %.cc,%.o,$(1)) : $(dir $(1))$(patsubst %/,%,$(dir $(1))).ih.gch
44 endef
45 $(foreach src,$(SRCS),$(eval $(call depend_on_compiled_header,$(src))))
47 clean:
48 rm -f odcread *.o */*.o */*.d */*.ih.gch
50 # Include the generated dependency files (if they exist)
51 -include $(patsubst %,%/module.d,$(MODULES))
53 # TODO: rename all %/%.ih files to %/module.ih for simplicity of matching rules