/share/mk/bsd.dep.mk

https://bitbucket.org/freebsd/freebsd-head/ · Makefile · 192 lines · 133 code · 15 blank · 44 comment · 14 complexity · adbb9973b4fa692a3e8928a896342f61 MD5 · raw file

  1. # $FreeBSD$
  2. #
  3. # The include file <bsd.dep.mk> handles Makefile dependencies.
  4. #
  5. #
  6. # +++ variables +++
  7. #
  8. # CTAGS A tags file generation program [gtags]
  9. #
  10. # CTAGSFLAGS Options for ctags(1) [not set]
  11. #
  12. # DEPENDFILE dependencies file [.depend]
  13. #
  14. # GTAGSFLAGS Options for gtags(1) [-o]
  15. #
  16. # HTAGSFLAGS Options for htags(1) [not set]
  17. #
  18. # MKDEP Options for ${MKDEPCMD} [not set]
  19. #
  20. # MKDEPCMD Makefile dependency list program [mkdep]
  21. #
  22. # SRCS List of source files (c, c++, assembler)
  23. #
  24. # DPSRCS List of source files which are needed for generating
  25. # dependencies, ${SRCS} are always part of it.
  26. #
  27. # +++ targets +++
  28. #
  29. # cleandepend:
  30. # Remove depend and tags file
  31. #
  32. # depend:
  33. # Make the dependencies for the source files, and store
  34. # them in the file ${DEPENDFILE}.
  35. #
  36. # tags:
  37. # In "ctags" mode, create a tags file for the source files.
  38. # In "gtags" mode, create a (GLOBAL) gtags file for the
  39. # source files. If HTML is defined, htags(1) is also run
  40. # after gtags(1).
  41. .if !target(__<bsd.init.mk>__)
  42. .error bsd.dep.mk cannot be included directly.
  43. .endif
  44. CTAGS?= gtags
  45. CTAGSFLAGS?=
  46. GTAGSFLAGS?= -o
  47. HTAGSFLAGS?=
  48. .if ${CC} != "cc"
  49. MKDEPCMD?= CC='${CC}' mkdep
  50. .else
  51. MKDEPCMD?= mkdep
  52. .endif
  53. DEPENDFILE?= .depend
  54. # Keep `tags' here, before SRCS are mangled below for `depend'.
  55. .if !target(tags) && defined(SRCS) && !defined(NO_TAGS)
  56. tags: ${SRCS}
  57. .if ${CTAGS:T} == "gtags"
  58. @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR}
  59. .if defined(HTML)
  60. @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR}
  61. .endif
  62. .else
  63. @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \
  64. ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET}
  65. .endif
  66. .endif
  67. .if defined(SRCS)
  68. CLEANFILES?=
  69. .if !exists(${.OBJDIR}/${DEPENDFILE})
  70. .for _S in ${SRCS:N*.[hly]}
  71. ${_S:R}.o: ${_S}
  72. .endfor
  73. .endif
  74. .for _LSRC in ${SRCS:M*.l:N*/*}
  75. .for _LC in ${_LSRC:R}.c
  76. ${_LC}: ${_LSRC}
  77. ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET}
  78. .if !exists(${.OBJDIR}/${DEPENDFILE})
  79. ${_LC:R}.o: ${_LC}
  80. .endif
  81. SRCS:= ${SRCS:S/${_LSRC}/${_LC}/}
  82. CLEANFILES+= ${_LC}
  83. .endfor
  84. .endfor
  85. .for _YSRC in ${SRCS:M*.y:N*/*}
  86. .for _YC in ${_YSRC:R}.c
  87. SRCS:= ${SRCS:S/${_YSRC}/${_YC}/}
  88. CLEANFILES+= ${_YC}
  89. .if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h)
  90. .ORDER: ${_YC} y.tab.h
  91. ${_YC} y.tab.h: ${_YSRC}
  92. ${YACC} ${YFLAGS} ${.ALLSRC}
  93. cp y.tab.c ${_YC}
  94. CLEANFILES+= y.tab.c y.tab.h
  95. .elif !empty(YFLAGS:M-d)
  96. .for _YH in ${_YC:R}.h
  97. ${_YH}: ${_YC}
  98. ${_YC}: ${_YSRC}
  99. ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
  100. SRCS+= ${_YH}
  101. CLEANFILES+= ${_YH}
  102. .endfor
  103. .else
  104. ${_YC}: ${_YSRC}
  105. ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC}
  106. .endif
  107. .if !exists(${.OBJDIR}/${DEPENDFILE})
  108. ${_YC:R}.o: ${_YC}
  109. .endif
  110. .endfor
  111. .endfor
  112. .endif
  113. .if !target(depend)
  114. .if defined(SRCS)
  115. depend: beforedepend ${DEPENDFILE} afterdepend
  116. # Tell bmake not to look for generated files via .PATH
  117. .NOPATH: ${DEPENDFILE}
  118. # Different types of sources are compiled with slightly different flags.
  119. # Split up the sources, and filter out headers and non-applicable flags.
  120. MKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} ${CFLAGS:M-std=*} \
  121. ${CFLAGS:M-ansi}
  122. MKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} \
  123. ${CXXFLAGS:M-std=*} ${CXXFLAGS:M-ansi} ${CXXFLAGS:M-stdlib=*}
  124. DPSRCS+= ${SRCS}
  125. ${DEPENDFILE}: ${DPSRCS}
  126. rm -f ${DEPENDFILE}
  127. .if !empty(DPSRCS:M*.[cS])
  128. ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
  129. ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]}
  130. .endif
  131. .if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \
  132. !empty(DPSRCS:M*.cxx)
  133. ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \
  134. ${MKDEP_CXXFLAGS} \
  135. ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx}
  136. .endif
  137. .if target(_EXTRADEPEND)
  138. _EXTRADEPEND: .USE
  139. ${DEPENDFILE}: _EXTRADEPEND
  140. .endif
  141. .ORDER: ${DEPENDFILE} afterdepend
  142. .else
  143. depend: beforedepend afterdepend
  144. .endif
  145. .if !target(beforedepend)
  146. beforedepend:
  147. .else
  148. .ORDER: beforedepend ${DEPENDFILE}
  149. .ORDER: beforedepend afterdepend
  150. .endif
  151. .if !target(afterdepend)
  152. afterdepend:
  153. .endif
  154. .endif
  155. .if !target(cleandepend)
  156. cleandepend:
  157. .if defined(SRCS)
  158. .if ${CTAGS:T} == "gtags"
  159. rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS
  160. .if defined(HTML)
  161. rm -rf HTML
  162. .endif
  163. .else
  164. rm -f ${DEPENDFILE} tags
  165. .endif
  166. .endif
  167. .endif
  168. .if !target(checkdpadd) && (defined(DPADD) || defined(LDADD))
  169. _LDADD_FROM_DPADD= ${DPADD:C;^/usr/lib/lib(.*)\.a$;-l\1;}
  170. _LDADD_CANONICALIZED= ${LDADD:S/$//}
  171. checkdpadd:
  172. .if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED}
  173. @echo ${.CURDIR}
  174. @echo "DPADD -> ${_LDADD_FROM_DPADD}"
  175. @echo "LDADD -> ${_LDADD_CANONICALIZED}"
  176. .endif
  177. .endif