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 # $*: [prog|inc|lib]=<name[ name...]>
81 # the name(s) of tool(s) to test for
83 # eg: prog=bash prog="curl wget"
85 # the name of the variable to test and set
87 # eg: var=bash if ${bash} is set and non-null, use that,
88 # else check for bash and set bash=$(which bash)
90 # for each 'prog', test if $(prog --version) matches 'regexp'
92 # eg: ver='^GNU bash, version [34]\.'
93 # $*: err=<error_message>
94 # the error message to print if tool is missing
95 # optional, defaults to: '${prog}: none found'
96 # eg: err="'bash' 3.x or above was not found"
105 for item in "${@}"; do
107 prog=*|inc=*|lib=*|var=*|ver=*|err=*)
108 eval ${item%%=*}="'${item#*=}'"
110 *) do_error "has_or_abort: incorrect parameters: '$@'";;
114 case "${prog}:${inc}:${lib}" in
116 for item in ${prog}; do
117 printf "Checking for '${item}'... "
118 if [ -n "${var}" ]; then
119 eval val="\${${var}}"
120 if [ -n "${val}" ]; then
121 printf "${val} (cached)\n"
125 where="$( which "${item}" 2>/dev/null )"
126 if [ -z "${where}" ]; then
129 elif [ -n "${ver}" ]; then
130 str=$( "${where}" --version 2>&1 |grep -E "${ver}" |head -n 1 )
131 if [ -z "${str}" ]; then
142 for item in ${inc}; do
143 printf "Checking for '${item}'... "
144 if printf "#include \"${item}\"" |gcc -x c -c - -o /dev/null >/dev/null 2>&1; then
153 for item in ${lib}; do
154 printf "Checking for '${item}'... "
155 where="$( gcc -print-file-name="${item}" )"
156 if [ "${where}" != "${item}" ]; then
157 where="$( readlink -e "${where}" )"
165 if [ -z "${status}" ]; then
166 printf "\n${err:-${prog}${inc}${lib}: none found}\n\n"
167 printf "Either you are missing entirely the needed tool,\n"
168 printf "or the version you have is too old.\n"
169 if [ -n "${var}" ]; then
170 printf "You can give the path to this tool using: --with-${var}=PATH\n"
172 # FORCE can be set in the environment
173 [ -z "${FORCE}" ] && do_error "Bailing out..."
176 printf "<* FORCE in action: *>\n"
177 printf "<* Continuing despite missing pre-requisite *>\n"
178 printf "<* Prepare for breakage *>\n"
183 if [ -n "${var}" ]; then
184 eval ${var}='"'"${where}"'"'
185 add_to_var_list "${var}"
193 \`configure' configures crosstool-NG-${VERSION} to adapt to many kind of systems.
195 USAGE: ./configure [OPTION]...
197 Defaults for the options are specified in brackets.
200 -h, --help display this help and exit
201 --force force configure to continue, even in case
202 some pre-requisites are missing
204 Installation directories:
205 --prefix=PREFIX install files in PREFIX [${PREFIX_DEFAULT}]
206 --local don't install, and use current directory
208 By default, \`make install' will install all the files in
209 \`${PREFIX_DEFAULT}/bin', \`${PREFIX_DEFAULT}/lib' etc. You can specify
210 an installation prefix other than \`${PREFIX_DEFAULT}' using \`--prefix',
211 for instance \`--prefix=\${HOME}'.
213 For better control, use the options below.
215 Fine tuning of the installation directories:
216 --bindir=DIR user executables [PREFIX/bin]
217 --libdir=DIR object code libraries [PREFIX/lib]
218 --docdir=DIR info documentation [PREFIX/share/doc]
219 --mandir=DIR man documentation [PREFIX/share/man]
222 --with-install=PATH Specify the full PATH to GNU install
223 --with-make=PATH Specify the full PATH to GNU make >= 3.80
224 --with-grep=PATH Specify the full PATH to GNU grep
225 --with-sed=PATH Specify the full PATH to GNU sed
226 --with-bash=PATH Specify the full PATH to bash >= 3.0
230 #---------------------------------------------------------------------
233 while [ $# -ne 0 ]; do
235 --local) LOCAL_set="y"; shift;;
236 --prefix*) set_prefix "$1" "$2" && shift || shift 2;;
237 --bindir*) set_bindir "$1" "$2" && shift || shift 2;;
238 --libdir*) set_libdir "$1" "$2" && shift || shift 2;;
239 --docdir*) set_docdir "$1" "$2" && shift || shift 2;;
240 --mandir*) set_mandir "$1" "$2" && shift || shift 2;;
241 --with-*) set_tool "$1" "$2" && shift || shift 2;;
242 --force) FORCE=1; shift;;
243 --help|-h) do_help; exit 0;;
244 *) printf "Unrecognised option: '${1}'\n"; do_help; exit 1;;
249 [ -z "${PREFIX}" ] && set_prefix "" "${PREFIX_DEFAULT}"
251 # Special case when installing locally
252 if [ "${LOCAL_set}" = "y" ]; then
253 set_prefix "" "$( pwd )"
254 set_bindir "" "$( pwd )"
255 set_libdir "" "$( pwd )"
256 set_docdir "" "$( pwd )/docs"
257 set_mandir "" "$( pwd )/docs"
260 #---------------------------------------------------------------------
261 # Some sanity checks, now
263 # We check for grep and sed manually, because they are used in has_or_abort
264 printf "Checking for 'grep'... "
265 if [ -n "${grep}" ]; then
266 printf "${grep} (cached)\n"
268 grep="$( which grep 2>/dev/null )"
269 if [ -z "${grep}" ]; then
273 printf "Checking whether '${grep}' supports -E... "
274 if echo 'foo' |"${grep}" -E 'foo' >/dev/null 2>&1; then
282 if [ -z "${grep}" ]; then
283 printf "Either you are missing entirely the needed tool,\n"
284 printf "or the version you have is too old.\n"
285 printf "You can give the path to this tool using: --with-grep=PATH\n"
286 do_error "Bailing out..."
290 printf "Checking for 'sed'... "
291 if [ -n "${sed}" ]; then
292 printf "${sed} (cached)\n"
294 sed="$( which sed 2>/dev/null )"
295 if [ -z "${sed}" ]; then
299 printf "Checking whether '${sed}' supports -i and -e... "
300 touch .ct-ng.sed.test
301 if "${sed}" -r -i -e 's/foo/bar/' .ct-ng.sed.test >/dev/null 2>&1; then
307 rm -f .ct-ng.sed.test
310 if [ -z "${sed}" ]; then
311 printf "Either you are missing entirely the needed tool,\n"
312 printf "or the version you have is too old.\n"
313 printf "You can give the path to this tool using: --with-sed=PATH\n"
314 do_error "Bailing out..."
318 # The regular list of tools we can now easily check for
319 has_or_abort prog=bash \
321 ver='^GNU bash, version [34]\.' \
322 err="'bash' 3.x or above was not found"
323 has_or_abort prog=cut
324 has_or_abort prog=install var=install
325 has_or_abort prog=make \
327 ver='^GNU Make (3.[89][[:digit:]]|[4-9])' \
328 err="GNU 'make' 3.80 or above was not found"
329 has_or_abort prog=gcc
330 has_or_abort prog=awk
331 has_or_abort prog=bison
332 has_or_abort prog=flex
333 has_or_abort prog=makeinfo
334 has_or_abort prog=automake \
335 ver='\(GNU automake\) (1\.[[:digit:]]{2,}\.|[2-9][[:digit:]]*\.)' \
336 err="'automake' 1.10 or above was not found"
337 has_or_abort prog=libtool \
338 ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)' \
339 err="'libtool' 1.5.26 or above was not found"
340 has_or_abort prog="curl wget"
341 has_or_abort prog=cvs
342 has_or_abort prog=patch
343 has_or_abort prog=tar
344 has_or_abort prog=gzip
345 has_or_abort prog=bzip2
346 has_or_abort prog=lzma
347 has_or_abort prog=readlink
349 has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h" \
350 err="'ncurses' headers files were not found"
352 ncurses_libs="$( for l in ncursesw ncurses curses; do \
353 for x in so a dylib; do \
354 printf "lib$l.$x "; \
358 has_or_abort lib="${ncurses_libs}" \
359 err="'ncurses' library was not found"
361 #---------------------------------------------------------------------
362 # Compute the version string
364 # If this version is a svn snapshot, try to get the revision number
365 # If we can't get the revision number, use date
368 has_or_abort prog=svnversion
369 printf "Computing version string... "
370 REVISION="$( LC_ALL=C svnversion )"
371 case "${REVISION}" in
373 VERSION="${VERSION}_unknown@$( date +%Y%m%d.%H%M%S )";;
375 URL="$( LC_ALL=C svn info 2>/dev/null \
379 ROOT="$( LC_ALL=C svn info 2>/dev/null \
380 |"${grep}" '^Repository Root: ' \
383 VERSION="${VERSION}${URL#${ROOT}}@${REVISION}"
386 # Arrange to have no / in the directory name, no need to create an
387 # arbitrarily deep directory structure
388 VERSION="$( printf "${VERSION}\n" |"${sed}" -r -e 's|/+|_|g;' )"
393 #---------------------------------------------------------------------
394 # Compute and check install paths
396 # Now we have the version string, we can build up the paths
397 [ -z "${BINDIR_set}" ] && BINDIR="${PREFIX}/bin"
398 [ -z "${LIBDIR_set}" ] && LIBDIR="${PREFIX}/lib/ct-ng-${VERSION}"
399 [ -z "${DOCDIR_set}" ] && DOCDIR="${PREFIX}/share/doc/ct-ng-${VERSION}"
400 [ -z "${MANDIR_set}" ] && MANDIR="${PREFIX}/share/man/man1"
402 # Check that install PATHs are absolute
403 for p in BIN LIB DOC MAN; do
405 eval v='"${'"${var}"'}"'
408 *) do_error "'${var}' is not an absolute path: '${v}'"
412 #---------------------------------------------------------------------
415 printf "Building up Makefile... "
416 var_sed="$( for var_name in ${var_list}; do
417 eval echo 's,@@${var_name}@@,${'"${var_name}"'},g'
420 "${sed}" -r -e "s,@@BINDIR@@,${BINDIR},g
421 s,@@LIBDIR@@,${LIBDIR},g
422 s,@@DOCDIR@@,${DOCDIR},g
423 s,@@MANDIR@@,${MANDIR},g
424 s,@@VERSION@@,${VERSION},g
427 s,@@LOCAL@@,${LOCAL_set},g" Makefile.in >Makefile
432 crosstool-NG configured as follows:
442 if [ "${LOCAL_set}" != "y" ]; then
443 printf " make install\n"