summaryrefslogtreecommitdiffhomepage
path: root/subr/ex_pkg_env.subr
blob: 5048c9395f1e7c6d7554137c01d38552ec67f7eb (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#
# set +o errexit -o noglob -o nounset is assumed.
#

#
# exp_pkg_env_defaults() - set package variable defaults for single named package
# @_build_steps_default:	list of default build steps
# @_pkg_name:			single package name
# @_workdir:			pathname to build-specific temporary directory
#
# Return:			zero (0) on success, non-zero (>0) on failure
#
exp_pkg_env_defaults() {
	local _build_steps_default="${1}" _pkg_name="${2}" _workdir="${3}";
	: ${PKG_NAME:="${_pkg_name}"};
	: ${MIDIPIX_BUILD_PWD:="$(pwd)"};
	: ${PKG_BASE_DIR:="${_workdir}/${_pkg_name}-${PKG_BUILD_TYPE}-${PKG_TARGET}"};
	if [ -n "${PKG_BUILD_STEPS_DISABLE:-}" ]; then
		: ${PKG_BUILD_STEPS:="$(rtl_lfilter "${_build_steps_default}" "${PKG_BUILD_STEPS_DISABLE:-}")"};
	else
		: ${PKG_BUILD_STEPS:="${_build_steps_default}"};
	fi;
	if [ -n "${PKG_URL:-}" ]; then
		: ${PKG_FNAME:="${PKG_URL##*/}"};
	fi;
	if [ -z "${PKG_SUBDIR:-}" ]; then
		if [ -n "${PKG_URLS_GIT:-}" ]\
		&& [ -n "${PKG_FNAME:-}" ]; then
			rtl_log_msg fatalexit "Error: \${PKG_SUBDIR} must be specified given both \${PKG_FNAME} and \${PKG_URLS_GIT}.";
		elif [ -n "${PKG_URLS_GIT:-}" ]; then
			PKG_SUBDIR="${PKG_URLS_GIT%%=*}";
		else case "${PKG_FNAME:-}" in
		*.t*)	PKG_SUBDIR="${PKG_FNAME%%.t*}"; ;;
		*)	PKG_SUBDIR="${_pkg_name}"; ;;
		esac; fi;
	fi;
	if [ -z "${PKG_BUILD_DIR:-}" ]; then
		case "${PKG_IN_TREE:-0}" in
		0) PKG_BUILD_DIR="obj"; ;;
		1) PKG_BUILD_DIR="${PKG_SUBDIR}"; ;;
		esac;
	fi;
	PKG_BUILD_DIR="${PKG_BASE_DIR}/${PKG_BUILD_DIR}";
	PKG_CONFIGURE="${PKG_BASE_DIR}/${PKG_CONFIGURE:-${PKG_SUBDIR}/configure}";
	PKG_DESTDIR="${PKG_BASE_DIR}/${PKG_DESTDIR:-destdir}";
	PKG_DESTDIR_HOST="${PKG_BASE_DIR}/${PKG_DESTDIR_HOST:-destdir_host}";
};

#
# exp_pkg_env_set() - set package variables for single named package
# @_build_vars_default:	list of default build variables
# @_group_name:		build group name
# @_nounset:		don't clear package variable namespace
# @_pkg_name:		single package name
#
# Sets package variables from either defaults, defaults specific to build type,
# build group, package to inherit from if any, or package for a single named
# package, exports variables optionally named in ${PKG_ENV_VARS_EXTRA}, and
# clears the package variable namespace.
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
exp_pkg_env_set() {
	local	_build_vars_default="${1}" _group_name="${2}" _nounset="${3}"\
		_pkg_name="${4}" _var_prefixes="" _vars_set="" _vname="" IFS IFS0;
	rtl_set_vars _vars_set BUILD_TYPE "DEFAULT ${_group_name} PKG_${_pkg_name}";
	rtl_set_vars _vars_set INHERIT_FROM "PKG_${_pkg_name}";
	_var_prefixes="$(rtl_toupper "DEFAULT DEFAULT_${PKG_BUILD_TYPE} ${_group_name}")";
	for _vname in $(rtl_lfilter "${_build_vars_default}" BUILD_TYPE); do
		if [ -n "${PKG_INHERIT_FROM:-}" ]; then
			rtl_set_vars _vars_set "${_vname}"				\
				"$(rtl_lconcat "${_var_prefixes}"			\
				"$(rtl_toupper "PKG_${PKG_INHERIT_FROM} PKG_${PKG_INHERIT_FROM}_${BUILD_KIND} PKG_${_pkg_name} PKG_${_pkg_name}_${BUILD_KIND}")")";
		else
			rtl_set_vars _vars_set "${_vname}"				\
				"$(rtl_lconcat "${_var_prefixes}"			\
				"$(rtl_toupper "PKG_${_pkg_name} PKG_${_pkg_name}_${BUILD_KIND}")")";
		fi;
	done;
	IFS0="${IFS:- }"; IFS=":"; for _vname in ${PKG_ENV_VARS_EXTRA:-}; do
		export "${_vname}";
	done; IFS="${IFS0}";
	if [ "${_nounset:-0}" -eq 0 ]; then
		rtl_unset_vars $(rtl_lfilter						\
			"$(set | sed -ne '/^PKG_[^=]*=/s/=.*$//p' | paste -s -d " ")"	\
			"${_vars_set}");
	fi;
};

