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"
190 where="$( which "${item}" 2>/dev/null )"
191 if [ -z "${where}" ]; then
194 elif [ -n "${ver}" ]; then
195 str=$( LC_ALL=C "${where}" --version 2>&1 \
199 if [ -z "${str}" ]; then
208 if [ -z "${status}" ]; then
215 if [ -n "${inc}" ]; then
216 for item in ${inc}; do
217 printf "Checking for '${item}'... "
218 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
225 if [ -z "${status}" ]; then
232 if [ -n "${lib}" ]; then
233 if [ -z "${lib_exts}" ]; then
234 do_error "check_for: no library extension specified for '${lib}'"
236 for item in ${lib}; do
237 for ext in ${lib_exts}; do
238 printf "Checking for '${item}.${ext}'... "
239 where="$( gcc -print-file-name="${item}.${ext}" )"
240 if [ "${where}" != "${item}.${ext}" ]; then
241 where="$( readlink "${where}" )"
248 if [ -z "${status}" ]; then
255 if [ -n "${var}" ]; then
256 eval ${var}='"'"${where}"'"'
258 if [ -n "${kconfig}" ]; then
263 # This function checks for a tool, and aborts if not found
264 # See check_for(), above, for how to call has_or_abort
266 # We declare these 6 variables here, although they are
267 # set in check_for(), called below
269 local var ver err kconfig
271 if ! check_for "$@"; then
272 printf " * A mandatory dependency is missing, or version mis-match:\n"
273 printf " * - ${err:-${prog}${inc}${lib}: none found}\n"
274 if [ -n "${var}" ]; then
275 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
278 # Bail out if --force is not specified
279 [ -z "${FORCE}" ] && do_error "Bailing out..."
281 printf "<* FORCE in action: *>\n"
282 printf "<* Continuing despite missing pre-requisite *>\n"
283 printf "<* Prepare for breakage *>\n"
289 # This function checks for a tool, and warns if not found
290 # See check_for(), above, for how to call has_or_abort
291 # Note: if err is not set, then no error message is printed
293 # We declare these 6 variables here, although they are
294 # set in check_for(), called below
296 local var ver err kconfig
298 if ! check_for "$@"; then
299 printf " * An optional dependency is missing, some features will be disabled"
300 printf "${err:+:\n * - ${err}}\n"
301 if [ -n "${var}" ]; then
302 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
309 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
311 USAGE: ./configure [OPTION]...
313 Defaults for the options are specified in brackets.
316 -h, --help display this help and exit
317 --force force configure to continue, even in case
318 some pre-requisites are missing
320 Installation directories:
321 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
322 --local don't install, and use current directory
324 By default, \`make install' will install all the files in
325 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
326 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
327 for instance \`--prefix=\${HOME}'.
329 For better control, use the options below.
330 Note: options marked as \`ignored' are recognised, but not acted upon, as
331 they make no sense for crosstool-NG, or they are not implemented yet.
333 Fine tuning of the installation directories:
334 --bindir=DIR user executables [PREFIX/bin]
335 --libdir=DIR object code libraries [PREFIX/lib]
336 --docdir=DIR info documentation [PREFIX/share/doc]
337 --mandir=DIR man documentation [PREFIX/share/man]
338 --infodir=DIR info documentation [DATAROOTDIR/info] (ignored)
339 --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
341 --sysconfdir=DIR read-only single-machine data [PREFIX/etc] (ignored)
342 --localstatedir=DIR modifiable single-machine data [PREFIX/var] (ignored)
345 --program-prefix=PREFIX prepend PREFIX to installed program names
346 --program-suffix=SUFFIX append SUFFIX to installed program names
347 --program-transform-name=PROGRAM run sed PROGRAM on installed program names
350 --build=BUILD configure for building on BUILD [guessed] (ignored)
351 --host=HOST cross-compile to build programs to run on HOST [BUILD]
355 --enable-shared[=PKGS] build shared libraries [default=yes] (ignored)
356 --enable-static[=PKGS] build static libraries [default=yes] (ignored)
359 --with-install=PATH Specify the full PATH to GNU install
360 --with-make=PATH Specify the full PATH to GNU make >= 3.80
361 --with-grep=PATH Specify the full PATH to GNU grep
362 --with-sed=PATH Specify the full PATH to GNU sed
363 --with-bash=PATH Specify the full PATH to bash >= 3.0
367 #---------------------------------------------------------------------
370 while [ $# -ne 0 ]; do
372 --local) LOCAL_set="y"; shift;;
373 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
374 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
375 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
376 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
377 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
378 --with-*) set_tool "$1" "$2" && shift || shift 2;;
379 --program-prefix=*|--program-prefix)
380 set_program_prefix "$1" "$2" && shift || shift 2
382 --program-suffix=*|--program-suffix)
383 set_program_suffix "$1" "$2" && shift || shift 2
385 --program-transform-name=*|--program-transform-name)
386 set_program_transform_name "$1" "$2" && shift || shift 2
388 --force) FORCE=1; shift;;
389 --help|-h) do_help; exit 0;;
390 # Skip, auto-stuff compatibility
391 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
392 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
393 --enable-shared|--disable-shared|--enable-static|--disable-static) shift;;
394 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
399 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
401 # Special case when installing locally
402 if [ "${LOCAL_set}" = "y" ]; then
403 set_prefix "" "$( pwd )"
404 set_bindir "" "$( pwd )"
405 set_libdir "" "$( pwd )"
406 set_docdir "" "$( pwd )/docs"
407 set_mandir "" "$( pwd )/docs"
408 set_program_prefix "" ""
409 set_program_suffix "" ""
410 set_program_transform_name "" ""
413 #---------------------------------------------------------------------
414 # Some sanity checks, now
416 # We check for grep and sed manually, because they are used in check_for()
417 printf "Checking for 'grep'... "
418 if [ -n "${grep}" ]; then
419 printf "${grep} (cached)\n"
421 grep="$( which grep 2>/dev/null )"
422 if [ -z "${grep}" ]; then
426 printf "Checking whether '${grep}' supports -E... "
427 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
435 if [ -z "${grep}" ]; then
436 printf "Either you are missing entirely the needed tool,\n"
437 printf "or the version you have is too old.\n"
438 printf "You can give the path to this tool using: --with-grep=PATH\n"
439 do_error "Bailing out..."
443 printf "Checking for 'sed'... "
444 if [ -n "${sed}" ]; then
445 printf "${sed} (cached)\n"
447 sed="$( which sed 2>/dev/null )"
448 if [ -z "${sed}" ]; then
452 printf "Checking whether '${sed}' supports -i and -e... "
453 touch .ct-ng.sed.test
454 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
460 rm -f .ct-ng.sed.test
463 if [ -z "${sed}" ]; then
464 printf "Either you are missing entirely the needed tool,\n"
465 printf "or the version you have is too old.\n"
466 printf "You can give the path to this tool using: --with-sed=PATH\n"
467 do_error "Bailing out..."
471 # The regular list of tools we can now easily check for
472 has_or_abort prog=bash \
474 ver='^GNU bash, version (3\.[1-9]|4)' \
475 err="'bash' 3.1 or above was not found"
476 has_or_abort prog=cut
477 has_or_abort prog=install var=install
478 has_or_abort prog=make \
480 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
481 err="GNU 'make' 3.80 or above was not found"
482 has_or_abort prog=gcc
483 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
484 has_or_abort prog=bison
485 has_or_abort prog=flex
486 has_or_abort prog=makeinfo
487 has_or_abort prog=automake \
488 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
489 err="'automake' 1.10 or above was not found"
490 has_or_abort prog=libtool \
492 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
493 err="'libtool' 1.5.26 or above was not found"
494 has_or_abort prog=libtoolize \
496 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
497 err="'libtoolize' 1.5.26 or above was not found"
498 has_or_abort prog=stat
499 has_or_abort prog="curl"
500 has_or_abort prog=patch
501 has_or_abort prog=tar
502 has_or_abort prog=gzip
503 has_or_abort prog=bzip2
504 has_or_warn prog=xz \
505 kconfig=has_xzutils \
506 err="xz-compressed tarballs will not be used"
507 has_or_warn prog=lzma \
509 skip="${has_xzutils}" \
510 err="lzma-compressed tarballs will not be used"
511 has_or_abort prog=readlink
512 has_or_abort prog=objcopy var=objcopy
513 has_or_abort prog=objdump var=objdump
514 has_or_abort prog=readelf var=readelf
515 has_or_abort prog=patch var=patch
516 has_or_warn prog=cvs \
518 err="it will not be possible to use newlib cvs snapshots"
519 has_or_warn prog=svn \
521 err="subversion is required to download eglibc"
524 libs_exts="so dylib a"
526 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
527 ncurses_libs="libncursesw libncurses libcurses"
528 has_or_abort lib="${ncurses_libs}" \
529 lib_exts="${libs_exts}" \
530 inc="${ncurses_hdrs}" \
531 err="The 'ncurses' library is needed fo the menuconfig frontend"
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}'";;
581 case "${PROG_PFX}" in
582 */*) do_error "program prefix '${PROG_PFX}' contains a '/'";;
584 case "${PROG_SFX}" in
585 */*) do_error "program suffix '${PROG_SFX}' contains a '/'";;
588 #---------------------------------------------------------------------
591 printf "Building up Makefile... "
592 var_sed="$( for var_name in ${var_list}; do
593 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
596 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
597 eval printf \"${k_name}=\${${k_name}} \"
600 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
601 -e "s,@@LIBDIR@@,${LIBDIR},g" \
602 -e "s,@@DOCDIR@@,${DOCDIR},g" \
603 -e "s,@@MANDIR@@,${MANDIR},g" \
604 -e "s,@@PROG_PFX@@,${PROG_PFX},g" \
605 -e "s,@@PROG_SFX@@,${PROG_SFX},g" \
606 -e "s,@@PROG_SED@@,${PROG_SED},g" \
607 -e "s,@@VERSION@@,${VERSION},g" \
608 -e "s,@@DATE@@,${DATE},g" \
609 -e "s,@@LOCAL@@,${LOCAL_set},g" \
611 -e "${kconfig_sed}" \
618 crosstool-NG configured as follows:
624 PROG_PFX='${PROG_PFX}'
625 PROG_SFX='${PROG_SFX}'
626 PROG_SED='${PROG_SED}'
631 if [ "${LOCAL_set}" != "y" ]; then
632 printf " make install\n"