5 VERSION=$( cat .version )
8 PREFIX_DEFAULT=/usr/local
21 # Simply print the error message, and exit. Obvious, he?
23 printf "${myname}: ${@}\n"
27 # Given an option string and the following argument,
28 # echoes the value of the option.
29 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
30 # If --var val => echoes val and returns non null, meaning second arg was used
44 # The set_xxx functions will set the corresponding configuration variable
45 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
47 PREFIX="$( get_optval "$1" "$2" )"
51 BINDIR="$( get_optval "$1" "$2" )"
55 LIBDIR="$( get_optval "$1" "$2" )"
59 DOCDIR="$( get_optval "$1" "$2" )"
63 MANDIR="$( get_optval "$1" "$2" )"
65 set_program_prefix() {
66 PROG_PFX="$( get_optval "$1" "$2" )"
68 set_program_suffix() {
69 PROG_SFX="$( get_optval "$1" "$2" )"
72 local var_name="${1%%=*}"
73 var_name="${var_name#--with-}"
74 eval ${var_name}="\$( get_optval "$1" "$2" )"
77 # var_list is a list of variables, each one holding a path to a
78 # tool, either detected by ./configure, or specified by the user.
82 # This function adds a variable name to the above list of variable names.
83 # $1: the name of the variable to add to the list
86 for v in ${var_list}; do
87 [ "${v}" = "${1}" ] && return 0
89 var_list="${var_list} ${1}"
91 add_to_kconfig_list() {
93 for k in ${kconfig_list}; do
94 [ "${k}" = "${1}" ] && return 0
96 kconfig_list="${kconfig_list} ${1}"
99 # A function to test for required tools/headers/libraries
100 # Return 0 (true) if found, !0 (false) if not found
102 # $*: [prog|inc|lib]=<name[ name...]>
103 # the name(s) of tool(s) to test for
105 # eg: prog=bash prog="curl wget"
107 # the name of the variable to test and set
109 # eg: var=bash if ${bash} is set and non-null, use that,
110 # else check for bash and set bash=$(which bash)
112 # for each 'prog', test if $(prog --version) matches 'regexp'
114 # eg: ver='^GNU bash, version [34]\.'
115 # $*: lib_exts=<extension[ extension...]>
116 # the list of allowed library extension
118 # eg: lib_exts="so dylib" lib_exts="so dylib a"
119 # $*: err=<error_message>
120 # the error message to print if tool is missing
121 # optional, defaults to: '${prog}: none found'
122 # eg: err="'bash' 3.x or above was not found"
123 # Note: err may be printed by caller, not us
124 # $*: kconfig=<var_name>
125 # the name of a variable to pass down to kconfig if
126 # the prog/inc/lib was found
127 # optional, defaults to none
128 # eg: kconfig=has_libncurses
130 # if set to 'y', skip the test, but still register the
131 # kconfig and var variables; if 'n' or empty, do the
133 # optional, default to 'n'
134 # eg: skip="${static_link_ko}"
144 # Note: prog/inc/lib and var/kconfig/ver/err are set here,
145 # but declared by the caller (because it needs it)
146 for item in "${@}"; do
148 prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*|lib_exts=*|skip=*)
149 eval ${item%%=*}=\"${item#*=}\"
151 *) do_error "check_for: incorrect parameters: '${item}'";;
155 case "${prog}:${inc}:${lib}" in
156 ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
157 if [ -n "${var}" ]; then
158 do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
161 ::) do_error "check_for: [prog|inc|lib] is mandatory";;
164 if [ -n "${var}" ]; then
165 add_to_var_list "${var}"
167 if [ -n "${kconfig}" ]; then
168 add_to_kconfig_list "${kconfig}"
171 if [ "${skip}" = "y" ]; then
175 if [ -n "${prog}" ]; then
176 for item in ${prog}; do
177 printf "Checking for '${item}'... "
178 if [ -n "${var}" ]; then
179 eval val="\${${var}}"
180 if [ -n "${val}" ]; then
181 status="${val} (cached)\n"
185 where="$( which "${item}" 2>/dev/null )"
186 if [ -z "${where}" ]; then
189 elif [ -n "${ver}" ]; then
190 str=$( LC_ALL=C "${where}" --version 2>&1 \
194 if [ -z "${str}" ]; then
203 if [ -z "${status}" ]; then
210 if [ -n "${inc}" ]; then
211 for item in ${inc}; do
212 printf "Checking for '${item}'... "
213 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
220 if [ -z "${status}" ]; then
227 if [ -n "${lib}" ]; then
228 if [ -z "${lib_exts}" ]; then
229 do_error "check_for: no library extension specified for '${lib}'"
231 for item in ${lib}; do
232 for ext in ${lib_exts}; do
233 printf "Checking for '${item}.${ext}'... "
234 where="$( gcc -print-file-name="${item}.${ext}" )"
235 if [ "${where}" != "${item}.${ext}" ]; then
236 where="$( readlink "${where}" )"
243 if [ -z "${status}" ]; then
250 if [ -n "${var}" ]; then
251 eval ${var}='"'"${where}"'"'
253 if [ -n "${kconfig}" ]; then
258 # This function checks for a tool, and aborts if not found
259 # See check_for(), above, for how to call has_or_abort
261 # We declare these 6 variables here, although they are
262 # set in check_for(), called below
264 local var ver err kconfig
266 if ! check_for "$@"; then
267 printf " * A mandatory dependency is missing, or version mis-match:\n"
268 printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
269 if [ -n "${var}" ]; then
270 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
273 # Bail out if --force is not specified
274 [ -z "${FORCE}" ] && do_error "Bailing out..."
276 printf "<* FORCE in action: *>\n"
277 printf "<* Continuing despite missing pre-requisite *>\n"
278 printf "<* Prepare for breakage *>\n"
284 # This function checks for a tool, and warns if not found
285 # See check_for(), above, for how to call has_or_abort
286 # Note: if err is not set, then no error message is printed
288 # We declare these 6 variables here, although they are
289 # set in check_for(), called below
291 local var ver err kconfig
293 if ! check_for "$@"; then
294 printf " * An optional dependency is missing, some features will be disabled"
295 printf "${err:+:\n * - ${err}}\n"
296 if [ -n "${var}" ]; then
297 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
304 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
306 USAGE: ./configure [OPTION]...
308 Defaults for the options are specified in brackets.
311 -h, --help display this help and exit
312 --force force configure to continue, even in case
313 some pre-requisites are missing
315 Installation directories:
316 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
317 --local don't install, and use current directory
319 By default, \`make install' will install all the files in
320 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
321 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
322 for instance \`--prefix=\${HOME}'.
324 For better control, use the options below.
325 Note: options marked as \`ignored' are recognised, but not acted upon, as
326 they make no sense for crosstool-NG, or they are not implemented yet.
328 Fine tuning of the installation directories:
329 --bindir=DIR user executables [PREFIX/bin]
330 --libdir=DIR object code libraries [PREFIX/lib]
331 --docdir=DIR info documentation [PREFIX/share/doc]
332 --mandir=DIR man documentation [PREFIX/share/man]
333 --infodir=DIR info documentation [DATAROOTDIR/info] (ignored)
334 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
336 --sysconfdir=DIR read-only single-machine data [PREFIX/etc] (ignored)
337 --localstatedir=DIR modifiable single-machine data [PREFIX/var] (ignored)
340 --program-prefix=PREFIX prepend PREFIX to installed program names
341 --program-suffix=SUFFIX append SUFFIX to installed program names
344 --build=BUILD configure for building on BUILD [guessed] (ignored)
345 --host=HOST cross-compile to build programs to run on HOST [BUILD]
349 --enable-shared[=PKGS] build shared libraries [default=yes] (ignored)
350 --enable-static[=PKGS] build static libraries [default=yes] (ignored)
353 --with-install=PATH Specify the full PATH to GNU install
354 --with-make=PATH Specify the full PATH to GNU make >= 3.80
355 --with-grep=PATH Specify the full PATH to GNU grep
356 --with-sed=PATH Specify the full PATH to GNU sed
357 --with-bash=PATH Specify the full PATH to bash >= 3.0
361 #---------------------------------------------------------------------
364 while [ $# -ne 0 ]; do
366 --local) LOCAL_set="y"; shift;;
367 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
368 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
369 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
370 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
371 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
372 --with-*) set_tool "$1" "$2" && shift || shift 2;;
373 --program-prefix=*|--program-prefix)
374 set_program_prefix "$1" "$2" && shift || shift 2
376 --program-suffix=*|--program-suffix)
377 set_program_suffix "$1" "$2" && shift || shift 2
379 --force) FORCE=1; shift;;
380 --help|-h) do_help; exit 0;;
381 # Skip, auto-stuff compatibility
382 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
383 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
384 --enable-shared|--disable-shared|--enable-static|--disable-static) shift;;
385 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
390 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
392 # Special case when installing locally
393 if [ "${LOCAL_set}" = "y" ]; then
394 set_prefix "" "$( pwd )"
395 set_bindir "" "$( pwd )"
396 set_libdir "" "$( pwd )"
397 set_docdir "" "$( pwd )/docs"
398 set_mandir "" "$( pwd )/docs"
399 set_program_prefix "" ""
400 set_program_suffix "" ""
403 #---------------------------------------------------------------------
404 # Some sanity checks, now
406 # We check for grep and sed manually, because they are used in check_for()
407 printf "Checking for 'grep'... "
408 if [ -n "${grep}" ]; then
409 printf "${grep} (cached)\n"
411 grep="$( which grep 2>/dev/null )"
412 if [ -z "${grep}" ]; then
416 printf "Checking whether '${grep}' supports -E... "
417 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
425 if [ -z "${grep}" ]; then
426 printf "Either you are missing entirely the needed tool,\n"
427 printf "or the version you have is too old.\n"
428 printf "You can give the path to this tool using: --with-grep=PATH\n"
429 do_error "Bailing out..."
433 printf "Checking for 'sed'... "
434 if [ -n "${sed}" ]; then
435 printf "${sed} (cached)\n"
437 sed="$( which sed 2>/dev/null )"
438 if [ -z "${sed}" ]; then
442 printf "Checking whether '${sed}' supports -i and -e... "
443 touch .ct-ng.sed.test
444 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
450 rm -f .ct-ng.sed.test
453 if [ -z "${sed}" ]; then
454 printf "Either you are missing entirely the needed tool,\n"
455 printf "or the version you have is too old.\n"
456 printf "You can give the path to this tool using: --with-sed=PATH\n"
457 do_error "Bailing out..."
461 # The regular list of tools we can now easily check for
462 has_or_abort prog=bash \
464 ver='^GNU bash, version (3\.[1-9]|4)' \
465 err="'bash' 3.1 or above was not found"
466 has_or_abort prog=cut
467 has_or_abort prog=install var=install
468 has_or_abort prog=make \
470 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
471 err="GNU 'make' 3.80 or above was not found"
472 has_or_abort prog=gcc
473 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
474 has_or_abort prog=bison
475 has_or_abort prog=flex
476 has_or_abort prog=makeinfo
477 has_or_abort prog=automake \
478 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
479 err="'automake' 1.10 or above was not found"
480 has_or_abort prog=libtool \
482 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
483 err="'libtool' 1.5.26 or above was not found"
484 has_or_abort prog=stat
485 has_or_abort prog="curl wget"
486 has_or_abort prog=patch
487 has_or_abort prog=tar
488 has_or_abort prog=gzip
489 has_or_abort prog=bzip2
490 has_or_warn prog=xz \
491 kconfig=has_xzutils \
492 err="xz-comoressed tarballs will not be used"
493 has_or_abort prog=readlink
494 has_or_abort prog=objcopy var=objcopy
495 has_or_abort prog=objdump var=objdump
496 has_or_abort prog=readelf var=readelf
497 has_or_abort prog=patch var=patch
498 has_or_warn prog=cvs \
500 err="it will not be possible to use newlib cvs snapshots"
501 has_or_warn prog=svn \
503 err="subversion is required to download eglibc"
507 printf "Checking for host system... "
509 printf "%s\n" "${host}"
514 printf " * Runing under %s is not fully tested\n" "${host}"
515 printf " * You may encounter some weird behavior\n"
519 printf "Checking if static linking is possible... "
524 if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1 <<-_EOF_
525 int main() { return 0; }
533 if [ "${static_link_ok}" = "y" ]; then
539 printf " * An optional host feature is missing, some features will be disabled:\n"
540 printf " * - It will not be possible to statically link toolchain's binaries\n"
542 add_to_kconfig_list static_link_ok
546 if [ "${static_link_ok}" = "y" ]; then
547 libs_exts="${libs_exts} a"
550 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
551 ncurses_libs="libncursesw libncurses libcurses"
552 has_or_abort lib="${ncurses_libs}" \
553 lib_exts="${libs_exts}" \
554 inc="${ncurses_hdrs}" \
555 err="The 'ncurses' library is needed fo the menuconfig frontend"
557 has_or_abort lib="libstdc++" \
558 lib_exts="${libs_exts}" \
559 err="The 'libstdc++' library is needed to build gcc"
561 # Yes, we may be checking twice for libstdc++.a
562 # The first is because we need one instance of libstdc++ (shared or static)
563 # because it is needed for PPL; the second is because the static version is
564 # required for static-linking, and if missing, the option is removed.
565 has_or_warn lib="libstdc++" \
567 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
568 kconfig=has_static_libstdcxx \
569 skip="${static_link_ko}"
571 has_or_warn inc="expat.h" \
573 lib_exts="${libs_exts}" \
574 err="The 'expat' header file and library are needed to link cross-gdb's executables" \
577 # Yes, we may be checking twice for libexpat.a
578 # The first is because we need one instance of libexpat (shared or static)
579 # because it is needed for cross-gdb; the second is because the static version
580 # is required for static-linking, and if missing, the option is removed.
581 has_or_warn lib="libexpat" \
583 err="static 'expat' is needed to statically link cross-gdb's executables" \
584 kconfig=has_static_expat \
585 skip="${static_link_ko}"
588 python_incs="${python_incs} python2.${v}/Python.h"
589 python_libs="${python_libs} libpython2.${v}"
591 has_or_warn inc="${python_incs}" \
592 lib="${python_libs}" \
593 lib_exts="${libs_exts}" \
594 err="The 'python' header file and library are needed for some features of cross-gdb"
596 #---------------------------------------------------------------------
597 # Compute the version string
599 # If this version is n hg clone, try to get the revision number
600 # If we can't get the revision number, use date
601 printf "\nComputing version string... "
604 REVISION="$( hg id -n 2>/dev/null || true )"
605 case "${REVISION}" in
607 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
609 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
612 # Arrange to have no / in the directory name, no need to create an
613 # arbitrarily deep directory structure
614 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
617 printf "${VERSION}\n"
619 #---------------------------------------------------------------------
620 # Compute and check install paths
622 # Now we have the version string, we can build up the paths
623 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
624 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
625 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
626 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
628 # Install support files in our own sub-dir, so as not to mangle (system)
629 # files and dirs, but only if not --local
630 if [ -z "${LOCAL_set}" ]; then
631 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
632 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
635 # Check that install PATHs are absolute
636 for p in BIN LIB DOC MAN; do
638 eval v='"${'"${var}"'}"'
641 *) do_error "'${var}' is not an absolute path: '${v}'";;
644 case "${PROG_PFX}" in
645 */*) do_error "program prefix '${PROG_PFX}' contains a '/'";;
647 case "${PROG_SFX}" in
648 */*) do_error "program suffix '${PROG_SFX}' contains a '/'";;
651 #---------------------------------------------------------------------
654 printf "Building up Makefile... "
655 var_sed="$( for var_name in ${var_list}; do
656 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
659 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
660 eval printf \"${k_name}=\${${k_name}} \"
663 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
664 -e "s,@@LIBDIR@@,${LIBDIR},g" \
665 -e "s,@@DOCDIR@@,${DOCDIR},g" \
666 -e "s,@@MANDIR@@,${MANDIR},g" \
667 -e "s,@@PROG_PFX@@,${PROG_PFX},g" \
668 -e "s,@@PROG_SFX@@,${PROG_SFX},g" \
669 -e "s,@@VERSION@@,${VERSION},g" \
670 -e "s,@@DATE@@,${DATE},g" \
671 -e "s,@@LOCAL@@,${LOCAL_set},g" \
673 -e "${kconfig_sed}" \
680 crosstool-NG configured as follows:
686 PROG_PFX='${PROG_PFX}'
687 PROG_SFX='${PROG_SFX}'
692 if [ "${LOCAL_set}" != "y" ]; then
693 printf " make install\n"