aboutsummaryrefslogtreecommitdiff
path: root/contrib/bmake/mk
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2013-05-20 22:51:11 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2013-05-20 22:51:11 +0000
commit52d86256168d7f996587fd411f4c692fa750ff72 (patch)
treec22bfafacf1ef1525514f8ec6e3ff8d81ab28b8d /contrib/bmake/mk
parentb3f35be0c65ed70515d14d9441d8397a606e1554 (diff)
parentdca4585d16e9cd593a0b85c0d317ceab4bb4b3c0 (diff)
downloadsrc-52d86256168d7f996587fd411f4c692fa750ff72.tar.gz
src-52d86256168d7f996587fd411f4c692fa750ff72.zip
Notes
Diffstat (limited to 'contrib/bmake/mk')
-rw-r--r--contrib/bmake/mk/ChangeLog20
-rw-r--r--contrib/bmake/mk/FILES1
-rw-r--r--contrib/bmake/mk/gendirdeps.mk28
-rw-r--r--contrib/bmake/mk/install-mk4
-rw-r--r--contrib/bmake/mk/meta.stage.mk15
-rwxr-xr-xcontrib/bmake/mk/meta2deps.py41
-rwxr-xr-xcontrib/bmake/mk/meta2deps.sh95
-rw-r--r--contrib/bmake/mk/options.mk23
-rw-r--r--contrib/bmake/mk/progs.mk9
-rwxr-xr-xcontrib/bmake/mk/stage-install.sh98
10 files changed, 281 insertions, 53 deletions
diff --git a/contrib/bmake/mk/ChangeLog b/contrib/bmake/mk/ChangeLog
index 0f49477da486..32e064ba44d5 100644
--- a/contrib/bmake/mk/ChangeLog
+++ b/contrib/bmake/mk/ChangeLog
@@ -1,3 +1,23 @@
+2013-05-10 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): 20130505
+ * gendirdeps.mk, meta2deps.py, meta2deps.sh: handle $TARGET_SPEC
+ for when $MACHINE isn't enough for objdir distinction.
+ Bring meta2deps.sh closer to par with meta2deps.py.
+
+2013-04-18 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * meta.stage.mk: set INSTALL to STAGE_INSTALL when making 'all'
+ also if the target 'beforeinstall' exists, make it depend on
+ .dirdep (incase it uses STAGE_INSTALL).
+
+2013-04-17 Simon J. Gerraty <sjg@bad.crufty.net>
+
+ * install-mk (MK_VERSION): 20130401 ;-)
+ * meta.stage.mk (STAGE_INSTALL_SH): add stage-install.sh as
+ wrapper around install(1).
+ * options.mk (OPTION_PREFIX): Allow a prefix other than MK_
+
2013-03-30 Simon J. Gerraty <sjg@bad.crufty.net>
* meta2deps.py (MetaFile.__init__): ensure self.cwd is initialized.
diff --git a/contrib/bmake/mk/FILES b/contrib/bmake/mk/FILES
index 7a2bf294e43f..443aa2e9644c 100644
--- a/contrib/bmake/mk/FILES
+++ b/contrib/bmake/mk/FILES
@@ -31,6 +31,7 @@ progs.mk
rst2htm.mk
scripts.mk
srctop.mk
+stage-install.sh
subdir.mk
sys.mk
sys.clean-env.mk
diff --git a/contrib/bmake/mk/gendirdeps.mk b/contrib/bmake/mk/gendirdeps.mk
index 5742c6fbcc1d..9be367369f57 100644
--- a/contrib/bmake/mk/gendirdeps.mk
+++ b/contrib/bmake/mk/gendirdeps.mk
@@ -1,4 +1,4 @@
-# $Id: gendirdeps.mk,v 1.21 2013/03/28 20:01:05 sjg Exp $
+# $Id: gendirdeps.mk,v 1.22 2013/05/11 05:16:26 sjg Exp $
# Copyright (c) 2010-2013, Juniper Networks, Inc.
# All rights reserved.
@@ -111,13 +111,24 @@ _py_d =
.if ${META2DEPS:E} == "py"
# we can afford to do this all the time.
DPDEPS ?= no
-META2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d} \
- -R ${RELDIR} -H ${HOST_TARGET} \
- ${M2D_OBJROOTS:O:u:@o@-O $o@}
-
+META2DEPS_CMD = ${_time} ${PYTHON} ${META2DEPS} ${_py_d}
.if ${DPDEPS:tl} != "no"
META2DEPS_CMD += -D ${DPDEPS}
.endif
+META2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
+.elif ${META2DEPS:E} == "sh"
+META2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} OBJTOP=${_OBJTOP}
+.else
+META2DEPS_CMD ?= ${META2DEPS}
+.endif
+
+.if ${TARGET_OBJ_SPEC:U${MACHINE}} != ${MACHINE}
+META2DEPS_CMD += -T ${TARGET_OBJ_SPEC}
+.endif
+META2DEPS_CMD += \
+ -R ${RELDIR} -H ${HOST_TARGET} \
+ ${M2D_OBJROOTS:O:u:@o@-O $o@}
+
M2D_OBJROOTS += ${OBJTOP} ${_OBJROOT} ${_objroot}
.if defined(SB_OBJROOT)
@@ -133,13 +144,6 @@ META2DEPS_ARGS += MACHINE=none
META2DEPS_CMD += -S ${SB_BACKING_SB}/src
M2D_OBJROOTS += ${SB_BACKING_SB}/${SB_OBJPREFIX}
.endif
-META2DEPS_FILTER = sed 's,^src:,${SRCTOP}/,;s,^\([^/]\),${OBJTOP}/\1,' |
-.elif ${META2DEPS:E} == "sh"
-META2DEPS_CMD = ${_time} ${_sh_x} ${META2DEPS} \
- OBJTOP=${_objtop} SB_OBJROOT=${_objroot}
-.else
-META2DEPS_CMD ?= ${META2DEPS}
-.endif
# we are only interested in the dirs
# sepecifically those we read something from.
diff --git a/contrib/bmake/mk/install-mk b/contrib/bmake/mk/install-mk
index c45c6ca828d0..da15d8041d14 100644
--- a/contrib/bmake/mk/install-mk
+++ b/contrib/bmake/mk/install-mk
@@ -55,7 +55,7 @@
# Simon J. Gerraty <sjg@crufty.net>
# RCSid:
-# $Id: install-mk,v 1.88 2013/03/31 22:31:59 sjg Exp $
+# $Id: install-mk,v 1.90 2013/05/11 05:16:26 sjg Exp $
#
# @(#) Copyright (c) 1994 Simon J. Gerraty
#
@@ -70,7 +70,7 @@
# sjg@crufty.net
#
-MK_VERSION=20130330
+MK_VERSION=20130505
OWNER=
GROUP=
MODE=444
diff --git a/contrib/bmake/mk/meta.stage.mk b/contrib/bmake/mk/meta.stage.mk
index 0faeef34cbcc..2f02700fdc19 100644
--- a/contrib/bmake/mk/meta.stage.mk
+++ b/contrib/bmake/mk/meta.stage.mk
@@ -1,4 +1,4 @@
-# $Id: meta.stage.mk,v 1.24 2013/03/23 02:25:19 sjg Exp $
+# $Id: meta.stage.mk,v 1.30 2013/04/19 16:32:57 sjg Exp $
#
# @(#) Copyright (c) 2011, Simon J. Gerraty
#
@@ -228,4 +228,17 @@ STAGING_WAIT ?= .WAIT
all: ${STAGING_WAIT} staging
+.if exists(${.PARSEDIR}/stage-install.sh) && !defined(STAGE_INSTALL)
+# this will run install(1) and then followup with .dirdep files.
+STAGE_INSTALL := sh ${.PARSEDIR:tA}/stage-install.sh INSTALL="${INSTALL}" OBJDIR=${.OBJDIR:tA}
+.endif
+
+# if ${INSTALL} gets run during 'all' assume it is for staging?
+.if ${.TARGETS:Nall} == "" && defined(STAGE_INSTALL)
+INSTALL := ${STAGE_INSTALL}
+.if target(beforeinstall)
+beforeinstall: .dirdep
+.endif
+.endif
+
.endif
diff --git a/contrib/bmake/mk/meta2deps.py b/contrib/bmake/mk/meta2deps.py
index 6b6157c3ab4c..8c42303373f0 100755
--- a/contrib/bmake/mk/meta2deps.py
+++ b/contrib/bmake/mk/meta2deps.py
@@ -35,7 +35,7 @@ We only pay attention to a subset of the information in the
"""
RCSid:
- $Id: meta2deps.py,v 1.12 2013/03/31 22:31:59 sjg Exp $
+ $Id: meta2deps.py,v 1.13 2013/05/11 05:16:26 sjg Exp $
Copyright (c) 2011-2013, Juniper Networks, Inc.
All rights reserved.
@@ -124,6 +124,12 @@ def sort_unique(list, cmp=None, key=None, reverse=False):
nl.append(e)
return nl
+def add_trims(x):
+ return ['/' + x + '/',
+ '/' + x,
+ x + '/',
+ x]
+
class MetaFile:
"""class to parse meta files generated by bmake."""
@@ -152,6 +158,9 @@ class MetaFile:
set to 'none' if we are not cross-building.
More specifically if machine cannot be deduced from objdirs.
+ TARGET_SPEC
+ Sometimes MACHINE isn't enough.
+
HOST_TARGET
when we build for the psuedo machine 'host'
the object tree uses HOST_TARGET rather than MACHINE.
@@ -177,6 +186,8 @@ class MetaFile:
self.debug_out = getv(conf, 'debug_out', sys.stderr)
self.machine = getv(conf, 'MACHINE', '')
+ self.machine_arch = getv(conf, 'MACHINE_ARCH', '')
+ self.target_spec = getv(conf, 'TARGET_SPEC', '')
self.curdir = getv(conf, 'CURDIR')
self.reldir = getv(conf, 'RELDIR')
self.dpdeps = getv(conf, 'DPDEPS')
@@ -196,16 +207,11 @@ class MetaFile:
if not _srctop in self.srctops:
self.srctops.append(_srctop)
- trim_list = ['/' + self.machine + '/',
- '/' + self.machine,
- self.machine + '/',
- self.machine]
-
+ trim_list = add_trims(self.machine)
if self.machine == 'host':
- trim_list += ['/' + self.host_target + '/',
- '/' + self.host_target,
- self.host_target + '/',
- self.host_target]
+ trim_list += add_trims(self.host_target)
+ if self.target_spec:
+ trim_list += add_trims(self.target_spec)
for objroot in getv(conf, 'OBJROOTS', []):
for e in trim_list:
@@ -303,6 +309,8 @@ class MetaFile:
print >> self.debug_out, "found %s: %s\n" % (ddepf, ddep)
if ddep.endswith(self.machine):
ddep = ddep[0:-(1+len(self.machine))]
+ elif self.target_spec and ddep.endswith(self.target_spec):
+ ddep = ddep[0:-(1+len(self.target_spec))]
if not ddep:
# no .dirdeps, so remember that we've seen the raw input
@@ -520,6 +528,8 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
-m "MACHINE"
+ -a "MACHINE_ARCH"
+
-H "HOST_TARGET"
-D "DPDEPS"
@@ -548,6 +558,9 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
machine = os.environ['MACHINE']
if machine:
conf['MACHINE'] = machine
+ machine_arch = os.environ['MACHINE_ARCH']
+ if machine_arch:
+ conf['MACHINE_ARCH'] = machine_arch
srctop = os.environ['SB_SRC']
if srctop:
conf['SRCTOPS'].append(srctop)
@@ -560,9 +573,11 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
debug = 0
output = True
- opts, args = getopt.getopt(argv[1:], 'dS:C:O:R:m:D:H:q' + xopts)
+ opts, args = getopt.getopt(argv[1:], 'a:dS:C:O:R:m:D:H:qT:' + xopts)
for o, a in opts:
- if o == '-d':
+ if o == '-a':
+ conf['MACHINE_ARCH'] = a
+ elif o == '-d':
debug += 1
elif o == '-q':
output = False
@@ -582,6 +597,8 @@ def main(argv, klass=MetaFile, xopts='', xoptf=None):
conf['DPDEPS'] = a
elif o == '-m':
conf['MACHINE'] = a
+ elif o == '-T':
+ conf['TARGET_SPEC'] = a
elif xoptf:
xoptf(o, a, conf)
diff --git a/contrib/bmake/mk/meta2deps.sh b/contrib/bmake/mk/meta2deps.sh
index 9c76b77964dd..f63aee329b6b 100755
--- a/contrib/bmake/mk/meta2deps.sh
+++ b/contrib/bmake/mk/meta2deps.sh
@@ -49,8 +49,8 @@
# The output, is a set of absolute paths with "SB" like:
#.nf
#
-# $SB/obj-i386/junos/gnu/lib/csu
-# $SB/obj-i386/junos/gnu/lib/libgcc
+# $SB/obj-i386/bsd/gnu/lib/csu
+# $SB/obj-i386/bsd/gnu/lib/libgcc
# $SB/obj-i386/bsd/include
# $SB/obj-i386/bsd/lib/csu/i386-elf
# $SB/obj-i386/bsd/lib/libc
@@ -77,9 +77,9 @@
# RCSid:
-# $Id: meta2deps.sh,v 1.5 2013/02/10 19:21:46 sjg Exp $
+# $Id: meta2deps.sh,v 1.6 2013/05/11 05:16:26 sjg Exp $
-# Copyright (c) 2010-2012, Juniper Networks, Inc.
+# Copyright (c) 2010-2013, Juniper Networks, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -115,16 +115,89 @@ meta2dirs() {
sort -u
}
+add_list() {
+ sep=' '
+ suffix=
+ while :
+ do
+ case "$1" in
+ "|") sep="$1"; shift;;
+ -s) suffix="$2"; shift 2;;
+ *) break;;
+ esac
+ done
+ name=$1
+ shift
+ eval list="\$$name"
+ for top in "$@"
+ do
+ case "$sep$list$sep" in
+ *"$sep$top$suffix$sep"*) continue;;
+ esac
+ list="${list:+$list$sep}$top$suffix"
+ done
+ eval "$name=\"$list\""
+}
+
meta2deps() {
DPDEPS=
+ SRCTOPS=$SRCTOP
+ OBJROOTS=
while :
do
case "$1" in
*=*) eval export "$1"; shift;;
+ -a) MACHINE_ARCH=$2; shift 2;;
+ -m) MACHINE=$2; shift 2;;
+ -C) CURDIR=$2; shift 2;;
+ -H) HOST_TARGET=$2; shift 2;;
+ -S) add_list SRCTOPS $2; shift 2;;
+ -O) add_list OBJROOTS $2; shift 2;;
+ -R) RELDIR=$2; shift 2;;
+ -T) TARGET_SPEC=$2; shift 2;;
*) break;;
esac
done
+ _th= _o=
+ case "$MACHINE" in
+ host) _ht=$HOST_TARGET;;
+ esac
+
+ for o in $OBJROOTS
+ do
+ case "$MACHINE,/$o/" in
+ host,*$HOST_TARGET*) ;;
+ *$MACHINE*|*${TARGET_SPEC:-$MACHINE}*) ;;
+ *) add_list _o $o; continue;;
+ esac
+ for x in $_ht $TARGET_SPEC $MACHINE
+ do
+ case "$o" in
+ "") continue;;
+ */$x/) add_list _o ${o%$x/}; o=;;
+ */$x) add_list _o ${o%$x}; o=;;
+ *$x/) add_list _o ${o%$x/}; o=;;
+ *$x) add_list _o ${o%$x}; o=;;
+ esac
+ done
+ done
+ OBJROOTS="$_o"
+
+ case "$OBJTOP" in
+ "")
+ for o in $OBJROOTS
+ do
+ OBJTOP=$o${TARGET_SPEC:-$MACHINE}
+ break
+ done
+ ;;
+ esac
+ src_re=
+ obj_re=
+ add_list '|' -s '/*' src_re $SRCTOPS
+ add_list '|' -s '*' obj_re $OBJROOTS
+
[ -z "$RELDIR" ] && unset DPDEPS
tf=/tmp/m2d$$-$USER
rm -f $tf.*
@@ -166,8 +239,7 @@ meta2deps() {
esac
case "$op,$path" in
- *.dirdep) continue;;
- W,*srcrel) continue;;
+ W,*srcrel|*.dirdep) continue;;
C,*)
case "$path" in
/*) cwd=$path;;
@@ -182,8 +254,7 @@ meta2deps() {
;;
*) dir=${path%/*}
case "$path" in
- $SB/*|${SB_BACKING_SB:-$SB}/*) ;;
- $SB_OBJROOT*) ;;
+ $src_re|$obj_re) ;;
/*/stage/*) ;;
/*) continue;;
*) for path in $ldir/$path $cwd/$path
@@ -215,7 +286,7 @@ meta2deps() {
esac
case "$dir" in
${CURDIR:-.}|${CURDIR:-.}/*|"") continue;;
- $SRCTOP/*|${SB_BACKING_SB:-$SB}/src/*)
+ $src_re)
# avoid repeating ourselves...
case "$DPDEPS,$seensrc," in
,*)
@@ -241,7 +312,7 @@ meta2deps() {
[ -f $path ] || continue
case "$dir" in
$CWD) continue;; # ignore
- $SRCTOP/*|${SB_BACKING_SB:-$SB}/src/*)
+ $src_re)
seenit="$seenit,$seen"
echo $dir >> $tf.srcdep
case "$DPDEPS,$reldir,$seensrc," in
@@ -267,7 +338,7 @@ meta2deps() {
fi
seenit="$seenit,$seen"
case "$dir" in
- $SB/*|${SB_OBJROOT:-$SB/}*|${SB_BACKING_SB:-$SB}/*)
+ $obj_re)
echo $dir;;
esac
done > $tf.dirdep
@@ -283,7 +354,7 @@ meta2deps() {
# qualified with .<machine> as needed.
# We strip .$MACHINE though
xargs cat < $f | sort -u |
- sed "s,^# ,,;s,^,$OBJTOP/,;s,\.$MACHINE\$,,"
+ sed "s,^# ,,;s,^,$OBJTOP/,;s,\.${TARGET_SPEC:-$MACHINE}\$,,;s,\.$MACHINE\$,,"
;;
*) sort -u $f;;
esac
diff --git a/contrib/bmake/mk/options.mk b/contrib/bmake/mk/options.mk
index 7d1bf67915a0..aa54754b2ff4 100644
--- a/contrib/bmake/mk/options.mk
+++ b/contrib/bmake/mk/options.mk
@@ -1,4 +1,4 @@
-# $Id: options.mk,v 1.6 2013/01/28 19:28:52 sjg Exp $
+# $Id: options.mk,v 1.7 2013/04/17 20:32:38 sjg Exp $
#
# @(#) Copyright (c) 2012, Simon J. Gerraty
#
@@ -13,7 +13,7 @@
# sjg@crufty.net
#
-# Inspired by FreeBSD bsd.own.mk, but intentionally simpler.
+# Inspired by FreeBSD bsd.own.mk, but intentionally simpler and more flexible.
# Options are normally listed in either OPTIONS_DEFAULT_{YES,NO}
# We convert these to ${OPTION}/{yes,no} in OPTIONS_DEFAULT_VALUES.
@@ -24,35 +24,36 @@
# ${OPTION}/yes in OPTIONS_DEFAULT_VALUES.
# A makefile may set NO_* (or NO*) to indicate it cannot do something.
# User sets WITH_* and WITHOUT_* to indicate what they want.
-# We set MK_* which is then all we need care about.
+# We set ${OPTION_PREFIX:UMK_}* which is then all we need care about.
OPTIONS_DEFAULT_VALUES += \
${OPTIONS_DEFAULT_NO:O:u:S,$,/no,} \
${OPTIONS_DEFAULT_YES:O:u:S,$,/yes,}
+OPTION_PREFIX ?= MK_
.for o in ${OPTIONS_DEFAULT_VALUES:M*/*}
.if ${o:T:tl} == "no"
.if defined(WITH_${o:H}) && !defined(NO_${o:H}) && !defined(NO${o:H})
-MK_${o:H} ?= yes
+${OPTION_PREFIX}${o:H} ?= yes
.else
-MK_${o:H} ?= no
+${OPTION_PREFIX}${o:H} ?= no
.endif
.else
.if defined(WITHOUT_${o:H}) || defined(NO_${o:H}) || defined(NO${o:H})
-MK_${o:H} ?= no
+${OPTION_PREFIX}${o:H} ?= no
.else
-MK_${o:H} ?= yes
+${OPTION_PREFIX}${o:H} ?= yes
.endif
.endif
.endfor
# OPTIONS_DEFAULT_DEPENDENT += FOO_UTILS/FOO
-# if neither WITH[OUT]_FOO_UTILS is set, use value of MK_FOO
+# if neither WITH[OUT]_FOO_UTILS is set, use value of ${OPTION_PREFIX}FOO
.for o in ${OPTIONS_DEFAULT_DEPENDENT:M*/*:O:u}
.if defined(WITH_${o:H}) && !defined(NO_${o:H}) && !defined(NO${o:H})
-MK_${o:H} ?= yes
+${OPTION_PREFIX}${o:H} ?= yes
.elif defined(WITHOUT_${o:H}) || defined(NO_${o:H}) || defined(NO${o:H})
-MK_${o:H} ?= no
+${OPTION_PREFIX}${o:H} ?= no
.else
-MK_${o:H} ?= ${MK_${o:T}}
+${OPTION_PREFIX}${o:H} ?= ${${OPTION_PREFIX}${o:T}}
.endif
.endfor
diff --git a/contrib/bmake/mk/progs.mk b/contrib/bmake/mk/progs.mk
index 0fd23120b620..f74f64012849 100644
--- a/contrib/bmake/mk/progs.mk
+++ b/contrib/bmake/mk/progs.mk
@@ -1,4 +1,4 @@
-# $Id: progs.mk,v 1.11 2012/11/06 17:18:54 sjg Exp $
+# $Id: progs.mk,v 1.12 2013/04/22 18:10:04 sjg Exp $
#
# @(#) Copyright (c) 2006, Simon J. Gerraty
#
@@ -35,9 +35,11 @@ PROG ?= $t
.if defined(PROG)
# just one of many
-PROG_VARS += CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD MAN SRCS
+PROG_VARS += BINDIR CFLAGS CPPFLAGS CXXFLAGS DPADD DPLIBS LDADD MAN SRCS
.for v in ${PROG_VARS:O:u}
+.if defined(${v}.${PROG})
$v += ${${v}_${PROG}:U${${v}.${PROG}}}
+.endif
.endfor
# for meta mode, there can be only one!
@@ -63,7 +65,8 @@ UPDATE_DEPENDFILE = NO
.include <${.PARSEFILE:S,progs,prog,}>
.ifndef PROG
-PROGS_TARGETS += clean
+# tell progs.mk we might want to install things
+PROGS_TARGETS+= cleandepend cleandir cleanobj depend install
.for p in ${PROGS}
.if defined(PROGS_CXX) && !empty(PROGS_CXX:M$p)
diff --git a/contrib/bmake/mk/stage-install.sh b/contrib/bmake/mk/stage-install.sh
new file mode 100755
index 000000000000..64d044fa048c
--- /dev/null
+++ b/contrib/bmake/mk/stage-install.sh
@@ -0,0 +1,98 @@
+#!/bin/sh
+
+# NAME:
+# stage-install.sh - wrapper around install
+#
+# SYNOPSIS:
+# stage-install.sh [variable="value"] "args" "dest"
+#
+# DESCRIPTION:
+# This script is a wrapper around the normal install(1).
+# Its role is to add '.dirdep' files to the destination.
+# The variables we might use are:
+#
+# INSTALL
+# Path to actual install(1), default is
+# $REAL_INSTALL
+#
+# OBJDIR
+# Path to the dir where '.dirdep' was generated,
+# default is '.'
+#
+# _DIRDEP
+# Path to actual '.dirdep' file, default is
+# $OBJDIR/.dirdep
+#
+# The "args" and "dest" are passed as is to install(1), and if a
+# '.dirdep' file exists it will be linked or copied to each
+# "file".dirdep placed in "dest" or "dest".dirdep if it happed
+# to be a file rather than a directory.
+#
+# SEE ALSO:
+# meta.stage.mk
+#
+
+# RCSid:
+# $Id: stage-install.sh,v 1.5 2013/04/19 16:32:24 sjg Exp $
+#
+# @(#) Copyright (c) 2013, Simon J. Gerraty
+#
+# This file is provided in the hope that it will
+# be of use. There is absolutely NO WARRANTY.
+# Permission to copy, redistribute or otherwise
+# use this file is hereby granted provided that
+# the above copyright notice and this notice are
+# left intact.
+#
+# Please send copies of changes and bug-fixes to:
+# sjg@crufty.net
+#
+
+INSTALL=${REAL_INSTALL:-install}
+OBJDIR=.
+
+while :
+do
+ case "$1" in
+ *=*) eval "$1"; shift;;
+ *) break;;
+ esac
+done
+
+# if .dirdep doesn't exist, just run install and be done
+_DIRDEP=${_DIRDEP:-$OBJDIR/.dirdep}
+[ -s $_DIRDEP ] && EXEC= || EXEC=exec
+$EXEC $INSTALL "$@" || exit 1
+
+# from meta.stage.mk
+LnCp() {
+ rm -f $2 2> /dev/null
+ ln $1 $2 2> /dev/null || cp -p $1 $2
+}
+
+StageDirdep() {
+ t=$1
+ if [ -s $t.dirdep ]; then
+ cmp -s $_DIRDEP $t.dirdep && return
+ echo "ERROR: $t installed by `cat $t.dirdep` not `cat $_DIRDEP`" >&2
+ exit 1
+ fi
+ LnCp $_DIRDEP $t.dirdep || exit 1
+}
+
+args="$@"
+while [ $# -gt 8 ]
+do
+ shift 8
+done
+eval dest=\$$#
+if [ -f $dest ]; then
+ # a file, there can be only one .dirdep needed
+ StageDirdep $dest
+elif [ -d $dest ]; then
+ for f in $args
+ do
+ test -f $f || continue
+ StageDirdep $dest/${f##*/}
+ done
+fi