Project

General

Profile

« Previous | Next » 

Revision 9016

lib/sh/util.sh: split make utils out into separate make.sh

View differences:

inputs/GBIF/table.run
1 1
#!/bin/bash -e
2 2
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/runscripts/table.run
3
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/sh/make.sh
3 4

  
4 5
if self_not_included; then
5 6

  
schemas/VegCore/VegCore.ERD.mwb.run
3 3
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/runscripts/util.run
4 4
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/sh/archives.sh
5 5
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/sh/local.sh
6
. "$(dirname "${BASH_SOURCE[0]}")"/../../lib/sh/make.sh
6 7

  
7 8
if self_not_included; then
8 9

  
lib/sh/util.sh
251 251
	done
252 252
}
253 253

  
254
#### make
255

  
256
# usage: target_filename/command () { echo_func; set_make_vars; ...; }
257
alias set_make_vars="$(cat <<'EOF'
258
local command="${FUNCNAME##*/}"; echo_vars command
259
local target_filename="${FUNCNAME%/*}"; echo_vars target_filename
260
local target="$top_dir/$target_filename"; echo_vars target
261
EOF
262
)"
263

  
264
# usage: set_make_vars; check_target_exists
265
alias check_target_exists='! test -e "$target" || return 0'
266

  
267
# usage: set_make_vars; to_target cmd...
268
alias to_target='stdout="$target" to_file ' # last space alias-expands next word
269

  
270
make () { echo_func; stdout2stderr=1 limit_stderr_cmd self "$@"; }
271

  
272
if false; then ## usage:
273
inline_make 3<<'EOF'
274
target:
275
	$(self_dir)/cmd >$@
276
EOF
277
# target will be run automatically because it's first in the makefile
278
fi ##
279
inline_make ()
280
{
281
	echo_func
282
	local self="$(readlink -f "${BASH_SOURCE[1]}")"
283
	local self_dir="$(dirname "$self")"
284
	export self self_dir
285
	
286
	make --makefile=<((
287
		cat /dev/fd/3
288
		echo -n "
289
.SUFFIXES: # turn off built-in suffix rules
290
.SECONDARY: # don't automatically delete intermediate files
291
.DELETE_ON_ERROR: # delete target if recipe fails
292
"
293
	)|echo_stdin) "$@"
294
}
295

  
296 254
#### URLs
297 255

  
298 256
localize_url () { test _"$1" = _"$(hostname -f)" || echo "$1"; }
lib/sh/make.sh
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
# 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
0 47

  

Also available in: Unified diff