1 |
8291
|
aaronmk
|
#!/bin/bash -e
|
2 |
|
|
shopt -s expand_aliases
|
3 |
8272
|
aaronmk
|
# 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 |
8291
|
aaronmk
|
#!/bin/bash -e
|
9 |
8272
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/util.run or file_including_util.run
|
10 |
|
|
. "$(dirname "${BASH_SOURCE[0]}")"/other_includes
|
11 |
|
|
|
12 |
|
|
cmd ()
|
13 |
|
|
{
|
14 |
8280
|
aaronmk
|
echo_func "$FUNCNAME" "$@"
|
15 |
8272
|
aaronmk
|
"$(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 |
|
|
fi ####
|
20 |
|
|
|
21 |
8278
|
aaronmk
|
echo_cmd () { echo "$PS4$*" >&2; }
|
22 |
8272
|
aaronmk
|
|
23 |
8278
|
aaronmk
|
echo_run () { echo_cmd "$@"; "$@"; }
|
24 |
|
|
|
25 |
8279
|
aaronmk
|
# usage: echo_func "$FUNCNAME" "$@"
|
26 |
8298
|
aaronmk
|
echo_func () { echo_cmd "${BASH_SOURCE[1]}:${BASH_LINENO[0]}" "$@"; }
|
27 |
8279
|
aaronmk
|
|
28 |
8275
|
aaronmk
|
echo_stdin () { tee -a /dev/stderr; } # usage: input|echo_stdin|cmd
|
29 |
|
|
|
30 |
8272
|
aaronmk
|
usage () { echo "Usage: $1" >&2; (exit 2); }
|
31 |
|
|
|
32 |
|
|
top_dir="$(dirname "$0")" # outermost script
|
33 |
|
|
|
34 |
|
|
run_cmd ()
|
35 |
|
|
{
|
36 |
8292
|
aaronmk
|
test "$?" -eq 0 || return
|
37 |
8289
|
aaronmk
|
set -- "${BASH_ARGV[@]}"
|
38 |
8290
|
aaronmk
|
test "$#" -ge 1 || set -- all
|
39 |
8289
|
aaronmk
|
echo_cmd "$0" "$@"; "$@"
|
40 |
8272
|
aaronmk
|
}
|
41 |
8289
|
aaronmk
|
trap run_cmd EXIT
|
42 |
8272
|
aaronmk
|
|
43 |
8284
|
aaronmk
|
fwd () # usage: subdirs=(...); fwd "$FUNCNAME" "$@"
|
44 |
8272
|
aaronmk
|
{
|
45 |
8280
|
aaronmk
|
echo_func "$FUNCNAME" "$@"
|
46 |
8284
|
aaronmk
|
: "${subdirs?}"
|
47 |
|
|
|
48 |
8272
|
aaronmk
|
for subdir in "${subdirs[@]}"; do
|
49 |
8280
|
aaronmk
|
"$(dirname "${BASH_SOURCE[1]}")"/"$subdir"/run "$@"
|
50 |
8272
|
aaronmk
|
done
|
51 |
|
|
}
|
52 |
|
|
|
53 |
8280
|
aaronmk
|
make ()
|
54 |
|
|
{
|
55 |
|
|
echo_func "$FUNCNAME" "$@"
|
56 |
|
|
echo_run env make --directory="$top_dir" "$@"
|
57 |
|
|
}
|
58 |
8272
|
aaronmk
|
|
59 |
8276
|
aaronmk
|
if false; then ## usage:
|
60 |
|
|
inline_make <<'EOF'
|
61 |
|
|
target:
|
62 |
|
|
$(self_dir)/cmd >$@
|
63 |
|
|
EOF
|
64 |
|
|
# target will be run automatically because it's first in the makefile
|
65 |
|
|
fi ##
|
66 |
|
|
inline_make ()
|
67 |
|
|
{
|
68 |
8280
|
aaronmk
|
echo_func "$FUNCNAME" "$@"
|
69 |
8276
|
aaronmk
|
(cat
|
70 |
|
|
cat <<EOF
|
71 |
|
|
|
72 |
|
|
.SUFFIXES: # turn off built-in suffix rules
|
73 |
|
|
.SECONDARY: # don't automatically delete intermediate files
|
74 |
|
|
.DELETE_ON_ERROR: # delete target if recipe fails
|
75 |
|
|
EOF
|
76 |
|
|
)|echo_stdin|make --makefile=/dev/stdin \
|
77 |
|
|
self_dir="$(dirname "$(readlink -f "${BASH_SOURCE[1]}")")" "$@"
|
78 |
|
|
}
|