Project

General

Profile

1
#!/bin/bash -e
2
# runscripts: a bash-based replacement for make
3
# unlike make, supports full bash functionality including multiline commands
4
# usage: path/to/dir/run cmd args
5

    
6
if false; then #### run script template:
7
#!/bin/bash -e
8
. "$(dirname "${BASH_SOURCE[0]}")"/path/to/util.run or file_including_util.run
9
.rel other_includes
10

    
11
cmd()
12
{
13
	echo_func
14
	"$(dirname "${BASH_SOURCE[0]}")"/path_relative_to_self
15
	"$(dirname "${BASH_SOURCE[1]}")"/path_relative_to_caller
16
	"$top_dir"/path_relative_to_outermost_script
17
}
18
fi ####
19

    
20
. "$(dirname "${BASH_SOURCE[0]}")"/../sh/util.sh
21
.rel ../sh/make.sh
22

    
23
if self_not_included; then
24

    
25

    
26
#### setup
27

    
28
run_args_cmd() # runs the command line args command
29
{
30
	eval set -- "$(reverse "${BASH_ARGV[@]}")"
31
	test $# -ge 1 || set -- all
32
	echo_cmd "$top_script" "$@"; time "$@"
33
}
34

    
35
# users can override run_args_cmd to perform other commands (or no commands)
36
# after the script is read
37
on_exit() { test $? -eq 0 || return; run_args_cmd; }
38
trap on_exit EXIT
39

    
40
func_override set_paths__util_sh
41
set_paths()
42
{
43
	set_paths__util_sh "$@"
44
	top_file="${top_script%[./]run}"; echo_vars top_file
45
	top_filename="$(basename "$top_file")"; echo_vars top_filename
46
}
47
set_paths
48

    
49

    
50
#### utils
51

    
52
# usage: to_top_file cmd...
53
alias to_top_file='stdout="$top_file" to_file ' #last sp alias-expands next word
54

    
55
,() # usage: .../run , cmd1 cmd2 ... (like `make cmd1 cmd2 ...`)
56
# treats each of the command-line args as commands the way make does
57
# (instead of as args to the same command, the way runscripts do)
58
{ echo_func; for cmd in "$@"; do time echo_run "$cmd"; done; }
59

    
60
fwd() # usage: subdirs=(...); fwd "$FUNCNAME" "$@"
61
{
62
	echo_func
63
	: "${subdirs?}"
64
	
65
	for subdir in "${subdirs[@]}"; do "$top_dir"/"$subdir"/run "$@"; done
66
}
67

    
68
fi
(10-10/11)