5 VERSION=$( cat .version )
8 PREFIX_DEFAULT=/usr/local
19 # Simply print the error message, and exit. Obvious, he?
21 printf "${myname}: ${@}\n"
25 # Given an option string and the following argument,
26 # echoes the value of the option.
27 # If --var=val => echoes val and returns 0, meaning second arg was not consumed
28 # If --var val => echoes val and returns non null, meaning second arg was used
42 # The set_xxx functions will set the corresponding configuration variable
43 # They return 0 if second arg was not consumed, and non-zero if it was consumed.
45 PREFIX="$( get_optval "$1" "$2" )"
49 BINDIR="$( get_optval "$1" "$2" )"
53 LIBDIR="$( get_optval "$1" "$2" )"
57 DOCDIR="$( get_optval "$1" "$2" )"
61 MANDIR="$( get_optval "$1" "$2" )"
64 local var_name="${1%%=*}"
65 var_name="${var_name#--with-}"
66 eval ${var_name}="\$( get_optval "$1" "$2" )"
69 # var_list is a list of variables, each one holding a path to a
70 # tool, either detected by ./configure, or specified by the user.
74 # This function adds a variable name to the above list of variable names.
75 # $1: the name of the variable to add to the list
78 for v in ${var_list}; do
79 [ "${v}" = "${1}" ] && return 0
81 var_list="${var_list} ${1}"
83 add_to_kconfig_list() {
85 for k in ${kconfig_list}; do
86 [ "${k}" = "${1}" ] && return 0
88 kconfig_list="${kconfig_list} ${1}"
91 # A function to test for required tools/headers/libraries
92 # Return 0 (true) if found, !0 (false) if not found
94 # $*: [prog|inc|lib]=<name[ name...]>
95 # the name(s) of tool(s) to test for
97 # eg: prog=bash prog="curl wget"
99 # the name of the variable to test and set
101 # eg: var=bash if ${bash} is set and non-null, use that,
102 # else check for bash and set bash=$(which bash)
104 # for each 'prog', test if $(prog --version) matches 'regexp'
106 # eg: ver='^GNU bash, version [34]\.'
107 # $*: lib_exts=<extension[ extension...]>
108 # the list of allowed library extension
110 # eg: lib_exts="so dylib" lib_exts="so dylib a"
111 # $*: err=<error_message>
112 # the error message to print if tool is missing
113 # optional, defaults to: '${prog}: none found'
114 # eg: err="'bash' 3.x or above was not found"
115 # Note: err may be printed by caller, not us
116 # $*: kconfig=<var_name>
117 # the name of a variable to pass down to kconfig if
118 # the prog/inc/lib was found
119 # optional, defaults to none
120 # eg: kconfig=has_libncurses
122 # if set to 'y', skip the test, but still register the
123 # kconfig and var variables; if 'n' or empty, do the
125 # optional, default to 'n'
126 # eg: skip="${static_link_ko}"
136 # Note: prog/inc/lib and var/kconfig/ver/err are set here,
137 # but declared by the caller (because it needs it)
138 for item in "${@}"; do
140 prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*|lib_exts=*|skip=*)
141 eval ${item%%=*}=\"${item#*=}\"
143 *) do_error "check_for: incorrect parameters: '${item}'";;
147 case "${prog}:${inc}:${lib}" in
148 ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
149 if [ -n "${var}" ]; then
150 do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
153 ::) do_error "check_for: [prog|inc|lib] is mandatory";;
156 if [ -n "${var}" ]; then
157 add_to_var_list "${var}"
159 if [ -n "${kconfig}" ]; then
160 add_to_kconfig_list "${kconfig}"
163 if [ "${skip}" = "y" ]; then
167 if [ -n "${prog}" ]; then
168 for item in ${prog}; do
169 printf "Checking for '${item}'... "
170 if [ -n "${var}" ]; then
171 eval val="\${${var}}"
172 if [ -n "${val}" ]; then
173 status="${val} (cached)\n"
177 where="$( which "${item}" 2>/dev/null )"
178 if [ -z "${where}" ]; then
181 elif [ -n "${ver}" ]; then
182 str=$( LC_ALL=C "${where}" --version 2>&1 \
186 if [ -z "${str}" ]; then
195 if [ -z "${status}" ]; then
202 if [ -n "${inc}" ]; then
203 for item in ${inc}; do
204 printf "Checking for '${item}'... "
205 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
212 if [ -z "${status}" ]; then
219 if [ -n "${lib}" ]; then
220 if [ -z "${lib_exts}" ]; then
221 do_error "check_for: no library extension specified for '${lib}'"
223 for item in ${lib}; do
224 for ext in ${lib_exts}; do
225 printf "Checking for '${item}.${ext}'... "
226 where="$( gcc -print-file-name="${item}.${ext}" )"
227 if [ "${where}" != "${item}.${ext}" ]; then
228 where="$( readlink "${where}" )"
235 if [ -z "${status}" ]; then
242 if [ -n "${var}" ]; then
243 eval ${var}='"'"${where}"'"'
245 if [ -n "${kconfig}" ]; then
250 # This function checks for a tool, and aborts if not found
251 # See check_for(), above, for how to call has_or_abort
253 # We declare these 6 variables here, although they are
254 # set in check_for(), called below
256 local var ver err kconfig
258 if ! check_for "$@"; then
259 printf " * A mandatory dependency is missing, or version mis-match:\n"
260 printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
261 if [ -n "${var}" ]; then
262 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
265 # Bail out if --force is not specified
266 [ -z "${FORCE}" ] && do_error "Bailing out..."
268 printf "<* FORCE in action: *>\n"
269 printf "<* Continuing despite missing pre-requisite *>\n"
270 printf "<* Prepare for breakage *>\n"
276 # This function checks for a tool, and warns if not found
277 # See check_for(), above, for how to call has_or_abort
278 # Note: if err is not set, then no error message is printed
280 # We declare these 6 variables here, although they are
281 # set in check_for(), called below
283 local var ver err kconfig
285 if ! check_for "$@"; then
286 printf " * An optional dependency is missing, some features will be disabled"
287 printf "${err:+:\n * - ${err}}\n"
288 if [ -n "${var}" ]; then
289 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
296 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
298 USAGE: ./configure [OPTION]...
300 Defaults for the options are specified in brackets.
303 -h, --help display this help and exit
304 --force force configure to continue, even in case
305 some pre-requisites are missing
307 Installation directories:
308 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
309 --local don't install, and use current directory
311 By default, \`make install' will install all the files in
312 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
313 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
314 for instance \`--prefix=\${HOME}'.
316 For better control, use the options below.
318 Fine tuning of the installation directories:
319 --bindir=DIR user executables [PREFIX/bin]
320 --libdir=DIR object code libraries [PREFIX/lib]
321 --docdir=DIR info documentation [PREFIX/share/doc]
322 --mandir=DIR man documentation [PREFIX/share/man]
325 --with-install=PATH Specify the full PATH to GNU install
326 --with-make=PATH Specify the full PATH to GNU make >= 3.80
327 --with-grep=PATH Specify the full PATH to GNU grep
328 --with-sed=PATH Specify the full PATH to GNU sed
329 --with-bash=PATH Specify the full PATH to bash >= 3.0
333 #---------------------------------------------------------------------
336 while [ $# -ne 0 ]; do
338 --local) LOCAL_set="y"; shift;;
339 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
340 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
341 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
342 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
343 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
344 --with-*) set_tool "$1" "$2" && shift || shift 2;;
345 --force) FORCE=1; shift;;
346 --help|-h) do_help; exit 0;;
347 # Skip, auto-stuff compatibility
348 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
349 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
350 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
355 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
357 # Special case when installing locally
358 if [ "${LOCAL_set}" = "y" ]; then
359 set_prefix "" "$( pwd )"
360 set_bindir "" "$( pwd )"
361 set_libdir "" "$( pwd )"
362 set_docdir "" "$( pwd )/docs"
363 set_mandir "" "$( pwd )/docs"
366 #---------------------------------------------------------------------
367 # Some sanity checks, now
369 # We check for grep and sed manually, because they are used in check_for()
370 printf "Checking for 'grep'... "
371 if [ -n "${grep}" ]; then
372 printf "${grep} (cached)\n"
374 grep="$( which grep 2>/dev/null )"
375 if [ -z "${grep}" ]; then
379 printf "Checking whether '${grep}' supports -E... "
380 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
388 if [ -z "${grep}" ]; then
389 printf "Either you are missing entirely the needed tool,\n"
390 printf "or the version you have is too old.\n"
391 printf "You can give the path to this tool using: --with-grep=PATH\n"
392 do_error "Bailing out..."
396 printf "Checking for 'sed'... "
397 if [ -n "${sed}" ]; then
398 printf "${sed} (cached)\n"
400 sed="$( which sed 2>/dev/null )"
401 if [ -z "${sed}" ]; then
405 printf "Checking whether '${sed}' supports -i and -e... "
406 touch .ct-ng.sed.test
407 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
413 rm -f .ct-ng.sed.test
416 if [ -z "${sed}" ]; 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-sed=PATH\n"
420 do_error "Bailing out..."
424 # The regular list of tools we can now easily check for
425 has_or_abort prog=bash \
427 ver='^GNU bash, version (3\.[1-9]|4)' \
428 err="'bash' 3.1 or above was not found"
429 has_or_abort prog=cut
430 has_or_abort prog=install var=install
431 has_or_abort prog=make \
433 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
434 err="GNU 'make' 3.80 or above was not found"
435 has_or_abort prog=gcc
436 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
437 has_or_abort prog=bison
438 has_or_abort prog=flex
439 has_or_abort prog=makeinfo
440 has_or_abort prog=automake \
441 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
442 err="'automake' 1.10 or above was not found"
443 has_or_abort prog=libtool \
445 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
446 err="'libtool' 1.5.26 or above was not found"
447 has_or_abort prog=stat
448 has_or_abort prog="curl wget"
449 has_or_abort prog=cvs
450 has_or_abort prog=patch
451 has_or_abort prog=tar
452 has_or_abort prog=gzip
453 has_or_abort prog=bzip2
454 has_or_abort prog=lzma
455 has_or_abort prog=readlink
456 has_or_abort prog=objcopy var=objcopy
457 has_or_abort prog=objdump var=objdump
458 has_or_abort prog=readelf var=readelf
459 has_or_abort prog=patch var=patch
463 printf "Checking for host system... "
465 printf "%s\n" "${host}"
470 printf " * Runing under %s is not fully tested\n" "${host}"
471 printf " * You may encounter some weird behavior\n"
475 printf "Checking if static linking is possible... "
480 if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1<<-_EOF_
481 int main() { return 0; }
489 if [ "${static_link_ok}" = "y" ]; then
495 printf " * An optional host feature is missing, some features will be disabled:\n"
496 printf " * - It will not be possible to statically link toolchain's binaries\n"
498 add_to_kconfig_list static_link_ok
502 if [ "${static_link_ok}" = "y" ]; then
506 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
507 ncurses_libs="libncursesw libncurses libcurses"
508 has_or_abort lib="${ncurses_libs}" \
509 lib_exts="${libs_exts}" \
510 inc="${ncurses_hdrs}" \
511 err="The 'ncurses' library is needed fo the menuconfig frontend"
513 has_or_abort lib="libstdc++" \
514 lib_exts="${libs_exts}" \
515 err="The 'libstdc++' library is needed to build gcc"
517 # Yes, we may be checking twice for libstdc++.a
518 # The first is because we need one instance of libstdc++ (shared or static)
519 # because it is needed for PPL; the second is because the static version is
520 # required for static-linking, and if missing, the option is removed.
521 has_or_warn lib="libstdc++" \
523 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
524 kconfig=has_static_libstdcxx \
525 skip="${static_link_ko}"
527 has_or_warn inc="expat.h" \
529 lib_exts="${libs_exts}" \
530 err="The 'expat' header file and library are needed to link cross-gdb's executables" \
533 # Yes, we may be checking twice for libexpat.a
534 # The first is because we need one instance of libexpat (shared or static)
535 # because it is needed for cross-gdb; the second is because the static version
536 # is required for static-linking, and if missing, the option is removed.
537 has_or_warn lib="libexpat" \
539 err="static 'expat' is needed to statically link cross-gdb's executables" \
540 kconfig=has_static_expat \
541 skip="${static_link_ko}"
544 python_incs="${python_incs} python2.${v}/Python.h"
545 python_libs="${python_libs} libpython2.${v}"
547 has_or_warn inc="${python_incs}" \
548 lib="${python_libs}" \
549 lib_exts="${libs_exts}" \
550 err="The 'python' header file and library are needed for some features of cross-gdb"
552 #---------------------------------------------------------------------
553 # Compute the version string
555 # If this version is n hg clone, try to get the revision number
556 # If we can't get the revision number, use date
557 printf "\nComputing version string... "
560 REVISION="$( hg id -n 2>/dev/null || true )"
561 case "${REVISION}" in
563 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
565 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
568 # Arrange to have no / in the directory name, no need to create an
569 # arbitrarily deep directory structure
570 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
573 printf "${VERSION}\n"
575 #---------------------------------------------------------------------
576 # Compute and check install paths
578 # Now we have the version string, we can build up the paths
579 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
580 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
581 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
582 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
584 # Install support files in our own sub-dir, so as not to mangle (system)
585 # files and dirs, but only if not --local
586 if [ -z "${LOCAL_set}" ]; then
587 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
588 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
591 # Check that install PATHs are absolute
592 for p in BIN LIB DOC MAN; do
594 eval v='"${'"${var}"'}"'
597 *) do_error "'${var}' is not an absolute path: '${v}'"
601 #---------------------------------------------------------------------
604 printf "Building up Makefile... "
605 var_sed="$( for var_name in ${var_list}; do
606 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
609 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
610 eval printf \"${k_name}=\${${k_name}} \"
613 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
614 -e "s,@@LIBDIR@@,${LIBDIR},g" \
615 -e "s,@@DOCDIR@@,${DOCDIR},g" \
616 -e "s,@@MANDIR@@,${MANDIR},g" \
617 -e "s,@@VERSION@@,${VERSION},g" \
618 -e "s,@@DATE@@,${DATE},g" \
619 -e "s,@@LOCAL@@,${LOCAL_set},g" \
621 -e "${kconfig_sed}" \
628 crosstool-NG configured as follows:
638 if [ "${LOCAL_set}" != "y" ]; then
639 printf " make install\n"