1# $Id: bsd.dep.mk,v 1.24 1998/05/15 09:34:48 bde Exp $ 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 31MKDEPCMD?= mkdep 32DEPENDFILE?= .depend 33 34.if defined(SRCS) 35CLEANFILES?= 36 37.for _LSRC in ${SRCS:M*.l:N*/*} 38.for _LC in ${_LSRC:S/.l/.c/} 39${_LC}: ${_LSRC} 40 ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} 41SRCS:= ${SRCS:S/${_LSRC}/${_LC}/} 42CLEANFILES:= ${CLEANFILES} ${_LC} 43.endfor 44.endfor 45 46.for _YSRC in ${SRCS:M*.y:N*/*} 47.for _YC in ${_YSRC:S/.y/.c/} 48SRCS:= ${SRCS:S/${_YSRC}/${_YC}/} 49CLEANFILES:= ${CLEANFILES} ${_YC} 50.if ${YFLAGS:M-d} != "" && ${SRCS:My.tab.h} 51.ORDER: ${_YC} y.tab.h 52${_YC} y.tab.h: ${_YSRC} 53 ${YACC} ${YFLAGS} ${.ALLSRC} 54 cp y.tab.c ${_YC} 55SRCS:= ${SRCS} y.tab.h 56CLEANFILES:= ${CLEANFILES} y.tab.c y.tab.h 57.elif ${YFLAGS:M-d} != "" 58.for _YH in ${_YC:S/.c/.h/} 59.ORDER: ${_YC} ${_YH} 60${_YC} ${_YH}: ${_YSRC} 61 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 62SRCS:= ${SRCS} ${_YH} 63CLEANFILES:= ${CLEANFILES} ${_YH} 64.endfor 65.else 66${_YC}: ${_YSRC} 67 ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 68.endif 69.endfor 70.endfor 71.endif 72 73.if !target(depend) 74.if defined(SRCS) 75depend: beforedepend ${DEPENDFILE} afterdepend _SUBDIR 76 77# Different types of sources are compiled with slightly different flags. 78# Split up the sources, and filter out headers and non-applicable flags. 79${DEPENDFILE}: ${SRCS} 80 rm -f ${DEPENDFILE} 81.if ${SRCS:M*.[sS]} != "" 82 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 83 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 84 ${AINC} \ 85 ${.ALLSRC:M*.[sS]} 86.endif 87.if ${SRCS:M*.c} != "" 88 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 89 ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BID]*} \ 90 ${.ALLSRC:M*.c} 91.endif 92.if ${SRCS:M*.cc} != "" || ${SRCS:M*.C} != "" || ${SRCS:M*.cpp} != "" || \ 93 ${SRCS:M*.cxx} != "" 94 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 95 ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BID]*} \ 96 ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} 97.endif 98.if ${SRCS:M*.m} != "" 99 ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 100 ${OBJCFLAGS:M-nostdinc*} ${OBJCFLAGS:M-[BID]*} \ 101 ${OBJCFLAGS:M-Wno-import*} \ 102 ${.ALLSRC:M*.m} 103.endif 104.if target(_EXTRADEPEND) 105 cd ${.CURDIR}; ${MAKE} _EXTRADEPEND 106.endif 107 108.ORDER: ${DEPENDFILE} afterdepend 109.else 110depend: beforedepend afterdepend _SUBDIR 111.endif 112.if !target(beforedepend) 113beforedepend: 114.else 115.ORDER: beforedepend ${DEPENDFILE} 116.ORDER: beforedepend afterdepend 117.endif 118.if !target(afterdepend) 119afterdepend: 120.endif 121.endif 122 123.if defined(NOTAGS) 124tags: 125.endif 126 127.if !target(tags) 128tags: ${SRCS} _SUBDIR 129 @cd ${.CURDIR} && gtags ${GTAGSFLAGS} ${.OBJDIR} 130.if defined(HTML) 131 @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR} 132.endif 133.endif 134 135.if !target(cleandepend) 136cleandepend: _SUBDIR 137.if defined(SRCS) 138 rm -f ${DEPENDFILE} ${.OBJDIR}/GRTAGS ${.OBJDIR}/GSYMS ${.OBJDIR}/GTAGS 139.if defined(HTML) 140 rm -rf ${.OBJDIR}/HTML 141.endif 142.endif 143.endif 144