bsd.obj.mk revision 94940
1# $FreeBSD: head/share/mk/bsd.obj.mk 94940 2002-04-17 13:49:29Z ru $ 2# 3# The include file <bsd.obj.mk> handles creating the 'obj' directory 4# and cleaning up object files, etc. 5# 6# Under construction: it also contains the _SUBDIR target (which is used 7# by most `mk' files to recurse into subdirectories) and defaults for the 8# cleandepend, depend and tags targets. It may eventually be merged with 9# with bsd.subdir.mk. 10# 11# +++ variables +++ 12# 13# CLEANDIRS Additional directories to remove for the clean target. 14# 15# CLEANFILES Additional files to remove for the clean target. 16# 17# MAKEOBJDIR A pathname for the directory where the targets 18# are built. Note: MAKEOBJDIR is an *enviroment* variable 19# and works properly only if set as an enviroment variable, 20# not as a global or command line variable! 21# 22# E.g. use `env MAKEOBJDIR=temp-obj make' 23# 24# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object 25# tree. Note: MAKEOBJDIRPREFIX is an *enviroment* variable 26# and works properly only if set as an enviroment variable, 27# not as a global or command line variable! 28# 29# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make' 30# 31# NOOBJ Do not create object directories. This should not be set 32# if anything is built. 33# 34# +++ targets +++ 35# 36# clean: 37# remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents. 38# 39# cleandir: 40# remove the build directory (and all its contents) created by obj 41# 42# obj: 43# create build directory. 44# 45 46.if !target(__<bsd.obj.mk>__) 47__<bsd.obj.mk>__: 48.include <bsd.own.mk> 49 50.if defined(MAKEOBJDIRPREFIX) 51CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} 52.else 53CANONICALOBJDIR:=/usr/obj${.CURDIR} 54.endif 55 56# 57# Warn of unorthodox object directory. 58# 59# The following directories are tried in order for ${.OBJDIR}: 60# 61# 1. ${MAKEOBJDIRPREFIX}/`pwd` 62# 2. ${MAKEOBJDIR} 63# 3. obj.${MACHINE} 64# 4. obj 65# 5. /usr/obj/`pwd` 66# 6. ${.CURDIR} 67# 68# If ${.OBJDIR} is constructed using canonical cases 1 or 5, or 69# case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise, 70# issue a warning differentiating between cases 6 and (3 or 4). 71# 72objwarn: 73.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \ 74 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \ 75 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/)) 76.if ${.OBJDIR} == ${.CURDIR} 77 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}" 78.elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/) 79 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\ 80 canonical ${CANONICALOBJDIR}" 81.endif 82.endif 83 84.if !target(obj) 85.if defined(NOOBJ) 86obj: 87.else 88obj: _SUBDIR 89 @if ! test -d ${CANONICALOBJDIR}/; then \ 90 mkdir -p ${CANONICALOBJDIR}; \ 91 if ! test -d ${CANONICALOBJDIR}/; then \ 92 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \ 93 exit 1; \ 94 fi; \ 95 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \ 96 fi 97.endif 98.endif 99 100.if !target(objlink) 101objlink: _SUBDIR 102 @if test -d ${CANONICALOBJDIR}/; then \ 103 rm -f ${.CURDIR}/obj; \ 104 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \ 105 else \ 106 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \ 107 fi 108.endif 109 110# 111# where would that obj directory be? 112# 113.if !target(whereobj) 114whereobj: 115 @echo ${.OBJDIR} 116.endif 117 118cleanobj: 119.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/) 120 @rm -rf ${CANONICALOBJDIR} 121.else 122 @cd ${.CURDIR} && ${MAKE} clean cleandepend 123.endif 124 @if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi 125 126.if !target(clean) 127clean: _SUBDIR 128.if defined(CLEANFILES) && !empty(CLEANFILES) 129 rm -f ${CLEANFILES} 130.endif 131.if defined(CLEANDIRS) && !empty(CLEANDIRS) 132 rm -rf ${CLEANDIRS} 133.endif 134.endif 135 136.if !target(checkdpadd) 137checkdpadd: _SUBDIR 138.if (defined(DPADD) || defined(LDADD)) 139checkdpadd: 140.if ${OBJFORMAT} != aout 141 @ldadd=`echo \`for lib in ${DPADD} ; do \ 142 echo $$lib | sed 's;^/usr/lib/lib\(.*\)\.a;-l\1;' ; \ 143 done \`` ; \ 144 ldadd1=`echo ${LDADD}` ; \ 145 if [ "$$ldadd" != "$$ldadd1" ] ; then \ 146 echo ${.CURDIR} ; \ 147 echo "DPADD -> $$ldadd" ; \ 148 echo "LDADD -> $$ldadd1" ; \ 149 fi 150.else 151 @dpadd=`echo \`ld -Bstatic -f ${LDADD}\`` ; \ 152 if [ "$$dpadd" != "${DPADD}" ] ; then \ 153 echo ${.CURDIR} ; \ 154 echo "LDADD -> $$dpadd" ; \ 155 echo "DPADD = ${DPADD}" ; \ 156 fi 157.endif 158.endif 159.endif 160 161cleandir: cleanobj _SUBDIR 162 163.for __target in cleandepend depend tags 164.if !target(${__target}) 165${__target}: _SUBDIR 166.endif 167.endfor 168 169_SUBDIR: .USE 170.if defined(SUBDIR) && !empty(SUBDIR) 171 @for entry in ${SUBDIR}; do \ 172 (${ECHODIR} "===> ${DIRPRFX}$$entry"; \ 173 if test -d ${.CURDIR}/$${entry}.${MACHINE_ARCH}; then \ 174 cd ${.CURDIR}/$${entry}.${MACHINE_ARCH}; \ 175 else \ 176 cd ${.CURDIR}/$${entry}; \ 177 fi; \ 178 ${MAKE} ${.TARGET:S/realinstall/install/} DIRPRFX=${DIRPRFX}$$entry/); \ 179 done 180.endif 181 182.endif !target(__<bsd.obj.mk>__) 183