From 2fb2613ec1106f055776b3173a4e65a3b73a6ae6 Mon Sep 17 00:00:00 2001 From: Andrew Fyfe Date: Sat, 2 Jun 2007 18:04:41 +0100 Subject: scripts/makepkg.in: Rewrite check_{options,buildenv} to tidy them up. Signed-off-by: Andrew Fyfe --- scripts/makepkg.in | 128 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 49 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.in b/scripts/makepkg.in index f4f18108..32bf2ad8 100644 --- a/scripts/makepkg.in +++ b/scripts/makepkg.in @@ -107,74 +107,104 @@ strip_url() { echo "$1" | sed 's|^.*://.*/||g' } -# checks to see if options are present in makepkg.conf or PKGBUILD; -# PKGBUILD options always take precedence + +## +# Checks to see if options are present in makepkg.conf or PKGBUILD; +# PKGBUILD options always take precedence. +# +# usage : check_option( $option ) +# return : y - enabled +# n - disabled +# ? - not found +## check_option() { + local ret=$(in_opt_array "$1" ${options[@]}) + if [ "$ret" != '?' ]; then + echo $ret + return + fi + + # BEGIN DEPRECATED + # TODO: This code should be removed in the next release of makepkg. local needle=$(echo $1 | tr [:upper:] [:lower:]) - local i - # loop PKGBUILD opts first so it overrides makepkg.conf - for i in ${options[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "$needle" ]; then - echo "y" - return - elif [ "$lc" = "!$needle" ]; then - echo "n" - return - # START DEPRECATED - # TODO This code should be removed in the next release of makepkg - elif [ "$lc" = "no$needle" ]; then + local opt + for opt in ${options[@]}; do + opt=$(echo $opt | tr [:upper:] [:lower:]) + if [ "$opt" = "no$needle" ]; then warning "$(gettext "Options beginning with 'no' will be deprecated in the next version of makepkg!")" - plain "$(gettext "Please replace 'no' with '!': no%s -> !%s.")" "$needle" "$needle" - echo "n" + plain "$(gettext "Please replace 'no' with '!': %s -> %s.")" "no$needle" "!$needle" + echo 'n' # Disabled return - elif [ "$lc" = "keepdocs" -a "$needle" = "docs" ]; then + elif [ "$opt" = "keepdocs" -a "$needle" = "docs" ]; then warning "$(gettext "Option 'keepdocs' may not work as intended. Please replace with 'docs'.")" - # END DEPRECATED - fi - done - # fall back to makepkg.conf options - for i in ${OPTIONS[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "$needle" ]; then - echo "y" - return - elif [ "$lc" = "!$needle" ]; then - echo "n" + echo 'y' # Enabled return fi done - echo "$(gettext "unknown")" - return + # END DEPRECATED + + # fall back to makepkg.conf options + ret=$(in_opt_array "$1" ${OPTIONS[@]}) + if [ "$ret" != '?' ]; then + echo $ret + return + fi + + echo '?' # Not Found } -# check if option is present in BUILDENV + +## +# Check if option is present in BUILDENV +# +# usage : check_buildenv( $option ) +# return : y - enabled +# n - disabled +# ? - not found +## check_buildenv() { - local needle=$(echo $1 | tr [:upper:] [:lower:]) - local i - # use options from makepkg.conf - for i in ${BUILDENV[@]}; do - local lc=$(echo $i | tr [:upper:] [:lower:]) - if [ "$lc" = "$needle" ]; then - echo "y" + echo $(in_opt_array "$1" ${BUILDENV[@]}) +} + + +## +# usage : in_opt_array( $needle, $haystack ) +# return : y - enabled +# n - disabled +# ? - not found +## +in_opt_array() { + local needle=$(echo $1 | tr [:upper:] [:lower:]); shift + + local opt + for opt in "$@"; do + opt=$(echo $opt | tr [:upper:] [:lower:]) + if [ "$opt" = "$needle" ]; then + echo 'y' # Enabled return - elif [ "$lc" = "!$needle" ]; then - echo "n" + elif [ "$opt" = "!$needle" ]; then + echo 'n' # Disabled return fi done - echo "$(gettext "unknown")" - return + + echo '?' # Not Found } + +## +# usage : in_array( $needle, $haystack ) +# return : 0 - found +# 1 - not found +## in_array() { - local needle=$1 - shift 1 - [ -z "$1" ] && return 1 - for i in $*; do - [ "$i" = "$needle" ] && return 0 + local needle=$1; shift + [ -z "$1" ] && return 1 # Not Found + local item + for item in "$@"; do + [ "$item" = "$needle" ] && return 0 # Found done - return 1 + return 1 # Not Found } get_downloadclient() { -- cgit v1.2.3-70-g09d2