Subject: making objdirs automatically
To: None <lukem@netbsd.org>
From: Simon J. Gerraty <sjg@crufty.net>
List: tech-toolchain
Date: 04/17/2004 16:08:22
Luke,

further to our conversation (and one with a colleague) the other day ,
the following simple makefile demonstrates how objdirs can be made
automatically - without the need for a separate 'make obj' pass.

$ cat ~/make-tests/aobj
MAKEOBJDIRPREFIX=/tmp/obj-${USER}-${MACHINE_ARCH}

__objdir=${MAKEOBJDIRPREFIX}${.CURDIR}
.if !exists(${__objdir})
__objdir:= ${__objdir:!umask ${OBJDIR_UMASK:U002}; mkdir -p ${__objdir}; echo ${__objdir}!}
.endif

.OBJDIR:	${__objdir}

all:
	@echo "here is=`pwd`"
	@echo ".OBJDIR=${.OBJDIR}"
	@echo ".CURDIR=${.CURDIR}"

$ rm -rf /tmp/obj-sjg-i386; make -f /homes/sjg/make-tests/aobj all
here is=/tmp/obj-sjg-i386/h/users/sjg
.OBJDIR=/tmp/obj-sjg-i386/h/users/sjg
.CURDIR=/h/users/sjg
$

of course, how you arrive at what value to use for __objdir is
orthogonal.  The important thing is you can ensure consitent results
regardless of the starting environment.

--sjg