summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-09-29 22:37:25 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-09-29 22:37:25 (EDT)
commitc133181e5184b77c8e3e5cf4f1ba9a54ade05c00 (patch)
tree6a435bfbadbd2c4dcd965a98fea1392c5bd1b2ae /lib
parentdb60ec5f224b9818da40599af683f18e2a22b5e5 (diff)
Implement ob_match_arch() and ob_match_plat().
Diffstat (limited to 'lib')
-rw-r--r--lib/metadata.sh89
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/metadata.sh b/lib/metadata.sh
index 28a984b..687d96a 100644
--- a/lib/metadata.sh
+++ b/lib/metadata.sh
@@ -139,6 +139,95 @@ ob_get_system_plat()
return ${?}
}
+ob_match_arch()
+{
+ _ob_local _obma_arch _obma_arch_field _obma_a \
+ _obma_a_pat_norm _obma_a_pat_hyph
+
+ if [ ${#} -eq 2 ]; then
+ _obma_arch="${1}"
+ _obma_arch_field="${2}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ for _obma_a in ${_obma_arch_field}; do
+
+ # "all" == "all"
+ if [ "${_obma_arch}" = 'all' ]; then
+ if [ "${_obma_a}" = 'all' ]; then
+ _ob_return 0
+ return ${?}
+ else
+ continue
+ fi
+ fi
+
+ # "foo-bar-baz" == "any"
+ if [ "${_obma_a}" = 'any' ]; then
+ _ob_return 0
+ return ${?}
+ fi
+
+ # Compile patterns to match hyphenated architectures.
+ _obma_a_pat_norm="$(echo "${_obma_a}" | \
+ sed 's/^any-/*-/;s/-any-/-*-/g;s/-any$/-*/g')"
+ _obma_a_pat_hyph="$(echo "${_obma_a}" | \
+ sed 's/^any-/*-*-/;s/-any-/-*-*-/g;s/-any$/-*-*/g')"
+
+ # "foo-bar-baz" == "foo-any-any"
+ case "${_obma_arch}" in
+ ${_obma_a_pat_hyph})
+ continue
+ ;;
+ ${_obma_a_pat_norm})
+ _ob_return 0
+ return ${?}
+ ;;
+ *)
+ continue
+ ;;
+ esac
+
+ done
+
+ # Nothing matched.
+ _ob_return 1
+ return ${?}
+}
+
+ob_match_plat()
+{
+ _ob_local _obmp_plat _obmp_plat_field _obmp_p
+
+ if [ ${#} -eq 2 ]; then
+ _obmp_plat="${1}"
+ _obmp_plat_field="${2}"
+ else
+ _ob_return 125
+ return ${?}
+ fi
+
+ for _obmp_p in ${_obmp_plat_field}; do
+ if [ "${_obmp_plat}" = 'all' ]; then
+ if [ "${_obmp_p}" = 'all' ]; then
+ _ob_return 0
+ return ${?}
+ else
+ continue
+ fi
+ fi
+ if [ "${_obmp_p}" = 'any' ]; then
+ _ob_return 0
+ return ${?}
+ fi
+ done
+
+ _ob_return 1
+ return ${?}
+}
+
_ob_metadata_do()
{
_ob_local _obmd_func