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 " * ${err:-${prog}${inc}${lib}: none found}\n"
219 printf " * Either you are missing entirely the needed tool,\n"
220 printf " * or the version you have is too old.\n"
221 if [ -n "${var}" ]; then
222 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
225 # Bail out if --force is not specified
226 [ -z "${FORCE}" ] && do_error "Bailing out..."
228 printf "<* FORCE in action: *>\n"
229 printf "<* Continuing despite missing pre-requisite *>\n"
230 printf "<* Prepare for breakage *>\n"
236 # This function checks for a tool, and warns if not found
237 # See check_for(), above, for how to call has_or_abort
238 # Note: if err is not set, then no error message is printed
240 # We declare these 6 variables here, although they are
241 # set in check_for(), called below
243 local var ver err kconfig
245 if ! check_for "$@"; then
246 printf " * optional dependency is missing, some features will be disabled\n"
247 printf "${err:+ * ${err}\n}"
248 if [ -n "${var}" ]; then
249 printf " * --> You can give the path to this tool using: --with-${var}=PATH\n"
256 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
258 USAGE: ./configure [OPTION]...
260 Defaults for the options are specified in brackets.
263 -h, --help display this help and exit
264 --force force configure to continue, even in case
265 some pre-requisites are missing
267 Installation directories:
268 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
269 --local don't install, and use current directory
271 By default, \`make install' will install all the files in
272 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
273 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
274 for instance \`--prefix=\${HOME}'.
276 For better control, use the options below.
278 Fine tuning of the installation directories:
279 --bindir=DIR user executables [PREFIX/bin]
280 --libdir=DIR object code libraries [PREFIX/lib]
281 --docdir=DIR info documentation [PREFIX/share/doc]
282 --mandir=DIR man documentation [PREFIX/share/man]
285 --with-install=PATH Specify the full PATH to GNU install
286 --with-make=PATH Specify the full PATH to GNU make >= 3.80
287 --with-grep=PATH Specify the full PATH to GNU grep
288 --with-sed=PATH Specify the full PATH to GNU sed
289 --with-bash=PATH Specify the full PATH to bash >= 3.0
293 #---------------------------------------------------------------------
296 while [ $# -ne 0 ]; do
298 --local) LOCAL_set="y"; shift;;
299 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
300 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
301 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
302 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
303 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
304 --with-*) set_tool "$1" "$2" && shift || shift 2;;
305 --force) FORCE=1; shift;;
306 --help|-h) do_help; exit 0;;
307 # Skip, auto-stuff compatibility
308 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
309 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
310 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
315 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
317 # Special case when installing locally
318 if [ "${LOCAL_set}" = "y" ]; then
319 set_prefix "" "$( pwd )"
320 set_bindir "" "$( pwd )"
321 set_libdir "" "$( pwd )"
322 set_docdir "" "$( pwd )/docs"
323 set_mandir "" "$( pwd )/docs"
326 #---------------------------------------------------------------------
327 # Some sanity checks, now
329 # We check for grep and sed manually, because they are used in check_for()
330 printf "Checking for 'grep'... "
331 if [ -n "${grep}" ]; then
332 printf "${grep} (cached)\n"
334 grep="$( which grep 2>/dev/null )"
335 if [ -z "${grep}" ]; then
339 printf "Checking whether '${grep}' supports -E... "
340 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
348 if [ -z "${grep}" ]; then
349 printf "Either you are missing entirely the needed tool,\n"
350 printf "or the version you have is too old.\n"
351 printf "You can give the path to this tool using: --with-grep=PATH\n"
352 do_error "Bailing out..."
356 printf "Checking for 'sed'... "
357 if [ -n "${sed}" ]; then
358 printf "${sed} (cached)\n"
360 sed="$( which sed 2>/dev/null )"
361 if [ -z "${sed}" ]; then
365 printf "Checking whether '${sed}' supports -i and -e... "
366 touch .ct-ng.sed.test
367 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
373 rm -f .ct-ng.sed.test
376 if [ -z "${sed}" ]; 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-sed=PATH\n"
380 do_error "Bailing out..."
384 # The regular list of tools we can now easily check for
385 has_or_abort prog=bash \
387 ver='^GNU bash, version (3\.[1-9]|4)' \
388 err="'bash' 3.1 or above was not found"
389 has_or_abort prog=cut
390 has_or_abort prog=install var=install
391 has_or_abort prog=make \
393 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
394 err="GNU 'make' 3.80 or above was not found"
395 has_or_abort prog=gcc
396 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
397 has_or_abort prog=bison
398 has_or_abort prog=flex
399 has_or_abort prog=makeinfo
400 has_or_abort prog=automake \
401 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
402 err="'automake' 1.10 or above was not found"
403 has_or_abort prog=libtool \
405 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
406 err="'libtool' 1.5.26 or above was not found"
407 has_or_abort prog=stat
408 has_or_abort prog="curl wget"
409 has_or_abort prog=cvs
410 has_or_abort prog=patch
411 has_or_abort prog=tar
412 has_or_abort prog=gzip
413 has_or_abort prog=bzip2
414 has_or_abort prog=lzma
415 has_or_abort prog=readlink
416 has_or_abort prog=objcopy var=objcopy
417 has_or_abort prog=objdump var=objdump
418 has_or_abort prog=readelf var=readelf
419 has_or_abort prog=patch var=patch
421 has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h" \
422 err="'ncurses' headers files were not found"
424 ncurses_libs="$( for l in ncursesw ncurses curses; do \
425 for x in so a dylib; do \
426 printf "lib$l.$x "; \
430 has_or_abort lib="${ncurses_libs}" \
431 err="'ncurses' library was not found"
433 stdcxx_libs="$( for x in so dylib a; do \
434 printf "libstdc++.$x "; \
437 has_or_abort lib="${stdcxx_libs}" \
438 err="'libstdc++' shared library was not found"
440 # Yes, we may be checking twice for libstdc++.a
441 # The first is because we need one instance of libstdc++ (shared or static)
442 # because it is needed for PPL; the second is because the static version is
443 # required for static-linking, and if missing, the option is removed.
444 has_or_warn lib="libstdc++.a" \
445 err="static 'libstdc++' is needed to statically link the toolchain's executables" \
446 kconfig=has_static_libstdcxx
448 #---------------------------------------------------------------------
449 # Compute the version string
451 # If this version is n hg clone, try to get the revision number
452 # If we can't get the revision number, use date
453 printf "\nComputing version string... "
456 REVISION="$( hg id -n 2>/dev/null || true )"
457 case "${REVISION}" in
459 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
461 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
464 # Arrange to have no / in the directory name, no need to create an
465 # arbitrarily deep directory structure
466 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
469 printf "${VERSION}\n"
471 #---------------------------------------------------------------------
472 # Compute and check install paths
474 # Now we have the version string, we can build up the paths
475 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
476 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
477 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
478 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
480 # Install support files in our own sub-dir, so as not to mangle (system)
481 # files and dirs, but only if not --local
482 if [ -z "${LOCAL_set}" ]; then
483 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
484 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
487 # Check that install PATHs are absolute
488 for p in BIN LIB DOC MAN; do
490 eval v='"${'"${var}"'}"'
493 *) do_error "'${var}' is not an absolute path: '${v}'"
497 #---------------------------------------------------------------------
500 printf "Building up Makefile... "
501 var_sed="$( for var_name in ${var_list}; do
502 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
505 kconfig_sed="s/@@KCONFIG@@/$( for k_name in ${kconfig_list}; do
506 eval printf \"${k_name}=\${${k_name}} \"
509 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g" \
510 -e "s,@@LIBDIR@@,${LIBDIR},g" \
511 -e "s,@@DOCDIR@@,${DOCDIR},g" \
512 -e "s,@@MANDIR@@,${MANDIR},g" \
513 -e "s,@@VERSION@@,${VERSION},g" \
514 -e "s,@@DATE@@,${DATE},g" \
515 -e "s,@@LOCAL@@,${LOCAL_set},g" \
517 -e "${kconfig_sed}" \
524 crosstool-NG configured as follows:
534 if [ "${LOCAL_set}" != "y" ]; then
535 printf " make install\n"