xref: /freebsd/share/mk/stage-install.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1*fb0cb808SSimon J. Gerraty#!/bin/sh
2*fb0cb808SSimon J. Gerraty
3*fb0cb808SSimon J. Gerraty# NAME:
4*fb0cb808SSimon J. Gerraty#	stage-install.sh - wrapper around install
5*fb0cb808SSimon J. Gerraty#
6*fb0cb808SSimon J. Gerraty# SYNOPSIS:
7*fb0cb808SSimon J. Gerraty#	stage-install.sh [variable="value"] "args" "dest"
8*fb0cb808SSimon J. Gerraty#
9*fb0cb808SSimon J. Gerraty# DESCRIPTION:
10*fb0cb808SSimon J. Gerraty#	This script is a wrapper around the normal install(1).
11*fb0cb808SSimon J. Gerraty#	Its role is to add '.dirdep' files to the destination.
12*fb0cb808SSimon J. Gerraty#	The variables we might use are:
13*fb0cb808SSimon J. Gerraty#
14*fb0cb808SSimon J. Gerraty#	INSTALL
15*fb0cb808SSimon J. Gerraty#		Path to actual install(1), default is
16*fb0cb808SSimon J. Gerraty#		$REAL_INSTALL
17*fb0cb808SSimon J. Gerraty#
18*fb0cb808SSimon J. Gerraty#	OBJDIR
19*fb0cb808SSimon J. Gerraty#		Path to the dir where '.dirdep' was generated,
20*fb0cb808SSimon J. Gerraty#		default is '.'
21*fb0cb808SSimon J. Gerraty#
22*fb0cb808SSimon J. Gerraty#	_DIRDEP
23*fb0cb808SSimon J. Gerraty#		Path to actual '.dirdep' file, default is
24*fb0cb808SSimon J. Gerraty#		$OBJDIR/.dirdep
25*fb0cb808SSimon J. Gerraty#
26*fb0cb808SSimon J. Gerraty#	The "args" and "dest" are passed as is to install(1), and if a
27*fb0cb808SSimon J. Gerraty#	'.dirdep' file exists it will be linked or copied to each
28*fb0cb808SSimon J. Gerraty#	"file".dirdep placed in "dest" or "dest".dirdep if it happed
29*fb0cb808SSimon J. Gerraty#	to be a file rather than a directory.
30*fb0cb808SSimon J. Gerraty#
31*fb0cb808SSimon J. Gerraty# SEE ALSO:
32*fb0cb808SSimon J. Gerraty#	meta.stage.mk
33*fb0cb808SSimon J. Gerraty#
34*fb0cb808SSimon J. Gerraty
35*fb0cb808SSimon J. Gerraty# RCSid:
36*fb0cb808SSimon J. Gerraty#	$Id: stage-install.sh,v 1.5 2013/04/19 16:32:24 sjg Exp $
37*fb0cb808SSimon J. Gerraty#
38*fb0cb808SSimon J. Gerraty#	@(#) Copyright (c) 2013, Simon J. Gerraty
39*fb0cb808SSimon J. Gerraty#
40*fb0cb808SSimon J. Gerraty#	This file is provided in the hope that it will
41*fb0cb808SSimon J. Gerraty#	be of use.  There is absolutely NO WARRANTY.
42*fb0cb808SSimon J. Gerraty#	Permission to copy, redistribute or otherwise
43*fb0cb808SSimon J. Gerraty#	use this file is hereby granted provided that
44*fb0cb808SSimon J. Gerraty#	the above copyright notice and this notice are
45*fb0cb808SSimon J. Gerraty#	left intact.
46*fb0cb808SSimon J. Gerraty#
47*fb0cb808SSimon J. Gerraty#	Please send copies of changes and bug-fixes to:
48*fb0cb808SSimon J. Gerraty#	sjg@crufty.net
49*fb0cb808SSimon J. Gerraty#
50*fb0cb808SSimon J. Gerraty
51*fb0cb808SSimon J. GerratyINSTALL=${REAL_INSTALL:-install}
52*fb0cb808SSimon J. GerratyOBJDIR=.
53*fb0cb808SSimon J. Gerraty
54*fb0cb808SSimon J. Gerratywhile :
55*fb0cb808SSimon J. Gerratydo
56*fb0cb808SSimon J. Gerraty    case "$1" in
57*fb0cb808SSimon J. Gerraty    *=*) eval "$1"; shift;;
58*fb0cb808SSimon J. Gerraty    *) break;;
59*fb0cb808SSimon J. Gerraty    esac
60*fb0cb808SSimon J. Gerratydone
61*fb0cb808SSimon J. Gerraty
62*fb0cb808SSimon J. Gerraty# if .dirdep doesn't exist, just run install and be done
63*fb0cb808SSimon J. Gerraty_DIRDEP=${_DIRDEP:-$OBJDIR/.dirdep}
64*fb0cb808SSimon J. Gerraty[ -s $_DIRDEP ] && EXEC= || EXEC=exec
65*fb0cb808SSimon J. Gerraty$EXEC $INSTALL "$@" || exit 1
66*fb0cb808SSimon J. Gerraty
67*fb0cb808SSimon J. Gerraty# from meta.stage.mk
68*fb0cb808SSimon J. GerratyLnCp() {
69*fb0cb808SSimon J. Gerraty    rm -f $2 2> /dev/null
70*fb0cb808SSimon J. Gerraty    ln $1 $2 2> /dev/null || cp -p $1 $2
71*fb0cb808SSimon J. Gerraty}
72*fb0cb808SSimon J. Gerraty
73*fb0cb808SSimon J. GerratyStageDirdep() {
74*fb0cb808SSimon J. Gerraty  t=$1
75*fb0cb808SSimon J. Gerraty  if [ -s $t.dirdep ]; then
76*fb0cb808SSimon J. Gerraty      cmp -s $_DIRDEP $t.dirdep && return
77*fb0cb808SSimon J. Gerraty      echo "ERROR: $t installed by `cat $t.dirdep` not `cat $_DIRDEP`" >&2
78*fb0cb808SSimon J. Gerraty      exit 1
79*fb0cb808SSimon J. Gerraty  fi
80*fb0cb808SSimon J. Gerraty  LnCp $_DIRDEP $t.dirdep || exit 1
81*fb0cb808SSimon J. Gerraty}
82*fb0cb808SSimon J. Gerraty
83*fb0cb808SSimon J. Gerratyargs="$@"
84*fb0cb808SSimon J. Gerratywhile [ $# -gt 8 ]
85*fb0cb808SSimon J. Gerratydo
86*fb0cb808SSimon J. Gerraty    shift 8
87*fb0cb808SSimon J. Gerratydone
88*fb0cb808SSimon J. Gerratyeval dest=\$$#
89*fb0cb808SSimon J. Gerratyif [ -f $dest ]; then
90*fb0cb808SSimon J. Gerraty    # a file, there can be only one .dirdep needed
91*fb0cb808SSimon J. Gerraty    StageDirdep $dest
92*fb0cb808SSimon J. Gerratyelif [ -d $dest ]; then
93*fb0cb808SSimon J. Gerraty    for f in $args
94*fb0cb808SSimon J. Gerraty    do
95*fb0cb808SSimon J. Gerraty        test -f $f || continue
96*fb0cb808SSimon J. Gerraty        StageDirdep $dest/${f##*/}
97*fb0cb808SSimon J. Gerraty    done
98*fb0cb808SSimon J. Gerratyfi
99