blob: 51d4cd636a8c00bfa11585b76cf57630d9bcd371 [file] [log] [blame]
Constantin Kaplinsky0bb538b2006-05-30 06:05:33 +00001#
2# C / C++ header dependency stuff
3#
4# Needs GNU make and vncmkdepend, a hacked version of makedepend
5
6.SUFFIXES: .d
7
8CMAKEDEPEND = vncmkdepend
9CXXMAKEDEPEND = vncmkdepend
10
11#
12# The recommended method of doing dependency analysis in the GNU make manual
13# turns out to be painfully slow. This method is similar but it's
14# substantially faster and retains the desirable property that the user doesn't
15# need to manually invoke a "make depend" step.
16#
17# As with the method described in the manual, we generate a separate dependency
18# (.d) file for each source file. The .d file records the header files that
19# each C or C++ source file includes. Any source file recorded in SRCS or
20# CXXSRCS will cause us to try and include the corresponding .d file and GNU
21# make then treats each .d file as a target to be remade.
22#
23# Unlike the manual's method, the rule we provide for making the .d file is
24# actually a fake. All it does is record in a temporary file that the .d file
25# needs to be remade. But as well as all the .d files, we also try to include
26# a file called "depend.phony". This file never exists, but it causes GNU make
27# to try and make the target "depend.phony". The rule for depend.phony then
28# looks at the temporary files generated by the .d rules and then invokes the
29# "omkdepend" program on all of the source files in one go.
30#
31
32#
33# We use simple assignment here to remove any of the depend.tmp files
34# at the time make parses this bit.
35#
36
37dummyvariable := $(shell $(RM) cdepend.tmp cxxdepend.tmp)
38
39#
40# Now the "fake" rules for generating .d files.
41#
42
43%.d: %.c
44 @echo "$<" >> cdepend.tmp
45
46%.d: %.cxx
47 @echo "$<" >> cxxdepend.tmp
48
49#
50# The depend.phony rule which actually runs omkdepend.
51#
52
53depend.phony:
54 @if [ -f cdepend.tmp ]; then \
55 echo $(CMAKEDEPEND) $(ALL_CPPFLAGS) `cat cdepend.tmp`; \
56 $(CMAKEDEPEND) $(ALL_CPPFLAGS) `cat cdepend.tmp`; \
57 rm -f cdepend.tmp; \
58 fi; \
59 if [ -f cxxdepend.tmp ]; then \
60 echo $(CXXMAKEDEPEND) $(ALL_CPPFLAGS) `cat cxxdepend.tmp`; \
61 $(CXXMAKEDEPEND) $(ALL_CPPFLAGS) `cat cxxdepend.tmp`; \
62 rm -f cxxdepend.tmp; \
63 fi
64
65#
66# Now include the .d files and the "depend.phony" file which never exists.
67# For some reason GNU make evaluates the targets in reverse order, so we need
68# to include depend.phony first. The "-" tells make not to complain that it
69# can't find the file.
70#
71
72-include depend.phony
73
74ifdef SRCS
75-include $(patsubst %.c,%.d,$(patsubst %.cxx,%.d,$(SRCS)))
76endif