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"
189 where="$( which "${item}" 2>/dev/null )"
190 if [ -z "${where}" ]; then
193 elif [ -n "${ver}" ]; then
194 str=$( LC_ALL=C "${where}" --version 2>&1 \
198 if [ -z "${str}" ]; then
207 if [ -z "${status}" ]; then
214 if [ -n "${inc}" ]; then
215 for item in ${inc}; do
216 printf "Checking for '${item}'... "
217 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
224 if [ -z "${status}" ]; then
231 if [ -n "${lib}" ]; then
232 if [ -z "${lib_exts}" ]; then
233 do_error "check_for: no library extension specified for '${lib}'"
235 for item in ${lib}; do
236 for ext in ${lib_exts}; do
237 printf "Checking for '${item}.${ext}'... "
238 where="$( gcc -print-file-name="${item}.${ext}" )"
239 if [ "${where}" != "${item}.${ext}" ]; then
240 where="$( readlink "${where}" )"
247 if [ -z "${status}" ]; then
254 if [ -n "${var}" ]; then
255 eval ${var}='"'"${where}"'"'
257 if [ -n "${kconfig}" ]; then
262 # This function checks for a tool, and aborts if not found
263 # See check_for(), above, for how to call has_or_abort
265 # We declare these 6 variables here, although they are
266 # set in check_for(), called below
268 local var ver err kconfig
270 if ! check_for "$@"; then
271 printf " * A mandatory dependency is missing, or version mis-match:\n"
272 printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
273 if [ -n "${var}" ]; then
274 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
277 # Bail out if --force is not specified
278 [ -z "${FORCE}" ] && do_error "Bailing out..."
280 printf "<* FORCE in action: *>\n"
281 printf "<* Continuing despite missing pre-requisite *>\n"
282 printf "<* Prepare for breakage *>\n"
288 # This function checks for a tool, and warns if not found
289 # See check_for(), above, for how to call has_or_abort
290 # Note: if err is not set, then no error message is printed
292 # We declare these 6 variables here, although they are
293 # set in check_for(), called below
295 local var ver err kconfig
297 if ! check_for "$@"; then
298 printf " * An optional dependency is missing, some features will be disabled"
299 printf "${err:+:\n * - ${err}}\n"
300 if [ -n "${var}" ]; then
301 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
308 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
310 USAGE: ./configure [OPTION]...
312 Defaults for the options are specified in brackets.
315 -h, --help display this help and exit
316 --force force configure to continue, even in case
317 some pre-requisites are missing
319 Installation directories:
320 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
321 --local don't install, and use current directory
323 By default, \`make install' will install all the files in
324 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
325 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
326 for instance \`--prefix=\${HOME}'.
328 For better control, use the options below.
329 Note: options marked as \`ignored' are recognised, but not acted upon, as
330 they make no sense for crosstool-NG, or they are not implemented yet.
332 Fine tuning of the installation directories:
333 --bindir=DIR user executables [PREFIX/bin]
334 --libdir=DIR object code libraries [PREFIX/lib]
335 --docdir=DIR info documentation [PREFIX/share/doc]
336 --mandir=DIR man documentation [PREFIX/share/man]
337 --infodir=DIR info documentation [DATAROOTDIR/info] (ignored)
338 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
340 --sysconfdir=DIR read-only single-machine data [PREFIX/etc] (ignored)
341 --localstatedir=DIR modifiable single-machine data [PREFIX/var] (ignored)
344 --program-prefix=PREFIX prepend PREFIX to installed program names
345 --program-suffix=SUFFIX append SUFFIX to installed program names
346 --program-transform-name=PROGRAM run sed PROGRAM on installed program names
349 --build=BUILD configure for building on BUILD [guessed] (ignored)
350 --host=HOST cross-compile to build programs to run on HOST [BUILD]
354 --enable-shared[=PKGS] build shared libraries [default=yes] (ignored)
355 --enable-static[=PKGS] build static libraries [default=yes] (ignored)
358 --with-install=PATH Specify the full PATH to GNU install
359 --with-make=PATH Specify the full PATH to GNU make >= 3.80
360 --with-grep=PATH Specify the full PATH to GNU grep
361 --with-sed=PATH Specify the full PATH to GNU sed
362 --with-bash=PATH Specify the full PATH to bash >= 3.0
366 #---------------------------------------------------------------------
369 while [ $# -ne 0 ]; do
371 --local) LOCAL_set="y"; shift;;
372 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
373 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
374 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
375 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
376 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
377 --with-*) set_tool "$1" "$2" && shift || shift 2;;
378 --program-prefix=*|--program-prefix)
379 set_program_prefix "$1" "$2" && shift || shift 2
381 --program-suffix=*|--program-suffix)
382 set_program_suffix "$1" "$2" && shift || shift 2
384 --program-transform-name=*|--program-transform-name)
385 set_program_transform_name "$1" "$2" && shift || shift 2
387 --force) FORCE=1; shift;;
388 --help|-h) do_help; exit 0;;
389 # Skip, auto-stuff compatibility
390 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
391 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
392 --enable-shared|--disable-shared|--enable-static|--disable-static) shift;;
393 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
398 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
400 # Special case when installing locally
401 if [ "${LOCAL_set}" = "y" ]; then
402 set_prefix "" "$( pwd )"
403 set_bindir "" "$( pwd )"
404 set_libdir "" "$( pwd )"
405 set_docdir "" "$( pwd )/docs"
406 set_mandir "" "$( pwd )/docs"
407 set_program_prefix "" ""
408 set_program_suffix "" ""
409 set_program_transform_name "" ""
412 #---------------------------------------------------------------------
413 # Some sanity checks, now
415 # We check for grep and sed manually, because they are used in check_for()
416 printf "Checking for 'grep'... "
417 if [ -n "${grep}" ]; then
418 printf "${grep} (cached)\n"
420 grep="$( which grep 2>/dev/null )"
421 if [ -z "${grep}" ]; then
425 printf "Checking whether '${grep}' supports -E... "
426 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
434 if [ -z "${grep}" ]; then
435 printf "Either you are missing entirely the needed tool,\n"
436 printf "or the version you have is too old.\n"
437 printf "You can give the path to this tool using: --with-grep=PATH\n"
438 do_error "Bailing out..."
442 printf "Checking for 'sed'... "
443 if [ -n "${sed}" ]; then
444 printf "${sed} (cached)\n"
446 sed="$( which sed 2>/dev/null )"
447 if [ -z "${sed}" ]; then
451 printf "Checking whether '${sed}' supports -i and -e... "
452 touch .ct-ng.sed.test
453 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
459 rm -f .ct-ng.sed.test
462 if [ -z "${sed}" ]; then
463 printf "Either you are missing entirely the needed tool,\n"
464 printf "or the version you have is too old.\n"
465 printf "You can give the path to this tool using: --with-sed=PATH\n"
466 do_error "Bailing out..."
470 # The regular list of tools we can now easily check for
471 has_or_abort prog=bash \
473 ver='^GNU bash, version (3\.[1-9]|4)' \
474 err="'bash' 3.1 or above was not found"
475 has_or_abort prog=cut
476 has_or_abort prog=install var=install
477 has_or_abort prog=make \
479 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
480 err="GNU 'make' 3.80 or above was not found"
481 has_or_abort prog=gcc
482 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
483 has_or_abort prog=bison
484 has_or_abort prog=flex
485 has_or_abort prog=makeinfo
486 has_or_abort prog=automake \
487 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
488 err="'automake' 1.10 or above was not found"
489 has_or_abort prog=libtool \
491 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
492 err="'libtool' 1.5.26 or above was not found"
493 has_or_abort prog=stat
494 has_or_abort prog="curl wget"
495 has_or_abort prog=patch
496 has_or_abort prog=tar
497 has_or_abort prog=gzip
498 has_or_abort prog=bzip2
499 has_or_warn prog=xz \
500 kconfig=has_xzutils \
501 err="xz-comoressed tarballs will not be used"
502 has_or_abort prog=readlink
503 has_or_abort prog=objcopy var=objcopy
504 has_or_abort prog=objdump var=objdump
505 has_or_abort prog=readelf var=readelf
506 has_or_abort prog=patch var=patch
507 has_or_warn prog=cvs \
509 err="it will not be possible to use newlib cvs snapshots"
510 has_or_warn prog=svn \
512 err="subversion is required to download eglibc"
516 printf "Checking for host system... "
518 printf "%s\n" "${host}"
523 printf " * Runing under %s is not fully tested\n" "${host}"
524 printf " * You may encounter some weird behavior\n"
528 printf "Checking if static linking is possible... "
533 if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1 <<-_EOF_
534 int main() { return 0; }
542 if [ "${static_link_ok}" = "y" ]; then
548 printf " * An optional host feature is missing, some features will be disabled:\n"
549 printf " * - It will not be possible to statically link toolchain's binaries\n"
551 add_to_kconfig_list static_link_ok
555 if [ "${static_link_ok}" = "y" ]; then
556 libs_exts="${libs_exts} a"
559 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
560 ncurses_libs="libncursesw libncurses libcurses"
561 has_or_abort lib="${ncurses_libs}" \
562 lib_exts="${libs_exts}" \
563 inc="${ncurses_hdrs}" \
564 err="The 'ncurses' library is needed fo the menuconfig frontend"
566 has_or_abort lib="libstdc++" \
567 lib_exts="${libs_exts}" \
568 err="The 'libstdc++' library is needed to build gcc"
570 # Yes, we may be checking twice for libstdc++.a
571 # The first is because we need one instance of libstdc++ (shared or static)
572 # because it is needed for PPL; the second is because the static version is
573 # required for static-linking, and if missing, the option is removed.
574 has_or_warn lib="libstdc++" \
576 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
577 kconfig=has_static_libstdcxx \
578 skip="${static_link_ko}"
580 has_or_warn inc="expat.h" \
582 lib_exts="${libs_exts}" \
583 err="The 'expat' header file and library are needed to link cross-gdb's executables" \
586 # Yes, we may be checking twice for libexpat.a
587 # The first is because we need one instance of libexpat (shared or static)
588 # because it is needed for cross-gdb; the second is because the static version
589 # is required for static-linking, and if missing, the option is removed.
590 has_or_warn lib="libexpat" \
592 err="static 'expat' is needed to statically link cross-gdb's executables" \
593 kconfig=has_static_expat \
594 skip="${static_link_ko}"
597 python_incs="${python_incs} python2.${v}/Python.h"
598 python_libs="${python_libs} libpython2.${v}"
600 has_or_warn inc="${python_incs}" \
601 lib="${python_libs}" \
602 lib_exts="${libs_exts}" \
603 err="The 'python' header file and library are needed for some features of cross-gdb"
605 #---------------------------------------------------------------------
606 # Compute the version string
608 # If this version is n hg clone, try to get the revision number
609 # If we can't get the revision number, use date
610 printf "\nComputing version string... "
613 REVISION="$( hg id -n 2>/dev/null || true )"
614 case "${REVISION}" in
616 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
618 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
621 # Arrange to have no / in the directory name, no need to create an
622 # arbitrarily deep directory structure
623 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
626 printf "${VERSION}\n"
628 #---------------------------------------------------------------------
629 # Compute and check install paths
631 # Now we have the version string, we can build up the paths
632 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
633 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
634 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
635 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
637 # Install support files in our own sub-dir, so as not to mangle (system)
638 # files and dirs, but only if not --local
639 if [ -z "${LOCAL_set}" ]; then
640 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
641 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
644 # Check that install PATHs are absolute
645 for p in BIN LIB DOC MAN; do
647 eval v='"${'"${var}"'}"'
650 *) do_error "'${var}' is not an absolute path: '${v}'";;
653 case "${PROG_PFX}" in
654 */*) do_error "program prefix '${PROG_PFX}' contains a '/'";;
656 case "${PROG_SFX}" in
657 */*) do_error "program suffix '${PROG_SFX}' contains a '/'";;
660 #---------------------------------------------------------------------
663 printf "Building up Makefile... "
664 var_sed="$( for var_name in ${var_list}; do
665 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
668 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
669 eval printf \"${k_name}=\${${k_name}} \"
672 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
673 -e "s,@@LIBDIR@@,${LIBDIR},g" \
674 -e "s,@@DOCDIR@@,${DOCDIR},g" \
675 -e "s,@@MANDIR@@,${MANDIR},g" \
676 -e "s,@@PROG_PFX@@,${PROG_PFX},g" \
677 -e "s,@@PROG_SFX@@,${PROG_SFX},g" \
678 -e "s,@@PROG_SED@@,${PROG_SED},g" \
679 -e "s,@@VERSION@@,${VERSION},g" \
680 -e "s,@@DATE@@,${DATE},g" \
681 -e "s,@@LOCAL@@,${LOCAL_set},g" \
683 -e "${kconfig_sed}" \
690 crosstool-NG configured as follows:
696 PROG_PFX='${PROG_PFX}'
697 PROG_SFX='${PROG_SFX}'
698 PROG_SED='${PROG_SED}'
703 if [ "${LOCAL_set}" != "y" ]; then
704 printf " make install\n"