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"
107 for item in "${@}"; do
109 prog=*|inc=*|lib=*|var=*|ver=*|err=*)
110 eval ${item%%=*}="'${item#*=}'"
112 *) do_error "has_or_abort: incorrect parameters: '$@'";;
116 case "${prog}:${inc}:${lib}" in
118 for item in ${prog}; do
119 printf "Checking for '${item}'... "
120 if [ -n "${var}" ]; then
121 eval val="\${${var}}"
122 if [ -n "${val}" ]; then
123 printf "${val} (cached)\n"
124 add_to_var_list "${var}"
128 where="$( which "${item}" 2>/dev/null )"
129 if [ -z "${where}" ]; then
132 elif [ -n "${ver}" ]; then
133 str=$( LC_ALL=C "${where}" --version 2>&1 \
137 if [ -z "${str}" ]; then
148 for item in ${inc}; do
149 printf "Checking for '${item}'... "
150 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
159 for item in ${lib}; do
160 printf "Checking for '${item}'... "
161 where="$( gcc -print-file-name="${item}" )"
162 if [ "${where}" != "${item}" ]; then
163 where="$( readlink "${where}" )"
172 if [ -z "${status}" ]; then
173 printf "\n${err:-${prog}${inc}${lib}: none found}\n\n"
174 printf "Either you are missing entirely the needed tool,\n"
175 printf "or the version you have is too old.\n"
176 if [ -n "${var}" ]; then
177 printf "You can give the path to this tool using: --with-${var}=PATH\n"
184 if [ -n "${var}" ]; then
185 eval ${var}='"'"${where}"'"'
186 add_to_var_list "${var}"
191 # This function checks for a tool, and aborts if not found
192 # See check_for(), above, for how to call has_or_abort
194 if ! check_for "$@"; then
195 # FORCE can be set in the environment
196 [ -z "${FORCE}" ] && do_error "Bailing out..."
199 printf "<* FORCE in action: *>\n"
200 printf "<* Continuing despite missing pre-requisite *>\n"
201 printf "<* Prepare for breakage *>\n"
209 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
211 USAGE: ./configure [OPTION]...
213 Defaults for the options are specified in brackets.
216 -h, --help display this help and exit
217 --force force configure to continue, even in case
218 some pre-requisites are missing
220 Installation directories:
221 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
222 --local don't install, and use current directory
224 By default, \`make install' will install all the files in
225 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
226 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
227 for instance \`--prefix=\${HOME}'.
229 For better control, use the options below.
231 Fine tuning of the installation directories:
232 --bindir=DIR user executables [PREFIX/bin]
233 --libdir=DIR object code libraries [PREFIX/lib]
234 --docdir=DIR info documentation [PREFIX/share/doc]
235 --mandir=DIR man documentation [PREFIX/share/man]
238 --with-install=PATH Specify the full PATH to GNU install
239 --with-make=PATH Specify the full PATH to GNU make >= 3.80
240 --with-grep=PATH Specify the full PATH to GNU grep
241 --with-sed=PATH Specify the full PATH to GNU sed
242 --with-bash=PATH Specify the full PATH to bash >= 3.0
246 #---------------------------------------------------------------------
249 while [ $# -ne 0 ]; do
251 --local) LOCAL_set="y"; shift;;
252 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
253 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
254 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
255 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
256 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
257 --with-*) set_tool "$1" "$2" && shift || shift 2;;
258 --force) FORCE=1; shift;;
259 --help|-h) do_help; exit 0;;
260 # Skip, auto-stuff compatibility
261 --build=*|--host=*|--infodir=*|--datadir=*|--sysconfdir=*|--localstatedir=*) shift;;
262 --build|--host|--infodir|--datadir|--sysconfdir|--localstatedir) shift 2;;
263 --enable-shared|--disable-shared|--enable-static|--disable-static) shift;;
264 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
269 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
271 # Special case when installing locally
272 if [ "${LOCAL_set}" = "y" ]; then
273 set_prefix "" "$( pwd )"
274 set_bindir "" "$( pwd )"
275 set_libdir "" "$( pwd )"
276 set_docdir "" "$( pwd )/docs"
277 set_mandir "" "$( pwd )/docs"
280 #---------------------------------------------------------------------
281 # Some sanity checks, now
283 # We check for grep and sed manually, because they are used in check_for()
284 printf "Checking for 'grep'... "
285 if [ -n "${grep}" ]; then
286 printf "${grep} (cached)\n"
288 grep="$( which grep 2>/dev/null )"
289 if [ -z "${grep}" ]; then
293 printf "Checking whether '${grep}' supports -E... "
294 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
302 if [ -z "${grep}" ]; then
303 printf "Either you are missing entirely the needed tool,\n"
304 printf "or the version you have is too old.\n"
305 printf "You can give the path to this tool using: --with-grep=PATH\n"
306 do_error "Bailing out..."
310 printf "Checking for 'sed'... "
311 if [ -n "${sed}" ]; then
312 printf "${sed} (cached)\n"
314 sed="$( which sed 2>/dev/null )"
315 if [ -z "${sed}" ]; then
319 printf "Checking whether '${sed}' supports -i and -e... "
320 touch .ct-ng.sed.test
321 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
327 rm -f .ct-ng.sed.test
330 if [ -z "${sed}" ]; then
331 printf "Either you are missing entirely the needed tool,\n"
332 printf "or the version you have is too old.\n"
333 printf "You can give the path to this tool using: --with-sed=PATH\n"
334 do_error "Bailing out..."
338 # The regular list of tools we can now easily check for
339 has_or_abort prog=bash \
341 ver='^GNU bash, version (3\.[1-9]|4)' \
342 err="'bash' 3.1 or above was not found"
343 has_or_abort prog=cut
344 has_or_abort prog=install var=install
345 has_or_abort prog=make \
347 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
348 err="GNU 'make' 3.80 or above was not found"
349 has_or_abort prog=gcc
350 has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
351 has_or_abort prog=bison
352 has_or_abort prog=flex
353 has_or_abort prog=makeinfo
354 has_or_abort prog=automake \
355 ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)' \
356 err="'automake' 1.10 or above was not found"
357 has_or_abort prog=libtool \
359 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
360 err="'libtool' 1.5.26 or above was not found"
361 has_or_abort prog=stat
362 has_or_abort prog="curl wget"
363 has_or_abort prog=cvs
364 has_or_abort prog=patch
365 has_or_abort prog=tar
366 has_or_abort prog=gzip
367 has_or_abort prog=bzip2
368 has_or_abort prog=lzma
369 has_or_abort prog=readlink
370 has_or_abort prog=objcopy var=objcopy
371 has_or_abort prog=objdump var=objdump
372 has_or_abort prog=readelf var=readelf
373 has_or_abort prog=patch var=patch
375 has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h" \
376 err="'ncurses' headers files were not found"
378 ncurses_libs="$( for l in ncursesw ncurses curses; do \
379 for x in so a dylib; do \
380 printf "lib$l.$x "; \
384 has_or_abort lib="${ncurses_libs}" \
385 err="'ncurses' library was not found"
387 #---------------------------------------------------------------------
388 # Compute the version string
390 # If this version is n hg clone, try to get the revision number
391 # If we can't get the revision number, use date
392 printf "Computing version string... "
395 REVISION="$( hg id -n 2>/dev/null || true )"
396 case "${REVISION}" in
398 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
400 VERSION="${VERSION}_$( hg id -b )@${REVISION%%+}_$( hg id -i )"
403 # Arrange to have no / in the directory name, no need to create an
404 # arbitrarily deep directory structure
405 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
408 printf "${VERSION}\n"
410 #---------------------------------------------------------------------
411 # Compute and check install paths
413 # Now we have the version string, we can build up the paths
414 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
415 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib"
416 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc"
417 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man"
419 # Install support files in our own sub-dir, so as not to mangle (system)
420 # files and dirs, but only if not --local
421 if [ -z "${LOCAL_set}" ]; then
422 LIBDIR="${LIBDIR}/ct-ng-${VERSION}"
423 DOCDIR="${DOCDIR}/ct-ng-${VERSION}"
426 # Check that install PATHs are absolute
427 for p in BIN LIB DOC MAN; do
429 eval v='"${'"${var}"'}"'
432 *) do_error "'${var}' is not an absolute path: '${v}'"
436 #---------------------------------------------------------------------
439 printf "Building up Makefile... "
440 var_sed="$( for var_name in ${var_list}; do
441 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
444 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g
445 s,@@LIBDIR@@,${LIBDIR},g
446 s,@@DOCDIR@@,${DOCDIR},g
447 s,@@MANDIR@@,${MANDIR},g
448 s,@@VERSION@@,${VERSION},g
451 s,@@LOCAL@@,${LOCAL_set},g" Makefile.in >Makefile
456 crosstool-NG configured as follows:
466 if [ "${LOCAL_set}" != "y" ]; then
467 printf " make install\n"