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 # $*: err=<error_message>
108 # the error message to print if tool is missing
109 # optional, defaults to: '${prog}: none found'
110 # eg: err="'bash' 3.x or above was not found"
111 # Note: err may be printed by caller, not us
112 # $*: kconfig=<var_name>
113 # the name of a variable to pass down to kconfig if
114 # the prog/inc/lib was found
115 # optional, defaults to none
116 # eg: kconfig=has_libncurses
123 # Note: prog/inc/lib and var/kconfig/ver/err are set here,
124 # but declared by the caller (because it needs it)
125 for item in "${@}"; do
127 prog=*|inc=*|lib=*|var=*|ver=*|err=*|kconfig=*)
128 eval ${item%%=*}=\"${item#*=}\"
130 *) do_error "check_for: incorrect parameters: '$@'";;
134 case "${prog}:${inc}:${lib}" in
135 ?*:?*:|?*::?*|:?*:?*|?*:?*:?*)
136 if [ -n "${var}" ]; then
137 do_error "check_for: the use of var is not compatible with passing several of [prog|inc|lib] at once"
140 ::) do_error "check_for: [prog|inc|lib] is mandatory";;
143 if [ -n "${kconfig}" ]; then
144 add_to_kconfig_list "${kconfig}"
147 if [ -n "${prog}" ]; then
148 for item in ${prog}; do
149 printf "Checking for '${item}'... "
150 if [ -n "${var}" ]; then
151 eval val="\${${var}}"
152 if [ -n "${val}" ]; then
153 printf "${val} (cached)\n"
154 add_to_var_list "${var}"
158 where="$( which "${item}" 2>/dev/null )"
159 if [ -z "${where}" ]; then
162 elif [ -n "${ver}" ]; then
163 str=$( LC_ALL=C "${where}" --version 2>&1 \
167 if [ -z "${str}" ]; then
176 if [ -z "${status}" ]; then
183 if [ -n "${inc}" ]; then
184 for item in ${inc}; do
185 printf "Checking for '${item}'... "
186 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
193 if [ -z "${status}" ]; then
200 if [ -n "${lib}" ]; then
201 for item in ${lib}; do
202 printf "Checking for '${item}'... "
203 where="$( gcc -print-file-name="${item}" )"
204 if [ "${where}" != "${item}" ]; then
205 where="$( readlink "${where}" )"
211 if [ -z "${status}" ]; then
218 if [ -n "${var}" ]; then
219 eval ${var}='"'"${where}"'"'
220 add_to_var_list "${var}"
222 if [ -n "${kconfig}" ]; then
227 # This function checks for a tool, and aborts if not found
228 # See check_for(), above, for how to call has_or_abort
230 # We declare these 6 variables here, although they are
231 # set in check_for(), called below
233 local var ver err kconfig
235 if ! check_for "$@"; then
236 printf " * A mandatory dependency is missing, or version mis-match\n"
237 printf " * ${err:-${prog}${inc}${lib}: none found}\n"
238 if [ -n "${var}" ]; then
239 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
242 # Bail out if --force is not specified
243 [ -z "${FORCE}" ] && do_error "Bailing out..."
245 printf "<* FORCE in action: *>\n"
246 printf "<* Continuing despite missing pre-requisite *>\n"
247 printf "<* Prepare for breakage *>\n"
253 # This function checks for a tool, and warns if not found
254 # See check_for(), above, for how to call has_or_abort
255 # Note: if err is not set, then no error message is printed
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 " * An optional dependency is missing, some features will be disabled\n"
264 printf "${err:+ * ${err}\n}"
265 if [ -n "${var}" ]; then
266 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
273 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
275 USAGE: ./configure [OPTION]...
277 Defaults for the options are specified in brackets.
280 -h, --help display this help and exit
281 --force force configure to continue, even in case
282 some pre-requisites are missing
284 Installation directories:
285 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
286 --local don't install, and use current directory
288 By default, \`make install' will install all the files in
289 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
290 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
291 for instance \`--prefix=\${HOME}'.
293 For better control, use the options below.
295 Fine tuning of the installation directories:
296 --bindir=DIR user executables [PREFIX/bin]
297 --libdir=DIR object code libraries [PREFIX/lib]
298 --docdir=DIR info documentation [PREFIX/share/doc]
299 --mandir=DIR man documentation [PREFIX/share/man]
302 --with-install=PATH Specify the full PATH to GNU install
303 --with-make=PATH Specify the full PATH to GNU make >= 3.80
304 --with-grep=PATH Specify the full PATH to GNU grep
305 --with-sed=PATH Specify the full PATH to GNU sed
306 --with-bash=PATH Specify the full PATH to bash >= 3.0
310 #---------------------------------------------------------------------
313 while [ $# -ne 0 ]; do
315 --local) LOCAL_set="y"; shift;;
316 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
317 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
318 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
319 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
320 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
321 --with-*) set_tool "$1" "$2" && shift || shift 2;;
322 --force) FORCE=1; shift;;
323 --help|-h) do_help; exit 0;;
324 # Skip, auto-stuff compatibility
325 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
326 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
327 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
332 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
334 # Special case when installing locally
335 if [ "${LOCAL_set}" = "y" ]; then
336 set_prefix "" "$( pwd )"
337 set_bindir "" "$( pwd )"
338 set_libdir "" "$( pwd )"
339 set_docdir "" "$( pwd )/docs"
340 set_mandir "" "$( pwd )/docs"
343 #---------------------------------------------------------------------
344 # Some sanity checks, now
346 # We check for grep and sed manually, because they are used in check_for()
347 printf "Checking for 'grep'... "
348 if [ -n "${grep}" ]; then
349 printf "${grep} (cached)\n"
351 grep="$( which grep 2>/dev/null )"
352 if [ -z "${grep}" ]; then
356 printf "Checking whether '${grep}' supports -E... "
357 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
365 if [ -z "${grep}" ]; then
366 printf "Either you are missing entirely the needed tool,\n"
367 printf "or the version you have is too old.\n"
368 printf "You can give the path to this tool using: --with-grep=PATH\n"
369 do_error "Bailing out..."
373 printf "Checking for 'sed'... "
374 if [ -n "${sed}" ]; then
375 printf "${sed} (cached)\n"
377 sed="$( which sed 2>/dev/null )"
378 if [ -z "${sed}" ]; then
382 printf "Checking whether '${sed}' supports -i and -e... "
383 touch .ct-ng.sed.test
384 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
390 rm -f .ct-ng.sed.test
393 if [ -z "${sed}" ]; then
394 printf "Either you are missing entirely the needed tool,\n"
395 printf "or the version you have is too old.\n"
396 printf "You can give the path to this tool using: --with-sed=PATH\n"
397 do_error "Bailing out..."
401 # The regular list of tools we can now easily check for
402 has_or_abort prog=bash \
404 ver='^GNU bash, version (3\.[1-9]|4)' \
405 err="'bash' 3.1 or above was not found"
406 has_or_abort prog=cut
407 has_or_abort prog=install var=install
408 has_or_abort prog=make \
410 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
411 err="GNU 'make' 3.80 or above was not found"
412 has_or_abort prog=gcc
413 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
414 has_or_abort prog=bison
415 has_or_abort prog=flex
416 has_or_abort prog=makeinfo
417 has_or_abort prog=automake \
418 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
419 err="'automake' 1.10 or above was not found"
420 has_or_abort prog=libtool \
422 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
423 err="'libtool' 1.5.26 or above was not found"
424 has_or_abort prog=stat
425 has_or_abort prog="curl wget"
426 has_or_abort prog=cvs
427 has_or_abort prog=patch
428 has_or_abort prog=tar
429 has_or_abort prog=gzip
430 has_or_abort prog=bzip2
431 has_or_abort prog=lzma
432 has_or_abort prog=readlink
433 has_or_abort prog=objcopy var=objcopy
434 has_or_abort prog=objdump var=objdump
435 has_or_abort prog=readelf var=readelf
436 has_or_abort prog=patch var=patch
438 ncurses_hdrs="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"
439 ncurses_libs="$( for l in ncursesw ncurses curses; do \
440 for x in so a dylib; do \
441 printf "lib$l.$x "; \
445 has_or_abort lib="${ncurses_libs}" \
446 inc="${ncurses_hdrs}" \
447 err="The 'ncurses' library is needed fo the menuconfig frontend"
449 stdcxx_libs="$( for x in so dylib a; do \
450 printf "libstdc++.$x "; \
453 has_or_abort lib="${stdcxx_libs}" \
454 err="The 'libstdc++' library is needed to build gcc"
456 # Yes, we may be checking twice for libstdc++.a
457 # The first is because we need one instance of libstdc++ (shared or static)
458 # because it is needed for PPL; the second is because the static version is
459 # required for static-linking, and if missing, the option is removed.
460 has_or_warn lib="libstdc++.a" \
461 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
462 kconfig=has_static_libstdcxx
464 expat_libs="$( for x in so dylib a; do \
465 printf "libexpat.$x "; \
468 has_or_warn inc="expat.h" \
469 lib="${expat_libs}" \
470 err="The 'expat' header file and library are needed to link cross-gdb's executables" \
473 # Yes, we may be checking twice for libexpat.a
474 # The first is because we need one instance of libexpat (shared or static)
475 # because it is needed for cross-gdb; the second is because the static version
476 # is required for static-linking, and if missing, the option is removed.
477 has_or_warn lib="libexpat.a" \
478 err="static 'expat' is needed to statically link cross-gdb's executables" \
479 kconfig=has_static_expat
482 python_incs="${python_incs}$( printf "python2.$v/Python.h " )"
483 python_libs="${python_libs}$( for x in so dylib a; do \
484 printf "libpython2.$v.$x "; \
488 has_or_warn inc="${python_incs}" \
489 lib="${python_libs}" \
490 err="The 'python' header file and library are needed for some features of cross-gdb"
492 #---------------------------------------------------------------------
493 # Compute the version string
495 # If this version is n hg clone, try to get the revision number
496 # If we can't get the revision number, use date
497 printf "\nComputing version string... "
500 REVISION="$( hg id -n 2>/dev/null || true )"
501 case "${REVISION}" in
503 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
505 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
508 # Arrange to have no / in the directory name, no need to create an
509 # arbitrarily deep directory structure
510 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
513 printf "${VERSION}\n"
515 #---------------------------------------------------------------------
516 # Compute and check install paths
518 # Now we have the version string, we can build up the paths
519 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
520 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
521 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
522 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
524 # Install support files in our own sub-dir, so as not to mangle (system)
525 # files and dirs, but only if not --local
526 if [ -z "${LOCAL_set}" ]; then
527 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
528 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
531 # Check that install PATHs are absolute
532 for p in BIN LIB DOC MAN; do
534 eval v='"${'"${var}"'}"'
537 *) do_error "'${var}' is not an absolute path: '${v}'"
541 #---------------------------------------------------------------------
544 printf "Building up Makefile... "
545 var_sed="$( for var_name in ${var_list}; do
546 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
549 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
550 eval printf \"${k_name}=\${${k_name}} \"
553 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
554 -e "s,@@LIBDIR@@,${LIBDIR},g" \
555 -e "s,@@DOCDIR@@,${DOCDIR},g" \
556 -e "s,@@MANDIR@@,${MANDIR},g" \
557 -e "s,@@VERSION@@,${VERSION},g" \
558 -e "s,@@DATE@@,${DATE},g" \
559 -e "s,@@LOCAL@@,${LOCAL_set},g" \
561 -e "${kconfig_sed}" \
568 crosstool-NG configured as follows:
578 if [ "${LOCAL_set}" != "y" ]; then
579 printf " make install\n"