5 VERSION=$( cat .version )
8 PREFIX_DEFAULT=/usr/local
22 # Simply print the error message, and exit. Obvious, he?
24 printf "${myname}: ${@}\n"
28 # Given an option string and the following argument,
29 # echoes the value of the option.
30 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
31 # If --var val => echoes val and returns non null, meaning second arg was used
45 # The set_xxx functions will set the corresponding configuration variable
46 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
48 PREFIX="$( get_optval "$1" "$2" )"
52 BINDIR="$( get_optval "$1" "$2" )"
56 LIBDIR="$( get_optval "$1" "$2" )"
60 DOCDIR="$( get_optval "$1" "$2" )"
64 MANDIR="$( get_optval "$1" "$2" )"
66 set_program_prefix() {
67 PROG_PFX="$( get_optval "$1" "$2" )"
69 set_program_suffix() {
70 PROG_SFX="$( get_optval "$1" "$2" )"
72 set_program_transform_name() {
73 PROG_SED="$( get_optval "$1" "$2" )"
76 local var_name="${1%%=*}"
77 var_name="${var_name#--with-}"
78 eval ${var_name}="\$( get_optval "$1" "$2" )"
81 # var_list is a list of variables, each one holding a path to a
82 # tool, either detected by ./configure, or specified by the user.
86 # This function adds a variable name to the above list of variable names.
87 # $1: the name of the variable to add to the list
90 for v in ${var_list}; do
91 [ "${v}" = "${1}" ] && return 0
93 var_list="${var_list} ${1}"
95 add_to_kconfig_list() {
97 for k in ${kconfig_list}; do
98 [ "${k}" = "${1}" ] && return 0
100 kconfig_list="${kconfig_list} ${1}"
103 # A function to test for required tools/headers/libraries
104 # Return 0 (true) if found, !0 (false) if not found
106 # $*: [prog|inc|lib]=<name[ name...]>
107 # the name(s) of tool(s) to test for
109 # eg: prog=bash prog="curl wget"
111 # the name of the variable to test and set
113 # eg: var=bash if ${bash} is set and non-null, use that,
114 # else check for bash and set bash=$(which bash)
116 # for each 'prog', test if $(prog --version) matches 'regexp'
118 # eg: ver='^GNU bash, version [34]\.'
119 # $*: lib_exts=<extension[ extension...]>
120 # the list of allowed library extension
122 # eg: lib_exts="so dylib" lib_exts="so dylib a"
123 # $*: err=<error_message>
124 # the error message to print if tool is missing
125 # optional, defaults to: '${prog}: none found'
126 # eg: err="'bash' 3.x or above was not found"
127 # Note: err may be printed by caller, not us
128 # $*: kconfig=<var_name>
129 # the name of a variable to pass down to kconfig if
130 # the prog/inc/lib was found
131 # optional, defaults to none
132 # eg: kconfig=has_libncurses
134 # if set to 'y', skip the test, but still register the
135 # kconfig and var variables; if 'n' or empty, do the
137 # optional, default to 'n'
138 # eg: skip="${static_link_ko}"
148 # Note: prog/inc/lib and var/kconfig/ver/err are set here,
149 # but declared by the caller (because it needs it)
150 for item in "${@}"; do
152 prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*|lib_exts=*|skip=*)
153 eval ${item%%=*}=\"${item#*=}\"
155 *) do_error "check_for: incorrect parameters: '${item}'";;
159 case "${prog}:${inc}:${lib}" in
160 ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
161 if [ -n "${var}" ]; then
162 do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
165 ::) do_error "check_for: [prog|inc|lib] is mandatory";;
168 if [ -n "${var}" ]; then
169 add_to_var_list "${var}"
171 if [ -n "${kconfig}" ]; then
172 add_to_kconfig_list "${kconfig}"
175 if [ "${skip}" = "y" ]; then
179 if [ -n "${prog}" ]; then
180 for item in ${prog}; do
181 printf "Checking for '${item}'... "
182 if [ -n "${var}" ]; then
183 eval val="\${${var}}"
184 if [ -n "${val}" ]; then
185 status="${val} (cached)\n"
190 where="$( which "${item}" 2>/dev/null )"
191 if [ -z "${where}" ]; then
194 elif [ -n "${ver}" ]; then
195 str=$( LC_ALL=C "${where}" --version 2>&1 \
199 if [ -z "${str}" ]; then
208 if [ -z "${status}" ]; then
215 if [ -n "${inc}" ]; then
216 for item in ${inc}; do
217 printf "Checking for '${item}'... "
218 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
225 if [ -z "${status}" ]; then
232 if [ -n "${lib}" ]; then
233 if [ -z "${lib_exts}" ]; then
234 do_error "check_for: no library extension specified for '${lib}'"
236 for item in ${lib}; do
237 for ext in ${lib_exts}; do
238 printf "Checking for '${item}.${ext}'... "
239 where="$( gcc -print-file-name="${item}.${ext}" )"
240 if [ "${where}" != "${item}.${ext}" ]; then
241 where="$( readlink "${where}" )"
248 if [ -z "${status}" ]; then
255 if [ -n "${var}" ]; then
256 eval ${var}='"'"${where}"'"'
258 if [ -n "${kconfig}" ]; then
263 # This function checks for a tool, and aborts if not found
264 # See check_for(), above, for how to call has_or_abort
266 # We declare these 6 variables here, although they are
267 # set in check_for(), called below
269 local var ver err kconfig
271 if ! check_for "$@"; then
272 printf " * A mandatory dependency is missing, or version mis-match:\n"
273 printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
274 if [ -n "${var}" ]; then
275 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
278 # Bail out if --force is not specified
279 [ -z "${FORCE}" ] && do_error "Bailing out..."
281 printf "<* FORCE in action: *>\n"
282 printf "<* Continuing despite missing pre-requisite *>\n"
283 printf "<* Prepare for breakage *>\n"
289 # This function checks for a tool, and warns if not found
290 # See check_for(), above, for how to call has_or_abort
291 # Note: if err is not set, then no error message is printed
293 # We declare these 6 variables here, although they are
294 # set in check_for(), called below
296 local var ver err kconfig
298 if ! check_for "$@"; then
299 printf " * An optional dependency is missing, some features will be disabled"
300 printf "${err:+:\n * - ${err}}\n"
301 if [ -n "${var}" ]; then
302 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
309 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
311 USAGE: ./configure [OPTION]...
313 Defaults for the options are specified in brackets.
316 -h, --help display this help and exit
317 --force force configure to continue, even in case
318 some pre-requisites are missing
320 Installation directories:
321 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
322 --local don't install, and use current directory
324 By default, \`make install' will install all the files in
325 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
326 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
327 for instance \`--prefix=\${HOME}'.
329 For better control, use the options below.
330 Note: options marked as \`ignored' are recognised, but not acted upon, as
331 they make no sense for crosstool-NG, or they are not implemented yet.
333 Fine tuning of the installation directories:
334 --bindir=DIR user executables [PREFIX/bin]
335 --libdir=DIR object code libraries [PREFIX/lib]
336 --docdir=DIR info documentation [PREFIX/share/doc]
337 --mandir=DIR man documentation [PREFIX/share/man]
338 --infodir=DIR info documentation [DATAROOTDIR/info] (ignored)
339 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
341 --sysconfdir=DIR read-only single-machine data [PREFIX/etc] (ignored)
342 --localstatedir=DIR modifiable single-machine data [PREFIX/var] (ignored)
345 --program-prefix=PREFIX prepend PREFIX to installed program names
346 --program-suffix=SUFFIX append SUFFIX to installed program names
347 --program-transform-name=PROGRAM run sed PROGRAM on installed program names
350 --build=BUILD configure for building on BUILD [guessed] (ignored)
351 --host=HOST cross-compile to build programs to run on HOST [BUILD]
355 --enable-shared[=PKGS] build shared libraries [default=yes] (ignored)
356 --enable-static[=PKGS] build static libraries [default=yes] (ignored)
359 --with-install=PATH Specify the full PATH to GNU install
360 --with-make=PATH Specify the full PATH to GNU make >= 3.80
361 --with-grep=PATH Specify the full PATH to GNU grep
362 --with-sed=PATH Specify the full PATH to GNU sed
363 --with-bash=PATH Specify the full PATH to bash >= 3.0
367 #---------------------------------------------------------------------
370 while [ $# -ne 0 ]; do
372 --local) LOCAL_set="y"; shift;;
373 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
374 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
375 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
376 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
377 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
378 --with-*) set_tool "$1" "$2" && shift || shift 2;;
379 --program-prefix=*|--program-prefix)
380 set_program_prefix "$1" "$2" && shift || shift 2
382 --program-suffix=*|--program-suffix)
383 set_program_suffix "$1" "$2" && shift || shift 2
385 --program-transform-name=*|--program-transform-name)
386 set_program_transform_name "$1" "$2" && shift || shift 2
388 --force) FORCE=1; shift;;
389 --help|-h) do_help; exit 0;;
390 # Skip, auto-stuff compatibility
391 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
392 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
393 --enable-shared|--disable-shared|--enable-static|--disable-static) shift;;
394 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
399 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
401 # Special case when installing locally
402 if [ "${LOCAL_set}" = "y" ]; then
403 set_prefix "" "$( pwd )"
404 set_bindir "" "$( pwd )"
405 set_libdir "" "$( pwd )"
406 set_docdir "" "$( pwd )/docs"
407 set_mandir "" "$( pwd )/docs"
408 set_program_prefix "" ""
409 set_program_suffix "" ""
410 set_program_transform_name "" ""
413 #---------------------------------------------------------------------
414 # Some sanity checks, now
416 # We check for grep and sed manually, because they are used in check_for()
417 printf "Checking for 'grep'... "
418 if [ -n "${grep}" ]; then
419 printf "${grep} (cached)\n"
421 grep="$( which grep 2>/dev/null )"
422 if [ -z "${grep}" ]; then
426 printf "Checking whether '${grep}' supports -E... "
427 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
435 if [ -z "${grep}" ]; then
436 printf "Either you are missing entirely the needed tool,\n"
437 printf "or the version you have is too old.\n"
438 printf "You can give the path to this tool using: --with-grep=PATH\n"
439 do_error "Bailing out..."
443 printf "Checking for 'sed'... "
444 if [ -n "${sed}" ]; then
445 printf "${sed} (cached)\n"
447 sed="$( which sed 2>/dev/null )"
448 if [ -z "${sed}" ]; then
452 printf "Checking whether '${sed}' supports -i and -e... "
453 touch .ct-ng.sed.test
454 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
460 rm -f .ct-ng.sed.test
463 if [ -z "${sed}" ]; then
464 printf "Either you are missing entirely the needed tool,\n"
465 printf "or the version you have is too old.\n"
466 printf "You can give the path to this tool using: --with-sed=PATH\n"
467 do_error "Bailing out..."
471 # The regular list of tools we can now easily check for
472 has_or_abort prog=bash \
474 ver='^GNU bash, version (3\.[1-9]|4)' \
475 err="'bash' 3.1 or above was not found"
476 has_or_abort prog=cut
477 has_or_abort prog=install var=install
478 has_or_abort prog=make \
480 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
481 err="GNU 'make' 3.80 or above was not found"
482 has_or_abort prog=gcc
483 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
484 has_or_abort prog=bison
485 has_or_abort prog=flex
486 has_or_abort prog=makeinfo
487 has_or_abort prog=automake \
488 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
489 err="'automake' 1.10 or above was not found"
490 has_or_abort prog=libtool \
492 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
493 err="'libtool' 1.5.26 or above was not found"
494 has_or_abort prog=stat
495 has_or_abort prog="curl wget"
496 has_or_abort prog=patch
497 has_or_abort prog=tar
498 has_or_abort prog=gzip
499 has_or_abort prog=bzip2
500 has_or_warn prog=xz \
501 kconfig=has_xzutils \
502 err="xz-comoressed tarballs will not be used"
503 has_or_abort prog=readlink
504 has_or_abort prog=objcopy var=objcopy
505 has_or_abort prog=objdump var=objdump
506 has_or_abort prog=readelf var=readelf
507 has_or_abort prog=patch var=patch
508 has_or_warn prog=cvs \
510 err="it will not be possible to use newlib cvs snapshots"
511 has_or_warn prog=svn \
513 err="subversion is required to download eglibc"
517 printf "Checking for host system... "
519 printf "%s\n" "${host}"
524 printf " * Runing under %s is not fully tested\n" "${host}"
525 printf " * You may encounter some weird behavior\n"
529 printf "Checking if static linking is possible... "
534 if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1 <<-_EOF_
535 int main() { return 0; }
543 if [ "${static_link_ok}" = "y" ]; then
549 printf " * An optional host feature is missing, some features will be disabled:\n"
550 printf " * - It will not be possible to statically link toolchain's binaries\n"
552 add_to_kconfig_list static_link_ok
556 if [ "${static_link_ok}" = "y" ]; then
557 libs_exts="${libs_exts} a"
560 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
561 ncurses_libs="libncursesw libncurses libcurses"
562 has_or_abort lib="${ncurses_libs}" \
563 lib_exts="${libs_exts}" \
564 inc="${ncurses_hdrs}" \
565 err="The 'ncurses' library is needed fo the menuconfig frontend"
567 has_or_abort lib="libstdc++" \
568 lib_exts="${libs_exts}" \
569 err="The 'libstdc++' library is needed to build gcc"
571 # Yes, we may be checking twice for libstdc++.a
572 # The first is because we need one instance of libstdc++ (shared or static)
573 # because it is needed for PPL; the second is because the static version is
574 # required for static-linking, and if missing, the option is removed.
575 has_or_warn lib="libstdc++" \
577 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
578 kconfig=has_static_libstdcxx \
579 skip="${static_link_ko}"
581 has_or_warn inc="expat.h" \
583 lib_exts="${libs_exts}" \
584 err="The 'expat' header file and library are needed to link cross-gdb's executables" \
587 # Yes, we may be checking twice for libexpat.a
588 # The first is because we need one instance of libexpat (shared or static)
589 # because it is needed for cross-gdb; the second is because the static version
590 # is required for static-linking, and if missing, the option is removed.
591 has_or_warn lib="libexpat" \
593 err="static 'expat' is needed to statically link cross-gdb's executables" \
594 kconfig=has_static_expat \
595 skip="${static_link_ko}"
598 python_incs="${python_incs} python2.${v}/Python.h"
599 python_libs="${python_libs} libpython2.${v}"
601 has_or_warn inc="${python_incs}" \
602 lib="${python_libs}" \
603 lib_exts="${libs_exts}" \
604 err="The 'python' header file and library are needed for some features of cross-gdb"
606 #---------------------------------------------------------------------
607 # Compute the version string
609 # If this version is n hg clone, try to get the revision number
610 # If we can't get the revision number, use date
611 printf "\nComputing version string... "
614 REVISION="$( hg id -n 2>/dev/null || true )"
615 case "${REVISION}" in
617 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
619 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
622 # Arrange to have no / in the directory name, no need to create an
623 # arbitrarily deep directory structure
624 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
627 printf "${VERSION}\n"
629 #---------------------------------------------------------------------
630 # Compute and check install paths
632 # Now we have the version string, we can build up the paths
633 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
634 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
635 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
636 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
638 # Install support files in our own sub-dir, so as not to mangle (system)
639 # files and dirs, but only if not --local
640 if [ -z "${LOCAL_set}" ]; then
641 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
642 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
645 # Check that install PATHs are absolute
646 for p in BIN LIB DOC MAN; do
648 eval v='"${'"${var}"'}"'
651 *) do_error "'${var}' is not an absolute path: '${v}'";;
654 case "${PROG_PFX}" in
655 */*) do_error "program prefix '${PROG_PFX}' contains a '/'";;
657 case "${PROG_SFX}" in
658 */*) do_error "program suffix '${PROG_SFX}' contains a '/'";;
661 #---------------------------------------------------------------------
664 printf "Building up Makefile... "
665 var_sed="$( for var_name in ${var_list}; do
666 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
669 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
670 eval printf \"${k_name}=\${${k_name}} \"
673 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
674 -e "s,@@LIBDIR@@,${LIBDIR},g" \
675 -e "s,@@DOCDIR@@,${DOCDIR},g" \
676 -e "s,@@MANDIR@@,${MANDIR},g" \
677 -e "s,@@PROG_PFX@@,${PROG_PFX},g" \
678 -e "s,@@PROG_SFX@@,${PROG_SFX},g" \
679 -e "s,@@PROG_SED@@,${PROG_SED},g" \
680 -e "s,@@VERSION@@,${VERSION},g" \
681 -e "s,@@DATE@@,${DATE},g" \
682 -e "s,@@LOCAL@@,${LOCAL_set},g" \
684 -e "${kconfig_sed}" \
691 crosstool-NG configured as follows:
697 PROG_PFX='${PROG_PFX}'
698 PROG_SFX='${PROG_SFX}'
699 PROG_SED='${PROG_SED}'
704 if [ "${LOCAL_set}" != "y" ]; then
705 printf " make install\n"