1 |
9016
|
aaronmk
|
#!/bin/bash -e
|
2 |
|
|
. "$(dirname "${BASH_SOURCE[0]}")"/util.sh
|
3 |
|
|
|
4 |
|
|
if self_not_included; then
|
5 |
|
|
|
6 |
9354
|
aaronmk
|
# usage: target_filename/command() { echo_func; set_make_vars; use $target...; }
|
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 |
9431
|
aaronmk
|
local target_stem="${target_filename%.*}"; echo_vars target_stem
|
12 |
9016
|
aaronmk
|
EOF
|
13 |
|
|
)"
|
14 |
|
|
|
15 |
9147
|
aaronmk
|
if isset rm; then : "${remake:=$rm}"; fi #mnemonic: files are rm'd (overwritten)
|
16 |
|
|
|
17 |
9348
|
aaronmk
|
# usage: remaking || check if exists
|
18 |
|
|
# cmd line usage: [remake=1] func
|
19 |
9054
|
aaronmk
|
alias remaking='test "$remake"'
|
20 |
|
|
|
21 |
9016
|
aaronmk
|
# usage: set_make_vars; check_target_exists
|
22 |
9122
|
aaronmk
|
alias check_target_exists='remaking || require_not_exists "$target" || return 0'
|
23 |
9059
|
aaronmk
|
alias check_fake_target_exists='remaking || declare if_not_exists=1'
|
24 |
|
|
# defer check until to_file
|
25 |
9016
|
aaronmk
|
|
26 |
|
|
# usage: set_make_vars; to_target cmd...
|
27 |
|
|
alias to_target='stdout="$target" to_file ' # last space alias-expands next word
|
28 |
|
|
|
29 |
9214
|
aaronmk
|
make() { echo_func; cmd_log_fd=1 self "$@"; }
|
30 |
9016
|
aaronmk
|
|
31 |
9505
|
aaronmk
|
top_make() { echo_func; make --directory="$top_dir" "$@"; }
|
32 |
|
|
|
33 |
9016
|
aaronmk
|
if false; then ## usage:
|
34 |
9353
|
aaronmk
|
inline_make <<'EOF'
|
35 |
9016
|
aaronmk
|
target:
|
36 |
|
|
$(self_dir)/cmd >$@
|
37 |
|
|
EOF
|
38 |
|
|
# target will be run automatically because it's first in the makefile
|
39 |
|
|
fi ##
|
40 |
9074
|
aaronmk
|
inline_make()
|
41 |
9016
|
aaronmk
|
{
|
42 |
|
|
echo_func
|
43 |
9237
|
aaronmk
|
local_export self="$(readlink -f "${BASH_SOURCE[1]}")"; echo_vars self
|
44 |
|
|
local_export self_dir="$(dirname "$self")"; echo_vars self_dir
|
45 |
9016
|
aaronmk
|
|
46 |
|
|
make --makefile=<((
|
47 |
9353
|
aaronmk
|
cat # script stdin from caller-provided stdin
|
48 |
9016
|
aaronmk
|
echo -n "
|
49 |
|
|
.SUFFIXES: # turn off built-in suffix rules
|
50 |
|
|
.SECONDARY: # don't automatically delete intermediate files
|
51 |
|
|
.DELETE_ON_ERROR: # delete target if recipe fails
|
52 |
|
|
"
|
53 |
9353
|
aaronmk
|
)|echo_stdin) "$@" <&20 # make's stdin from global stdin
|
54 |
9016
|
aaronmk
|
}
|
55 |
|
|
|
56 |
|
|
fi
|