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