bsd.dep.mk revision 94841
1# $FreeBSD: head/share/mk/bsd.dep.mk 94841 2002-04-16 12:27:07Z ru $ 2# 3# The include file <bsd.dep.mk> handles Makefile dependencies. 4# 5# 6# +++ variables +++ 7# 8# DEPENDFILE dependencies file [.depend] 9# 10# MKDEP Options for ${MKDEPCMD} [not set] 11# 12# MKDEPCMD Makefile dependency list program [mkdep] 13# 14# SRCS List of source files (c, c++, assembler) 15# 16# 17# +++ targets +++ 18# 19# cleandepend: 20# Remove depend and tags file 21# 22# depend: 23# Make the dependencies for the source files, and store 24# them in the file ${DEPENDFILE}. 25# 26# tags: 27# Create a (GLOBAL) gtags file for the source files. 28# If HTML is defined, htags is also run after gtags. 29 30 31.if ${CC} != "cc" 32MKDEPCMD?= CC=${CC} mkdep 33.else 34MKDEPCMD?= mkdep 35.endif 36DEPENDFILE?= .depend 37 38.if defined(SRCS) 39CLEANFILES?= 40 41.for _LSRC in ${SRCS:M*.l:N*/*} 42.for _LC in ${_LSRC:S/.l/.c/} 43${_LC}: ${_LSRC} 44 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} 45SRCS:= ${SRCS:S/${_LSRC}/${_LC}/} 46CLEANFILES:= ${CLEANFILES} ${_LC} 47.endfor 48.endfor 49 50.for _YSRC in ${SRCS:M*.y:N*/*} 51.for _YC in ${_YSRC:S/.y/.c/} 52SRCS:= ${SRCS:S/${_YSRC}/${_YC}/} 53CLEANFILES:= ${CLEANFILES} ${_YC} 54.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h} 55.ORDER: ${_YC} y.tab.h 56${_YC} y.tab.h: ${_YSRC} 57 ${YACC} ${YFLAGS} ${.ALLSRC} 58 cp y.tab.c ${_YC} 59SRCS:= ${SRCS} y.tab.h 60CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h 61.elif ${YFLAGS:M-d} != "" 62.for _YH in ${_YC:S/.c/.h/} 63.ORDER: ${_YC} ${_YH} 64${_YC} ${_YH}: ${_YSRC} 65 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 66SRCS:= ${SRCS} ${_YH} 67CLEANFILES:= ${CLEANFILES} ${_YH} 68.endfor 69.else 70${_YC}: ${_YSRC} 71 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 72.endif 73.endfor 74.endfor 75.endif 76 77.if !target(depend) 78.if defined(SRCS) 79depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIR 80 81# Different types of sources are compiled with slightly different flags. 82# Split up the sources, and filter out headers and non-applicable flags. 83${DEPENDFILE}: _MKDEP 84_MKDEP: ${SRCS} 85 rm -f ${DEPENDFILE} 86.if ${SRCS:M*.[sS]} != "" 87 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 88 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 89 ${AINC} \ 90 ${.ALLSRC:M*.[sS]} 91.endif 92.if ${SRCS:M*.c} != "" 93 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 94 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 95 ${.ALLSRC:M*.c} 96.endif 97.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \ 98 ${SRCS:M*.cxx} != "" 99 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 100 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \ 101 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} 102.endif 103.if ${SRCS:M*.m} != "" 104 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 105 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \ 106 ${OBJCFLAGS:M-Wno-import*} \ 107 ${.ALLSRC:M*.m} 108.endif 109.if target(_EXTRADEPEND) 110${DEPENDFILE}: _EXTRADEPEND 111.ORDER: _MKDEP _EXTRADEPEND 112.endif 113 114.ORDER: ${DEPENDFILE} afterdepend 115.else 116depend: beforedepend afterdepend _SUBDIR 117.endif 118.if !target(beforedepend) 119beforedepend: 120.else 121.ORDER: beforedepend ${DEPENDFILE} 122.ORDER: beforedepend afterdepend 123.endif 124.if !target(afterdepend) 125afterdepend: 126.endif 127.endif 128 129.if defined(NOTAGS) 130tags: 131.endif 132 133.if !target(tags) 134tags: ${SRCS} _SUBDIR 135 @cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR} 136.if defined(HTML) 137 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR} 138.endif 139.endif 140 141.if !target(cleandepend) 142cleandepend: _SUBDIR 143.if defined(SRCS) 144 rm -f ${DEPENDFILE} ${.OBJDIR}/GPATH ${.OBJDIR}/GRTAGS \ 145 ${.OBJDIR}/GSYMS ${.OBJDIR}/GTAGS 146.if defined(HTML) 147 rm -rf ${.OBJDIR}/HTML 148.endif 149.endif 150.endif 151