1# $FreeBSD: src/share/mk/bsd.obj.mk,v 1.30.2.10 2003/02/15 05:36:25 kris Exp $ 2# $DragonFly: src/share/mk/bsd.obj.mk,v 1.5 2005/10/08 11:31:29 corecode Exp $ 3# 4# The include file <bsd.obj.mk> handles creating the 'obj' directory 5# and cleaning up object files, etc. 6# 7# +++ variables +++ 8# 9# CLEANDIRS Additional directories to remove for the clean target. 10# 11# CLEANFILES Additional files to remove for the clean target. 12# 13# MAKEOBJDIR A pathname for the directory where the targets 14# are built. Note: MAKEOBJDIR is an *environment* variable 15# and works properly only if set as an environment variable, 16# not as a global or command line variable! 17# 18# E.g. use `env MAKEOBJDIR=temp-obj make' 19# 20# MAKEOBJDIRPREFIX Specifies somewhere other than /usr/obj to root the object 21# tree. Note: MAKEOBJDIRPREFIX is an *environment* variable 22# and works properly only if set as an environment variable, 23# not as a global or command line variable! 24# 25# E.g. use `env MAKEOBJDIRPREFIX=/somewhere/obj make' 26# 27# NOOBJ Do not create object directories. This should not be set 28# if anything is built. 29# 30# +++ targets +++ 31# 32# clean: 33# remove ${CLEANFILES}; remove ${CLEANDIRS} and all contents. 34# 35# cleandir: 36# remove the build directory (and all its contents) created by obj 37# 38# obj: 39# create build directory. 40# 41 42.if !target(__<bsd.obj.mk>__) 43__<bsd.obj.mk>__: 44.include <bsd.own.mk> 45 46.if defined(MAKEOBJDIRPREFIX) 47CANONICALOBJDIR:=${MAKEOBJDIRPREFIX}${.CURDIR} 48.else 49CANONICALOBJDIR:=/usr/obj${.CURDIR} 50.endif 51 52# 53# Warn of unorthodox object directory. 54# 55# The following directories are tried in order for ${.OBJDIR}: 56# 57# 1. ${MAKEOBJDIRPREFIX}/`pwd` 58# 2. ${MAKEOBJDIR} 59# 3. obj.${MACHINE} 60# 4. obj 61# 5. /usr/obj/`pwd` 62# 6. ${.CURDIR} 63# 64# If ${.OBJDIR} is constructed using canonical cases 1 or 5, or 65# case 2 (using MAKEOBJDIR), don't issue a warning. Otherwise, 66# issue a warning differentiating between cases 6 and (3 or 4). 67# 68objwarn: 69.if !defined(NOOBJ) && ${.OBJDIR} != ${CANONICALOBJDIR} && \ 70 !(defined(MAKEOBJDIRPREFIX) && exists(${CANONICALOBJDIR}/)) && \ 71 !(defined(MAKEOBJDIR) && exists(${MAKEOBJDIR}/)) 72.if ${.OBJDIR} == ${.CURDIR} 73 @${ECHO} "Warning: Object directory not changed from original ${.CURDIR}" 74.elif exists(${.CURDIR}/obj.${MACHINE}/) || exists(${.CURDIR}/obj/) 75 @${ECHO} "Warning: Using ${.OBJDIR} as object directory instead of\ 76 canonical ${CANONICALOBJDIR}" 77.endif 78.endif 79 80.if !defined(NOOBJ) 81.if !target(obj) 82obj: 83 @if ! test -d ${CANONICALOBJDIR}/; then \ 84 mkdir -p ${CANONICALOBJDIR}; \ 85 if ! test -d ${CANONICALOBJDIR}/; then \ 86 ${ECHO} "Unable to create ${CANONICALOBJDIR}."; \ 87 exit 1; \ 88 fi; \ 89 ${ECHO} "${CANONICALOBJDIR} created for ${.CURDIR}"; \ 90 fi 91.endif 92 93.if !target(objlink) 94objlink: 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.endif # !defined(NOOBJ) 103 104# 105# where would that obj directory be? 106# 107.if !target(whereobj) 108whereobj: 109 @echo ${.OBJDIR} 110.endif 111 112cleanobj: 113.if ${CANONICALOBJDIR} != ${.CURDIR} && exists(${CANONICALOBJDIR}/) 114 rm -rf ${CANONICALOBJDIR} 115.else 116 @cd ${.CURDIR} && ${MAKE} clean cleandepend 117.endif 118 @if [ -L ${.CURDIR}/obj ]; then \ 119 echo rm -f ${.CURDIR}/obj; \ 120 rm -f ${.CURDIR}/obj; \ 121 fi 122 123.if !target(clean) 124clean: 125.if defined(CLEANFILES) && !empty(CLEANFILES) 126 rm -f ${CLEANFILES} 127.endif 128.if defined(CLEANDIRS) && !empty(CLEANDIRS) 129 rm -rf ${CLEANDIRS} 130.endif 131.endif 132 133cleandir: cleanobj 134 135.include <bsd.subdir.mk> 136 137.endif # !target(__<bsd.obj.mk>__) 138