1 |
8272
|
aaronmk
|
#!/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 |
|
|
usage () { echo "Usage: $1" >&2; (exit 2); }
|
26 |
|
|
|
27 |
|
|
top_dir="$(dirname "$0")" # outermost script
|
28 |
|
|
|
29 |
|
|
run_cmd ()
|
30 |
|
|
{
|
31 |
|
|
# only if called in outermost script (+1 for this script)
|
32 |
|
|
if test "${#BASH_SOURCE[@]}" -eq 2; then
|
33 |
|
|
test "$#" -ge 1 || usage "$0 cmd args" || return
|
34 |
|
|
"$@"
|
35 |
|
|
fi
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
fwd ()
|
39 |
|
|
{
|
40 |
|
|
for subdir in "${subdirs[@]}"; do
|
41 |
|
|
echo_cmd "$(dirname "${BASH_SOURCE[1]}")"/"$subdir"/run "$@"
|
42 |
|
|
done
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
make () { echo_cmd env make --directory="$top_dir" "$@"; }
|
46 |
|
|
|
47 |
|
|
run_cmd "$@"
|