diff -r c9d37346d57f -r c20c96f8e999 configure --- a/configure Wed Jun 25 08:38:51 2008 +0000 +++ b/configure Mon Jul 07 21:22:25 2008 +0000 @@ -11,9 +11,13 @@ MANDIR_set= LOCAL_set= -qo_quit= +do_quit= CONTRIB_list= +# Given an option string and the following argument, +# echoes the value of the option. +# 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 get_optval(){ local ret case "$1" in @@ -29,46 +33,55 @@ return ${ret} } +# 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. set_prefix() { PREFIX=$(get_optval "$1" "$2") return $? } - set_bindir() { BINDIR_set=1 BINDIR=$(get_optval "$1" "$2") return $? } - set_libdir() { LIBDIR_set=1 LIBDIR=$(get_optval "$1" "$2") return $? } - set_docdir() { DOCDIR_set=1 DOCDIR=$(get_optval "$1" "$2") return $? } - set_mandir() { MANDIR_set=1 MANDIR=$(get_optval "$1" "$2") return $? } +# The set_contrib function is different in that it will work like the others, +# except in two cases: +# If all => replaces all with the list of all available contribs +# If list => just echoes the list of all available contribs, and instructs +# caller to quit immediately by setting do_quit to non null. +# (can't use the return code, see above). set_contrib() { opt_val=$(get_optval "$1" "$2") local ret=$? case "${opt_val}" in all) - CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma |sed -r -e 's|.*/||; s|\.patch\.lzma||;') + CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma \ + |xargs -I {} basename {} .patch.lzma \ + |sed -r -e ':a; /$/N; s/\n/,/; ta;' + ) ;; list) do_quit=1 echo "Available contributions:" - LC_ALL=C ls -1 contrib/*.patch.lzma |sed -r -e 's|.*/||; s|\.patch\.lzma||; s|^| |;' + LC_ALL=C ls -1 contrib/*.patch.lzma \ + |xargs -I {} basename {} .patch.lzma \ + |sed -r -e 's/^/ /;' ;; *) CONTRIB_list="${CONTRIB_list},${opt_val}";; esac @@ -136,7 +149,10 @@ esac done +# Use defaults [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}" + +# Special case when installing locally if [ "${LOCAL_set}" = "1" ]; then set_prefix "" $(pwd) set_bindir "" $(pwd) @@ -150,7 +166,7 @@ # If this version is a svn snapshot, try to get the revision number # If we can't get the revision number, use date -echo -n "Computing version string... " +printf "Computing version string... " case "${VERSION}" in *+svn) REVISION=$(LC_ALL=C svnversion) @@ -163,7 +179,9 @@ VERSION="${VERSION}${URL#${ROOT}}@${REVISION}" ;; esac - VERSION="${VERSION/\//_}" + # 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 echo "${VERSION}" @@ -175,16 +193,18 @@ [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1" # Check bash is present, and at least version 3.0 -echo -n "Checking bash is at least bash-3.0... " +printf "Checking bash is at least bash-3.0... " [ -x /bin/bash ] || do_error "bash 3.0 or above was not found in /bin/bash" bash_version=$(/bin/bash -c 'echo ${BASH_VERSION}') bash_major=$(/bin/bash -c 'echo ${BASH_VERSINFO[0]}') [ ${bash_major} -ge 3 ] || do_error "bash 3.0 or above is needed (/bin/bash is ${bash_version})" echo "ok (${bash_version})" -echo -n "Applying contributed code: " -for c in ${CONTRIB_list//,/ }; do - echo -n "${c}... " +printf "Applying contributed code: " +# It's safer to change all ',' to spaces rather than setting IFS +CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g;') +for c in ${CONTRIB_list}; do + printf "${c}, " if [ ! -f "contrib/${c}.patch.lzma" ]; then do_error "Contribution '${c}' does not exist" fi @@ -192,7 +212,7 @@ done echo "done" -echo -n "Building up Makefile... " +printf "Building up Makefile... " sed -r -e "s,@@BINDIR@@,${BINDIR},g;" \ -e "s,@@LIBDIR@@,${LIBDIR},g;" \ -e "s,@@DOCDIR@@,${DOCDIR},g;" \ @@ -210,6 +230,5 @@ LIBDIR='${LIBDIR}' DOCDIR='${DOCDIR}' MANDIR='${MANDIR}' - CONTRIB='${CONTRIB_list// -/,}' + CONTRIB='${CONTRIB_list}' __EOF__