Subject: .mk "subroutine" for getting objdir locations
To: None <tech-toolchain@netbsd.org>
From: Todd Vierling <tv@wasabisystems.com>
List: tech-toolchain
Date: 08/06/2001 20:52:35
The following I plan to add as src/share/mk/bsd.getobj.mk by Wednesday
evening if there are no major objections (mainly, I'm testing the waters to
see what people think of the *name* ... I couldn't come up with many good
ideas).

This .mk file is intended to replace the very ugly, and quite slow,
shellcode hacks that have been used to find out the proper obj subdirectory
of a given source directory.  Currently a recursive make is called from a
!=, which is very high overhead, particularly on slower architectures.  In
the toolchain hacking I've been doing, there are loads of these !=
constructs, and I want to flatten them.

Feel free to discuss, but I feel this probably doesn't warrant a long
thread.

=====
#	$NetBSD$

# Subroutine to obtains the object directory of a given subdirectory,
# without the overhead of a subshell invocation.  Can be included
# multiple times as needed.
#
# Set the following:
# GETOBJ_SRC	Source directory to resolve to an objdir
# GETOBJ_VAR	Variable to set with objdir location

.include <bsd.own.mk>

# The following follow the make(1) rules, not those in <bsd.obj.mk> --
# we care what exists, not what the user requested in /etc/mk.conf.

.undef ${GETOBJ_VAR}

# Fallback to same path.
${GETOBJ_VAR}:=	${GETOBJ_SRC}

.if defined(MAKEOBJDIRPREFIX)

.if exists(${MAKEOBJDIRPREFIX}${GETOBJ_SRC})
${GETOBJ_VAR}:=	${MAKEOBJDIRPREFIX}${GETOBJ_SRC}
.endif

.elif defined(MAKEOBJDIR)

.if exists(${GETOBJ_SRC}/${MAKEOBJDIR})
${GETOBJ_VAR}:=	${GETOBJ_SRC}/${MAKEOBJDIR}
.endif

.elif exists(${GETOBJ_SRC}/obj.${MACHINE})

${GETOBJ_VAR}:=	${GETOBJ_SRC}/obj.${MACHINE}

.elif exists(${GETOBJ_SRC}/obj)

${GETOBJ_VAR}:=	${GETOBJ_SRC}/obj

.endif
=====

-- 
-- Todd Vierling <tv@wasabisystems.com>  *  Wasabi NetBSD:  Run with it.
-- NetBSD 1.5 now available on CD-ROM  --  http://www.wasabisystems.com/