configure: prefer lib64 on 64-bit platforms
[tinycc.git] / configure
blobf02d6e452541f69b5266909177d18bfcfc88940f
1 #!/bin/sh
3 # tcc configure script (c) 2003 Fabrice Bellard
5 # set temporary file name
6 # if test ! -z "$TMPDIR" ; then
7 # TMPDIR1="${TMPDIR}"
8 # elif test ! -z "$TEMPDIR" ; then
9 # TMPDIR1="${TEMPDIR}"
10 # else
11 # TMPDIR1="/tmp"
12 # fi
14 # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
16 TMPN="./conftest-$$"
17 TMPH=$TMPN.h
19 # default parameters
20 build_cross="no"
21 use_libgcc="no"
22 prefix=""
23 execprefix=""
24 bindir=""
25 libdir=""
26 tccdir=""
27 includedir=""
28 mandir=""
29 infodir=""
30 sysroot=""
31 cross_prefix=""
32 cc="gcc"
33 ar="ar"
34 strip="strip"
35 cygwin="no"
36 gprof="no"
37 bigendian="no"
38 mingw32="no"
39 LIBSUF=".a"
40 EXESUF=""
41 tcc_sysincludepaths=""
42 tcc_libpaths=""
43 tcc_crtprefix=""
44 tcc_elfinterp=""
45 triplet=
46 tcc_lddir=
47 confvars=
48 cpu=
50 # OS specific
51 targetos=`uname`
52 case $targetos in
53 MINGW*) mingw32=yes;;
54 MSYS*) mingw32=yes;;
55 DragonFly) noldl=yes;;
56 OpenBSD) noldl=yes;;
57 FreeBSD) noldl=yes;;
58 NetBSD) noldl=yes;;
59 *) ;;
60 esac
62 # find source path
63 # XXX: we assume an absolute path is given when launching configure,
64 # except in './configure' case.
65 source_path=${0%configure}
66 source_path=${source_path%/}
67 source_path_used="yes"
68 if test -z "$source_path" -o "$source_path" = "." ; then
69 source_path=`pwd`
70 source_path_used="no"
73 for opt do
74 eval opt=\"$opt\"
75 case "$opt" in
76 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
78 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
80 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
82 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
84 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
86 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
88 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
90 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
92 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
94 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
96 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
98 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
100 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
102 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
104 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
106 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
108 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
110 --extra-libs=*) extralibs="${opt#--extra-libs=}"
112 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
114 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
116 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
118 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
120 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
122 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
124 --enable-gprof) gprof="yes"
126 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
128 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
130 --enable-cross) build_cross="yes"
132 --disable-static) disable_static="yes"
134 --disable-rpath) disable_rpath="yes"
136 --strip-binaries) strip_binaries="yes"
138 --with-libgcc) use_libgcc="yes"
140 --with-selinux) have_selinux="yes"
142 --help|-h) show_help="yes"
144 *) echo "configure: WARNING: unrecognized option $opt"
146 esac
147 done
149 if test -z "$cpu" ; then
150 if test -n "$ARCH" ; then
151 cpu="$ARCH"
152 else
153 cpu=`uname -m`
157 case "$cpu" in
158 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
159 cpu="x86"
161 x86_64|amd64)
162 cpu="x86-64"
164 arm*)
165 case "$cpu" in
166 arm|armv4l)
167 cpuver=4
169 armv5tel|armv5tejl)
170 cpuver=5
172 armv6j|armv6l)
173 cpuver=6
175 armv7a|armv7l)
176 cpuver=7
178 esac
179 cpu="armv4l"
181 aarch64)
182 cpu="aarch64"
184 alpha)
185 cpu="alpha"
187 "Power Macintosh"|ppc|ppc64)
188 cpu="powerpc"
190 mips)
191 cpu="mips"
193 s390)
194 cpu="s390"
197 cpu="unknown"
199 esac
201 # Checking for CFLAGS
202 if test -z "$CFLAGS"; then
203 CFLAGS="-Wall -g -O2"
206 if test "$mingw32" = "yes" ; then
207 if test x"$tccdir" = x""; then
208 tccdir="tcc"
210 if test -z "$prefix" ; then
211 prefix="C:/Program Files/${tccdir}"
213 if test -z "$sharedir" ; then
214 sharedir="${prefix}"
216 execprefix="$prefix"
217 bindir="${prefix}"
218 tccdir="${prefix}"
219 libdir="${prefix}/lib"
220 docdir="${sharedir}/doc"
221 mandir="${sharedir}/man"
222 infodir="${sharedir}/info"
223 LIBSUF=".lib"
224 EXESUF=".exe"
225 else
226 if test -z "$prefix" ; then
227 prefix="/usr/local"
229 if test -z "$sharedir" ; then
230 sharedir="${prefix}/share"
232 if test x"$execprefix" = x""; then
233 execprefix="${prefix}"
235 if test x"$libdir" = x""; then
236 libdir="${execprefix}/lib"
238 if test x"$bindir" = x""; then
239 bindir="${execprefix}/bin"
241 if test x"$docdir" = x""; then
242 docdir="${sharedir}/doc"
244 if test x"$mandir" = x""; then
245 mandir="${sharedir}/man"
247 if test x"$infodir" = x""; then
248 infodir="${sharedir}/info"
250 if test x"$tccdir" = x""; then
251 tccdir="${libdir}/tcc"
253 fi # mingw32
255 if test x"$includedir" = x""; then
256 includedir="${prefix}/include"
259 if test x"$show_help" = "xyes" ; then
260 cat << EOF
261 Usage: configure [options]
262 Options: [defaults in brackets after descriptions]
264 Standard options:
265 --help print this message
266 --prefix=PREFIX install in PREFIX [$prefix]
267 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
268 [same as prefix]
269 --bindir=DIR user executables in DIR [EPREFIX/bin]
270 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
271 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
272 --includedir=DIR C header files in DIR [PREFIX/include]
273 --sharedir=DIR documentation root DIR [PREFIX/share]
274 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
275 --mandir=DIR man documentation in DIR [SHAREDIR/man]
276 --infodir=DIR info documentation in DIR [SHAREDIR/info]
278 Advanced options (experts only):
279 --source-path=PATH path of source code [$source_path]
280 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
281 --sysroot=PREFIX prepend PREFIX to library/include paths []
282 --cc=CC use C compiler CC [$cc]
283 --ar=AR create archives using AR [$ar]
284 --extra-cflags= specify compiler flags [$CFLAGS]
285 --extra-ldflags= specify linker options []
286 --cpu=CPU CPU [$cpu]
287 --strip-binaries strip symbol tables from resulting binaries
288 --disable-static make libtcc.so instead of libtcc.a
289 --disable-rpath disable use of -rpath with the above
290 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
291 --enable-mingw32 build windows version on linux with mingw32
292 --enable-cygwin build windows version on windows with cygwin
293 --enable-cross build cross compilers
294 --with-selinux use mmap for exec mem [needs writable /tmp]
295 --sysincludepaths=... specify system include paths, colon separated
296 --libpaths=... specify system library paths, colon separated
297 --crtprefix=... specify locations of crt?.o, colon separated
298 --elfinterp=... specify elf interpreter
299 --triplet=... specify system library/include directory triplet
301 #echo "NOTE: The object files are build at the place where configure is launched"
302 exit 1
305 cc="${cross_prefix}${cc}"
306 ar="${cross_prefix}${ar}"
307 strip="${cross_prefix}${strip}"
309 CONFTEST=./conftest$EXESUF
311 if test -z "$cross_prefix" ; then
312 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
313 echo "configure: error: '$cc' failed to compile conftest.c."
314 else
315 bigendian="$($CONFTEST bigendian)"
316 gcc_major="$($CONFTEST version)"
317 gcc_minor="$($CONFTEST minor)"
318 if test "$mingw32" = "no" ; then
320 if test -z "$triplet"; then
321 tt="$($CONFTEST triplet)"
322 if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
323 triplet="$tt"
327 if test -z "$triplet"; then
328 if test $cpu = "x86-64" -o $cpu = "aarch64" ; then
329 if test -f "/usr/lib64/crti.o" ; then
330 tcc_lddir="lib64"
335 if test "$cpu" = "armv4l" ; then
336 if test "${triplet%eabihf}" != "$triplet" ; then
337 confvars="$confvars arm_eabihf"
338 elif test "${triplet%eabi}" != "$triplet" ; then
339 confvars="$confvars arm_eabi"
341 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
342 confvars="$confvars arm_vfp"
346 if test -f "/lib/ld-uClibc.so.0" ; then
347 confvars="$confvars uClibc"
352 else
353 # if cross compiling, cannot launch a program, so make a static guess
354 case $cpu in
355 powerpc|mips|s390) bigendian=yes;;
356 esac
359 # a final configuration tuning
360 $cc -v --help > cc_help.txt 2>&1
361 W_OPTIONS="declaration-after-statement"
362 for i in $W_OPTIONS; do
363 O_PRESENT="$(grep -- -W$i cc_help.txt)"
364 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -W$i"; fi
365 done
366 W_OPTIONS="deprecated-declarations strict-aliasing pointer-sign sign-compare unused-result uninitialized"
367 for i in $W_OPTIONS; do
368 O_PRESENT="$(grep -- -W$i cc_help.txt)"
369 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -Wno-$i"; fi
370 done
371 F_OPTIONS="strict-aliasing"
372 for i in $F_OPTIONS; do
373 O_PRESENT="$(grep -- -f$i cc_help.txt)"
374 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -fno-$i"; fi
375 done
376 rm -f cc_help.txt
378 fcho() { if test -n "$2"; then echo "$1$2"; else echo "$1-"; fi }
380 echo "Binary directory $bindir"
381 echo "TinyCC directory $tccdir"
382 echo "Library directory $libdir"
383 echo "Include directory $includedir"
384 echo "Manual directory $mandir"
385 echo "Info directory $infodir"
386 echo "Doc directory $docdir"
387 fcho "Target root prefix " "$sysroot"
388 echo "Source path $source_path"
389 echo "C compiler $cc"
390 echo "Target OS $targetos"
391 echo "CPU $cpu"
392 echo "Big Endian $bigendian"
393 echo "Profiling $gprof"
394 echo "Cross compilers $build_cross"
395 echo "Use libgcc $use_libgcc"
396 fcho "Triplet " "$triplet"
398 echo "Creating config.mak and config.h"
400 cat >config.mak <<EOF
401 # Automatically generated by configure - do not modify
402 prefix=$prefix
403 bindir=\$(DESTDIR)$bindir
404 tccdir=\$(DESTDIR)$tccdir
405 libdir=\$(DESTDIR)$libdir
406 includedir=\$(DESTDIR)$includedir
407 mandir=\$(DESTDIR)$mandir
408 infodir=\$(DESTDIR)$infodir
409 docdir=\$(DESTDIR)$docdir
410 CC=$cc
411 GCC_MAJOR=$gcc_major
412 GCC_MINOR=$gcc_minor
413 AR=$ar
414 STRIP=$strip -s -R .comment -R .note
415 CFLAGS=$CFLAGS
416 LDFLAGS=$LDFLAGS
417 LIBSUF=$LIBSUF
418 EXESUF=$EXESUF
421 print_inc() {
422 if test -n "$2"; then
423 echo "#ifndef $1" >> $TMPH
424 echo "# define $1 \"$2\"" >> $TMPH
425 echo "#endif" >> $TMPH
428 print_mak() {
429 if test -n "$2"; then
430 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
434 echo "/* Automatically generated by configure - do not modify */" > $TMPH
436 print_inc CONFIG_SYSROOT "$sysroot"
437 print_inc CONFIG_TCCDIR "$tccdir"
438 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
439 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
440 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
441 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
442 print_mak CONFIG_LDDIR "$tcc_lddir"
443 print_mak CONFIG_TRIPLET "$triplet"
445 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
446 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
448 if test "$cpu" = "x86" ; then
449 echo "ARCH=i386" >> config.mak
450 elif test "$cpu" = "x86-64" ; then
451 echo "ARCH=x86-64" >> config.mak
452 elif test "$cpu" = "armv4l" ; then
453 echo "ARCH=arm" >> config.mak
454 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
455 elif test "$cpu" = "aarch64" ; then
456 echo "ARCH=arm64" >> config.mak
457 elif test "$cpu" = "powerpc" ; then
458 echo "ARCH=ppc" >> config.mak
459 elif test "$cpu" = "mips" ; then
460 echo "ARCH=mips" >> config.mak
461 elif test "$cpu" = "s390" ; then
462 echo "ARCH=s390" >> config.mak
463 elif test "$cpu" = "alpha" ; then
464 echo "ARCH=alpha" >> config.mak
465 else
466 echo "Unsupported CPU"
467 exit 1
470 echo "TARGETOS=$targetos" >> config.mak
472 for v in $confvars ; do
473 echo "CONFIG_$v=yes" >> config.mak
474 done
475 if test "$noldl" = "yes" ; then
476 echo "CONFIG_NOLDL=yes" >> config.mak
478 if test "$mingw32" = "yes" ; then
479 echo "CONFIG_WIN32=yes" >> config.mak
481 if test "$cygwin" = "yes" ; then
482 echo "#ifndef _WIN32" >> $TMPH
483 echo "# define _WIN32" >> $TMPH
484 echo "#endif" >> $TMPH
485 echo "AR=ar" >> config.mak
487 if test "$bigendian" = "yes" ; then
488 echo "WORDS_BIGENDIAN=yes" >> config.mak
489 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
491 if test "$gprof" = "yes" ; then
492 echo "TARGET_GPROF=yes" >> config.mak
493 echo "#define HAVE_GPROF 1" >> $TMPH
495 if test "$build_cross" = "yes" ; then
496 echo "CONFIG_CROSS=yes" >> config.mak
498 if test "$disable_static" = "yes" ; then
499 echo "DISABLE_STATIC=yes" >> config.mak
501 if test "$disable_rpath" = "yes" ; then
502 echo "DISABLE_RPATH=yes" >> config.mak
504 if test "$strip_binaries" = "yes" ; then
505 echo "STRIP_BINARIES=yes" >> config.mak
507 if test "$use_libgcc" = "yes" ; then
508 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
509 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
511 if test "$have_selinux" = "yes" ; then
512 echo "#define HAVE_SELINUX" >> $TMPH
513 echo "HAVE_SELINUX=yes" >> config.mak
516 version=`head $source_path/VERSION`
517 echo "VERSION = $version" >> config.mak
518 echo "#define TCC_VERSION \"$version\"" >> $TMPH
519 echo "@set VERSION $version" > config.texi
521 if test "$source_path_used" = "yes" ; then
522 case $source_path in
523 /*) echo "TOPSRC=$source_path";;
524 *) echo "TOPSRC=\$(TOP)/$source_path";;
525 esac >>config.mak
526 else
527 echo 'TOPSRC=$(TOP)' >>config.mak
530 diff $TMPH config.h >/dev/null 2>&1
531 if test $? -ne 0 ; then
532 mv -f $TMPH config.h
533 else
534 echo "config.h is unchanged"
537 rm -f $TMPN* $CONFTEST
539 # ---------------------------------------------------------------------------
540 # build tree in object directory if source path is different from current one
542 fn_makelink()
544 tgt=$1/$2
545 case $2 in
546 */*) dn=${2%/*}
547 test -d $dn || mkdir -p $dn
548 case $1 in
549 /*) ;;
550 *) while test $dn ; do
551 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
552 done
554 esac
556 esac
558 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
561 if test "$source_path_used" = "yes" ; then
562 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
563 for f in $FILES ; do
564 fn_makelink $source_path $f
565 done
568 # ---------------------------------------------------------------------------