gcc options and mingw: move a gcc options detection from a makefile to the configure
[tinycc.git] / configure
blob3637252d62104d15739990555338a04146366c39
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 enable_assert="no"
23 prefix=""
24 execprefix=""
25 bindir=""
26 libdir=""
27 tccdir=""
28 includedir=""
29 mandir=""
30 infodir=""
31 sysroot=""
32 cross_prefix=""
33 cc="gcc"
34 host_cc="gcc"
35 ar="ar"
36 strip="strip"
37 cygwin="no"
38 gprof="no"
39 bigendian="no"
40 mingw32="no"
41 LIBSUF=".a"
42 EXESUF=""
43 tcc_sysincludepaths=""
44 tcc_libpaths=""
45 tcc_crtprefix=""
46 tcc_elfinterp=""
47 tcc_lddir=
48 confvars=
49 cpu=
51 # OS specific
52 targetos=`uname -s`
53 case $targetos in
54 MINGW32*) 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 classify_cpu ()
75 cpu="$1"
77 case "$cpu" in
78 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
79 cpu="x86"
81 x86_64|amd64)
82 cpu="x86-64"
84 arm*)
85 case "$cpu" in
86 arm|armv4l)
87 cpuver=4
89 armv5tel|armv5tejl)
90 cpuver=5
92 armv6j|armv6l)
93 cpuver=6
95 armv7a|armv7l)
96 cpuver=7
98 esac
99 cpu="armv4l"
101 aarch64)
102 cpu="aarch64"
104 alpha)
105 cpu="alpha"
107 "Power Macintosh"|ppc|ppc64)
108 cpu="powerpc"
110 mips)
111 cpu="mips"
113 s390)
114 cpu="s390"
117 echo "Unsupported CPU: $cpu"
118 exit 1
120 esac
123 for opt do
124 eval opt=\"$opt\"
125 case "$opt" in
126 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
128 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
130 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
132 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
134 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
136 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
138 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
140 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
142 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
144 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
146 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
148 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
150 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
152 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
154 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
156 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
158 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
160 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
162 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
164 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
166 --extra-libs=*) extralibs=${opt#--extra-libs=}
168 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
170 --enable-gprof) gprof="yes"
172 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
174 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
176 --enable-cross) build_cross="yes"
178 --enable-assert) enable_assert="yes"
180 --disable-static) disable_static="yes"
182 --disable-rpath) disable_rpath="yes"
184 --strip-binaries) strip_binaries="yes"
186 --with-libgcc) use_libgcc="yes"
188 --with-selinux) have_selinux="yes"
190 --help|-h) show_help="yes"
192 *) echo "configure: WARNING: unrecognized option $opt"
194 esac
195 done
197 if test -z "$cpu" ; then
198 if test -n "$ARCH" ; then
199 cpu="$ARCH"
200 else
201 cpu=`uname -m`
204 classify_cpu "$cpu"
206 # Checking for CFLAGS
207 if test -z "$CFLAGS"; then
208 CFLAGS="-Wall -g -O2"
211 if test "$mingw32" = "yes" ; then
212 if test x"$tccdir" = x""; then
213 tccdir="tcc"
215 if test -z "$prefix" ; then
216 prefix="C:/Program Files/${tccdir}"
218 if test -z "$sharedir" ; then
219 sharedir="${prefix}"
221 execprefix="$prefix"
222 bindir="${prefix}"
223 tccdir="${prefix}"
224 libdir="${prefix}/lib"
225 docdir="${sharedir}/doc"
226 mandir="${sharedir}/man"
227 infodir="${sharedir}/info"
228 LIBSUF=".lib"
229 EXESUF=".exe"
230 else
231 if test -z "$prefix" ; then
232 prefix="/usr/local"
234 if test -z "$sharedir" ; then
235 sharedir="${prefix}/share"
237 if test x"$execprefix" = x""; then
238 execprefix="${prefix}"
240 if test x"$tccdir" = x""; then
241 tccdir="tcc"
243 if test x"$libdir" = x""; then
244 libdir="${execprefix}/lib"
245 if test -n "${tccdir}"; then
246 tccdir="${libdir}/${tccdir}"
247 else
248 tccdir="${libdir}"
250 if test "$cpu" = "x86-64"; then
251 libdir="${execprefix}/lib64"
253 else
254 tccdir="${libdir}/${tccdir}"
256 if test x"$bindir" = x""; then
257 bindir="${execprefix}/bin"
259 if test x"$docdir" = x""; then
260 docdir="${sharedir}/doc/${tccdir}"
262 if test x"$mandir" = x""; then
263 mandir="${sharedir}/man"
265 if test x"$infodir" = x""; then
266 infodir="${sharedir}/info"
268 fi # mingw32
270 if test x"$includedir" = x""; then
271 includedir="${prefix}/include"
274 if test x"$show_help" = "xyes" ; then
275 cat << EOF
276 Usage: configure [options]
277 Options: [defaults in brackets after descriptions]
279 Standard options:
280 --help print this message
281 --prefix=PREFIX install in PREFIX [$prefix]
282 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
283 [same as prefix]
284 --bindir=DIR user executables in DIR [EPREFIX/bin]
285 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
286 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
287 --includedir=DIR C header files in DIR [PREFIX/include]
288 --sharedir=DIR documentation root DIR [PREFIX/share]
289 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
290 --mandir=DIR man documentation in DIR [SHAREDIR/man]
291 --infodir=DIR info documentation in DIR [SHAREDIR/info]
293 Advanced options (experts only):
294 --source-path=PATH path of source code [$source_path]
295 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
296 --sysroot=PREFIX prepend PREFIX to library/include paths []
297 --cc=CC use C compiler CC [$cc]
298 --extra-cflags= specify compiler flags [$CFLAGS]
299 --extra-ldflags= specify linker options []
300 --cpu=CPU CPU [$cpu]
301 --strip-binaries strip symbol tables from resulting binaries
302 --disable-static make libtcc.so instead of libtcc.a
303 --disable-rpath disable use of -rpath with the above
304 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
305 --enable-mingw32 build windows version on linux with mingw32
306 --enable-cygwin build windows version on windows with cygwin
307 --enable-cross build cross compilers
308 --enable-assert enable debug assertions
309 --with-selinux use mmap for exec mem [needs writable /tmp]
310 --sysincludepaths=... specify system include paths, colon separated
311 --libpaths=... specify system library paths, colon separated
312 --crtprefix=... specify locations of crt?.o, colon separated
313 --elfinterp=... specify elf interpreter
315 #echo "NOTE: The object files are build at the place where configure is launched"
316 exit 1
319 cc="${cross_prefix}${cc}"
320 ar="${cross_prefix}${ar}"
321 strip="${cross_prefix}${strip}"
323 CONFTEST=./conftest$EXESUF
325 if test -z "$cross_prefix" ; then
326 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
327 echo "configure: error: '$cc' failed to compile conftest.c."
328 else
329 bigendian="$($CONFTEST bigendian)"
330 gcc_major="$($CONFTEST version)"
331 gcc_minor="$($CONFTEST minor)"
332 if test "$mingw32" = "no" ; then
333 triplet="$($CONFTEST triplet)"
334 if test -f "/usr/lib/$triplet/crti.o" ; then
335 tcc_lddir="lib"
336 multiarch_triplet="$triplet"
337 elif test "$cpu" != "x86" -a -f "/usr/lib64/crti.o" ; then
338 tcc_lddir="lib64"
341 if test "$cpu" = "armv4l" ; then
342 if test "${triplet%eabihf}" != "$triplet" ; then
343 confvars="$confvars arm_eabihf"
344 elif test "${triplet%eabi}" != "$triplet" ; then
345 confvars="$confvars arm_eabi"
347 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
348 confvars="$confvars arm_vfp"
352 # multiarch_triplet=${libc_dir#*/}
353 # multiarch_triplet=${multiarch_triplet%/}
354 # tcc_lddir="${libc_dir%%/*}"
355 # if test -n "$multiarch_triplet" ; then
356 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
357 # fi
359 if test -f "/lib/ld-uClibc.so.0" ; then
360 confvars="$confvars uClibc"
362 # gr: maybe for after the release:
363 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
364 # echo "elfinterp $tcc_elfinterp"
368 else
369 # if cross compiling, cannot launch a program, so make a static guess
370 case $cpu in
371 powerpc|mips|s390) bigendian=yes;;
372 esac
375 # a final configuration tuning
376 W_OPTIONS="deprecated-declarations strict-aliasing pointer-sign sign-compare unused-result uninitialized"
377 for i in $W_OPTIONS; do
378 O_PRESENT="$($cc -v --help 2>&1 | grep -- -W$i)"
379 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -Wno-$i"; fi
380 done
381 F_OPTIONS="strict-aliasing"
382 for i in $F_OPTIONS; do
383 O_PRESENT="$($cc -v --help 2>&1 | grep -- -f$i)"
384 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -fno-$i"; fi
385 done
386 if test -z "$tcc_lddir" -a "$cpu" = "x86-64"; then tcc_lddir="lib64"; fi
388 echo "Binary directory $bindir"
389 echo "TinyCC directory $tccdir"
390 echo "Library directory $libdir"
391 echo "Include directory $includedir"
392 echo "Manual directory $mandir"
393 echo "Info directory $infodir"
394 echo "Doc directory $docdir"
395 echo "Target root prefix $sysroot"
396 echo "Source path $source_path"
397 echo "C compiler $cc"
398 echo "cross compilers $build_cross"
399 if test "$build_cross" = "no"; then
400 echo "Target CPU $cpu"
402 echo "Target OS $targetos"
403 echo "Big Endian $bigendian"
404 echo "gprof enabled $gprof"
405 echo "use libgcc $use_libgcc"
407 echo "Creating config.mak and config.h"
409 cat >config.mak <<EOF
410 # Automatically generated by configure - do not modify
411 prefix=$prefix
412 bindir=\$(DESTDIR)$bindir
413 tccdir=\$(DESTDIR)$tccdir
414 libdir=\$(DESTDIR)$libdir
415 ln_libdir=$libdir
416 includedir=\$(DESTDIR)$includedir
417 mandir=\$(DESTDIR)$mandir
418 infodir=\$(DESTDIR)$infodir
419 docdir=\$(DESTDIR)$docdir
420 CC=$cc
421 GCC_MAJOR=$gcc_major
422 GCC_MINOR=$gcc_minor
423 HOST_CC=$host_cc
424 AR=$ar
425 STRIP=$strip -s -R .comment -R .note
426 CFLAGS=$CFLAGS
427 LDFLAGS=$LDFLAGS
428 LIBSUF=$LIBSUF
429 EXESUF=$EXESUF
431 if test "$mingw32" = "yes"; then
432 cat >>config.mak <<EOF
433 XCC=$cc
434 XAR=$ar
438 print_inc() {
439 if test -n "$2"; then
440 echo "#ifndef $1" >> $TMPH
441 echo "# define $1 \"$2\"" >> $TMPH
442 echo "#endif" >> $TMPH
445 print_mak() {
446 if test -n "$2"; then
447 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
451 echo "/* Automatically generated by configure - do not modify */" > $TMPH
453 print_inc CONFIG_SYSROOT "$sysroot"
454 print_inc CONFIG_TCCDIR "$tccdir"
455 print_inc CONFIG_LDDIR "$tcc_lddir"
456 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
457 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
458 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
459 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
460 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
462 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
463 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
465 if test "$cpu" = "x86" ; then
466 echo "ARCH=i386" >> config.mak
467 elif test "$cpu" = "x86-64" ; then
468 echo "ARCH=x86-64" >> config.mak
469 elif test "$cpu" = "armv4l" ; then
470 echo "ARCH=arm" >> config.mak
471 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
472 elif test "$cpu" = "aarch64" ; then
473 echo "ARCH=arm64" >> config.mak
474 elif test "$cpu" = "powerpc" ; then
475 echo "ARCH=ppc" >> config.mak
476 elif test "$cpu" = "mips" ; then
477 echo "ARCH=mips" >> config.mak
478 elif test "$cpu" = "s390" ; then
479 echo "ARCH=s390" >> config.mak
480 elif test "$cpu" = "alpha" ; then
481 echo "ARCH=alpha" >> config.mak
482 else
483 echo "Unsupported CPU"
484 exit 1
487 echo "TARGETOS=$targetos" >> config.mak
489 for v in $confvars ; do
490 echo "CONFIG_$v=yes" >> config.mak
491 done
492 if test "$noldl" = "yes" ; then
493 echo "CONFIG_NOLDL=yes" >> config.mak
495 if test "$mingw32" = "yes" ; then
496 echo "CONFIG_WIN32=yes" >> config.mak
497 echo "#define CONFIG_WIN32 1" >> $TMPH
499 if test "$cygwin" = "yes" ; then
500 echo "#ifndef _WIN32" >> $TMPH
501 echo "# define _WIN32" >> $TMPH
502 echo "#endif" >> $TMPH
503 echo "AR=ar" >> config.mak
505 if test "$bigendian" = "yes" ; then
506 echo "WORDS_BIGENDIAN=yes" >> config.mak
507 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
509 if test "$gprof" = "yes" ; then
510 echo "TARGET_GPROF=yes" >> config.mak
511 echo "#define HAVE_GPROF 1" >> $TMPH
513 if test "$build_cross" = "yes" ; then
514 echo "CONFIG_CROSS=yes" >> config.mak
516 if test "$disable_static" = "yes" ; then
517 echo "DISABLE_STATIC=yes" >> config.mak
519 if test "$disable_rpath" = "yes" ; then
520 echo "DISABLE_RPATH=yes" >> config.mak
522 if test "$strip_binaries" = "yes" ; then
523 echo "STRIP_BINARIES=yes" >> config.mak
525 if test "$use_libgcc" = "yes" ; then
526 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
527 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
529 if test "$have_selinux" = "yes" ; then
530 echo "#define HAVE_SELINUX" >> $TMPH
531 echo "HAVE_SELINUX=yes" >> config.mak
533 if test "$enable_assert" = "yes" ; then
534 echo "#define CONFIG_TCC_ASSERT" >> $TMPH
537 version=`head $source_path/VERSION`
538 echo "VERSION=$version" >>config.mak
539 echo "#define TCC_VERSION \"$version\"" >> $TMPH
540 echo "@set VERSION $version" > config.texi
541 echo "SRC_PATH=$source_path" >>config.mak
543 if test "$source_path_used" = "yes" ; then
544 case $source_path in
545 /*) echo "top_srcdir=$source_path";;
546 *) echo "top_srcdir=\$(TOP)/$source_path";;
547 esac >>config.mak
548 else
549 echo 'top_srcdir=$(TOP)' >>config.mak
551 echo 'top_builddir=$(TOP)' >>config.mak
553 diff $TMPH config.h >/dev/null 2>&1
554 if test $? -ne 0 ; then
555 mv -f $TMPH config.h
556 else
557 echo "config.h is unchanged"
560 rm -f $TMPN* $CONFTEST
562 # ---------------------------------------------------------------------------
563 # build tree in object directory if source path is different from current one
565 fn_makelink()
567 tgt=$1/$2
568 case $2 in
569 */*) dn=${2%/*}
570 test -d $dn || mkdir -p $dn
571 case $1 in
572 /*) ;;
573 *) while test $dn ; do
574 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
575 done
577 esac
579 esac
580 ln -sfn $tgt $2
583 if test "$source_path_used" = "yes" ; then
584 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
585 for f in $FILES ; do
586 fn_makelink $source_path $f
587 done
590 # ---------------------------------------------------------------------------