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