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