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# 25# +++ targets +++ 26# 27# cleandepend: 28# Remove depend and tags file 29# 30# depend: 31# Make the dependencies for the source files, and store 32# them in the file ${DEPENDFILE}. 33# 34# tags: 35# In "ctags" mode, create a tags file for the source files. 36# In "gtags" mode, create a (GLOBAL) gtags file for the 37# source files. If HTML is defined, htags(1) is also run 38# after gtags(1). 39 40.if !target(__<bsd.init.mk>__) 41.error bsd.dep.mk cannot be included directly. 42.endif 43 44CTAGS?= gtags 45CTAGSFLAGS?= 46GTAGSFLAGS?= -o 47HTAGSFLAGS?= 48 49.if ${CC} != "cc" 50MKDEPCMD?= CC='${CC}' mkdep 51.else 52MKDEPCMD?= mkdep 53.endif 54DEPENDFILE?= .depend 55 56# Keep `tags' here, before SRCS are mangled below for `depend'. 57.if !target(tags) && defined(SRCS) && !defined(NOTAGS) 58tags: ${SRCS} 59.if ${CTAGS:T} == "ctags" 60 @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \ 61 ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET} 62.elif ${CTAGS:T} == "gtags" 63 @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR} 64.if defined(HTML) 65 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR} 66.endif 67.endif 68.endif 69 70.if defined(SRCS) 71CLEANFILES?= 72 73.for _LSRC in ${SRCS:M*.l:N*/*} 74.for _LC in ${_LSRC:S/.l/.c/} 75${_LC}: ${_LSRC} 76 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} 77SRCS:= ${SRCS:S/${_LSRC}/${_LC}/} 78CLEANFILES:= ${CLEANFILES} ${_LC} 79.endfor 80.endfor 81 82.for _YSRC in ${SRCS:M*.y:N*/*} 83.for _YC in ${_YSRC:S/.y/.c/} 84SRCS:= ${SRCS:S/${_YSRC}/${_YC}/} 85CLEANFILES:= ${CLEANFILES} ${_YC} 86.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h} 87.ORDER: ${_YC} y.tab.h 88${_YC} y.tab.h: ${_YSRC} 89 ${YACC} ${YFLAGS} ${.ALLSRC} 90 cp y.tab.c ${_YC} 91SRCS:= ${SRCS} y.tab.h 92CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h 93.elif ${YFLAGS:M-d} != "" 94.for _YH in ${_YC:S/.c/.h/} 95.ORDER: ${_YC} ${_YH} 96${_YC} ${_YH}: ${_YSRC} 97 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 98SRCS:= ${SRCS} ${_YH} 99CLEANFILES:= ${CLEANFILES} ${_YH} 100.endfor 101.else 102${_YC}: ${_YSRC} 103 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 104.endif 105.endfor 106.endfor 107.endif 108 109.if !target(depend) 110.if defined(SRCS) 111depend: beforedepend ${DEPENDFILE} afterdepend 112 113# Different types of sources are compiled with slightly different flags. 114# Split up the sources, and filter out headers and non-applicable flags. 115${DEPENDFILE}: ${SRCS} 116 rm -f ${DEPENDFILE} 117.if ${SRCS:M*.[cS]} != "" 118 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 119 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 120 ${.ALLSRC:M*.[cS]} 121.endif 122.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \ 123 ${SRCS:M*.cxx} != "" 124 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 125 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \ 126 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} 127.endif 128.if ${SRCS:M*.m} != "" 129 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 130 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \ 131 ${OBJCFLAGS:M-Wno-import*} \ 132 ${.ALLSRC:M*.m} 133.endif 134.if target(_EXTRADEPEND) 135_EXTRADEPEND: .USE 136${DEPENDFILE}: _EXTRADEPEND 137.endif 138 139.ORDER: ${DEPENDFILE} afterdepend 140.else 141depend: beforedepend afterdepend 142.endif 143.if !target(beforedepend) 144beforedepend: 145.else 146.ORDER: beforedepend ${DEPENDFILE} 147.ORDER: beforedepend afterdepend 148.endif 149.if !target(afterdepend) 150afterdepend: 151.endif 152.endif 153 154.if !target(cleandepend) 155cleandepend: 156.if defined(SRCS) 157.if ${CTAGS:T} == "ctags" 158 rm -f ${DEPENDFILE} tags 159.elif ${CTAGS:T} == "gtags" 160 rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS 161.if defined(HTML) 162 rm -rf HTML 163.endif 164.endif 165.endif 166.endif 167 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/$//} 171checkdpadd: 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 178