summaryrefslogtreecommitdiff
path: root/mk/wrapper/wrapper-subr.sh
blob: 01486f8dcac1370df68f0d24a5d84158e39583e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# $NetBSD: wrapper-subr.sh,v 1.10 2007/02/22 14:54:32 rillig Exp $
#
# This file contains shell functions that are useful to the wrapper
# scripts.
#

# usage: transform_setname "current-file"
transform_setname() {
	wrapsubr_name="$1"
}

# usage: transform_to "newarg"
transform_to() {
	arg="$1"
	$debug_log $wrapperlog "    ($wrapsubr_name) to: $1"
	addtocache=yes
}

# usage: transform_to_and_split "newarg"
transform_to_and_split() {
	arg="$1"
	$debug_log $wrapperlog "    ($wrapsubr_name) to: $1 [split]"
	addtocache=yes
	split_arg=yes
}

# usage: transform_discard
transform_discard() {
	$debug_log $wrapperlog "    ($wrapsubr_name) discarded: $arg"
	arg=""
	addtocache=yes
	split_arg=yes
}

# usage: transform_discard_with_warning [warning]
transform_discard_with_warning() {
	_warning=${1-"discarding option $arg"}
	msg_log "$wrapperlog" "WARNING: [$wrapsubr_name] $_warning"
	transform_discard
	addtocache=no
}

# usage: transform_pass
transform_pass() {
	$debug_log $wrapperlog "    ($wrapsubr_name) to: $arg [unchanged]"
	addtocache=yes
}

# usage: transform_pass_with_warning [warning]
transform_pass_with_warning() {
	_warning=${1-"passing unknown option $arg"}
	msg_log "$wrapperlog" "WARNING: [$wrapsubr_name] $_warning"
	$debug_log $wrapperlog "    ($wrapsubr_name) to: $arg [unchanged]"
	addtocache=no
}

# usage: transform_fail "error message"
transform_fail() {
	msg_log "$wrapperlog" "ERROR: [$wrapsubr_name] $1"
	msg_log stderr "ERROR: [$wrapsubr_name] $1"
	exit 1
}

# usage: fail "source-file" "error message"
fail() {
	msg_log "$wrapperlog" "ERROR: [$1] $2"
	msg_log stderr "ERROR: [$1] $2"
	exit 1
}