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 "has_or_abort: incorrect parameters: '$@'";;
134 if [ -n "${kconfig}" ]; then
135 add_to_kconfig_list "${kconfig}"
138 case "${prog}:${inc}:${lib}" in
140 for item in ${prog}; do
141 printf "Checking for '${item}'... "
142 if [ -n "${var}" ]; then
143 eval val="\${${var}}"
144 if [ -n "${val}" ]; then
145 printf "${val} (cached)\n"
146 add_to_var_list "${var}"
150 where="$( which "${item}" 2>/dev/null )"
151 if [ -z "${where}" ]; then
154 elif [ -n "${ver}" ]; then
155 str=$( LC_ALL=C "${where}" --version 2>&1 \
159 if [ -z "${str}" ]; then
170 for item in ${inc}; do
171 printf "Checking for '${item}'... "
172 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
181 for item in ${lib}; do
182 printf "Checking for '${item}'... "
183 where="$( gcc -print-file-name="${item}" )"
184 if [ "${where}" != "${item}" ]; then
185 where="$( readlink "${where}" )"
194 if [ -z "${status}" ]; then
199 if [ -n "${var}" ]; then
200 eval ${var}='"'"${where}"'"'
201 add_to_var_list "${var}"
203 if [ -n "${kconfig}" ]; then
209 # This function checks for a tool, and aborts if not found
210 # See check_for(), above, for how to call has_or_abort
212 # We declare these 6 variables here, although they are
213 # set in check_for(), called below
215 local var ver err kconfig
217 if ! check_for "$@"; then
218 printf " * A mandatory dependency is missing, or version mis-match\n"
219 printf " * ${err:-${prog}${inc}${lib}: none found}\n"
220 if [ -n "${var}" ]; then
221 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
224 # Bail out if --force is not specified
225 [ -z "${FORCE}" ] && do_error "Bailing out..."
227 printf "<* FORCE in action: *>\n"
228 printf "<* Continuing despite missing pre-requisite *>\n"
229 printf "<* Prepare for breakage *>\n"
235 # This function checks for a tool, and warns if not found
236 # See check_for(), above, for how to call has_or_abort
237 # Note: if err is not set, then no error message is printed
239 # We declare these 6 variables here, although they are
240 # set in check_for(), called below
242 local var ver err kconfig
244 if ! check_for "$@"; then
245 printf " * An optional dependency is missing, some features will be disabled\n"
246 printf "${err:+ * ${err}\n}"
247 if [ -n "${var}" ]; then
248 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
255 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
257 USAGE: ./configure [OPTION]...
259 Defaults for the options are specified in brackets.
262 -h, --help display this help and exit
263 --force force configure to continue, even in case
264 some pre-requisites are missing
266 Installation directories:
267 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
268 --local don't install, and use current directory
270 By default, \`make install' will install all the files in
271 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
272 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
273 for instance \`--prefix=\${HOME}'.
275 For better control, use the options below.
277 Fine tuning of the installation directories:
278 --bindir=DIR user executables [PREFIX/bin]
279 --libdir=DIR object code libraries [PREFIX/lib]
280 --docdir=DIR info documentation [PREFIX/share/doc]
281 --mandir=DIR man documentation [PREFIX/share/man]
284 --with-install=PATH Specify the full PATH to GNU install
285 --with-make=PATH Specify the full PATH to GNU make >= 3.80
286 --with-grep=PATH Specify the full PATH to GNU grep
287 --with-sed=PATH Specify the full PATH to GNU sed
288 --with-bash=PATH Specify the full PATH to bash >= 3.0
292 #---------------------------------------------------------------------
295 while [ $# -ne 0 ]; do
297 --local) LOCAL_set="y"; shift;;
298 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
299 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
300 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
301 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
302 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
303 --with-*) set_tool "$1" "$2" && shift || shift 2;;
304 --force) FORCE=1; shift;;
305 --help|-h) do_help; exit 0;;
306 # Skip, auto-stuff compatibility
307 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
308 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
309 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
314 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
316 # Special case when installing locally
317 if [ "${LOCAL_set}" = "y" ]; then
318 set_prefix "" "$( pwd )"
319 set_bindir "" "$( pwd )"
320 set_libdir "" "$( pwd )"
321 set_docdir "" "$( pwd )/docs"
322 set_mandir "" "$( pwd )/docs"
325 #---------------------------------------------------------------------
326 # Some sanity checks, now
328 # We check for grep and sed manually, because they are used in check_for()
329 printf "Checking for 'grep'... "
330 if [ -n "${grep}" ]; then
331 printf "${grep} (cached)\n"
333 grep="$( which grep 2>/dev/null )"
334 if [ -z "${grep}" ]; then
338 printf "Checking whether '${grep}' supports -E... "
339 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
347 if [ -z "${grep}" ]; then
348 printf "Either you are missing entirely the needed tool,\n"
349 printf "or the version you have is too old.\n"
350 printf "You can give the path to this tool using: --with-grep=PATH\n"
351 do_error "Bailing out..."
355 printf "Checking for 'sed'... "
356 if [ -n "${sed}" ]; then
357 printf "${sed} (cached)\n"
359 sed="$( which sed 2>/dev/null )"
360 if [ -z "${sed}" ]; then
364 printf "Checking whether '${sed}' supports -i and -e... "
365 touch .ct-ng.sed.test
366 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
372 rm -f .ct-ng.sed.test
375 if [ -z "${sed}" ]; then
376 printf "Either you are missing entirely the needed tool,\n"
377 printf "or the version you have is too old.\n"
378 printf "You can give the path to this tool using: --with-sed=PATH\n"
379 do_error "Bailing out..."
383 # The regular list of tools we can now easily check for
384 has_or_abort prog=bash \
386 ver='^GNU bash, version (3\.[1-9]|4)' \
387 err="'bash' 3.1 or above was not found"
388 has_or_abort prog=cut
389 has_or_abort prog=install var=install
390 has_or_abort prog=make \
392 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
393 err="GNU 'make' 3.80 or above was not found"
394 has_or_abort prog=gcc
395 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
396 has_or_abort prog=bison
397 has_or_abort prog=flex
398 has_or_abort prog=makeinfo
399 has_or_abort prog=automake \
400 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
401 err="'automake' 1.10 or above was not found"
402 has_or_abort prog=libtool \
404 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
405 err="'libtool' 1.5.26 or above was not found"
406 has_or_abort prog=stat
407 has_or_abort prog="curl wget"
408 has_or_abort prog=cvs
409 has_or_abort prog=patch
410 has_or_abort prog=tar
411 has_or_abort prog=gzip
412 has_or_abort prog=bzip2
413 has_or_abort prog=lzma
414 has_or_abort prog=readlink
415 has_or_abort prog=objcopy var=objcopy
416 has_or_abort prog=objdump var=objdump
417 has_or_abort prog=readelf var=readelf
418 has_or_abort prog=patch var=patch
420 has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h" \
421 err="'ncurses' headers files were not found"
423 ncurses_libs="$( for l in ncursesw ncurses curses; do \
424 for x in so a dylib; do \
425 printf "lib$l.$x "; \
429 has_or_abort lib="${ncurses_libs}" \
430 err="The 'ncurses' library is needed fo the menuconfig frontend"
432 stdcxx_libs="$( for x in so dylib a; do \
433 printf "libstdc++.$x "; \
436 has_or_abort lib="${stdcxx_libs}" \
437 err="The 'libstdc++' library is needed to build gcc"
439 # Yes, we may be checking twice for libstdc++.a
440 # The first is because we need one instance of libstdc++ (shared or static)
441 # because it is needed for PPL; the second is because the static version is
442 # required for static-linking, and if missing, the option is removed.
443 has_or_warn lib="libstdc++.a" \
444 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
445 kconfig=has_static_libstdcxx
447 #---------------------------------------------------------------------
448 # Compute the version string
450 # If this version is n hg clone, try to get the revision number
451 # If we can't get the revision number, use date
452 printf "\nComputing version string... "
455 REVISION="$( hg id -n 2>/dev/null || true )"
456 case "${REVISION}" in
458 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
460 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
463 # Arrange to have no / in the directory name, no need to create an
464 # arbitrarily deep directory structure
465 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
468 printf "${VERSION}\n"
470 #---------------------------------------------------------------------
471 # Compute and check install paths
473 # Now we have the version string, we can build up the paths
474 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
475 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
476 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
477 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
479 # Install support files in our own sub-dir, so as not to mangle (system)
480 # files and dirs, but only if not --local
481 if [ -z "${LOCAL_set}" ]; then
482 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
483 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
486 # Check that install PATHs are absolute
487 for p in BIN LIB DOC MAN; do
489 eval v='"${'"${var}"'}"'
492 *) do_error "'${var}' is not an absolute path: '${v}'"
496 #---------------------------------------------------------------------
499 printf "Building up Makefile... "
500 var_sed="$( for var_name in ${var_list}; do
501 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
504 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
505 eval printf \"${k_name}=\${${k_name}} \"
508 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
509 -e "s,@@LIBDIR@@,${LIBDIR},g" \
510 -e "s,@@DOCDIR@@,${DOCDIR},g" \
511 -e "s,@@MANDIR@@,${MANDIR},g" \
512 -e "s,@@VERSION@@,${VERSION},g" \
513 -e "s,@@DATE@@,${DATE},g" \
514 -e "s,@@LOCAL@@,${LOCAL_set},g" \
516 -e "${kconfig_sed}" \
523 crosstool-NG configured as follows:
533 if [ "${LOCAL_set}" != "y" ]; then
534 printf " make install\n"