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