1# $Id: bsd.obj.mk,v 1.15 1996/09/28 19:39:18 nate Exp $ 2# 3# The include file <bsd.obj.mk> handles creating the 'obj' directory 4# and cleaning up object files, log files etc. 5# 6# 7# +++ variables +++ 8# 9# CLEANFILES Additional files to remove for the clean and cleandir targets. 10# 11# MAKEOBJDIR A pathname for the directory where the targets 12# are built. Note: MAKEOBJDIR is an *enviroment* variable 13# and works properly only if set as an enviroment variable, 14# not as a global or command line variable! 15# 16# E.g. use `env MAKEOBJDIR=temp-obj make' 17# 18# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object 19# tree. Note: MAKEOBJDIRPREFIX is an *enviroment* variable 20# and works properly only if set as an enviroment variable, 21# not as a global or command line variable! 22# 23# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make' 24# 25# NOOBJ Do not create object directories. This should not be set 26# if anything is built. 27# 28# OBJLINK Create a symbolic link from ${.CURDIR}/obj to 29# ${CANONICALOBJDIR}. Note: this BREAKS the read-only source 30# tree rule! 31# 32# +++ targets +++ 33# 34# clean: 35# remove a.out Errs errs mklog ${CLEANFILES} 36# 37# cleandir: 38# remove the build directory (and all its contents) created by obj 39# 40# obj: 41# create build directory. 42# 43 44.if defined(MAKEOBJDIRPREFIX) 45CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} 46.else 47CANONICALOBJDIR:=/usr/obj${.CURDIR} 48.endif 49 50# 51# Warn of unorthodox object directory 52# 53objwarn: 54.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} 55.if ${.OBJDIR} == ${.CURDIR} 56 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}" 57.elif !defined(MAKEOBJDIR) && !defined(MAKEOBJDIRPREFIX) && !defined(OBJLINK) 58 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\ 59 canonical ${CANONICALOBJDIR}" 60.endif 61.endif 62 63.if !target(obj) 64.if defined(NOOBJ) 65obj: 66.else 67.if !defined(OBJLINK) 68obj: _SUBDIR 69 @if ! test -d ${CANONICALOBJDIR}; then \ 70 mkdir -p ${CANONICALOBJDIR}; \ 71 if ! test -d ${CANONICALOBJDIR}; then \ 72 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \ 73 exit 1; \ 74 fi; \ 75 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \ 76 fi 77.else 78obj: _SUBDIR 79 @if ! test -d ${CANONICALOBJDIR}; then \ 80 mkdir -p ${CANONICALOBJDIR}; \ 81 if ! test -d ${CANONICALOBJDIR}; then \ 82 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \ 83 exit 1; \ 84 fi; \ 85 rm -f ${.CURDIR}/obj; \ 86 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \ 87 ${ECHO} "${.CURDIR} -> ${CANONICALOBJDIR}"; \ 88 fi 89.endif 90.endif 91.endif 92 93.if !target(objlink) 94objlink: _SUBDIR 95 @if test -d ${CANONICALOBJDIR}; then \ 96 rm -f ${.CURDIR}/obj; \ 97 ln -s ${CANONICALOBJDIR} ${.CURDIR}/obj; \ 98 else \ 99 echo "No ${CANONICALOBJDIR} to link to - do a make obj."; \ 100 fi 101.endif 102 103# 104# where would that obj directory be? 105# 106.if !target(whereobj) 107whereobj: 108 @cd ${.CURDIR}; ${MAKE} -V .OBJDIR 109.endif 110 111# 112# cleanup 113# 114cleanobj: 115 @if [ -d ${CANONICALOBJDIR} ]; then \ 116 rm -rf ${CANONICALOBJDIR}; \ 117 else \ 118 cd ${.CURDIR} && ${MAKE} clean cleandepend; \ 119 fi 120.if defined(OBJLINK) 121 @if [ -h ${.CURDIR}/obj ]; then rm -f ${.CURDIR}/obj; fi 122.endif 123 124.if !target(cleanfiles) 125cleanfiles: 126 rm -f a.out Errs errs mklog ${CLEANFILES} 127.endif 128 129# see bsd.dep.mk 130.if !target(cleandepend) 131cleandepend: 132 @rm -f .depend 133.endif 134 135.if !target(clean) 136clean: cleanfiles _SUBDIR 137.endif 138 139.if !target(checkdpadd) 140checkdpadd: _SUBDIR 141.if (defined(DPADD) || defined(LDADD)) 142checkdpadd: 143 @if [ "${DPADD:S;^/usr/lib/lib;-l;S;.a$;;}" != "${LDADD}" ] ; then \ 144 echo ${.CURDIR} ; \ 145 echo "DPADD -> " ${DPADD:S;^/usr/lib/lib;-l;S;.a$;;} ; \ 146 echo "LDADD = " ${LDADD} ; \ 147 fi 148.endif 149.endif 150 151cleandir: cleanobj _SUBDIR 152