Project

General

Profile

1
#!/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
alias remaking='test "$remake"'
15

    
16
# usage: set_make_vars; check_target_exists
17
alias check_target_exists='! test -e "$target" || return 0'
18

    
19
# usage: set_make_vars; to_target cmd...
20
alias to_target='stdout="$target" to_file ' # last space alias-expands next word
21

    
22
make () { echo_func; stdout2stderr=1 limit_stderr_cmd self "$@"; }
23

    
24
if false; then ## usage:
25
inline_make 3<<'EOF'
26
target:
27
	$(self_dir)/cmd >$@
28
EOF
29
# target will be run automatically because it's first in the makefile
30
fi ##
31
inline_make ()
32
{
33
	echo_func
34
	local self="$(readlink -f "${BASH_SOURCE[1]}")"
35
	local self_dir="$(dirname "$self")"
36
	export self self_dir
37
	
38
	make --makefile=<((
39
		cat /dev/fd/3
40
		echo -n "
41
.SUFFIXES: # turn off built-in suffix rules
42
.SECONDARY: # don't automatically delete intermediate files
43
.DELETE_ON_ERROR: # delete target if recipe fails
44
"
45
	)|echo_stdin) "$@"
46
}
47

    
48
fi
(4-4/5)