2005-02-16 14:13:18 +03:00
|
|
|
makeWrapper() {
|
2008-01-18 14:28:41 +03:00
|
|
|
local original=$1
|
|
|
|
local wrapper=$2
|
|
|
|
local params varName value command separator n fileNames
|
2008-06-15 00:45:58 +04:00
|
|
|
local flagsBefore flags
|
2005-02-16 14:13:18 +03:00
|
|
|
|
2012-01-19 00:16:00 +04:00
|
|
|
mkdir -p "$(dirname $wrapper)"
|
2005-02-16 14:13:18 +03:00
|
|
|
|
|
|
|
echo "#! $SHELL -e" > $wrapper
|
|
|
|
|
|
|
|
params=("$@")
|
|
|
|
for ((n = 2; n < ${#params[*]}; n += 1)); do
|
|
|
|
p=${params[$n]}
|
|
|
|
|
2005-03-09 22:07:23 +03:00
|
|
|
if test "$p" = "--set"; then
|
|
|
|
varName=${params[$((n + 1))]}
|
|
|
|
value=${params[$((n + 2))]}
|
|
|
|
n=$((n + 2))
|
|
|
|
echo "export $varName=$value" >> $wrapper
|
|
|
|
fi
|
|
|
|
|
2008-01-18 14:28:41 +03:00
|
|
|
if test "$p" = "--run"; then
|
|
|
|
command=${params[$((n + 1))]}
|
|
|
|
n=$((n + 1))
|
|
|
|
echo "$command" >> $wrapper
|
|
|
|
fi
|
|
|
|
|
2005-03-13 23:43:04 +03:00
|
|
|
if test "$p" = "--suffix" -o "$p" = "--prefix"; then
|
2005-02-16 14:13:18 +03:00
|
|
|
varName=${params[$((n + 1))]}
|
|
|
|
separator=${params[$((n + 2))]}
|
|
|
|
value=${params[$((n + 3))]}
|
|
|
|
n=$((n + 3))
|
2005-02-16 14:24:40 +03:00
|
|
|
if test -n "$value"; then
|
2005-03-13 23:43:04 +03:00
|
|
|
if test "$p" = "--suffix"; then
|
|
|
|
echo "export $varName=\$$varName\${$varName:+$separator}$value" >> $wrapper
|
|
|
|
else
|
|
|
|
echo "export $varName=$value\${$varName:+$separator}\$$varName" >> $wrapper
|
|
|
|
fi
|
2005-02-16 14:24:40 +03:00
|
|
|
fi
|
2005-02-16 14:13:18 +03:00
|
|
|
fi
|
2005-02-16 14:38:52 +03:00
|
|
|
|
|
|
|
if test "$p" = "--suffix-each"; then
|
|
|
|
varName=${params[$((n + 1))]}
|
|
|
|
separator=${params[$((n + 2))]}
|
|
|
|
values=${params[$((n + 3))]}
|
|
|
|
n=$((n + 3))
|
|
|
|
for value in $values; do
|
|
|
|
echo "export $varName=\$$varName\${$varName:+$separator}$value" >> $wrapper
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2009-07-16 15:22:37 +04:00
|
|
|
if test "$p" = "--suffix-contents" -o "$p" = "--prefix-contents"; then
|
2005-02-16 14:38:52 +03:00
|
|
|
varName=${params[$((n + 1))]}
|
|
|
|
separator=${params[$((n + 2))]}
|
|
|
|
fileNames=${params[$((n + 3))]}
|
|
|
|
n=$((n + 3))
|
|
|
|
for fileName in $fileNames; do
|
2009-07-16 15:22:37 +04:00
|
|
|
if test "$p" = "--suffix-contents"; then
|
|
|
|
echo "export $varName=\$$varName\${$varName:+$separator}$(cat $fileName)" >> $wrapper
|
|
|
|
else
|
|
|
|
echo "export $varName=$(cat $fileName)\${$varName:+$separator}\$$varName" >> $wrapper
|
|
|
|
fi
|
2005-02-16 14:38:52 +03:00
|
|
|
done
|
|
|
|
fi
|
2008-06-15 00:45:58 +04:00
|
|
|
|
|
|
|
if test "$p" = "--add-flags"; then
|
|
|
|
flags=${params[$((n + 1))]}
|
|
|
|
n=$((n + 1))
|
|
|
|
flagsBefore="$flagsBefore $flags"
|
|
|
|
fi
|
2005-02-16 14:13:18 +03:00
|
|
|
done
|
|
|
|
|
2009-04-05 22:13:59 +04:00
|
|
|
# Note: extraFlagsArray is an array containing additional flags
|
|
|
|
# that may be set by --run actions.
|
|
|
|
echo exec "$original" $flagsBefore '"${extraFlagsArray[@]}"' '"$@"' >> $wrapper
|
2005-02-16 14:13:18 +03:00
|
|
|
|
|
|
|
chmod +x $wrapper
|
|
|
|
}
|
2005-02-16 14:38:52 +03:00
|
|
|
|
|
|
|
addSuffix() {
|
|
|
|
suffix=$1
|
|
|
|
shift
|
|
|
|
for name in "$@"; do
|
|
|
|
echo "$name$suffix"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
filterExisting() {
|
|
|
|
for fn in "$@"; do
|
|
|
|
if test -e "$fn"; then
|
|
|
|
echo "$fn"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2008-01-18 13:29:58 +03:00
|
|
|
|
|
|
|
# Syntax: wrapProgram <PROGRAM> <MAKE-WRAPPER FLAGS...>
|
|
|
|
wrapProgram() {
|
|
|
|
local prog="$1"
|
2009-04-05 22:13:59 +04:00
|
|
|
local hidden="$(dirname "$prog")/.$(basename "$prog")"-wrapped
|
2008-01-18 13:29:58 +03:00
|
|
|
mv $prog $hidden
|
|
|
|
makeWrapper $hidden $prog "$@"
|
|
|
|
}
|