scripts/makepkg.in: Rewrite check_{options,buildenv} to tidy them up.

Signed-off-by: Andrew Fyfe <andrew@neptune-one.net>
This commit is contained in:
Andrew Fyfe 2007-06-02 18:04:41 +01:00 committed by Dan McGee
parent 3b1e67628e
commit 2fb2613ec1

View file

@ -107,74 +107,104 @@ strip_url() {
echo "$1" | sed 's|^.*://.*/||g' 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() { 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 needle=$(echo $1 | tr [:upper:] [:lower:])
local i local opt
# loop PKGBUILD opts first so it overrides makepkg.conf for opt in ${options[@]}; do
for i in ${options[@]}; do opt=$(echo $opt | tr [:upper:] [:lower:])
local lc=$(echo $i | tr [:upper:] [:lower:]) if [ "$opt" = "no$needle" ]; then
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
warning "$(gettext "Options beginning with 'no' will be deprecated in the next version of makepkg!")" 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" plain "$(gettext "Please replace 'no' with '!': %s -> %s.")" "no$needle" "!$needle"
echo "n" echo 'n' # Disabled
return 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'.")" warning "$(gettext "Option 'keepdocs' may not work as intended. Please replace with 'docs'.")"
# END DEPRECATED echo 'y' # Enabled
return
fi fi
done done
# END DEPRECATED
# fall back to makepkg.conf options # fall back to makepkg.conf options
for i in ${OPTIONS[@]}; do ret=$(in_opt_array "$1" ${OPTIONS[@]})
local lc=$(echo $i | tr [:upper:] [:lower:]) if [ "$ret" != '?' ]; then
if [ "$lc" = "$needle" ]; then echo $ret
echo "y" return
return fi
elif [ "$lc" = "!$needle" ]; then
echo "n" echo '?' # Not Found
return
fi
done
echo "$(gettext "unknown")"
return
} }
# 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() { check_buildenv() {
local needle=$(echo $1 | tr [:upper:] [:lower:]) echo $(in_opt_array "$1" ${BUILDENV[@]})
local i }
# use options from makepkg.conf
for i in ${BUILDENV[@]}; do
local lc=$(echo $i | tr [:upper:] [:lower:]) ##
if [ "$lc" = "$needle" ]; then # usage : in_opt_array( $needle, $haystack )
echo "y" # 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 return
elif [ "$lc" = "!$needle" ]; then elif [ "$opt" = "!$needle" ]; then
echo "n" echo 'n' # Disabled
return return
fi fi
done done
echo "$(gettext "unknown")"
return echo '?' # Not Found
} }
##
# usage : in_array( $needle, $haystack )
# return : 0 - found
# 1 - not found
##
in_array() { in_array() {
local needle=$1 local needle=$1; shift
shift 1 [ -z "$1" ] && return 1 # Not Found
[ -z "$1" ] && return 1 local item
for i in $*; do for item in "$@"; do
[ "$i" = "$needle" ] && return 0 [ "$item" = "$needle" ] && return 0 # Found
done done
return 1 return 1 # Not Found
} }
get_downloadclient() { get_downloadclient() {