win32: wchar.h: don't redifine WCHAR_MIN[/MAX] (after stdint.h)
[tinycc.git] / configure
blob5e467b6d2ed928d64350bf1bd63a6f06b103177c
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 host_os=`uname`
52 case $host_os in
53 MINGW32*) host_os=Windows; ;;
54 *) ;;
55 esac
57 # OS specific
58 targetos=`uname`
59 case $targetos in
60 MINGW32*) mingw32=yes; host_os=Windows; ;;
61 DragonFly) noldl=yes;;
62 OpenBSD) noldl=yes;;
63 FreeBSD) noldl=yes;;
64 NetBSD) noldl=yes;;
65 *) ;;
66 esac
68 # find source path
69 # XXX: we assume an absolute path is given when launching configure,
70 # except in './configure' case.
71 source_path=${0%configure}
72 source_path=${source_path%/}
73 source_path_used="yes"
74 if test -z "$source_path" -o "$source_path" = "." ; then
75 source_path=`pwd`
76 source_path_used="no"
79 classify_cpu ()
81 cpu="$1"
83 case "$cpu" in
84 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
85 cpu="x86"
87 x86_64|amd64)
88 cpu="x86-64"
90 arm*)
91 case "$cpu" in
92 arm|armv4l)
93 cpuver=4
95 armv5tel|armv5tejl)
96 cpuver=5
98 armv6j|armv6l)
99 cpuver=6
101 armv7a|armv7l)
102 cpuver=7
104 esac
105 cpu="armv4l"
107 aarch64)
108 cpu="aarch64"
110 alpha)
111 cpu="alpha"
113 "Power Macintosh"|ppc|ppc64)
114 cpu="powerpc"
116 mips)
117 cpu="mips"
119 s390)
120 cpu="s390"
123 echo "Unsupported CPU: $cpu"
124 exit 1
126 esac
129 for opt do
130 eval opt=\"$opt\"
131 case "$opt" in
132 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
134 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
136 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
138 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
140 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
142 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
144 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
146 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
148 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
150 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
152 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
154 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
156 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
158 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
160 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
162 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
164 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
166 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
168 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
170 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
172 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
174 --extra-libs=*) extralibs=${opt#--extra-libs=}
176 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
178 --enable-gprof) gprof="yes"
180 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86; targetos=Windows;
182 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86; targetos=Windows;
184 --enable-tcc32-mingw) mingw32="yes" ; cross_prefix="i386-win-" ; cpu=x86; cc=tcc; targetos=Windows;
186 --enable-tcc64-mingw) mingw32="yes" ; cross_prefix="x86_64-win-" ; cpu=x86_64; cc=tcc; targetos=Windows;
188 --enable-cross) build_cross="yes"
190 --enable-assert) enable_assert="yes"
192 --disable-static) disable_static="yes"
194 --disable-rpath) disable_rpath="yes"
196 --strip-binaries) strip_binaries="yes"
198 --with-libgcc) use_libgcc="yes"
200 --with-selinux) have_selinux="yes"
202 --help|-h) show_help="yes"
204 *) echo "configure: WARNING: unrecognized option $opt"
206 esac
207 done
209 if test -z "$cpu" ; then
210 if test -n "$ARCH" ; then
211 cpu="$ARCH"
212 else
213 cpu=`uname -m`
216 classify_cpu "$cpu"
218 # Checking for CFLAGS
219 if test -z "$CFLAGS"; then
220 CFLAGS="-Wall -g -O0"
223 if test "$mingw32" = "yes" ; then
224 if test x"$tccdir" = x""; then
225 tccdir="tcc"
227 if test -z "$prefix" ; then
228 prefix="C:/Program Files/${tccdir}"
230 if test -z "$sharedir" ; then
231 sharedir="${prefix}"
233 execprefix="$prefix"
234 bindir="${prefix}"
235 tccdir="${prefix}"
236 libdir="${prefix}/lib"
237 docdir="${sharedir}/doc"
238 mandir="${sharedir}/man"
239 infodir="${sharedir}/info"
240 LIBSUF=".lib"
241 EXESUF=".exe"
242 else
243 if test -z "$prefix" ; then
244 prefix="/usr/local"
246 if test -z "$sharedir" ; then
247 sharedir="${prefix}/share"
249 if test x"$execprefix" = x""; then
250 execprefix="${prefix}"
252 if test x"$tccdir" = x""; then
253 tccdir="tcc"
255 if test x"$libdir" = x""; then
256 libdir="${execprefix}/lib"
257 if test -n "${tccdir}"; then
258 tccdir="${libdir}/${tccdir}"
259 else
260 tccdir="${libdir}"
262 if test "$cpu" = "x86-64"; then
263 libdir="${execprefix}/lib64"
265 else
266 tccdir="${libdir}/${tccdir}"
268 if test x"$bindir" = x""; then
269 bindir="${execprefix}/bin"
271 if test x"$docdir" = x""; then
272 docdir="${sharedir}/doc"
274 if test x"$mandir" = x""; then
275 mandir="${sharedir}/man"
277 if test x"$infodir" = x""; then
278 infodir="${sharedir}/info"
280 fi # mingw32
282 if test x"$includedir" = x""; then
283 includedir="${prefix}/include"
286 if test x"$show_help" = "xyes" ; then
287 cat << EOF
288 Usage: configure [options]
289 Options: [defaults in brackets after descriptions]
291 Standard options:
292 --help print this message
293 --prefix=PREFIX install in PREFIX [$prefix]
294 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
295 [same as prefix]
296 --bindir=DIR user executables in DIR [EPREFIX/bin]
297 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
298 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
299 --includedir=DIR C header files in DIR [PREFIX/include]
300 --sharedir=DIR documentation root DIR [PREFIX/share]
301 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
302 --mandir=DIR man documentation in DIR [SHAREDIR/man]
303 --infodir=DIR info documentation in DIR [SHAREDIR/info]
305 Advanced options (experts only):
306 --source-path=PATH path of source code [$source_path]
307 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
308 --sysroot=PREFIX prepend PREFIX to library/include paths []
309 --cc=CC use C compiler CC [$cc]
310 --ar=AR create archives using AR [$ar]
311 --extra-cflags= specify compiler flags [$CFLAGS]
312 --extra-ldflags= specify linker options []
313 --cpu=CPU CPU [$cpu]
314 --strip-binaries strip symbol tables from resulting binaries
315 --disable-static make libtcc.so instead of libtcc.a
316 --disable-rpath disable use of -rpath with the above
317 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
318 --enable-tcc64-mingw build windows version on linux with x86_64-win-tcc
319 --enable-tcc32-mingw build windows version on linux with i386-win-tcc
320 --enable-mingw32 build windows version on linux with mingw32
321 --enable-cygwin build windows version on windows with cygwin
322 --enable-cross build cross compilers
323 --enable-assert enable debug assertions
324 --with-selinux use mmap for exec mem [needs writable /tmp]
325 --sysincludepaths=... specify system include paths, colon separated
326 --libpaths=... specify system library paths, colon separated
327 --crtprefix=... specify locations of crt?.o, colon separated
328 --elfinterp=... specify elf interpreter
330 #echo "NOTE: The object files are build at the place where configure is launched"
331 exit 1
334 if test "$cc" != "tcc"; then
335 ar="${cross_prefix}${ar}"
337 cc="${cross_prefix}${cc}"
338 strip="${cross_prefix}${strip}"
340 CONFTEST=./conftest$EXESUF
342 if test -z "$cross_prefix" ; then
343 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
344 echo "configure: error: '$cc' failed to compile conftest.c."
345 else
346 bigendian="$($CONFTEST bigendian)"
347 gcc_major="$($CONFTEST version)"
348 gcc_minor="$($CONFTEST minor)"
349 if test "$mingw32" = "no" ; then
350 triplet="$($CONFTEST triplet)"
351 if test -f "/usr/lib/$triplet/crti.o" ; then
352 tcc_lddir="lib"
353 multiarch_triplet="$triplet"
354 elif test "$cpu" != "x86" -a -f "/usr/lib64/crti.o" ; then
355 tcc_lddir="lib64"
358 if test "$cpu" = "armv4l" ; then
359 if test "${triplet%eabihf}" != "$triplet" ; then
360 confvars="$confvars arm_eabihf"
361 elif test "${triplet%eabi}" != "$triplet" ; then
362 confvars="$confvars arm_eabi"
364 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
365 confvars="$confvars arm_vfp"
369 # multiarch_triplet=${libc_dir#*/}
370 # multiarch_triplet=${multiarch_triplet%/}
371 # tcc_lddir="${libc_dir%%/*}"
372 # if test -n "$multiarch_triplet" ; then
373 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
374 # fi
376 if test -f "/lib/ld-uClibc.so.0" ; then
377 confvars="$confvars uClibc"
379 # gr: maybe for after the release:
380 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
381 # echo "elfinterp $tcc_elfinterp"
385 else
386 # if cross compiling, cannot launch a program, so make a static guess
387 case $cpu in
388 powerpc|mips|s390) bigendian=yes;;
389 esac
392 # a final configuration tuning
393 W_OPTIONS="declaration-after-statement"
394 for i in $W_OPTIONS; do
395 O_PRESENT="$($cc -v --help 2>&1 | grep -- -W$i)"
396 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -W$i"; fi
397 done
398 W_OPTIONS="deprecated-declarations strict-aliasing pointer-sign sign-compare unused-result uninitialized"
399 for i in $W_OPTIONS; do
400 O_PRESENT="$($cc -v --help 2>&1 | grep -- -W$i)"
401 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -Wno-$i"; fi
402 done
403 F_OPTIONS="strict-aliasing"
404 for i in $F_OPTIONS; do
405 O_PRESENT="$($cc -v --help 2>&1 | grep -- -f$i)"
406 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -fno-$i"; fi
407 done
408 if test -z "$tcc_lddir" -a "$cpu" = "x86-64"; then tcc_lddir="lib64"; fi
410 echo "Binary directory $bindir"
411 echo "TinyCC directory $tccdir"
412 echo "Library directory $libdir"
413 echo "Include directory $includedir"
414 echo "Manual directory $mandir"
415 echo "Info directory $infodir"
416 echo "Doc directory $docdir"
417 echo "Target root prefix $sysroot"
418 echo "Source path $source_path"
419 echo "C compiler $cc"
420 echo "ar $ar"
421 echo "cross compilers $build_cross"
422 if test "$build_cross" = "no"; then
423 echo "Target CPU $cpu"
425 echo "Host OS $host_os"
426 echo "Target OS $targetos"
427 echo "Big Endian $bigendian"
428 echo "gprof enabled $gprof"
429 echo "use libgcc $use_libgcc"
431 echo "Creating config.mak and config.h"
433 cat >config.mak <<EOF
434 # Automatically generated by configure - do not modify
435 prefix=$prefix
436 bindir=\$(DESTDIR)$bindir
437 tccdir=\$(DESTDIR)$tccdir
438 libdir=\$(DESTDIR)$libdir
439 ln_libdir=$libdir
440 includedir=\$(DESTDIR)$includedir
441 mandir=\$(DESTDIR)$mandir
442 infodir=\$(DESTDIR)$infodir
443 docdir=\$(DESTDIR)$docdir
444 CC=$cc
445 GCC_MAJOR=$gcc_major
446 GCC_MINOR=$gcc_minor
447 HOST_CC=$host_cc
448 AR=$ar
449 STRIP=$strip -s -R .comment -R .note
450 CFLAGS=$CFLAGS
451 LDFLAGS=$LDFLAGS
452 LIBSUF=$LIBSUF
453 EXESUF=$EXESUF
454 HOST_OS=$host_os
456 if test "$mingw32" = "yes" -a "$host_os" != "Windows" ; then
457 cat >>config.mak <<EOF
458 XCC=$cc
459 XAR=$ar
463 print_inc() {
464 if test -n "$2"; then
465 echo "#ifndef $1" >> $TMPH
466 echo "# define $1 \"$2\"" >> $TMPH
467 echo "#endif" >> $TMPH
470 print_mak() {
471 if test -n "$2"; then
472 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
476 echo "/* Automatically generated by configure - do not modify */" > $TMPH
478 print_inc CONFIG_SYSROOT "$sysroot"
479 print_inc CONFIG_TCCDIR "$tccdir"
480 if test "$build_cross" = "no"; then
481 print_inc CONFIG_LDDIR "$tcc_lddir"
483 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
484 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
485 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
486 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
487 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
489 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
490 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
492 if test "$cpu" = "x86" ; then
493 echo "ARCH=i386" >> config.mak
494 elif test "$cpu" = "x86-64" ; then
495 echo "ARCH=x86-64" >> config.mak
496 elif test "$cpu" = "armv4l" ; then
497 echo "ARCH=arm" >> config.mak
498 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
499 elif test "$cpu" = "aarch64" ; then
500 echo "ARCH=arm64" >> config.mak
501 elif test "$cpu" = "powerpc" ; then
502 echo "ARCH=ppc" >> config.mak
503 elif test "$cpu" = "mips" ; then
504 echo "ARCH=mips" >> config.mak
505 elif test "$cpu" = "s390" ; then
506 echo "ARCH=s390" >> config.mak
507 elif test "$cpu" = "alpha" ; then
508 echo "ARCH=alpha" >> config.mak
509 else
510 echo "Unsupported CPU"
511 exit 1
514 echo "TARGETOS=$targetos" >> config.mak
516 for v in $confvars ; do
517 echo "CONFIG_$v=yes" >> config.mak
518 done
519 if test "$noldl" = "yes" ; then
520 echo "CONFIG_NOLDL=yes" >> config.mak
522 if test "$mingw32" = "yes" ; then
523 if test "$cpu" = "x86-64"; then
524 echo "CONFIG_WIN64=yes" >> config.mak
525 echo "#define CONFIG_WIN64 1" >> $TMPH
526 else
527 echo "CONFIG_WIN32=yes" >> config.mak
528 echo "#define CONFIG_WIN32 1" >> $TMPH
531 if test "$cygwin" = "yes" ; then
532 echo "#ifndef _WIN32" >> $TMPH
533 echo "# define _WIN32" >> $TMPH
534 echo "#endif" >> $TMPH
535 echo "AR=ar" >> config.mak
537 if test "$bigendian" = "yes" ; then
538 echo "WORDS_BIGENDIAN=yes" >> config.mak
539 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
541 if test "$gprof" = "yes" ; then
542 echo "TARGET_GPROF=yes" >> config.mak
543 echo "#define HAVE_GPROF 1" >> $TMPH
545 if test "$build_cross" = "yes" ; then
546 echo "CONFIG_CROSS=yes" >> config.mak
548 if test "$disable_static" = "yes" ; then
549 echo "DISABLE_STATIC=yes" >> config.mak
551 if test "$disable_rpath" = "yes" ; then
552 echo "DISABLE_RPATH=yes" >> config.mak
554 if test "$strip_binaries" = "yes" ; then
555 echo "STRIP_BINARIES=yes" >> config.mak
557 if test "$use_libgcc" = "yes" ; then
558 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
559 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
561 if test "$have_selinux" = "yes" ; then
562 echo "#define HAVE_SELINUX" >> $TMPH
563 echo "HAVE_SELINUX=yes" >> config.mak
565 if test "$enable_assert" = "yes" ; then
566 echo "#define CONFIG_TCC_ASSERT" >> $TMPH
569 version=`head $source_path/VERSION`
570 echo "VERSION=$version" >>config.mak
571 echo "#define TCC_VERSION \"$version\"" >> $TMPH
572 echo "@set VERSION $version" > config.texi
573 echo "SRC_PATH=$source_path" >>config.mak
575 if test "$source_path_used" = "yes" ; then
576 case $source_path in
577 /*) echo "top_srcdir=$source_path";;
578 *) echo "top_srcdir=\$(TOP)/$source_path";;
579 esac >>config.mak
580 else
581 echo 'top_srcdir=$(TOP)' >>config.mak
583 echo 'top_builddir=$(TOP)' >>config.mak
585 diff $TMPH config.h >/dev/null 2>&1
586 if test $? -ne 0 ; then
587 mv -f $TMPH config.h
588 else
589 echo "config.h is unchanged"
592 rm -f $TMPN* $CONFTEST
594 # ---------------------------------------------------------------------------
595 # build tree in object directory if source path is different from current one
597 fn_makelink()
599 SRCDIR=$(realpath $1)
600 DIR=$(dirname $2)
601 FILE=$(basename $2)
602 if test ! -d "$DIR"; then
603 mkdir -p "$DIR"
605 ln -s $SRCDIR/$DIR/$FILE $DIR/
608 if test "$source_path_used" = "yes" ; then
609 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/* tests/pp/* tests/exsymtab/*"
610 for f in $FILES ; do
611 fn_makelink $source_path $f
612 done
615 # ---------------------------------------------------------------------------