bsd.obj.mk revision 76021
133965Sjdp# $FreeBSD: head/share/mk/bsd.obj.mk 76021 2001-04-26 11:14:50Z ru $ 2218822Sdim# 3218822Sdim# The include file <bsd.obj.mk> handles creating the 'obj' directory 433965Sjdp# and cleaning up object files, etc. 5104834Sobrien# 633965Sjdp# Under construction: it also contains the _SUBDIR target (which is used 7104834Sobrien# by most `mk' files to recurse into subdirectories) and defaults for the 8104834Sobrien# cleandepend, depend and tags targets. It may eventually be merged with 9104834Sobrien# with bsd.subdir.mk. 10104834Sobrien# 1133965Sjdp# +++ variables +++ 12104834Sobrien# 13104834Sobrien# CLEANDIRS Additional directories to remove for the clean target. 14104834Sobrien# 15104834Sobrien# CLEANFILES Additional files to remove for the clean target. 1633965Sjdp# 17104834Sobrien# MAKEOBJDIR A pathname for the directory where the targets 18104834Sobrien# are built. Note: MAKEOBJDIR is an *enviroment* variable 19218822Sdim# and works properly only if set as an enviroment variable, 2033965Sjdp# not as a global or command line variable! 21218822Sdim# 2233965Sjdp# E.g. use `env MAKEOBJDIR=temp-obj make' 2333965Sjdp# 24218822Sdim# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object 25218822Sdim# tree. Note: MAKEOBJDIRPREFIX is an *enviroment* variable 2633965Sjdp# and works properly only if set as an enviroment variable, 27218822Sdim# not as a global or command line variable! 28218822Sdim# 2933965Sjdp# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make' 30218822Sdim# 3160484Sobrien# NOOBJ Do not create object directories. This should not be set 3233965Sjdp# if anything is built. 3360484Sobrien# 34104834Sobrien# +++ targets +++ 35104834Sobrien# 36104834Sobrien# clean: 37104834Sobrien# remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents. 38218822Sdim# 39218822Sdim# cleandir: 40218822Sdim# remove the build directory (and all its contents) created by obj 41218822Sdim# 42218822Sdim# obj: 43218822Sdim# create build directory. 44104834Sobrien# 45104834Sobrien 46218822Sdim.if defined(MAKEOBJDIRPREFIX) 47218822SdimCANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} 4860484Sobrien.else 4960484SobrienCANONICALOBJDIR:=/usr/obj${.CURDIR} 5060484Sobrien.endif 51218822Sdim 52218822Sdim# 53218822Sdim# Warn of unorthodox object directory 54218822Sdim# 55218822Sdimobjwarn: 5660484Sobrien.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} 5733965Sjdp.if ${.OBJDIR} == ${.CURDIR} 58 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}" 59.elif !defined(MAKEOBJDIR) && !defined(MAKEOBJDIRPREFIX) 60 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\ 61 canonical ${CANONICALOBJDIR}" 62.endif 63.endif 64 65.if !target(obj) 66.if defined(NOOBJ) 67obj: 68.else 69obj: _SUBDIR 70 @if ! test -d ${CANONICALOBJDIR}/; then \ 71 mkdir -p ${CANONICALOBJDIR}; \ 72 if ! test -d ${CANONICALOBJDIR}/; then \ 73 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \ 74 exit 1; \ 75 fi; \ 76 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \ 77 fi 78.endif 79.endif 80 81.if !target(objlink) 82objlink: _SUBDIR 83 @if test -d ${CANONICALOBJDIR}/; then \ 84 rm -f ${.CURDIR}/obj; \ 85 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \ 86 else \ 87 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \ 88 fi 89.endif 90 91# 92# where would that obj directory be? 93# 94.if !target(whereobj) 95whereobj: 96 @echo ${.OBJDIR} 97.endif 98 99cleanobj: 100.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/) 101 @rm -rf ${CANONICALOBJDIR} 102.else 103 @cd ${.CURDIR} && ${MAKE} clean cleandepend 104.endif 105 @if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi 106 107.if !target(clean) 108clean: _SUBDIR 109.if defined(CLEANFILES) && !empty(CLEANFILES) 110 rm -f ${CLEANFILES} 111.endif 112.if defined(CLEANDIRS) && !empty(CLEANDIRS) 113 rm -rf ${CLEANDIRS} 114.endif 115.endif 116 117.if !target(checkdpadd) 118checkdpadd: _SUBDIR 119.if (defined(DPADD) || defined(LDADD)) 120checkdpadd: 121.if ${OBJFORMAT} != aout 122 @ldadd=`echo \`for lib in ${DPADD} ; do \ 123 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \ 124 done \`` ; \ 125 ldadd1=`echo ${LDADD}` ; \ 126 if [ "$$ldadd" != "$$ldadd1" ] ; then \ 127 echo ${.CURDIR} ; \ 128 echo "DPADD -> $$ldadd" ; \ 129 echo "LDADD -> $$ldadd1" ; \ 130 fi 131.else 132 @dpadd=`echo \`ld -Bstatic -f ${LDDESTDIR} ${LDADD}\`` ; \ 133 if [ "$$dpadd" != "${DPADD}" ] ; then \ 134 echo ${.CURDIR} ; \ 135 echo "LDADD -> $$dpadd" ; \ 136 echo "DPADD = ${DPADD}" ; \ 137 fi 138.endif 139.endif 140.endif 141 142cleandir: cleanobj _SUBDIR 143 144.for __target in cleandepend depend tags 145.if !target(${__target}) 146${__target}: _SUBDIR 147.endif 148.endfor 149 150_SUBDIR: .USE 151.if defined(SUBDIR) && !empty(SUBDIR) 152 @for entry in ${SUBDIR}; do \ 153 (${ECHODIR} "===> ${DIRPRFX}$$entry"; \ 154 if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \ 155 cd ${.CURDIR}/$${entry}.${MACHINE_ARCH}; \ 156 else \ 157 cd ${.CURDIR}/$${entry}; \ 158 fi; \ 159 ${MAKE} ${.TARGET:S/realinstall/install/:S/.depend/depend/} DIRPRFX=${DIRPRFX}$$entry/); \ 160 done 161.endif 162