1
|
#!/bin/bash
|
2
|
set -o errexit; shopt -s expand_aliases
|
3
|
# run scripts: a bash-based replacement for make
|
4
|
# unlike make, supports full bash functionality including multiline commands
|
5
|
# usage: path/to/dir/run cmd args
|
6
|
|
7
|
if false; then #### run script template:
|
8
|
#!/bin/bash
|
9
|
set -o errexit
|
10
|
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/util.run or file_including_util.run
|
11
|
. "$(dirname "${BASH_SOURCE[0]}")"/other_includes
|
12
|
|
13
|
cmd ()
|
14
|
{
|
15
|
"$(dirname "${BASH_SOURCE[0]}")"/path_relative_to_self
|
16
|
"$(dirname "${BASH_SOURCE[1]}")"/path_relative_to_caller
|
17
|
"$top_dir"/path_relative_to_outermost_script
|
18
|
}
|
19
|
|
20
|
run_cmd "$@"
|
21
|
fi ####
|
22
|
|
23
|
echo_cmd () { echo "$PS4$*" >&2; "$@"; }
|
24
|
|
25
|
echo_stdin () { tee -a /dev/stderr; } # usage: input|echo_stdin|cmd
|
26
|
|
27
|
usage () { echo "Usage: $1" >&2; (exit 2); }
|
28
|
|
29
|
top_dir="$(dirname "$0")" # outermost script
|
30
|
|
31
|
run_cmd ()
|
32
|
{
|
33
|
# only if called in outermost script (+1 for this script)
|
34
|
if test "${#BASH_SOURCE[@]}" -eq 2; then
|
35
|
test "$#" -ge 1 || usage "$0 cmd args" || return
|
36
|
"$@"
|
37
|
fi
|
38
|
}
|
39
|
|
40
|
fwd ()
|
41
|
{
|
42
|
for subdir in "${subdirs[@]}"; do
|
43
|
echo_cmd "$(dirname "${BASH_SOURCE[1]}")"/"$subdir"/run "$@"
|
44
|
done
|
45
|
}
|
46
|
|
47
|
make () { echo_cmd env make --directory="$top_dir" "$@"; }
|
48
|
|
49
|
run_cmd "$@"
|