You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

depend.mk 2.4KB

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