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