1 |
9016
|
aaronmk
|
#!/bin/bash -e
|
2 |
|
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
|
3 |
|
|
|
4 |
|
|
if self_not_included; then
|
5 |
|
|
|
6 |
9074
|
aaronmk
|
# usage: target_filename/command() { echo_func; set_make_vars; ...; }
|
7 |
9016
|
aaronmk
|
alias set_make_vars="$(cat <<'EOF'
|
8 |
|
|
local command="${FUNCNAME##*/}"; echo_vars command
|
9 |
|
|
local target_filename="${FUNCNAME%/*}"; echo_vars target_filename
|
10 |
|
|
local target="$top_dir/$target_filename"; echo_vars target
|
11 |
|
|
EOF
|
12 |
|
|
)"
|
13 |
|
|
|
14 |
9054
|
aaronmk
|
alias remaking='test "$remake"'
|
15 |
|
|
|
16 |
9016
|
aaronmk
|
# usage: set_make_vars; check_target_exists
|
17 |
9063
|
aaronmk
|
alias check_target_exists='remaking || require_exists "$target" || return 0'
|
18 |
9059
|
aaronmk
|
alias check_fake_target_exists='remaking || declare if_not_exists=1'
|
19 |
|
|
# defer check until to_file
|
20 |
9016
|
aaronmk
|
|
21 |
|
|
# usage: set_make_vars; to_target cmd...
|
22 |
|
|
alias to_target='stdout="$target" to_file ' # last space alias-expands next word
|
23 |
|
|
|
24 |
9074
|
aaronmk
|
make() { echo_func; stdout2stderr=1 limit_stderr_cmd self "$@"; }
|
25 |
9016
|
aaronmk
|
|
26 |
|
|
if false; then ## usage:
|
27 |
|
|
inline_make 3<<'EOF'
|
28 |
|
|
target:
|
29 |
|
|
$(self_dir)/cmd >$@
|
30 |
|
|
EOF
|
31 |
|
|
# target will be run automatically because it's first in the makefile
|
32 |
|
|
fi ##
|
33 |
9074
|
aaronmk
|
inline_make()
|
34 |
9016
|
aaronmk
|
{
|
35 |
|
|
echo_func
|
36 |
|
|
local self="$(readlink -f "${BASH_SOURCE[1]}")"
|
37 |
|
|
local self_dir="$(dirname "$self")"
|
38 |
|
|
export self self_dir
|
39 |
|
|
|
40 |
|
|
make --makefile=<((
|
41 |
|
|
cat /dev/fd/3
|
42 |
|
|
echo -n "
|
43 |
|
|
.SUFFIXES: # turn off built-in suffix rules
|
44 |
|
|
.SECONDARY: # don't automatically delete intermediate files
|
45 |
|
|
.DELETE_ON_ERROR: # delete target if recipe fails
|
46 |
|
|
"
|
47 |
|
|
)|echo_stdin) "$@"
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
fi
|