bsd.dep.mk revision 220755
167754Smsmith# $FreeBSD: head/share/mk/bsd.dep.mk 220755 2011-04-17 21:03:23Z dim $ 267754Smsmith# 367754Smsmith# The include file <bsd.dep.mk> handles Makefile dependencies. 483174Smsmith# 567754Smsmith# 667754Smsmith# +++ variables +++ 767754Smsmith# 867754Smsmith# CTAGS A tags file generation program [gtags] 967754Smsmith# 1067754Smsmith# CTAGSFLAGS Options for ctags(1) [not set] 1167754Smsmith# 1271867Smsmith# DEPENDFILE dependencies file [.depend] 1370243Smsmith# 1467754Smsmith# GTAGSFLAGS Options for gtags(1) [-o] 1567754Smsmith# 1667754Smsmith# HTAGSFLAGS Options for htags(1) [not set] 1767754Smsmith# 1867754Smsmith# MKDEP Options for ${MKDEPCMD} [not set] 1967754Smsmith# 2067754Smsmith# MKDEPCMD Makefile dependency list program [mkdep] 2167754Smsmith# 2267754Smsmith# SRCS List of source files (c, c++, assembler) 2367754Smsmith# 2467754Smsmith# DPSRCS List of source files which are needed for generating 2567754Smsmith# dependencies, ${SRCS} are always part of it. 2667754Smsmith# 2767754Smsmith# +++ targets +++ 2867754Smsmith# 2967754Smsmith# cleandepend: 3067754Smsmith# Remove depend and tags file 3167754Smsmith# 3267754Smsmith# depend: 3367754Smsmith# Make the dependencies for the source files, and store 3467754Smsmith# them in the file ${DEPENDFILE}. 3567754Smsmith# 3667754Smsmith# tags: 3767754Smsmith# In "ctags" mode, create a tags file for the source files. 3867754Smsmith# In "gtags" mode, create a (GLOBAL) gtags file for the 3967754Smsmith# source files. If HTML is defined, htags(1) is also run 4067754Smsmith# after gtags(1). 4167754Smsmith 4267754Smsmith.if !target(__<bsd.init.mk>__) 4367754Smsmith.error bsd.dep.mk cannot be included directly. 4467754Smsmith.endif 4567754Smsmith 4667754SmsmithCTAGS?= gtags 4767754SmsmithCTAGSFLAGS?= 4867754SmsmithGTAGSFLAGS?= -o 4967754SmsmithHTAGSFLAGS?= 5067754Smsmith 5167754Smsmith.if ${CC} != "cc" 5267754SmsmithMKDEPCMD?= CC='${CC}' mkdep 5367754Smsmith.else 5467754SmsmithMKDEPCMD?= mkdep 5567754Smsmith.endif 5667754SmsmithDEPENDFILE?= .depend 5767754Smsmith 5867754Smsmith# Keep `tags' here, before SRCS are mangled below for `depend'. 5967754Smsmith.if !target(tags) && defined(SRCS) && !defined(NO_TAGS) 6067754Smsmithtags: ${SRCS} 6167754Smsmith.if ${CTAGS:T} == "gtags" 6267754Smsmith @cd ${.CURDIR} && ${CTAGS} ${GTAGSFLAGS} ${.OBJDIR} 6367754Smsmith.if defined(HTML) 6467754Smsmith @cd ${.CURDIR} && htags ${HTAGSFLAGS} -d ${.OBJDIR} ${.OBJDIR} 6567754Smsmith.endif 6667754Smsmith.else 6767754Smsmith @${CTAGS} ${CTAGSFLAGS} -f /dev/stdout \ 6867754Smsmith ${.ALLSRC:N*.h} | sed "s;${.CURDIR}/;;" > ${.TARGET} 6967754Smsmith.endif 7067754Smsmith.endif 7167754Smsmith 7267754Smsmith.if defined(SRCS) 7367754SmsmithCLEANFILES?= 7467754Smsmith 7567754Smsmith.if !exists(${.OBJDIR}/${DEPENDFILE}) 7667754Smsmith.for _S in ${SRCS:N*.[hly]} 7767754Smsmith${_S:R}.o: ${_S} 7867754Smsmith.endfor 7967754Smsmith.endif 8067754Smsmith 8167754Smsmith.for _LSRC in ${SRCS:M*.l:N*/*} 8267754Smsmith.for _LC in ${_LSRC:R}.c 8367754Smsmith${_LC}: ${_LSRC} 8467754Smsmith ${LEX} -t ${LFLAGS} ${.ALLSRC} > ${.TARGET} 8567754Smsmith.if !exists(${.OBJDIR}/${DEPENDFILE}) 8667754Smsmith${_LC:R}.o: ${_LC} 8767754Smsmith.endif 8867754SmsmithSRCS:= ${SRCS:S/${_LSRC}/${_LC}/} 8967754SmsmithCLEANFILES+= ${_LC} 9067754Smsmith.endfor 9167754Smsmith.endfor 9267754Smsmith 9367754Smsmith.for _YSRC in ${SRCS:M*.y:N*/*} 9467754Smsmith.for _YC in ${_YSRC:R}.c 9567754SmsmithSRCS:= ${SRCS:S/${_YSRC}/${_YC}/} 9667754SmsmithCLEANFILES+= ${_YC} 9767754Smsmith.if !empty(YFLAGS:M-d) && !empty(SRCS:My.tab.h) 9867754Smsmith.ORDER: ${_YC} y.tab.h 9967754Smsmith${_YC} y.tab.h: ${_YSRC} 10067754Smsmith ${YACC} ${YFLAGS} ${.ALLSRC} 10167754Smsmith cp y.tab.c ${_YC} 10267754SmsmithCLEANFILES+= y.tab.c y.tab.h 10367754Smsmith.elif !empty(YFLAGS:M-d) 10467754Smsmith.for _YH in ${_YC:R}.h 10567754Smsmith.ORDER: ${_YC} ${_YH} 10667754Smsmith${_YC} ${_YH}: ${_YSRC} 10767754Smsmith ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 10867754SmsmithSRCS+= ${_YH} 10967754SmsmithCLEANFILES+= ${_YH} 11067754Smsmith.endfor 11167754Smsmith.else 11267754Smsmith${_YC}: ${_YSRC} 11367754Smsmith ${YACC} ${YFLAGS} -o ${_YC} ${.ALLSRC} 11467754Smsmith.endif 11567754Smsmith.if !exists(${.OBJDIR}/${DEPENDFILE}) 11667754Smsmith${_YC:R}.o: ${_YC} 11767754Smsmith.endif 11867754Smsmith.endfor 11967754Smsmith.endfor 12067754Smsmith.endif 12167754Smsmith 12267754Smsmith.if !target(depend) 12367754Smsmith.if defined(SRCS) 12467754Smsmithdepend: beforedepend ${DEPENDFILE} afterdepend 12567754Smsmith 12682367Smsmith# Different types of sources are compiled with slightly different flags. 12767754Smsmith# Split up the sources, and filter out headers and non-applicable flags. 12877424Smsmith.if ${CC:T:Micc} == "icc" 12977424SmsmithMKDEP_CFLAGS= ${CFLAGS:M-X*} ${CFLAGS:M-[BIDU]*} 13077424SmsmithMKDEP_CXXFLAGS= ${CXXFLAGS:M-X*} ${CXXFLAGS:M-[BIDU]*} 13177424Smsmith.else 13277424SmsmithMKDEP_CFLAGS= ${CFLAGS:M-nostdinc*} ${CFLAGS:M-[BIDU]*} 13377424SmsmithMKDEP_CXXFLAGS= ${CXXFLAGS:M-nostdinc*} ${CXXFLAGS:M-[BIDU]*} 13477424Smsmith.endif 13577424Smsmith 13677424SmsmithDPSRCS+= ${SRCS} 13778986Smsmith${DEPENDFILE}: ${DPSRCS} 13878986Smsmith rm -f ${DEPENDFILE} 13967754Smsmith.if !empty(DPSRCS:M*.[cS]) 14080062Smsmith ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 14180062Smsmith ${MKDEP_CFLAGS} ${.ALLSRC:M*.[cS]} 14280062Smsmith.endif 14380062Smsmith.if !empty(DPSRCS:M*.cc) || !empty(DPSRCS:M*.C) || !empty(DPSRCS:M*.cpp) || \ 14480062Smsmith !empty(DPSRCS:M*.cxx) 14580062Smsmith ${MKDEPCMD} -f ${DEPENDFILE} -a ${MKDEP} \ 14680062Smsmith ${MKDEP_CXXFLAGS} \ 14780062Smsmith ${.ALLSRC:M*.cc} ${.ALLSRC:M*.C} ${.ALLSRC:M*.cpp} ${.ALLSRC:M*.cxx} 14880062Smsmith.endif 14980062Smsmith.if target(_EXTRADEPEND) 15067754Smsmith_EXTRADEPEND: .USE 15180062Smsmith${DEPENDFILE}: _EXTRADEPEND 15267754Smsmith.endif 15377424Smsmith 15467754Smsmith.ORDER: ${DEPENDFILE} afterdepend 15567754Smsmith.else 15677424Smsmithdepend: beforedepend afterdepend 15777424Smsmith.endif 15867754Smsmith.if !target(beforedepend) 15977424Smsmithbeforedepend: 16082367Smsmith.else 16182367Smsmith.ORDER: beforedepend ${DEPENDFILE} 16282367Smsmith.ORDER: beforedepend afterdepend 16382367Smsmith.endif 16482367Smsmith.if !target(afterdepend) 16582367Smsmithafterdepend: 16682367Smsmith.endif 16782367Smsmith.endif 16882367Smsmith 16982367Smsmith.if !target(cleandepend) 17082367Smsmithcleandepend: 17182367Smsmith.if defined(SRCS) 17282367Smsmith.if ${CTAGS:T} == "gtags" 17383174Smsmith rm -f ${DEPENDFILE} GPATH GRTAGS GSYMS GTAGS 17482367Smsmith.if defined(HTML) 17583174Smsmith rm -rf HTML 17683174Smsmith.endif 17783174Smsmith.else 17883174Smsmith rm -f ${DEPENDFILE} tags 17983174Smsmith.endif 18083174Smsmith.endif 18183174Smsmith.endif 18283174Smsmith 18383174Smsmith.if !target(checkdpadd) && (defined(DPADD) || defined(LDADD)) 18483174Smsmith_LDADD_FROM_DPADD= ${DPADD:C;^/usr/lib/lib(.*)\.a$;-l\1;} 18583174Smsmith_LDADD_CANONICALIZED= ${LDADD:S/$//} 18683174Smsmithcheckdpadd: 18783174Smsmith.if ${_LDADD_FROM_DPADD} != ${_LDADD_CANONICALIZED} 18883174Smsmith @echo ${.CURDIR} 18983174Smsmith @echo "DPADD -> ${_LDADD_FROM_DPADD}" 19083174Smsmith @echo "LDADD -> ${_LDADD_CANONICALIZED}" 19183174Smsmith.endif 19283174Smsmith.endif 19382367Smsmith