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
129 # Note: prog/inc/lib and var/kconfig/ver/err are set here,
130 # but declared by the caller (because it needs it)
131 for item in "${@}"; do
133 prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*|lib_exts=*)
134 eval ${item%%=*}=\"${item#*=}\"
136 *) do_error "check_for: incorrect parameters: '${item}'";;
140 case "${prog}:${inc}:${lib}" in
141 ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
142 if [ -n "${var}" ]; then
143 do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
146 ::) do_error "check_for: [prog|inc|lib] is mandatory";;
149 if [ -n "${kconfig}" ]; then
150 add_to_kconfig_list "${kconfig}"
153 if [ -n "${prog}" ]; then
154 for item in ${prog}; do
155 printf "Checking for '${item}'... "
156 if [ -n "${var}" ]; then
157 eval val="\${${var}}"
158 if [ -n "${val}" ]; then
159 printf "${val} (cached)\n"
160 add_to_var_list "${var}"
164 where="$( which "${item}" 2>/dev/null )"
165 if [ -z "${where}" ]; then
168 elif [ -n "${ver}" ]; then
169 str=$( LC_ALL=C "${where}" --version 2>&1 \
173 if [ -z "${str}" ]; then
182 if [ -z "${status}" ]; then
189 if [ -n "${inc}" ]; then
190 for item in ${inc}; do
191 printf "Checking for '${item}'... "
192 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
199 if [ -z "${status}" ]; then
206 if [ -n "${lib}" ]; then
207 if [ -z "${lib_exts}" ]; then
208 do_error "check_for: no library extension specified for '${lib}'"
210 for item in ${lib}; do
211 for ext in ${lib_exts}; do
212 printf "Checking for '${item}.${ext}'... "
213 where="$( gcc -print-file-name="${item}.${ext}" )"
214 if [ "${where}" != "${item}.${ext}" ]; then
215 where="$( readlink "${where}" )"
222 if [ -z "${status}" ]; then
229 if [ -n "${var}" ]; then
230 eval ${var}='"'"${where}"'"'
231 add_to_var_list "${var}"
233 if [ -n "${kconfig}" ]; then
238 # This function checks for a tool, and aborts if not found
239 # See check_for(), above, for how to call has_or_abort
241 # We declare these 6 variables here, although they are
242 # set in check_for(), called below
244 local var ver err kconfig
246 if ! check_for "$@"; then
247 printf " * A mandatory dependency is missing, or version mis-match:\n"
248 printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
249 if [ -n "${var}" ]; then
250 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
253 # Bail out if --force is not specified
254 [ -z "${FORCE}" ] && do_error "Bailing out..."
256 printf "<* FORCE in action: *>\n"
257 printf "<* Continuing despite missing pre-requisite *>\n"
258 printf "<* Prepare for breakage *>\n"
264 # This function checks for a tool, and warns if not found
265 # See check_for(), above, for how to call has_or_abort
266 # Note: if err is not set, then no error message is printed
268 # We declare these 6 variables here, although they are
269 # set in check_for(), called below
271 local var ver err kconfig
273 if ! check_for "$@"; then
274 printf " * An optional dependency is missing, some features will be disabled"
275 printf "${err:+:\n * - ${err}}\n"
276 if [ -n "${var}" ]; then
277 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
284 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
286 USAGE: ./configure [OPTION]...
288 Defaults for the options are specified in brackets.
291 -h, --help display this help and exit
292 --force force configure to continue, even in case
293 some pre-requisites are missing
295 Installation directories:
296 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
297 --local don't install, and use current directory
299 By default, \`make install' will install all the files in
300 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
301 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
302 for instance \`--prefix=\${HOME}'.
304 For better control, use the options below.
306 Fine tuning of the installation directories:
307 --bindir=DIR user executables [PREFIX/bin]
308 --libdir=DIR object code libraries [PREFIX/lib]
309 --docdir=DIR info documentation [PREFIX/share/doc]
310 --mandir=DIR man documentation [PREFIX/share/man]
313 --with-install=PATH Specify the full PATH to GNU install
314 --with-make=PATH Specify the full PATH to GNU make >= 3.80
315 --with-grep=PATH Specify the full PATH to GNU grep
316 --with-sed=PATH Specify the full PATH to GNU sed
317 --with-bash=PATH Specify the full PATH to bash >= 3.0
321 #---------------------------------------------------------------------
324 while [ $# -ne 0 ]; do
326 --local) LOCAL_set="y"; shift;;
327 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
328 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
329 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
330 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
331 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
332 --with-*) set_tool "$1" "$2" && shift || shift 2;;
333 --force) FORCE=1; shift;;
334 --help|-h) do_help; exit 0;;
335 # Skip, auto-stuff compatibility
336 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
337 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
338 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
343 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
345 # Special case when installing locally
346 if [ "${LOCAL_set}" = "y" ]; then
347 set_prefix "" "$( pwd )"
348 set_bindir "" "$( pwd )"
349 set_libdir "" "$( pwd )"
350 set_docdir "" "$( pwd )/docs"
351 set_mandir "" "$( pwd )/docs"
354 #---------------------------------------------------------------------
355 # Some sanity checks, now
357 # We check for grep and sed manually, because they are used in check_for()
358 printf "Checking for 'grep'... "
359 if [ -n "${grep}" ]; then
360 printf "${grep} (cached)\n"
362 grep="$( which grep 2>/dev/null )"
363 if [ -z "${grep}" ]; then
367 printf "Checking whether '${grep}' supports -E... "
368 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
376 if [ -z "${grep}" ]; then
377 printf "Either you are missing entirely the needed tool,\n"
378 printf "or the version you have is too old.\n"
379 printf "You can give the path to this tool using: --with-grep=PATH\n"
380 do_error "Bailing out..."
384 printf "Checking for 'sed'... "
385 if [ -n "${sed}" ]; then
386 printf "${sed} (cached)\n"
388 sed="$( which sed 2>/dev/null )"
389 if [ -z "${sed}" ]; then
393 printf "Checking whether '${sed}' supports -i and -e... "
394 touch .ct-ng.sed.test
395 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
401 rm -f .ct-ng.sed.test
404 if [ -z "${sed}" ]; then
405 printf "Either you are missing entirely the needed tool,\n"
406 printf "or the version you have is too old.\n"
407 printf "You can give the path to this tool using: --with-sed=PATH\n"
408 do_error "Bailing out..."
412 # The regular list of tools we can now easily check for
413 has_or_abort prog=bash \
415 ver='^GNU bash, version (3\.[1-9]|4)' \
416 err="'bash' 3.1 or above was not found"
417 has_or_abort prog=cut
418 has_or_abort prog=install var=install
419 has_or_abort prog=make \
421 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
422 err="GNU 'make' 3.80 or above was not found"
423 has_or_abort prog=gcc
424 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
425 has_or_abort prog=bison
426 has_or_abort prog=flex
427 has_or_abort prog=makeinfo
428 has_or_abort prog=automake \
429 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
430 err="'automake' 1.10 or above was not found"
431 has_or_abort prog=libtool \
433 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
434 err="'libtool' 1.5.26 or above was not found"
435 has_or_abort prog=stat
436 has_or_abort prog="curl wget"
437 has_or_abort prog=cvs
438 has_or_abort prog=patch
439 has_or_abort prog=tar
440 has_or_abort prog=gzip
441 has_or_abort prog=bzip2
442 has_or_abort prog=lzma
443 has_or_abort prog=readlink
444 has_or_abort prog=objcopy var=objcopy
445 has_or_abort prog=objdump var=objdump
446 has_or_abort prog=readelf var=readelf
447 has_or_abort prog=patch var=patch
451 printf "Checking for host system... "
453 printf "%s\n" "${host}"
458 printf " * Runing under %s is not fully tested\n" "${host}"
459 printf " * You may encounter some weird behavior\n"
463 printf "Checking if static linking is possible... "
468 if gcc -xc - -static -o "${tmp}" >/dev/null 2>&1<<-_EOF_
469 int main() { return 0; }
477 if [ "${static_link_ok}" = "y" ]; then
481 printf " * An optional host feature is missing, some features will be disabled:\n"
482 printf " * - It will not be possible to statically link toolchain's binaries\n"
484 add_to_kconfig_list static_link_ok
487 libs_exts="so dylib a"
489 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
490 ncurses_libs="libncursesw libncurses libcurses"
491 has_or_abort lib="${ncurses_libs}" \
492 lib_exts="${libs_exts}" \
493 inc="${ncurses_hdrs}" \
494 err="The 'ncurses' library is needed fo the menuconfig frontend"
496 has_or_abort lib="libstdc++" \
497 lib_exts="${libs_exts}" \
498 err="The 'libstdc++' library is needed to build gcc"
500 # Yes, we may be checking twice for libstdc++.a
501 # The first is because we need one instance of libstdc++ (shared or static)
502 # because it is needed for PPL; the second is because the static version is
503 # required for static-linking, and if missing, the option is removed.
504 has_or_warn lib="libstdc++" \
506 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
507 kconfig=has_static_libstdcxx
509 has_or_warn inc="expat.h" \
511 lib_exts="${libs_exts}" \
512 err="The 'expat' header file and library are needed to link cross-gdb's executables" \
515 # Yes, we may be checking twice for libexpat.a
516 # The first is because we need one instance of libexpat (shared or static)
517 # because it is needed for cross-gdb; the second is because the static version
518 # is required for static-linking, and if missing, the option is removed.
519 has_or_warn lib="libexpat" \
521 err="static 'expat' is needed to statically link cross-gdb's executables" \
522 kconfig=has_static_expat
525 python_incs="${python_incs} python2.${v}/Python.h"
526 python_libs="${python_libs} libpython2.${v}"
528 has_or_warn inc="${python_incs}" \
529 lib="${python_libs}" \
530 lib_exts="${libs_exts}" \
531 err="The 'python' header file and library are needed for some features of cross-gdb"
533 #---------------------------------------------------------------------
534 # Compute the version string
536 # If this version is n hg clone, try to get the revision number
537 # If we can't get the revision number, use date
538 printf "\nComputing version string... "
541 REVISION="$( hg id -n 2>/dev/null || true )"
542 case "${REVISION}" in
544 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
546 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
549 # Arrange to have no / in the directory name, no need to create an
550 # arbitrarily deep directory structure
551 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
554 printf "${VERSION}\n"
556 #---------------------------------------------------------------------
557 # Compute and check install paths
559 # Now we have the version string, we can build up the paths
560 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
561 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
562 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
563 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
565 # Install support files in our own sub-dir, so as not to mangle (system)
566 # files and dirs, but only if not --local
567 if [ -z "${LOCAL_set}" ]; then
568 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
569 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
572 # Check that install PATHs are absolute
573 for p in BIN LIB DOC MAN; do
575 eval v='"${'"${var}"'}"'
578 *) do_error "'${var}' is not an absolute path: '${v}'"
582 #---------------------------------------------------------------------
585 printf "Building up Makefile... "
586 var_sed="$( for var_name in ${var_list}; do
587 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
590 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
591 eval printf \"${k_name}=\${${k_name}} \"
594 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
595 -e "s,@@LIBDIR@@,${LIBDIR},g" \
596 -e "s,@@DOCDIR@@,${DOCDIR},g" \
597 -e "s,@@MANDIR@@,${MANDIR},g" \
598 -e "s,@@VERSION@@,${VERSION},g" \
599 -e "s,@@DATE@@,${DATE},g" \
600 -e "s,@@LOCAL@@,${LOCAL_set},g" \
602 -e "${kconfig_sed}" \
609 crosstool-NG configured as follows:
619 if [ "${LOCAL_set}" != "y" ]; then
620 printf " make install\n"