mirror of
https://github.com/crosstool-ng/crosstool-ng.git
synced 2024-12-19 12:57:53 +00:00
Rationalise ./configure
- borrow a lot of ideas from Michael ABBOTT ( http://sourceware.org/ml/crossgcc/2008-12/msg00030.html ) - should be conforming to POSIX 1003.1-2008, non compliance due to bashsims is to be considered a bug - as a result, it now works with dash - make a little easier to read in some places - enforce 4-space indentation - get rid of futile 'return $?' - quote all variables assignments - save and restore IFS prior to and after using alternate values - simplify the TOOLS_TO_CHECK listing What's left: - provide a mean to actually _compare_ version numbers - change the TOOLS_TO_CHECK pattern style to be able to use '|' in regexp /trunk/configure | 243 127 116 0 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 127 insertions(+), 116 deletions(-)
This commit is contained in:
parent
b91d74858a
commit
a228413680
243
configure
vendored
243
configure
vendored
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
VERSION=$(cat .version)
|
VERSION=$( cat .version )
|
||||||
DATE=$(date +%Y%m%d)
|
DATE=$( date +%Y%m%d )
|
||||||
|
|
||||||
# All absolutely required tools, one per line to ease diff.
|
# All absolutely required tools, one per line to ease diff.
|
||||||
# See function 'has_or_abort, below, for syntax
|
# See function 'has_or_abort, below, for syntax
|
||||||
@ -12,42 +12,43 @@ DATE=$(date +%Y%m%d)
|
|||||||
#
|
#
|
||||||
# Format of a pattern to check for, one per line:
|
# Format of a pattern to check for, one per line:
|
||||||
# pattern := tool_test OR pattern|tool_test
|
# pattern := tool_test OR pattern|tool_test
|
||||||
# tool_test := tool/regexp
|
# tool_test := tool=regexp OR tool
|
||||||
# tool := name of the tool OR absolute pathname to the tool
|
# tool := basename of the tool OR absolute pathname to the tool
|
||||||
# regexp := valid grep(1) extended regular expression OR empty
|
# regexp := valid grep(1) extended regular expression, $( tool --version)
|
||||||
|
# will be matched against this regexp.
|
||||||
#
|
#
|
||||||
# In case a pattern list is given (eg foo|bar|buz), then tests are performed
|
# In case a pattern list is given (eg foo|bar|buz), then tests are performed
|
||||||
# from left to right, stopping at the first matching test (like the shell
|
# from left to right, stopping at the first matching test (like the shell
|
||||||
# would parse 'foo || bar || buz' ).
|
# would parse 'foo || bar || buz' ).
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# /bin/bash/^GNU bash, version 3\.
|
# /bin/bash=^GNU bash, version 3\.
|
||||||
# will ensure that /bin/bash exists, and that $(/bin/bash --version)
|
# will ensure that /bin/bash exists, and that $( /bin/bash --version )
|
||||||
# matches the regexp '^GNU bash, version 3\.'
|
# matches the regexp '^GNU bash, version 3\.'
|
||||||
# autoconf/(GNU Autoconf)|autoconf2.50/
|
# autoconf=(GNU Autoconf)|autoconf2.50
|
||||||
# will ensure that:
|
# will ensure that:
|
||||||
# - 'autoconf' is to be found in the PATH, and that $(autoconf
|
# - 'autoconf' is to be found in the PATH, and that $( autoconf --version )
|
||||||
# --version) matches the regexp '(GNU Autoconf)' (which btw is
|
# matches the regexp '(GNU Autoconf)' (which btw is the signature of
|
||||||
# the signature of autoconf >= 2.50),
|
# autoconf >= 2.50),
|
||||||
# OR that:
|
# OR that:
|
||||||
# - 'autoconf2.50' is to be found in the PATH
|
# - 'autoconf2.50' is to be found in the PATH
|
||||||
#
|
#
|
||||||
TOOLS_TO_CHECK='
|
TOOLS_TO_CHECK='
|
||||||
/bin/bash/^GNU bash, version 3\.
|
/bin/bash=^GNU bash, version 3\.
|
||||||
make/^GNU Make
|
make=^GNU Make
|
||||||
gcc/
|
gcc
|
||||||
gawk/^GNU Awk
|
gawk=^GNU Awk
|
||||||
sed/
|
sed
|
||||||
bison/
|
bison
|
||||||
flex/
|
flex
|
||||||
makeinfo/
|
makeinfo
|
||||||
automake/\(GNU automake\) [[:digit:]]+\.[[:digit:]]{2,}|automake/\(GNU automake\) [2-9][[:digit:]]*\.
|
automake=\(GNU automake\) [[:digit:]]+\.[[:digit:]]{2,}|automake=\(GNU automake\) [2-9][[:digit:]]*\.
|
||||||
libtool/
|
libtool
|
||||||
curl/|wget/
|
curl|wget
|
||||||
patch/
|
patch
|
||||||
tar/
|
tar
|
||||||
gzip/
|
gzip
|
||||||
bzip2/
|
bzip2
|
||||||
'
|
'
|
||||||
|
|
||||||
PREFIX_DEFAULT=/usr/local
|
PREFIX_DEFAULT=/usr/local
|
||||||
@ -73,31 +74,40 @@ do_error() {
|
|||||||
# Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for
|
# Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for
|
||||||
# complete pattern format)
|
# complete pattern format)
|
||||||
has_or_abort() {
|
has_or_abort() {
|
||||||
{ IFS="|"; for item in ${1}; do
|
save_IFS="${IFS}"
|
||||||
tool="${item%/*}"
|
IFS="|"
|
||||||
regexp="${item##*/}"
|
for item in ${1}; do
|
||||||
printf "Checking for '${tool}'... "
|
case "${item}" in
|
||||||
where=$(which "${tool}" 2>/dev/null || true)
|
*=*)
|
||||||
if [ -z "${where}" ]; then
|
tool="${item%%=*}"
|
||||||
echo "not found"
|
regexp="${item#*=}"
|
||||||
where=
|
;;
|
||||||
continue
|
*) tool="${item}"
|
||||||
else
|
regexp=
|
||||||
if [ -n "${regexp}" ]; then
|
;;
|
||||||
tool_version=$(${tool} --version 2>&1)
|
esac
|
||||||
str=$(echo "${tool_version}" |grep -E "${regexp}" |head -n 1)
|
printf "Checking for '${tool}'... "
|
||||||
if [ -z "${str}" ]; then
|
where=$( which "${tool}" 2>/dev/null )
|
||||||
echo "${where}: wrong version string: expecting regexp '${regexp}'"
|
if [ -z "${where}" ]; then
|
||||||
where=""
|
echo "not found"
|
||||||
continue
|
where=
|
||||||
fi
|
continue
|
||||||
fi
|
else
|
||||||
echo "${where}"
|
if [ -n "${regexp}" ]; then
|
||||||
return 0
|
tool_version=$( ${tool} --version 2>&1 )
|
||||||
fi
|
str=$( echo "${tool_version}" |grep -E "${regexp}" |head -n 1 )
|
||||||
done;
|
if [ -z "${str}" ]; then
|
||||||
}
|
echo "${where}: wrong version string: expecting regexp '${regexp}'"
|
||||||
[ ${FORCE} -eq 0 ] && do_error "Bailing out..."
|
where=""
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "${where}"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done;
|
||||||
|
IFS="${save_IFS}"
|
||||||
|
[ -z "${where}" -a ${FORCE} -eq 0 ] && do_error "Bailing out..."
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,45 +116,38 @@ has_or_abort() {
|
|||||||
# If --var=val => echoes val and returns 0, meaning second arg was not consumed
|
# If --var=val => echoes val and returns 0, meaning second arg was not consumed
|
||||||
# If --var val => echoes val and returns non null, meaning second arg was used
|
# If --var val => echoes val and returns non null, meaning second arg was used
|
||||||
get_optval(){
|
get_optval(){
|
||||||
local ret
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--*=?*)
|
--*=?*)
|
||||||
echo "${1}" |cut -d '=' -f 2-
|
echo "${1}" |cut -d '=' -f 2-
|
||||||
ret=0
|
return 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "${2}"
|
echo "${2}"
|
||||||
ret=1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
return ${ret}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# The set_xxx functions will set the corresponding configuration variable
|
# The set_xxx functions will set the corresponding configuration variable
|
||||||
# They return 0 if second arg was not consumed, and non-zero if it was consumed.
|
# They return 0 if second arg was not consumed, and non-zero if it was consumed.
|
||||||
set_prefix() {
|
set_prefix() {
|
||||||
PREFIX=$(get_optval "$1" "$2")
|
PREFIX="$( get_optval "$1" "$2" )"
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
set_bindir() {
|
set_bindir() {
|
||||||
BINDIR_set=1
|
BINDIR_set=1
|
||||||
BINDIR=$(get_optval "$1" "$2")
|
BINDIR="$( get_optval "$1" "$2" )"
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
set_libdir() {
|
set_libdir() {
|
||||||
LIBDIR_set=1
|
LIBDIR_set=1
|
||||||
LIBDIR=$(get_optval "$1" "$2")
|
LIBDIR="$( get_optval "$1" "$2" )"
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
set_docdir() {
|
set_docdir() {
|
||||||
DOCDIR_set=1
|
DOCDIR_set=1
|
||||||
DOCDIR=$(get_optval "$1" "$2")
|
DOCDIR="$( get_optval "$1" "$2" )"
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
set_mandir() {
|
set_mandir() {
|
||||||
MANDIR_set=1
|
MANDIR_set=1
|
||||||
MANDIR=$(get_optval "$1" "$2")
|
MANDIR="$( get_optval "$1" "$2" )"
|
||||||
return $?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# The set_contrib function is different in that it will work like the others,
|
# The set_contrib function is different in that it will work like the others,
|
||||||
@ -154,21 +157,21 @@ set_mandir() {
|
|||||||
# caller to quit immediately by setting do_quit to non null.
|
# caller to quit immediately by setting do_quit to non null.
|
||||||
# (can't use the return code, see above).
|
# (can't use the return code, see above).
|
||||||
set_contrib() {
|
set_contrib() {
|
||||||
opt_val=$(get_optval "$1" "$2")
|
opt_val="$( get_optval "$1" "$2" )"
|
||||||
local ret=$?
|
ret=$?
|
||||||
case "${opt_val}" in
|
case "${opt_val}" in
|
||||||
all)
|
all)
|
||||||
CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma \
|
CONTRIB_list="$( LC_ALL=C ls -1 contrib/*.patch.lzma \
|
||||||
|xargs -I {} basename {} .patch.lzma \
|
|xargs -I {} basename {} .patch.lzma \
|
||||||
|sed -r -e ':a; /$/N; s/\n/,/; ta;'
|
|sed -r -e ':a; /$/N; s/\n/,/; ta;' \
|
||||||
)
|
)"
|
||||||
;;
|
;;
|
||||||
list)
|
list)
|
||||||
do_quit=1
|
do_quit=1
|
||||||
echo "Available contributions:"
|
echo "Available contributions:"
|
||||||
LC_ALL=C ls -1 contrib/*.patch.lzma \
|
LC_ALL=C ls -1 contrib/*.patch.lzma \
|
||||||
|xargs -I {} basename {} .patch.lzma \
|
|xargs -I {} basename {} .patch.lzma \
|
||||||
|sed -r -e 's/^/ /;'
|
|sed -r -e 's/^/ /;'
|
||||||
;;
|
;;
|
||||||
*) CONTRIB_list="${CONTRIB_list},${opt_val}";;
|
*) CONTRIB_list="${CONTRIB_list},${opt_val}";;
|
||||||
esac
|
esac
|
||||||
@ -184,7 +187,7 @@ USAGE: ./configure [OPTION]...
|
|||||||
Defaults for the options are specified in brackets.
|
Defaults for the options are specified in brackets.
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
-h, --help display this help and exit
|
-h, --help display this help and exit
|
||||||
--force force ./configure to complete, even if one or more
|
--force force ./configure to complete, even if one or more
|
||||||
tools were not found. Use at your own risk, only if
|
tools were not found. Use at your own risk, only if
|
||||||
you know what you are doing!
|
you know what you are doing!
|
||||||
@ -240,11 +243,11 @@ done
|
|||||||
|
|
||||||
# Special case when installing locally
|
# Special case when installing locally
|
||||||
if [ "${LOCAL_set}" = "1" ]; then
|
if [ "${LOCAL_set}" = "1" ]; then
|
||||||
set_prefix "" $(pwd)
|
set_prefix "" "$( pwd )"
|
||||||
set_bindir "" $(pwd)
|
set_bindir "" "$( pwd )"
|
||||||
set_libdir "" $(pwd)
|
set_libdir "" "$( pwd )"
|
||||||
set_docdir "" $(pwd)/docs
|
set_docdir "" "$( pwd )/docs"
|
||||||
set_mandir "" $(pwd)/docs
|
set_mandir "" "$( pwd )/docs"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
@ -254,21 +257,27 @@ fi
|
|||||||
# If we can't get the revision number, use date
|
# If we can't get the revision number, use date
|
||||||
printf "Computing version string... "
|
printf "Computing version string... "
|
||||||
case "${VERSION}" in
|
case "${VERSION}" in
|
||||||
*+svn|svn)
|
*+svn|svn)
|
||||||
REVISION=$(LC_ALL=C svnversion)
|
REVISION="$( LC_ALL=C svnversion )"
|
||||||
case "${REVISION}" in
|
case "${REVISION}" in
|
||||||
exported)
|
exported)
|
||||||
VERSION="${VERSION}_unknown@$(date +%Y%m%d.%H%M%S)";;
|
VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
|
||||||
*)
|
*)
|
||||||
URL=$(LC_ALL=C svn info 2>/dev/null |egrep 'URL: ' |cut -d ' ' -f 2-)
|
URL="$( LC_ALL=C svn info 2>/dev/null \
|
||||||
ROOT=$(LC_ALL=C svn info 2>/dev/null |egrep 'Repository Root: ' |cut -d ' ' -f 3-)
|
|egrep 'URL: ' \
|
||||||
VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
|
|cut -d ' ' -f 2- \
|
||||||
|
)"
|
||||||
|
ROOT="$( LC_ALL=C svn info 2>/dev/null \
|
||||||
|
|egrep 'Repository Root: ' \
|
||||||
|
|cut -d ' ' -f 3- \
|
||||||
|
)"
|
||||||
|
VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
# Arrange to have no / in the directory name, no need to create an
|
||||||
|
# arbitrarily deep directory structure
|
||||||
|
VERSION="$( echo "${VERSION}" |sed -r -e 's|/+|_|g;' )"
|
||||||
;;
|
;;
|
||||||
esac
|
|
||||||
# Arrange to have no / in the directory name, no need to create an
|
|
||||||
# arbitrarily deep directory structure
|
|
||||||
VERSION=$(echo "${VERSION}" |sed -r -e 's|/+|_|g;')
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
echo "${VERSION}"
|
echo "${VERSION}"
|
||||||
|
|
||||||
@ -280,26 +289,29 @@ echo "${VERSION}"
|
|||||||
|
|
||||||
# Check that install PATHs are absolute
|
# Check that install PATHs are absolute
|
||||||
for p in BIN LIB DOC MAN; do
|
for p in BIN LIB DOC MAN; do
|
||||||
var="${p}DIR"
|
var="${p}DIR"
|
||||||
eval v="\${${var}}"
|
eval v='"${'"${var}"'}"'
|
||||||
case "${v}" in
|
case "${v}" in
|
||||||
/*) ;;
|
/*) ;;
|
||||||
*) do_error "'${var}' is not an absolute path: '${v}'"
|
*) do_error "'${var}' is not an absolute path: '${v}'"
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Check the existence of absolutely required tools
|
# Check the existence of absolutely required tools
|
||||||
{ IFS='
|
save_IFS="${IFS}"
|
||||||
';
|
IFS='
|
||||||
for tool in ${TOOLS_TO_CHECK}; do
|
'
|
||||||
has_or_abort "${tool}"
|
for tool in ${TOOLS_TO_CHECK}; do
|
||||||
done;
|
has_or_abort "${tool}"
|
||||||
}
|
done
|
||||||
|
IFS="${save_IFS}"
|
||||||
|
|
||||||
# It's safer to change all ',' to spaces rather than setting IFS
|
# It's safer to change all ',' to spaces rather than setting IFS
|
||||||
CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g; s/ +/ /g; s/^ //g; s/ $//g;')
|
CONTRIB_list="$( echo "${CONTRIB_list}" \
|
||||||
|
|sed -r -e 's/,+/ /g; s/ +/ /g; s/^ //g; s/ $//g;' \
|
||||||
|
)"
|
||||||
if [ -n "${CONTRIB_list}" ]; then
|
if [ -n "${CONTRIB_list}" ]; then
|
||||||
has_or_abort 'lzcat/'
|
has_or_abort 'lzcat'
|
||||||
printf "Applying contributed code: "
|
printf "Applying contributed code: "
|
||||||
for c in ${CONTRIB_list}; do
|
for c in ${CONTRIB_list}; do
|
||||||
printf "${c}, "
|
printf "${c}, "
|
||||||
@ -312,14 +324,13 @@ if [ -n "${CONTRIB_list}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
printf "Building up Makefile... "
|
printf "Building up Makefile... "
|
||||||
sed -r -e "s,@@BINDIR@@,${BINDIR},g;" \
|
sed -r -e "s,@@BINDIR@@,${BINDIR},g
|
||||||
-e "s,@@LIBDIR@@,${LIBDIR},g;" \
|
s,@@LIBDIR@@,${LIBDIR},g
|
||||||
-e "s,@@DOCDIR@@,${DOCDIR},g;" \
|
s,@@DOCDIR@@,${DOCDIR},g
|
||||||
-e "s,@@MANDIR@@,${MANDIR},g;" \
|
s,@@MANDIR@@,${MANDIR},g
|
||||||
-e "s,@@VERSION@@,${VERSION},g;" \
|
s,@@VERSION@@,${VERSION},g
|
||||||
-e "s,@@DATE@@,${DATE},g;" \
|
s,@@DATE@@,${DATE},g
|
||||||
-e "s,@@LOCAL@@,${LOCAL_set},g;" \
|
s,@@LOCAL@@,${LOCAL_set},g" Makefile.in >Makefile
|
||||||
Makefile.in >Makefile
|
|
||||||
echo "done"
|
echo "done"
|
||||||
|
|
||||||
cat <<__EOF__
|
cat <<__EOF__
|
||||||
|
Loading…
Reference in New Issue
Block a user