DEADSOFTWARE

Cleaner clean
[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 # This rule build an object (.o) from a source (.cc).
22 %.o: %.cc
23 g++ $(CFLAGS) $< -c -o $@
25 # For each implementation header (.ih) generate a dependency (.d) file which
26 # will ensure that the compiled header (.ih.gch) is rebuilt whenever the header
27 # files included by the .ih are updated.
28 # The options given to GCC for this are as follows:
29 # -MM : calculate dependencies, but exclude system headers
30 # -MF : output dependencies to the given file
31 # -MP : generate "header.h:" rules to avoid errors on deletion of headers
32 # -MT : the main rule has the given target (to handle subdirs correctly)
33 # The .d file is not an explicit target because it will need to be (re-)built
34 # if and only if the .ih.gch needs to be rebuilt.
35 %.ih.gch: %.ih
36 g++ $(CFLAGS) -x c++-header $< -MM -MF $*.d -MP -MT $@
37 g++ $(CFLAGS) -x c++-header $< -o $@
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))module.ih.gch
44 endef
45 $(foreach src,$(SRCS),$(eval $(call depend_on_compiled_header,$(src))))
47 clean:
48 rm -f */*.o */module.d */module.ih.gch
50 dist-clean: clean
51 rm -f odcread
52 # Include the generated dependency files (if they exist)
53 -include $(patsubst %,%/module.d,$(MODULES))