1 |
8291
|
aaronmk
|
#!/bin/bash -e
|
2 |
8715
|
aaronmk
|
# runscripts: a bash-based replacement for make
|
3 |
8272
|
aaronmk
|
# unlike make, supports full bash functionality including multiline commands
|
4 |
10834
|
aaronmk
|
# usage: .../run function args
|
5 |
10835
|
aaronmk
|
# this usage also applies to all files that include this file
|
6 |
8272
|
aaronmk
|
|
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 |
9854
|
aaronmk
|
.rel other_includes
|
11 |
8272
|
aaronmk
|
|
12 |
9074
|
aaronmk
|
cmd()
|
13 |
8272
|
aaronmk
|
{
|
14 |
8881
|
aaronmk
|
echo_func
|
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 |
9013
|
aaronmk
|
. "$(dirname "${BASH_SOURCE[0]}")"/../sh/util.sh
|
22 |
9854
|
aaronmk
|
.rel ../sh/make.sh
|
23 |
8703
|
aaronmk
|
|
24 |
8714
|
aaronmk
|
if self_not_included; then
|
25 |
8703
|
aaronmk
|
|
26 |
10271
|
aaronmk
|
|
27 |
|
|
#### setup
|
28 |
|
|
|
29 |
|
|
run_args_cmd() # runs the command line args command
|
30 |
|
|
{
|
31 |
|
|
eval set -- "$(reverse "${BASH_ARGV[@]}")"
|
32 |
|
|
test $# -ge 1 || set -- all
|
33 |
|
|
echo_cmd "$top_script" "$@"; time "$@"
|
34 |
|
|
}
|
35 |
|
|
|
36 |
8972
|
aaronmk
|
# users can override run_args_cmd to perform other commands (or no commands)
|
37 |
8464
|
aaronmk
|
# after the script is read
|
38 |
9298
|
aaronmk
|
on_exit() { test $? -eq 0 || return; run_args_cmd; }
|
39 |
8464
|
aaronmk
|
trap on_exit EXIT
|
40 |
|
|
|
41 |
9268
|
aaronmk
|
func_override set_paths__util_sh
|
42 |
|
|
set_paths()
|
43 |
9267
|
aaronmk
|
{
|
44 |
9268
|
aaronmk
|
set_paths__util_sh "$@"
|
45 |
9267
|
aaronmk
|
top_file="${top_script%[./]run}"; echo_vars top_file
|
46 |
|
|
top_filename="$(basename "$top_file")"; echo_vars top_filename
|
47 |
|
|
}
|
48 |
9268
|
aaronmk
|
set_paths
|
49 |
8988
|
aaronmk
|
|
50 |
10271
|
aaronmk
|
|
51 |
|
|
#### utils
|
52 |
|
|
|
53 |
11348
|
aaronmk
|
wrap_fn="$top_script" # usage: sudo "$wrap_fn" fn ...
|
54 |
|
|
|
55 |
10766
|
aaronmk
|
# usage: to_top_file cmd...
|
56 |
11359
|
aaronmk
|
function to_top_file() { echo_func; stdout="$top_file" to_file "$@"; }
|
57 |
11358
|
aaronmk
|
alias to_top_file='"to_top_file" ' # last space alias-expands next word
|
58 |
10766
|
aaronmk
|
|
59 |
10272
|
aaronmk
|
,() # usage: .../run , cmd1 cmd2 ... (like `make cmd1 cmd2 ...`)
|
60 |
|
|
# treats each of the command-line args as commands the way make does
|
61 |
|
|
# (instead of as args to the same command, the way runscripts do)
|
62 |
|
|
{ echo_func; for cmd in "$@"; do time echo_run "$cmd"; done; }
|
63 |
|
|
|
64 |
10271
|
aaronmk
|
fwd() # usage: subdirs=(...); fwd "$FUNCNAME" "$@"
|
65 |
|
|
{
|
66 |
|
|
echo_func
|
67 |
|
|
: "${subdirs?}"
|
68 |
|
|
|
69 |
|
|
for subdir in "${subdirs[@]}"; do "$top_dir"/"$subdir"/run "$@"; done
|
70 |
|
|
}
|
71 |
|
|
|
72 |
8704
|
aaronmk
|
fi
|