ex_pkg_env_sofort() {
	local	_pkg_base_dir="${1}" _pkg_sofort_force="${2}" _pkg_subdir="${3}"	\
		_vname="" _vname_new="" _vval="" _vval_old="";

	if [ -d "${_pkg_base_dir}/${_pkg_subdir}/sofort" ]				\
	|| [ "${_pkg_sofort_force:-0}" -eq 1 ]; then
		for _vname in	\
				PKG_SOFORT_NATIVE_CC					\
				PKG_SOFORT_NATIVE_CFLAGS				\
				PKG_SOFORT_NATIVE_CXX					\
				PKG_SOFORT_NATIVE_CXXFLAGS				\
				PKG_SOFORT_NATIVE_LD					\
				PKG_SOFORT_NATIVE_LDFLAGS; do
			_vname_new="PKG_${_vname#PKG_SOFORT_}";
			rtl_set_var_unsafe "${_vname_new}" "";
		done;
		for _vname in	\
				PKG_SOFORT_NATIVE_CC					\
				PKG_SOFORT_NATIVE_CFLAGS				\
				PKG_SOFORT_NATIVE_CFLAGS_EXTRA				\
				PKG_SOFORT_NATIVE_CXX					\
				PKG_SOFORT_NATIVE_CXXFLAGS				\
				PKG_SOFORT_NATIVE_CXXFLAGS_EXTRA			\
				PKG_SOFORT_NATIVE_LD					\
				PKG_SOFORT_NATIVE_LDFLAGS				\
				PKG_SOFORT_NATIVE_LDFLAGS_EXTRA; do
			if _vval="$(rtl_get_var_unsafe "${_vname}")"			\
			&& [ -n "${_vval}" ]; then
				_vname_new="${_vname#PKG_SOFORT_}";
				case "${_vname}" in
				*_EXTRA)
					_vval_old="$(rtl_get_var_unsafe "${_vname_new%_EXTRA}")";
					rtl_set_var_unsafe "${_vname_new%_EXTRA}" "${_vval_old:+${_vval_old} }${_vval}"; ;;
				*)
					rtl_set_var_unsafe "${_vname_new}" "${_vval}"; ;;
				esac;
				export "${_vname_new}";
			fi;
		done;
	fi; return 0;
};

#
# ex_pkg_env() - set package variables for single named package
# @_build_steps_default:	list of default build steps
# @_build_vars_default:		list of default build variables
# @_group_name:			build group name
# @_nounset:			don't clear package variable namespace
# @_pkg_name:			single package name
# @_restart_at:			optional comma-separated list of build steps at which to rebuild or ALL or LAST
# @_workdir:			pathname to build-specific temporary directory
#
# Return:			zero (0) on success, non-zero (>0) on failure
#
ex_pkg_env() {
	local	_build_steps_default="${1}" _build_vars_default="${2}" _group_name="${3}"	\
		_nounset="${4}" _pkg_name="${5}" _restart_at="${6}" _workdir="${7}" _vname="";
	rtl_fileop source_opt "vars/${_pkg_name}.vars" "${_group_name}/${_pkg_name}.${_group_name}";
	if ! exp_pkg_env_set "${_build_vars_default}" "${_group_name}" "${_nounset}" "${_pkg_name}"\
	|| ! exp_pkg_env_defaults "${_build_steps_default}" "${_pkg_name}" "${_workdir}"\
	|| ! ex_pkg_env_sofort "${PKG_BASE_DIR:-}" "${PKG_SOFORT_FORCE:-0}" "${PKG_SUBDIR:-}"; then
		return 1;
	fi;
};

#
# ex_pkg_state_set() - update build step status for single named package
# @_pkg_name:		single package name
# @_build_step:		build step set status of
# [@${@}]:		optional list of build steps to invalidate status of
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
ex_pkg_state_set() {
	rtl_state_set "${_workdir}" "${@}";
};

#
# ex_pkg_state_test() - test build step status of single named package
# @_pkg_name:		single package name
# @_build_step:		build step to test status of
# @_restart_at:		optional comma-separated list of build steps at which to rebuild or ALL or LAST
#
# Return:		zero (0) on success, non-zero (>0) on failure
#
ex_pkg_state_test() {
	rtl_state_test "${_workdir}" "${@}";
};

# vim:filetype=sh