yann@182: #!/bin/sh yann@182: yann@334: VERSION=$(cat .version) yann@182: DATE=$(date +%Y%m%d) yann@182: yann@673: # All absolutely required tools, one per line to ease diff. yann@673: # See function 'has_or_abort, below, for syntax yann@673: # - Hopefully, if gcc is present, then all associated tools will be yann@673: # - awk must be GNU awk yann@673: # - makeinfo for building docs, even if discarded later on yann@673: # - others obvious... :-/ yann@876: # yann@876: # Format of a pattern to check for, one per line: yann@876: # pattern := tool_test OR pattern|tool_test yann@876: # tool_test := tool/regexp yann@876: # tool := name of the tool OR absolute pathname to the tool yann@876: # regexp := valid grep(1) extended regular expression OR empty yann@876: # yann@876: # In case a pattern list is given (eg foo|bar|buz), then tests are performed yann@876: # from left to right, stopping at the first matching test (like the shell yann@876: # would parse 'foo || bar || buz' ). yann@876: # yann@876: # Examples: yann@876: # /bin/bash/^GNU bash, version 3\. yann@876: # will ensure that /bin/bash exists, and that $(/bin/bash --version) yann@876: # matches the regexp '^GNU bash, version 3\.' yann@876: # autoconf/(GNU Autoconf)|autoconf2.50/ yann@876: # will ensure that: yann@876: # - 'autoconf' is to be found in the PATH, and that $(autoconf yann@876: # --version) matches the regexp '(GNU Autoconf)' (which btw is yann@876: # the signature of autoconf >= 2.50), yann@876: # OR that: yann@876: # - 'autoconf2.50' is to be found in the PATH yann@876: # yann@673: TOOLS_TO_CHECK=' yann@870: /bin/bash/^GNU bash, version 3\. yann@870: make/^GNU Make yann@876: gcc/ yann@870: awk/^GNU Awk yann@876: sed/ yann@876: bison/ yann@876: flex/ yann@876: makeinfo/ yann@876: automake/ yann@876: libtool/ yann@876: patch/ yann@876: tar/ yann@876: gzip/ yann@876: bzip2/ yann@673: ' yann@673: yann@183: PREFIX_DEFAULT=/usr/local yann@182: yann@182: BINDIR_set= yann@182: LIBDIR_set= yann@182: DOCDIR_set= yann@182: MANDIR_set= yann@285: LOCAL_set= yann@182: yann@680: FORCE=0 yann@680: yann@641: do_quit= yann@614: CONTRIB_list= yann@614: yann@673: # Simply print the error message, and exit. Obvious, he? yann@673: do_error() { yann@673: echo "${@}" yann@673: exit 1 yann@673: } yann@673: yann@673: # A small function to test for existence of various tools yann@876: # Usage: has_or_abort test_pattern (see top of file, TOOLS_TO_CHECK, for yann@876: # complete pattern format) yann@673: has_or_abort() { yann@876: { IFS="|"; for item in ${1}; do yann@876: tool="${item%/*}" yann@876: regexp="${item##*/}" yann@876: printf "Checking for '${tool}'... " yann@876: where=$(which "${tool}" 2>/dev/null || true) yann@876: if [ -z "${where}" ]; then yann@876: echo "not found" yann@876: where= yann@876: continue yann@876: else yann@876: if [ -n "${regexp}" ]; then yann@876: str=$(${tool} --version 2>&1 |grep -E "${regexp}" |head -n 1) yann@876: if [ -z "${str}" ]; then yann@876: echo "wrong version string" yann@876: where="" yann@876: continue yann@876: fi yann@876: fi yann@876: echo "${where}" yann@876: return 0 yann@876: fi yann@876: done; yann@876: } yann@876: [ ${FORCE} -eq 0 ] && do_error "Bailing out..." yann@673: return 0 yann@673: } yann@673: yann@641: # Given an option string and the following argument, yann@641: # echoes the value of the option. yann@641: # If --var=val => echoes val and returns 0, meaning second arg was not consumed yann@641: # If --var val => echoes val and returns non null, meaning second arg was used yann@182: get_optval(){ yann@182: local ret yann@182: case "$1" in yann@182: --*=?*) yann@193: echo "${1}" |cut -d '=' -f 2- yann@182: ret=0 yann@182: ;; yann@182: *) yann@182: echo "${2}" yann@182: ret=1 yann@182: ;; yann@182: esac yann@182: return ${ret} yann@182: } yann@182: yann@641: # The set_xxx functions will set the corresponding configuration variable yann@641: # They return 0 if second arg was not consumed, and non-zero if it was consumed. yann@182: set_prefix() { yann@182: PREFIX=$(get_optval "$1" "$2") yann@376: return $? yann@182: } yann@182: set_bindir() { yann@376: BINDIR_set=1 yann@182: BINDIR=$(get_optval "$1" "$2") yann@376: return $? yann@182: } yann@182: set_libdir() { yann@376: LIBDIR_set=1 yann@182: LIBDIR=$(get_optval "$1" "$2") yann@376: return $? yann@182: } yann@182: set_docdir() { yann@376: DOCDIR_set=1 yann@182: DOCDIR=$(get_optval "$1" "$2") yann@376: return $? yann@182: } yann@182: set_mandir() { yann@376: MANDIR_set=1 yann@182: MANDIR=$(get_optval "$1" "$2") yann@376: return $? yann@182: } yann@182: yann@641: # The set_contrib function is different in that it will work like the others, yann@641: # except in two cases: yann@641: # If all => replaces all with the list of all available contribs yann@641: # If list => just echoes the list of all available contribs, and instructs yann@641: # caller to quit immediately by setting do_quit to non null. yann@641: # (can't use the return code, see above). yann@614: set_contrib() { yann@614: opt_val=$(get_optval "$1" "$2") yann@614: local ret=$? yann@614: case "${opt_val}" in yann@614: all) yann@641: CONTRIB_list=$(LC_ALL=C ls -1 contrib/*.patch.lzma \ yann@641: |xargs -I {} basename {} .patch.lzma \ yann@641: |sed -r -e ':a; /$/N; s/\n/,/; ta;' yann@641: ) yann@614: ;; yann@614: list) yann@614: do_quit=1 yann@614: echo "Available contributions:" yann@641: LC_ALL=C ls -1 contrib/*.patch.lzma \ yann@641: |xargs -I {} basename {} .patch.lzma \ yann@641: |sed -r -e 's/^/ /;' yann@614: ;; yann@614: *) CONTRIB_list="${CONTRIB_list},${opt_val}";; yann@614: esac yann@614: return $ret yann@614: } yann@614: yann@183: do_help() { yann@183: cat <<__EOF__ yann@197: \`configure' configures crosstool-NG ${VERSION} to adapt to many kind of systems. yann@183: yann@183: USAGE: ./configure [OPTION]... yann@183: yann@183: Defaults for the options are specified in brackets. yann@183: yann@183: Configuration: yann@183: -h, --help display this help and exit yann@683: --force force ./configure to complete, even if one or more yann@683: tools were not found. Use at your own risk, only if yann@683: you know what you are doing! yann@615: yann@615: Installation directories: yann@185: --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}] yann@285: --local don't install, and use current directory yann@183: yann@183: By default, \`make install' will install all the files in yann@183: \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify yann@183: an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix', yann@183: for instance \`--prefix=\${HOME}'. yann@183: yann@183: For better control, use the options below. yann@183: yann@183: Fine tuning of the installation directories: yann@683: --bindir=DIR user executables [PREFIX/bin] yann@683: --libdir=DIR object code libraries [PREFIX/lib] yann@683: --docdir=DIR info documentation [PREFIX/share/doc] yann@683: --mandir=DIR man documentation [PREFIX/share/man] yann@614: yann@614: Optional Features: yann@683: --with-contrib=XXX Include externally contributed features found in the yann@683: contrib/ sub-directory. Set to a comma-separated list yann@683: of features. Use 'all' to use all contributions, and yann@683: 'list' to see which are available. yann@183: __EOF__ yann@183: } yann@183: yann@376: #--------------------------------------------------------------------- yann@376: # Set user's options yann@376: yann@182: while [ $# -ne 0 ]; do yann@182: case "$1" in yann@182: --prefix*) set_prefix "$1" "$2" && shift || shift 2;; yann@182: --bindir*) set_bindir "$1" "$2" && shift || shift 2;; yann@182: --libdir*) set_libdir "$1" "$2" && shift || shift 2;; yann@182: --docdir*) set_docdir "$1" "$2" && shift || shift 2;; yann@182: --mandir*) set_mandir "$1" "$2" && shift || shift 2;; yann@285: --local) LOCAL_set=1; shift;; yann@680: --force) FORCE=1; shift;; yann@614: --with-contrib*) yann@614: set_contrib "$1" "$2" && shift || shift 2 yann@614: [ "${do_quit}" = "1" ] && exit 0 yann@614: ;; yann@183: --help|-h) do_help; exit 0;; yann@183: *) do_help; exit 1;; yann@182: esac yann@182: done yann@182: yann@641: # Use defaults yann@185: [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}" yann@641: yann@641: # Special case when installing locally yann@285: if [ "${LOCAL_set}" = "1" ]; then yann@285: set_prefix "" $(pwd) yann@285: set_bindir "" $(pwd) yann@285: set_libdir "" $(pwd) yann@285: set_docdir "" $(pwd)/docs yann@285: set_mandir "" $(pwd)/docs yann@285: fi yann@183: yann@376: #--------------------------------------------------------------------- yann@376: # Some sanity checks, now yann@376: yann@435: # If this version is a svn snapshot, try to get the revision number yann@435: # If we can't get the revision number, use date yann@641: printf "Computing version string... " yann@435: case "${VERSION}" in yann@435: *+svn) yann@542: REVISION=$(LC_ALL=C svnversion) yann@444: case "${REVISION}" in yann@444: exported) yann@554: VERSION="${VERSION}unknown@$(date +%Y%m%d.%H%M%S)";; yann@444: *) yann@542: URL=$(LC_ALL=C svn info 2>/dev/null |egrep 'URL: ' |cut -d ' ' -f 2-) yann@542: ROOT=$(LC_ALL=C svn info 2>/dev/null |egrep 'Repository Root: ' |cut -d ' ' -f 3-) yann@554: VERSION="${VERSION}${URL#${ROOT}}@${REVISION}" yann@444: ;; yann@444: esac yann@641: # Arrange to have no / in the directory name, no need to create an yann@641: # arbitrarily deep directory structure yann@641: VERSION=$(echo "${VERSION}" |sed -r -e 's|/+|_|g;') yann@435: ;; yann@435: esac yann@553: echo "${VERSION}" yann@435: yann@614: # Now we have the version string, we can build up the paths yann@554: [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin" yann@554: [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}" yann@554: [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}" yann@554: [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1" yann@554: yann@673: # Check the existence of absolutely required tools yann@870: { IFS=' yann@870: '; yann@870: for tool in ${TOOLS_TO_CHECK}; do yann@870: has_or_abort "${tool}" yann@870: done; yann@870: } yann@673: yann@641: # It's safer to change all ',' to spaces rather than setting IFS yann@641: CONTRIB_list=$(echo "${CONTRIB_list}" |sed -r -e 's/,+/ /g;') yann@673: if [ -n "${CONTRIB_list}" ]; then yann@673: has_or_abort lzcat yann@673: printf "Applying contributed code: " yann@673: for c in ${CONTRIB_list}; do yann@673: printf "${c}, " yann@673: if [ ! -f "contrib/${c}.patch.lzma" ]; then yann@673: do_error "Contribution '${c}' does not exist" yann@673: fi yann@673: lzcat "contrib/${c}.patch.lzma" |patch -p1 >/dev/null 2>&1 yann@673: done yann@673: echo "done" yann@673: fi yann@614: yann@641: printf "Building up Makefile... " yann@182: sed -r -e "s,@@BINDIR@@,${BINDIR},g;" \ yann@182: -e "s,@@LIBDIR@@,${LIBDIR},g;" \ yann@182: -e "s,@@DOCDIR@@,${DOCDIR},g;" \ yann@182: -e "s,@@MANDIR@@,${MANDIR},g;" \ yann@182: -e "s,@@VERSION@@,${VERSION},g;" \ yann@182: -e "s,@@DATE@@,${DATE},g;" \ yann@285: -e "s,@@LOCAL@@,${LOCAL_set},g;" \ yann@185: Makefile.in >Makefile yann@673: echo "done" yann@185: yann@185: cat <<__EOF__ yann@673: yann@197: crosstool-NG configured as follows: yann@554: PREFIX='${PREFIX}' yann@554: BINDIR='${BINDIR}' yann@554: LIBDIR='${LIBDIR}' yann@554: DOCDIR='${DOCDIR}' yann@554: MANDIR='${MANDIR}' yann@641: CONTRIB='${CONTRIB_list}' yann@185: __EOF__