DEADSOFTWARE

fix gcc 4.0
[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 CXXFLAGS = -I.
10 CXX = g++
12 # Variables for the modules to write to
13 SRCS :=
15 # Include module definitions
16 include $(patsubst %,%/Make.inc,$(MODULES))
18 # This rule just links the object files together
19 odcread: $(SRCS:.cc=.o)
20 $(CXX) -liconv -o $@ $^
22 # This rule build an object (.o) from a source (.cc).
23 %.o: %.cc
24 $(CXX) $(CXXFLAGS) $< -c -o $@
26 # For each implementation header (.ih) generate a dependency (.d) file which
27 # will ensure that the compiled header (.ih.gch) is rebuilt whenever the header
28 # files included by the .ih are updated.
29 # The options given to GCC for this are as follows:
30 # -MM : calculate dependencies, but exclude system headers
31 # -MF : output dependencies to the given file
32 # -MP : generate "header.h:" rules to avoid errors on deletion of headers
33 # -MT : the main rule has the given target (to handle subdirs correctly)
34 # The .d file is not an explicit target because it will need to be (re-)built
35 # if and only if the .ih.gch needs to be rebuilt.
36 %.ih.gch: %.ih
37 $(CXX) $(CXXFLAGS) -x c++-header $< -MM -MF $*.d -MP -MT $@
38 $(CXX) $(CXXFLAGS) -x c++-header $< -o $@
40 # Each module has a .ih file that should be *the only* include from the .cc
41 # files. These .ih files are pre-compiled to .ih.gch, and dependency caching
42 # is based on the .ih files, not the .cc files.
43 define depend_on_compiled_header
44 $(patsubst %.cc,%.o,$(1)) : $(dir $(1))module.ih.gch
45 endef
46 $(foreach src,$(SRCS),$(eval $(call depend_on_compiled_header,$(src))))
48 clean:
49 rm -f */*.o */module.d */module.ih.gch
51 dist-clean: clean
52 rm -f odcread
53 # Include the generated dependency files (if they exist)
54 -include $(patsubst %,%/module.d,$(MODULES))