* rebased llvm/hotfix-sparcv9-not-64.diff
[t2sde.git] / misc / tools-source / install_wrapper.sh
blob7ad4886253bca46385af5f277a2642976f55396d
1 #!/usr/bin/env bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # T2 SDE: misc/tools-source/install_wrapper.sh
4 # Copyright (C) 2004 - 2023 The T2 SDE Project
5 #
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 PATH="${PATH/:$INSTALL_WRAPPER_MYPATH:/:}"
14 PATH="${PATH#$INSTALL_WRAPPER_MYPATH:}"
15 PATH="${PATH%:$INSTALL_WRAPPER_MYPATH}"
17 if [ "$INSTALL_WRAPPER_NOLOOP" = 1 ]; then
18 echo "--"
19 echo "Found loop in install_wrapper: $0 $*" >&2
20 echo "INSTALL_WRAPPER_MYPATH=$INSTALL_WRAPPER_MYPATH"
21 echo "PATH=$PATH"
22 echo "--"
23 exit 1
25 export INSTALL_WRAPPER_NOLOOP=1
27 logfile="${INSTALL_WRAPPER_LOGFILE:-/dev/null}"
28 [ -z "${logfile##*/*}" -a ! -d "${logfile%/*}" ] && logfile=/dev/null
30 command="${0##*/}"
31 destination=
32 declare -a sources
33 newcommand="$command"
34 sources_counter=0
35 error=0
37 echo "" >> $logfile
38 echo "$PWD:" >> $logfile
39 echo "* ${INSTALL_WRAPPER_FILTER:-No Filter.}" >> $logfile
40 echo "- $command $*" >> $logfile
42 if [ "${*/--target-directory//}" != "$*" ]; then
43 echo "= $command $*" >> $logfile
44 $command "$@"; exit $?
47 while [ $# -gt 0 ]; do
48 # split combined args
49 case "$1" in
50 -*)
51 # split combined args, like -m755
52 for a in `echo $1 | sed '/^-[^-]/ {s/^-//; s/\([^0-9-]\)/ -\1/g}'`; do
53 case "$a" in
54 -g|-m|-o|-S|--group|--mode|--owner|--suffix)
55 newcommand="$newcommand $a $2"
56 shift
58 -s|--strip)
59 if [[ $command != *install ]]; then
60 newcommand="$newcommand $a"
63 -t)
64 : # skip -t for now, as we generate target filenames
66 -*)
67 newcommand="$newcommand $a"
69 esac
70 done
74 if [ -n "$destination" ]; then
75 sources[sources_counter++]="$destination"
77 destination="$1"
79 esac
80 shift
81 done
83 [ -z "${destination##/*}" ] || destination="$PWD/$destination"
85 if [ "$INSTALL_WRAPPER_FILTER" != "" ]; then
86 # normalize multiple / path separators to allow filters to just match
87 destination="$(eval "echo \"$destination\" | tr -s '/' | $INSTALL_WRAPPER_FILTER" )"
90 if [ -z "$destination" -o $sources_counter -eq 0 ]; then
91 echo "+ $newcommand $destination" >> $logfile
92 $newcommand "$destination" || error=$?
93 elif [ -d "$destination" ]; then
94 for source in "${sources[@]}"; do
95 thisdest="${destination}"
96 [ ! -d "${source//\/\///}" ] && thisdest="$thisdest/${source##*/}"
97 thisdest="${thisdest//\/\///}"
98 [ "$INSTALL_WRAPPER_FILTER" != "" ] &&
99 thisdest="$(eval "echo \"$thisdest\" | $INSTALL_WRAPPER_FILTER" )"
100 if [ ! -z "$thisdest" ]; then
101 echo "+ $newcommand $source $thisdest" >> $logfile
102 $newcommand "$source" "$thisdest" || error=$?
104 done
105 else
106 echo "+ $newcommand ${sources[*]} $destination" >> $logfile
107 $newcommand "${sources[@]}" "$destination" || error=$?
110 echo "===> Returncode: $error" >> $logfile
111 exit $error