5 VERSION=$( cat .version )
8 PREFIX_DEFAULT=/usr/local
20 # Simply print the error message, and exit. Obvious, he?
22 printf "${myname}: ${@}\n"
26 # Given an option string and the following argument,
27 # echoes the value of the option.
28 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
29 # If --var val => echoes val and returns non null, meaning second arg was used
43 # The set_xxx functions will set the corresponding configuration variable
44 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
46 PREFIX="$( get_optval "$1" "$2" )"
50 BINDIR="$( get_optval "$1" "$2" )"
54 LIBDIR="$( get_optval "$1" "$2" )"
58 DOCDIR="$( get_optval "$1" "$2" )"
62 MANDIR="$( get_optval "$1" "$2" )"
64 set_program_prefix() {
65 PROG_PFX="$( get_optval "$1" "$2" )"
68 local var_name="${1%%=*}"
69 var_name="${var_name#--with-}"
70 eval ${var_name}="\$( get_optval "$1" "$2" )"
73 # var_list is a list of variables, each one holding a path to a
74 # tool, either detected by ./configure, or specified by the user.
78 # This function adds a variable name to the above list of variable names.
79 # $1: the name of the variable to add to the list
82 for v in ${var_list}; do
83 [ "${v}" = "${1}" ] && return 0
85 var_list="${var_list} ${1}"
87 add_to_kconfig_list() {
89 for k in ${kconfig_list}; do
90 [ "${k}" = "${1}" ] && return 0
92 kconfig_list="${kconfig_list} ${1}"
95 # A function to test for required tools/headers/libraries
96 # Return 0 (true) if found, !0 (false) if not found
98 # $*: [prog|inc|lib]=<name[ name...]>
99 # the name(s) of tool(s) to test for
101 # eg: prog=bash prog="curl wget"
103 # the name of the variable to test and set
105 # eg: var=bash if ${bash} is set and non-null, use that,
106 # else check for bash and set bash=$(which bash)
108 # for each 'prog', test if $(prog --version) matches 'regexp'
110 # eg: ver='^GNU bash, version [34]\.'
111 # $*: lib_exts=<extension[ extension...]>
112 # the list of allowed library extension
114 # eg: lib_exts="so dylib" lib_exts="so dylib a"
115 # $*: err=<error_message>
116 # the error message to print if tool is missing
117 # optional, defaults to: '${prog}: none found'
118 # eg: err="'bash' 3.x or above was not found"
119 # Note: err may be printed by caller, not us
120 # $*: kconfig=<var_name>
121 # the name of a variable to pass down to kconfig if
122 # the prog/inc/lib was found
123 # optional, defaults to none
124 # eg: kconfig=has_libncurses
126 # if set to 'y', skip the test, but still register the
127 # kconfig and var variables; if 'n' or empty, do the
129 # optional, default to 'n'
130 # eg: skip="${static_link_ko}"
140 # Note: prog/inc/lib and var/kconfig/ver/err are set here,
141 # but declared by the caller (because it needs it)
142 for item in "${@}"; do
144 prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*|lib_exts=*|skip=*)
145 eval ${item%%=*}=\"${item#*=}\"
147 *) do_error "check_for: incorrect parameters: '${item}'";;
151 case "${prog}:${inc}:${lib}" in
152 ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
153 if [ -n "${var}" ]; then
154 do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
157 ::) do_error "check_for: [prog|inc|lib] is mandatory";;
160 if [ -n "${var}" ]; then
161 add_to_var_list "${var}"
163 if [ -n "${kconfig}" ]; then
164 add_to_kconfig_list "${kconfig}"
167 if [ "${skip}" = "y" ]; then
171 if [ -n "${prog}" ]; then
172 for item in ${prog}; do
173 printf "Checking for '${item}'... "
174 if [ -n "${var}" ]; then
175 eval val="\${${var}}"
176 if [ -n "${val}" ]; then
177 status="${val} (cached)\n"
181 where="$( which "${item}" 2>/dev/null )"
182 if [ -z "${where}" ]; then
185 elif [ -n "${ver}" ]; then
186 str=$( LC_ALL=C "${where}" --version 2>&1 \
190 if [ -z "${str}" ]; then
199 if [ -z "${status}" ]; then
206 if [ -n "${inc}" ]; then
207 for item in ${inc}; do
208 printf "Checking for '${item}'... "
209 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
216 if [ -z "${status}" ]; then
223 if [ -n "${lib}" ]; then
224 if [ -z "${lib_exts}" ]; then
225 do_error "check_for: no library extension specified for '${lib}'"
227 for item in ${lib}; do
228 for ext in ${lib_exts}; do
229 printf "Checking for '${item}.${ext}'... "
230 where="$( gcc -print-file-name="${item}.${ext}" )"
231 if [ "${where}" != "${item}.${ext}" ]; then
232 where="$( readlink "${where}" )"
239 if [ -z "${status}" ]; then
246 if [ -n "${var}" ]; then
247 eval ${var}='"'"${where}"'"'
249 if [ -n "${kconfig}" ]; then
254 # This function checks for a tool, and aborts if not found
255 # See check_for(), above, for how to call has_or_abort
257 # We declare these 6 variables here, although they are
258 # set in check_for(), called below
260 local var ver err kconfig
262 if ! check_for "$@"; then
263 printf " * A mandatory dependency is missing, or version mis-match:\n"
264 printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
265 if [ -n "${var}" ]; then
266 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
269 # Bail out if --force is not specified
270 [ -z "${FORCE}" ] && do_error "Bailing out..."
272 printf "<* FORCE in action: *>\n"
273 printf "<* Continuing despite missing pre-requisite *>\n"
274 printf "<* Prepare for breakage *>\n"
280 # This function checks for a tool, and warns if not found
281 # See check_for(), above, for how to call has_or_abort
282 # Note: if err is not set, then no error message is printed
284 # We declare these 6 variables here, although they are
285 # set in check_for(), called below
287 local var ver err kconfig
289 if ! check_for "$@"; then
290 printf " * An optional dependency is missing, some features will be disabled"
291 printf "${err:+:\n * - ${err}}\n"
292 if [ -n "${var}" ]; then
293 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
300 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
302 USAGE: ./configure [OPTION]...
304 Defaults for the options are specified in brackets.
307 -h, --help display this help and exit
308 --force force configure to continue, even in case
309 some pre-requisites are missing
311 Installation directories:
312 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
313 --local don't install, and use current directory
315 By default, \`make install' will install all the files in
316 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
317 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
318 for instance \`--prefix=\${HOME}'.
320 For better control, use the options below.
321 Note: options marked as \`ignored' are recognised, but not acted upon, as
322 they make no sense for crosstool-NG, or they are not implemented yet.
324 Fine tuning of the installation directories:
325 --bindir=DIR user executables [PREFIX/bin]
326 --libdir=DIR object code libraries [PREFIX/lib]
327 --docdir=DIR info documentation [PREFIX/share/doc]
328 --mandir=DIR man documentation [PREFIX/share/man]
329 --infodir=DIR info documentation [DATAROOTDIR/info] (ignored)
330 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
332 --sysconfdir=DIR read-only single-machine data [PREFIX/etc] (ignored)
333 --localstatedir=DIR modifiable single-machine data [PREFIX/var] (ignored)
336 --program-prefix=PREFIX prepend PREFIX to installed program names
339 --build=BUILD configure for building on BUILD [guessed] (ignored)
340 --host=HOST cross-compile to build programs to run on HOST [BUILD]
344 --enable-shared[=PKGS] build shared libraries [default=yes] (ignored)
345 --enable-static[=PKGS] build static libraries [default=yes] (ignored)
348 --with-install=PATH Specify the full PATH to GNU install
349 --with-make=PATH Specify the full PATH to GNU make >= 3.80
350 --with-grep=PATH Specify the full PATH to GNU grep
351 --with-sed=PATH Specify the full PATH to GNU sed
352 --with-bash=PATH Specify the full PATH to bash >= 3.0
356 #---------------------------------------------------------------------
359 while [ $# -ne 0 ]; do
361 --local) LOCAL_set="y"; shift;;
362 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
363 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
364 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
365 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
366 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
367 --with-*) set_tool "$1" "$2" && shift || shift 2;;
368 --program-prefix=*|--program-prefix)
369 set_program_prefix "$1" "$2" && shift || shift 2
371 --force) FORCE=1; shift;;
372 --help|-h) do_help; exit 0;;
373 # Skip, auto-stuff compatibility
374 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
375 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
376 --enable-shared|--disable-shared|--enable-static|--disable-static) shift;;
377 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
382 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
384 # Special case when installing locally
385 if [ "${LOCAL_set}" = "y" ]; then
386 set_prefix "" "$( pwd )"
387 set_bindir "" "$( pwd )"
388 set_libdir "" "$( pwd )"
389 set_docdir "" "$( pwd )/docs"
390 set_mandir "" "$( pwd )/docs"
391 set_program_prefix "" ""
394 #---------------------------------------------------------------------
395 # Some sanity checks, now
397 # We check for grep and sed manually, because they are used in check_for()
398 printf "Checking for 'grep'... "
399 if [ -n "${grep}" ]; then
400 printf "${grep} (cached)\n"
402 grep="$( which grep 2>/dev/null )"
403 if [ -z "${grep}" ]; then
407 printf "Checking whether '${grep}' supports -E... "
408 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
416 if [ -z "${grep}" ]; then
417 printf "Either you are missing entirely the needed tool,\n"
418 printf "or the version you have is too old.\n"
419 printf "You can give the path to this tool using: --with-grep=PATH\n"
420 do_error "Bailing out..."
424 printf "Checking for 'sed'... "
425 if [ -n "${sed}" ]; then
426 printf "${sed} (cached)\n"
428 sed="$( which sed 2>/dev/null )"
429 if [ -z "${sed}" ]; then
433 printf "Checking whether '${sed}' supports -i and -e... "
434 touch .ct-ng.sed.test
435 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
441 rm -f .ct-ng.sed.test
444 if [ -z "${sed}" ]; then
445 printf "Either you are missing entirely the needed tool,\n"
446 printf "or the version you have is too old.\n"
447 printf "You can give the path to this tool using: --with-sed=PATH\n"
448 do_error "Bailing out..."
452 # The regular list of tools we can now easily check for
453 has_or_abort prog=bash \
455 ver='^GNU bash, version (3\.[1-9]|4)' \
456 err="'bash' 3.1 or above was not found"
457 has_or_abort prog=cut
458 has_or_abort prog=install var=install
459 has_or_abort prog=make \
461 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
462 err="GNU 'make' 3.80 or above was not found"
463 has_or_abort prog=gcc
464 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
465 has_or_abort prog=bison
466 has_or_abort prog=flex
467 has_or_abort prog=makeinfo
468 has_or_abort prog=automake \
469 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
470 err="'automake' 1.10 or above was not found"
471 has_or_abort prog=libtool \
473 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
474 err="'libtool' 1.5.26 or above was not found"
475 has_or_abort prog=stat
476 has_or_abort prog="curl wget"
477 has_or_abort prog=patch
478 has_or_abort prog=tar
479 has_or_abort prog=gzip
480 has_or_abort prog=bzip2
481 has_or_warn prog=xz \
482 kconfig=has_xzutils \
483 err="xz-comoressed tarballs will not be used"
484 has_or_abort prog=readlink
485 has_or_abort prog=objcopy var=objcopy
486 has_or_abort prog=objdump var=objdump
487 has_or_abort prog=readelf var=readelf
488 has_or_abort prog=patch var=patch
489 has_or_warn prog=cvs \
491 err="it will not be possible to use newlib cvs snapshots"
492 has_or_warn prog=svn \
494 err="subversion is required to download eglibc"
498 printf "Checking for host system... "
500 printf "%s\n" "${host}"
505 printf " * Runing under %s is not fully tested\n" "${host}"
506 printf " * You may encounter some weird behavior\n"
510 printf "Checking if static linking is possible... "
515 if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1 <<-_EOF_
516 int main() { return 0; }
524 if [ "${static_link_ok}" = "y" ]; then
530 printf " * An optional host feature is missing, some features will be disabled:\n"
531 printf " * - It will not be possible to statically link toolchain's binaries\n"
533 add_to_kconfig_list static_link_ok
537 if [ "${static_link_ok}" = "y" ]; then
538 libs_exts="${libs_exts} a"
541 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
542 ncurses_libs="libncursesw libncurses libcurses"
543 has_or_abort lib="${ncurses_libs}" \
544 lib_exts="${libs_exts}" \
545 inc="${ncurses_hdrs}" \
546 err="The 'ncurses' library is needed fo the menuconfig frontend"
548 has_or_abort lib="libstdc++" \
549 lib_exts="${libs_exts}" \
550 err="The 'libstdc++' library is needed to build gcc"
552 # Yes, we may be checking twice for libstdc++.a
553 # The first is because we need one instance of libstdc++ (shared or static)
554 # because it is needed for PPL; the second is because the static version is
555 # required for static-linking, and if missing, the option is removed.
556 has_or_warn lib="libstdc++" \
558 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
559 kconfig=has_static_libstdcxx \
560 skip="${static_link_ko}"
562 has_or_warn inc="expat.h" \
564 lib_exts="${libs_exts}" \
565 err="The 'expat' header file and library are needed to link cross-gdb's executables" \
568 # Yes, we may be checking twice for libexpat.a
569 # The first is because we need one instance of libexpat (shared or static)
570 # because it is needed for cross-gdb; the second is because the static version
571 # is required for static-linking, and if missing, the option is removed.
572 has_or_warn lib="libexpat" \
574 err="static 'expat' is needed to statically link cross-gdb's executables" \
575 kconfig=has_static_expat \
576 skip="${static_link_ko}"
579 python_incs="${python_incs} python2.${v}/Python.h"
580 python_libs="${python_libs} libpython2.${v}"
582 has_or_warn inc="${python_incs}" \
583 lib="${python_libs}" \
584 lib_exts="${libs_exts}" \
585 err="The 'python' header file and library are needed for some features of cross-gdb"
587 #---------------------------------------------------------------------
588 # Compute the version string
590 # If this version is n hg clone, try to get the revision number
591 # If we can't get the revision number, use date
592 printf "\nComputing version string... "
595 REVISION="$( hg id -n 2>/dev/null || true )"
596 case "${REVISION}" in
598 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
600 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
603 # Arrange to have no / in the directory name, no need to create an
604 # arbitrarily deep directory structure
605 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
608 printf "${VERSION}\n"
610 #---------------------------------------------------------------------
611 # Compute and check install paths
613 # Now we have the version string, we can build up the paths
614 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
615 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
616 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
617 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
619 # Install support files in our own sub-dir, so as not to mangle (system)
620 # files and dirs, but only if not --local
621 if [ -z "${LOCAL_set}" ]; then
622 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
623 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
626 # Check that install PATHs are absolute
627 for p in BIN LIB DOC MAN; do
629 eval v='"${'"${var}"'}"'
632 *) do_error "'${var}' is not an absolute path: '${v}'";;
635 case "${PROG_PFX}" in
636 */*) do_error "program prefix '${PROG_PFX}' contains a '/'";;
639 #---------------------------------------------------------------------
642 printf "Building up Makefile... "
643 var_sed="$( for var_name in ${var_list}; do
644 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
647 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
648 eval printf \"${k_name}=\${${k_name}} \"
651 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
652 -e "s,@@LIBDIR@@,${LIBDIR},g" \
653 -e "s,@@DOCDIR@@,${DOCDIR},g" \
654 -e "s,@@MANDIR@@,${MANDIR},g" \
655 -e "s,@@PROG_PFX@@,${PROG_PFX},g" \
656 -e "s,@@VERSION@@,${VERSION},g" \
657 -e "s,@@DATE@@,${DATE},g" \
658 -e "s,@@LOCAL@@,${LOCAL_set},g" \
660 -e "${kconfig_sed}" \
667 crosstool-NG configured as follows:
673 PROG_PFX='${PROG_PFX}'
678 if [ "${LOCAL_set}" != "y" ]; then
679 printf " make install\n"