1# $Id: obj.mk,v 1.15 2012/11/11 22:37:02 sjg Exp $ 2# 3# @(#) Copyright (c) 1999-2010, Simon J. Gerraty 4# 5# This file is provided in the hope that it will 6# be of use. There is absolutely NO WARRANTY. 7# Permission to copy, redistribute or otherwise 8# use this file is hereby granted provided that 9# the above copyright notice and this notice are 10# left intact. 11# 12# Please send copies of changes and bug-fixes to: 13# sjg@crufty.net 14# 15 16.if !target(__${.PARSEFILE:S,bsd.,,}__) 17__${.PARSEFILE:S,bsd.,,}__: 18 19.include <init.mk> 20 21ECHO_TRACE ?= echo 22 23.if ${MK_OBJDIRS} == "no" 24obj: 25objlink: 26objwarn: 27.else 28 29# this has to match how make behaves 30.if defined(MAKEOBJDIRPREFIX) || defined(MAKEOBJDIR) 31.if defined(MAKEOBJDIRPREFIX) 32__objdir:= ${MAKEOBJDIRPREFIX}${.CURDIR} 33.else 34__objdir:= ${MAKEOBJDIR} 35.endif 36.else 37__objdir= ${__objlink} 38.endif 39 40.if defined(OBJMACHINE) 41__objlink= obj.${MACHINE} 42.else 43__objlink= obj 44.endif 45 46.if ${MK_AUTO_OBJ} == "yes" 47.-include "auto.obj.mk" 48.endif 49 50.NOPATH: ${__objdir} 51.PHONY: obj 52 53obj: _SUBDIRUSE 54 @if test ! -d ${__objdir}/.; then \ 55 mkdir -p ${__objdir}; \ 56 if test ! -d ${__objdir}; then \ 57 mkdir ${__objdir}; exit 1; \ 58 fi; \ 59 ${ECHO_TRACE} "[Creating objdir ${__objdir}...]" >&2; \ 60 fi 61 62.if !target(_SUBDIRUSE) 63# this just allows us to be included by ourselves 64_SUBDIRUSE: 65.endif 66 67# so we can interact with freebsd makefiles 68.if !target(objwarn) 69objwarn: 70.if ${.OBJDIR} == ${.CURDIR} 71 @echo "Warning Object directory is ${.CURDIR}" 72.elif ${.OBJDIR} != ${__objdir} 73 @echo "Warning Object directory is ${.OBJDIR} vs. ${__objdir}" 74.endif 75.endif 76 77.if !target(objlink) 78objlink: 79.if ${__objdir:T} != ${__objlink} 80 @if test -d ${__objdir}/.; then \ 81 ${RM} -f ${.CURDIR}/${__objlink}; \ 82 ${LN} -s ${__objdir} ${.CURDIR}/${__objlink}; \ 83 echo "${__objlink} -> ${__objdir}"; \ 84 else \ 85 echo "No ${__objdir} to link to - do a 'make obj'"; \ 86 fi 87.endif 88.endif 89.endif 90 91_CURDIR?= ${.CURDIR} 92_OBJDIR?= ${.OBJDIR} 93 94.if !target(print-objdir) 95print-objdir: 96 @echo ${_OBJDIR} 97.endif 98 99.if !target(whereobj) 100whereobj: 101 @echo ${_OBJDIR} 102.endif 103 104.if !target(destroy) 105.if ${.CURDIR} != ${.OBJDIR} 106destroy: 107 (cd ${_CURDIR} && rm -rf ${_OBJDIR}) 108.else 109destroy: clean 110.endif 111.endif 112 113.endif 114