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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
#
# Copyright (c) 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lucía Andrea Illanes Albornoz <lucia@luciaillanes.de>
# set +o errexit -o noglob -o nounset is assumed.
#
#
# ex_pkg_copy_group_vars() - copy build group variables into build group
# @_group_name_src: single source build group name
# @_group_name_dst: single destination build group name
# @[_build_vars_default]: optional list of default build variables, defaults to ${DEFAULT_BUILD_VARS}
#
# Returns: zero (0) on success, non-zero (>0) on failure.
#
ex_pkg_copy_group_vars() {
local _epcgv_group_name_src="${1#\$}" _epcgv_group_name_dst="${2#\$}" \
_epcgv_build_vars_default="${3:-${DEFAULT_BUILD_VARS}}" \
_epcgv_group_name_dst_uc="" _epcgv_group_name_src_uc="" \
_epcgv_vname="" _epcgv_vval="";
rtl_toupper2 \$_epcgv_group_name_dst \$_epcgv_group_name_dst_uc;
rtl_toupper2 \$_epcgv_group_name_src \$_epcgv_group_name_src_uc;
for _epcgv_vname in ${_epcgv_build_vars_default}; do
if rtl_get_var_unsafe \$_epcgv_vval "${_epcgv_group_name_src_uc}_${_epcgv_vname}"\
&& [ "${_epcgv_vval:+1}" = 1 ]; then
rtl_set_var_unsafe "${_epcgv_group_name_dst_uc}_${_epcgv_vname}" "${_epcgv_vval}";
fi;
done;
return 0;
};
#
# ex_pkg_find_package() - find build group a single named package belongs to
# @_rgroup_name: out reference to variable of build group name
# @_group_names: build group names
# @_pkg_name: single named package
#
# Returns: zero (0) on success, non-zero (>0) if package not found, group name on stdout if package was found.
#
ex_pkg_find_package() {
local _epfp_rgroup_name="${1#\$}" _epfp_group_names="${2}" _epfp_pkg_name="${3}" \
_epfp_foundfl=0 _epfp_group_name="" _epfp_pkg_names="";
for _epfp_group_name in ${_epfp_group_names}; do
if rtl_get_var_unsafe \$_epfp_pkg_names -u "${_epfp_group_name}_PACKAGES"\
&& [ "${_epfp_pkg_names:+1}" = 1 ]\
&& rtl_lmatch \$_epfp_pkg_names "${_epfp_pkg_name}"; then
_epfp_foundfl=1; break;
fi;
done;
case "${_epfp_foundfl:-0}" in
0) eval ${_epfp_rgroup_name}=;
return 1; ;;
1) eval ${_epfp_rgroup_name}='${_epfp_group_name}';
return 0; ;;
esac;
};
#
# ex_pkg_get_default() - get single package default value
# @_rdefault: out reference to variable of default value or "" on end of list
# @_default_idx: one-based single default value index
# @_pkg_name: single package name
# @_pkg_version: single package version
# @_ldefault: SP-separated list of default value names (any of: patches, patches_pre, vars_files)
#
# Returns: zero (0) on success, non-zero (>0) on invalid default value name or unknown package.
#
ex_pkg_get_default() {
local _epgd_rdefault="${1#\$}" _epgd_default_idx="${2}" _epgd_pkg_name="${3}" \
_epgd_pkg_version="${4}" _epgd_ldefault="${5}" \
_epgd_default="" _epgd_group_name="" _epgd_patch_fname="" \
_epgd_pkg_name_full="" _epgd_pkg_patches_extra="" _epgd_rc=0;
set --;
_epgd_pkg_name_full="${_epgd_pkg_name}${_epgd_pkg_version:+-${_epgd_pkg_version}}";
_epgd_rc=0;
for _epgd_default in ${_epgd_ldefault}; do
case "${_epgd_default}" in
patches)
rtl_get_var_unsafe \$_epgd_pkg_patches_extra -u "PKG_${_epgd_pkg_name}_PATCHES_EXTRA";
set +o noglob;
set -- \
"${@}" \
"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name}/"*.patch \
"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}.local.patch" \
"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}.local@${BUILD_HNAME}.patch" \
${_epgd_pkg_patches_extra};
set -o noglob;
;;
patches_pre)
set -- \
"${@}" \
"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}_pre.local.patch" \
"${MIDIPIX_BUILD_PWD}/patches/${_epgd_pkg_name_full}_pre.local@${BUILD_HNAME}.patch";
;;
vars_files)
rtl_get_var_unsafe \$_epgd_group_name -u "PKG_${_epgd_pkg_name}_GROUP";
set -- \
"vars/${_epgd_pkg_name}.vars" \
"vars.${_epgd_group_name}/${_epgd_pkg_name}.vars";
;;
*)
_epgd_rc=1; break;
;;
esac;
done;
if [ "${_epgd_rc}" = 0 ]; then
eval ${_epgd_rdefault}="\${${_epgd_default_idx}:-}";
fi;
return "${_epgd_rc}";
};
#
# ex_pkg_get_packages() - get list of packages belonging to single named build group
# @_rpkg_names: out reference to variable of package names
# @_group_name: build group name
#
# Returns: zero (0) on success, non-zero (>0) on failure, list of package names on stdout on success.
#
ex_pkg_get_packages() {
local _epgp_rpkg_names="${1#\$}" _epgp_group_name="${2}" \
_epgp_pkg_names="";
if rtl_get_var_unsafe \$_epgp_pkg_names -u "${_epgp_group_name}_PACKAGES"\
&& [ "${_epgp_pkg_names:+1}" = 1 ]; then
eval ${_epgp_rpkg_names}='${_epgp_pkg_names}';
return 0;
else
eval ${_epgp_rpkg_names}=;
return 1;
fi;
};
#
# ex_pkg_get_package_vars() - get package variable names
# @_rpkg_vnames: out reference to package variable names variable
# @_build_vars_default: list of default build variables
# @_pkg_name: single package name
#
# Returns: zero (0) on success, non-zero (>0) on failure, list of package names on stdout on success.
#
ex_pkg_get_package_vars() {
local _epgpv_rpkg_vnames="${1#\$}" _epgpv_build_vars_default="${2}" _epgpv_pkg_name="${3}" \
_epgpv_pkg_name_uc="" _epgpv_vname="" _epgpv_vnames="";
rtl_toupper2 \$_epgpv_pkg_name \$_epgpv_pkg_name_uc;
for _epgpv_vname in ${_epgpv_build_vars_default}; do
if eval [ \"\${PKG_${_epgpv_pkg_name_uc}_${_epgpv_vname}:+1}\" = 1 ]; then
rtl_lconcat \$_epgpv_vnames "PKG_${_epgpv_pkg_name_uc}_${_epgpv_vname}";
fi;
done;
eval ${_epgpv_rpkg_vnames}='${_epgpv_vnames}';
return 0;
};
#
# ex_pkg_load_vars() - load build variables
# @_rstatus: out reference to status string
# @_rbuild_arch: in reference to build architecture
# @_rbuild_kind: in reference to build kind
#
# Returns: zero (0) on success, non-zero (>0) on failure, build variables post-return on success.
#
ex_pkg_load_vars() {
local _eplv_rstatus="${1#\$}" _eplv_rbuild_arch="${2#\$}" _eplv_rbuild_kind="${3#\$}" \
_eplv_build_arch="" _eplv_rc=0 _eplv_fname="";
if ! rtl_lmatch "${_eplv_rbuild_arch}" "nt32 nt64"; then
_eplv_rc=1;
rtl_setrstatus "${_eplv_rstatus}" 'invalid architecture \`${'"${_eplv_rbuild_arch}"'}'\''.';
elif ! rtl_lmatch "${_eplv_rbuild_kind}" "debug release"; then
_eplv_rc=1;
rtl_setrstatus "${_eplv_rstatus}" 'unknown build type \`${'"${_eplv_rbuild_kind}"'}'\''.';
else
eval _eplv_build_arch="\${${_eplv_rbuild_arch}}";
case "${_eplv_build_arch}" in
nt32) DEFAULT_TARGET="i686-nt32-midipix"; ;;
nt64) DEFAULT_TARGET="x86_64-nt64-midipix"; ;;
esac;
if [ "${PREFIX_ROOT:+1}" ]\
&& [ "${PREFIX_ROOT#/}" = "${PREFIX_ROOT}" ]; then
PREFIX_ROOT="${PWD%/}/${PREFIX_ROOT}";
fi;
if [ "${PREFIX:+1}" ]\
&& [ "${PREFIX#/}" = "${PREFIX}" ]; then
PREFIX="${PWD%/}/${PREFIX}";
fi;
for _eplv_fname in \
"${HOME}/midipix_build.vars" \
"${HOME}/.midipix_build.vars" \
../midipix_build.vars;
do
if [ -r "${_eplv_fname}" ]; then
rtl_fileop source "${_eplv_fname}";
fi;
done;
set +o noglob;
for _eplv_fname in \
./vars.env.d/*.env;
do
set -o noglob;
if [ -r "${_eplv_fname}" ]; then
rtl_fileop source "${_eplv_fname}";
fi;
done;
set -o noglob;
fi;
return "${_eplv_rc}";
};
#
# ex_pkg_load_groups() - load all available build groups
# @_rgroups: out reference to variable of build groups
# @_rgroups_noauoto: optional out reference to variable of build groups not built automatically
#
# Returns: zero (0) on success, non-zero (>0) on failure.
#
ex_pkg_load_groups() {
local _eplg_rgroups="${1#\$}" _eplg_rgroups_noauto="${2#\$}" \
_eplg_build_groups="" _eplg_build_groups_noauto="" _eplg_fname="";
EXP_PKG_REGISTER_GROUP_RGROUPS="${_eplg_rgroups}";
EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO="${_eplg_rgroups_noauto}";
for _eplg_fname in $(find ./groups.d -name *.group | sort); do
rtl_fileop source_with_fnamevar "${_eplg_fname}";
done;
unset EXP_PKG_REGISTER_GROUP_RGROUPS;
unset EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO;
for _eplg_fname in $(find ./groups.d -mindepth 2 -name *.package | sort); do
rtl_fileop source_with_fnamevar "${_eplg_fname}";
done;
return 0;
};
#
# ex_pkg_register() - register single package
# @_pkg_name: single package name
# @_fname: pathname to file package is defined in, relative to midipix_build root
# @[_group_name]: optional build group name; inferred from @_fname if not specified
#
# Returns: zero (0) on success, non-zero (>0) on failure.
#
ex_pkg_register() {
local _epr_pkg_name="${1}" _epr_fname="${2}" _epr_group_name="${3:-}" \
_epr_group_name_uc="" _epr_group_noautofl=0;
if [ "${_epr_group_name:+1}" != 1 ]; then
_epr_group_name="${_epr_fname#./*/}";
_epr_group_name="${_epr_group_name%%/*}";
_epr_group_name="${_epr_group_name%.d}";
_epr_group_name="${_epr_group_name#*.}";
fi;
rtl_toupper2 \$_epr_group_name \$_epr_group_name_uc;
rtl_lconcat "\$${_epr_group_name_uc}_PACKAGES" "${_epr_pkg_name}";
rtl_set_var_unsafe -u "PKG_${_epr_pkg_name}_GROUP" "${_epr_group_name}";
rtl_set_var_unsafe -u "PKG_${_epr_pkg_name}_GROUP_FNAME" "${_epr_fname}";
return 0;
};
#
# ex_pkg_register_group() - register single group
# @_group_name: single group name
# @_fname: pathname to file group is defined in, relative to midipix_build root
# @[_ownerfl]: "owner" for groups that own their packages, "copy" for shorthand groups referring to packages from other groups
# @[_autofl]: "auto" for groups to build by default, "noauto" for optional groups only built when requested
# ${EXP_PKG_REGISTER_GROUP_RGROUPS}: inout reference to variable of build groups
# ${EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO}: inout reference to variable of build groups only built when requested
#
# Returns: zero (0) on success, non-zero (>0) on failure.
#
ex_pkg_register_group() {
local _eprg_group_name="${1}" _eprg_fname="${2}" \
_eprg_ownerfl="${3:-owner}" _eprg_autofl="${4:-auto}" \
_eprg_pkg_name="" _eprg_pkg_names="" _eprg_rgroups="";
case "${_eprg_autofl}" in
auto) _eprg_rgroups="${EXP_PKG_REGISTER_GROUP_RGROUPS}"; ;;
noauto) _eprg_rgroups="${EXP_PKG_REGISTER_GROUP_RGROUPS_NOAUTO}"; ;;
*) ;;
esac;
if ! rtl_lmatch "${_eprg_rgroups}" "${_eprg_group_name}"; then
rtl_lconcat "${_eprg_rgroups}" "${_eprg_group_name}";
fi;
case "${_eprg_ownerfl}" in
owner)
if rtl_get_var_unsafe \$_eprg_pkg_names -u "${_eprg_group_name}_PACKAGES"\
&& [ "${_eprg_pkg_names:+1}" = 1 ]; then
for _eprg_pkg_name in ${_eprg_pkg_names}; do
rtl_set_var_unsafe -u "PKG_${_eprg_pkg_name}_GROUP" "${_eprg_group_name}";
rtl_set_var_unsafe -u "PKG_${_eprg_pkg_name}_GROUP_FNAME" "${_eprg_fname}";
done;
fi;
;;
copy) ;;
*) ;;
esac;
return 0;
};
# vim:filetype=sh textwidth=0
|