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.
73 # This function adds a variable name to the above list of variable names.
74 # $1: the name of the variable to add to the list
76 var_list="${var_list} ${1}"
79 # A function to test for required tools/headers/libraries
80 # Return 0 (true) if found, !0 (false) if not found
82 # $*: [prog|inc|lib]=<name[ name...]>
83 # the name(s) of tool(s) to test for
85 # eg: prog=bash prog="curl wget"
87 # the name of the variable to test and set
89 # eg: var=bash if ${bash} is set and non-null, use that,
90 # else check for bash and set bash=$(which bash)
92 # for each 'prog', test if $(prog --version) matches 'regexp'
94 # eg: ver='^GNU bash, version [34]\.'
95 # $*: err=<error_message>
96 # the error message to print if tool is missing
97 # optional, defaults to: '${prog}: none found'
98 # eg: err="'bash' 3.x or above was not found"
99 # Note: err may be printed by caller, not us
106 # Note: prog/inc/lib and var/ver/err are set here,
107 # but declared by the caller (because it needs it)
108 for item in "${@}"; do
110 prog=*|inc=*|lib=*|var=*|ver=*|err=*)
111 eval ${item%%=*}="'${item#*=}'"
113 *) do_error "has_or_abort: incorrect parameters: '$@'";;
117 case "${prog}:${inc}:${lib}" in
119 for item in ${prog}; do
120 printf "Checking for '${item}'... "
121 if [ -n "${var}" ]; then
122 eval val="\${${var}}"
123 if [ -n "${val}" ]; then
124 printf "${val} (cached)\n"
125 add_to_var_list "${var}"
129 where="$( which "${item}" 2>/dev/null )"
130 if [ -z "${where}" ]; then
133 elif [ -n "${ver}" ]; then
134 str=$( LC_ALL=C "${where}" --version 2>&1 \
138 if [ -z "${str}" ]; then
149 for item in ${inc}; do
150 printf "Checking for '${item}'... "
151 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
160 for item in ${lib}; do
161 printf "Checking for '${item}'... "
162 where="$( gcc -print-file-name="${item}" )"
163 if [ "${where}" != "${item}" ]; then
164 where="$( readlink "${where}" )"
173 if [ -z "${status}" ]; then
178 if [ -n "${var}" ]; then
179 eval ${var}='"'"${where}"'"'
180 add_to_var_list "${var}"
185 # This function checks for a tool, and aborts if not found
186 # See check_for(), above, for how to call has_or_abort
188 # We declare these 6 variables here, although they are
189 # set in check_for(), called below
193 if ! check_for "$@"; then
194 printf "\n${err:-${prog}${inc}${lib}: none found}\n\n"
195 printf "Either you are missing entirely the needed tool,\n"
196 printf "or the version you have is too old.\n"
197 if [ -n "${var}" ]; then
198 printf "You can give the path to this tool using: --with-${var}=PATH\n"
201 # Bail out if --force is not specified
202 [ -z "${FORCE}" ] && do_error "Bailing out..."
204 printf "<* FORCE in action: *>\n"
205 printf "<* Continuing despite missing pre-requisite *>\n"
206 printf "<* Prepare for breakage *>\n"
212 # This function checks for a tool, and warns if not found
213 # See check_for(), above, for how to call has_or_abort
214 # Note: if err is not set, then no error message is printed
216 # We declare these 6 variables here, although they are
217 # set in check_for(), called below
221 if ! check_for "$@"; then
222 printf "${err:+${err}\n}"
223 if [ -n "${var}" ]; then
224 printf -- "--> You can give the path to this tool using: --with-${var}=PATH\n"
231 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
233 USAGE: ./configure [OPTION]...
235 Defaults for the options are specified in brackets.
238 -h, --help display this help and exit
239 --force force configure to continue, even in case
240 some pre-requisites are missing
242 Installation directories:
243 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
244 --local don't install, and use current directory
246 By default, \`make install' will install all the files in
247 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
248 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
249 for instance \`--prefix=\${HOME}'.
251 For better control, use the options below.
253 Fine tuning of the installation directories:
254 --bindir=DIR user executables [PREFIX/bin]
255 --libdir=DIR object code libraries [PREFIX/lib]
256 --docdir=DIR info documentation [PREFIX/share/doc]
257 --mandir=DIR man documentation [PREFIX/share/man]
260 --with-install=PATH Specify the full PATH to GNU install
261 --with-make=PATH Specify the full PATH to GNU make >= 3.80
262 --with-grep=PATH Specify the full PATH to GNU grep
263 --with-sed=PATH Specify the full PATH to GNU sed
264 --with-bash=PATH Specify the full PATH to bash >= 3.0
268 #---------------------------------------------------------------------
271 while [ $# -ne 0 ]; do
273 --local) LOCAL_set="y"; shift;;
274 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
275 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
276 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
277 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
278 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
279 --with-*) set_tool "$1" "$2" && shift || shift 2;;
280 --force) FORCE=1; shift;;
281 --help|-h) do_help; exit 0;;
282 # Skip, auto-stuff compatibility
283 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
284 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
285 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
290 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
292 # Special case when installing locally
293 if [ "${LOCAL_set}" = "y" ]; then
294 set_prefix "" "$( pwd )"
295 set_bindir "" "$( pwd )"
296 set_libdir "" "$( pwd )"
297 set_docdir "" "$( pwd )/docs"
298 set_mandir "" "$( pwd )/docs"
301 #---------------------------------------------------------------------
302 # Some sanity checks, now
304 # We check for grep and sed manually, because they are used in check_for()
305 printf "Checking for 'grep'... "
306 if [ -n "${grep}" ]; then
307 printf "${grep} (cached)\n"
309 grep="$( which grep 2>/dev/null )"
310 if [ -z "${grep}" ]; then
314 printf "Checking whether '${grep}' supports -E... "
315 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
323 if [ -z "${grep}" ]; then
324 printf "Either you are missing entirely the needed tool,\n"
325 printf "or the version you have is too old.\n"
326 printf "You can give the path to this tool using: --with-grep=PATH\n"
327 do_error "Bailing out..."
331 printf "Checking for 'sed'... "
332 if [ -n "${sed}" ]; then
333 printf "${sed} (cached)\n"
335 sed="$( which sed 2>/dev/null )"
336 if [ -z "${sed}" ]; then
340 printf "Checking whether '${sed}' supports -i and -e... "
341 touch .ct-ng.sed.test
342 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
348 rm -f .ct-ng.sed.test
351 if [ -z "${sed}" ]; then
352 printf "Either you are missing entirely the needed tool,\n"
353 printf "or the version you have is too old.\n"
354 printf "You can give the path to this tool using: --with-sed=PATH\n"
355 do_error "Bailing out..."
359 # The regular list of tools we can now easily check for
360 has_or_abort prog=bash \
362 ver='^GNU bash, version (3\.[1-9]|4)' \
363 err="'bash' 3.1 or above was not found"
364 has_or_abort prog=cut
365 has_or_abort prog=install var=install
366 has_or_abort prog=make \
368 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
369 err="GNU 'make' 3.80 or above was not found"
370 has_or_abort prog=gcc
371 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
372 has_or_abort prog=bison
373 has_or_abort prog=flex
374 has_or_abort prog=makeinfo
375 has_or_abort prog=automake \
376 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
377 err="'automake' 1.10 or above was not found"
378 has_or_abort prog=libtool \
380 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
381 err="'libtool' 1.5.26 or above was not found"
382 has_or_abort prog=stat
383 has_or_abort prog="curl wget"
384 has_or_abort prog=cvs
385 has_or_abort prog=patch
386 has_or_abort prog=tar
387 has_or_abort prog=gzip
388 has_or_abort prog=bzip2
389 has_or_abort prog=lzma
390 has_or_abort prog=readlink
391 has_or_abort prog=objcopy var=objcopy
392 has_or_abort prog=objdump var=objdump
393 has_or_abort prog=readelf var=readelf
394 has_or_abort prog=patch var=patch
396 has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h" \
397 err="'ncurses' headers files were not found"
399 ncurses_libs="$( for l in ncursesw ncurses curses; do \
400 for x in so a dylib; do \
401 printf "lib$l.$x "; \
405 has_or_abort lib="${ncurses_libs}" \
406 err="'ncurses' library was not found"
408 #---------------------------------------------------------------------
409 # Compute the version string
411 # If this version is n hg clone, try to get the revision number
412 # If we can't get the revision number, use date
413 printf "Computing version string... "
416 REVISION="$( hg id -n 2>/dev/null || true )"
417 case "${REVISION}" in
419 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
421 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
424 # Arrange to have no / in the directory name, no need to create an
425 # arbitrarily deep directory structure
426 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
429 printf "${VERSION}\n"
431 #---------------------------------------------------------------------
432 # Compute and check install paths
434 # Now we have the version string, we can build up the paths
435 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
436 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
437 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
438 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
440 # Install support files in our own sub-dir, so as not to mangle (system)
441 # files and dirs, but only if not --local
442 if [ -z "${LOCAL_set}" ]; then
443 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
444 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
447 # Check that install PATHs are absolute
448 for p in BIN LIB DOC MAN; do
450 eval v='"${'"${var}"'}"'
453 *) do_error "'${var}' is not an absolute path: '${v}'"
457 #---------------------------------------------------------------------
460 printf "Building up Makefile... "
461 var_sed="$( for var_name in ${var_list}; do
462 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
465 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g
466 s,@@LIBDIR@@,${LIBDIR},g
467 s,@@DOCDIR@@,${DOCDIR},g
468 s,@@MANDIR@@,${MANDIR},g
469 s,@@VERSION@@,${VERSION},g
472 s,@@LOCAL@@,${LOCAL_set},g" Makefile.in >Makefile
477 crosstool-NG configured as follows:
487 if [ "${LOCAL_set}" != "y" ]; then
488 printf " make install\n"