Fix cast_test for clang.
[tinycc.git] / configure
blobde55672e4e8594b2206751c19142a0a4a7cb0043
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 prefix=""
21 execprefix=""
22 bindir=""
23 libdir=""
24 tccdir=""
25 includedir=""
26 mandir=""
27 infodir=""
28 sysroot=""
29 cross_prefix=""
30 cc="gcc"
31 ar="ar"
32 strip="strip"
33 bigendian="no"
34 mingw32="no"
35 LIBSUF=".a"
36 EXESUF=""
37 DLLSUF=".so"
38 tcc_usrinclude=""
39 tcc_sysincludepaths=""
40 tcc_libpaths=""
41 tcc_crtprefix=""
42 tcc_elfinterp=""
43 triplet=
44 tcc_lddir=
45 confvars=
46 suggest="yes"
47 cpu=
48 cpuver=
49 gcc_major=0
50 gcc_minor=0
51 gcc_name="gcc"
53 # OS specific
54 targetos=`uname`
55 case $targetos in
56 Darwin)
57 confvars="$confvars OSX"
58 cc=`which cc`
59 cc=`readlink $cc`
60 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
61 DLLSUF=".dylib"
63 Windows_NT|MINGW*|MSYS*|CYGWIN*)
64 mingw32=yes
66 DragonFly|OpenBSD|FreeBSD|NetBSD)
67 confvars="$confvars ldl=no"
71 esac
73 # find source path
74 source_path=${0%configure}
75 source_path=${source_path%/}
76 source_path_used="yes"
77 if test -z "$source_path" -o "$source_path" = "." ; then
78 source_path=`pwd`
79 source_path_used="no"
82 for opt do
83 eval opt=\"$opt\"
84 case "$opt" in
85 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
87 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
89 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
91 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
93 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
95 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
97 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
99 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
101 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
103 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
105 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
107 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
109 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
111 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
113 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
115 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
117 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
119 --extra-libs=*) extralibs="${opt#--extra-libs=}"
121 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
123 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
125 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
127 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
129 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
131 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
133 --enable-cross) confvars="$confvars cross"
135 --disable-static) confvars="$confvars static=no"
137 --enable-static) confvars="$confvars static"
139 --disable-rpath) confvars="$confvars rpath=no"
141 --strip-binaries) confvars="$confvars strip"
143 --debug) confvars="$confvars strip=no"
145 --with-libgcc) confvars="$confvars libgcc"
147 --with-selinux) confvars="$confvars selinux"
149 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
151 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
153 --help|-h) show_help="yes"
155 *) echo "configure: WARNING: unrecognized option $opt"
157 esac
158 done
160 cc="${cross_prefix}${cc}"
161 ar="${cross_prefix}${ar}"
162 strip="${cross_prefix}${strip}"
164 if test -z "$cpu" ; then
165 if test -n "$ARCH" ; then
166 cpu="$ARCH"
167 else
168 cpu=`uname -m`
172 case "$cpu" in
173 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
174 cpu="i386"
176 x86_64|amd64|x86-64)
177 cpu="x86_64"
179 arm*)
180 case "$cpu" in
181 arm|armv4l)
182 cpuver=4
184 armv5tel|armv5tejl)
185 cpuver=5
187 armv6j|armv6l)
188 cpuver=6
190 armv7a|armv7l)
191 cpuver=7
193 esac
194 cpu="arm"
196 aarch64)
197 cpu="aarch64"
199 alpha)
200 cpu="alpha"
202 "Power Macintosh"|ppc|ppc64)
203 cpu="ppc"
205 mips)
206 cpu="mips"
208 s390)
209 cpu="s390"
211 riscv64)
212 cpu="riscv64"
215 echo "Unsupported CPU"
216 exit 1
218 esac
220 # Checking for CFLAGS
221 if test -z "$CFLAGS"; then
222 CFLAGS="-Wall -O2"
225 if test "$mingw32" = "yes" ; then
226 if test "$source_path_used" = "no"; then
227 source_path="."
229 if test "${cc%% *}" = "gcc"; then
230 test -z "$LDFLAGS" && LDFLAGS="-static"
232 test -z "$prefix" && prefix="C:/Program Files/tcc"
233 test -z "$tccdir" && tccdir="${prefix}"
234 test -z "$bindir" && bindir="${tccdir}"
235 test -z "$docdir" && docdir="${tccdir}/doc"
236 test -z "$libdir" && libdir="${tccdir}/libtcc"
237 confvars="$confvars WIN32"
238 LIBSUF=".lib"
239 EXESUF=".exe"
240 DLLSUF=".dll"
241 else
242 if test -z "$prefix" ; then
243 prefix="/usr/local"
245 if test -z "$sharedir" ; then
246 sharedir="${prefix}/share"
248 if test x"$execprefix" = x""; then
249 execprefix="${prefix}"
251 if test x"$libdir" = x""; then
252 libdir="${execprefix}/lib"
254 if test x"$bindir" = x""; then
255 bindir="${execprefix}/bin"
257 if test x"$docdir" = x""; then
258 docdir="${sharedir}/doc"
260 if test x"$mandir" = x""; then
261 mandir="${sharedir}/man"
263 if test x"$infodir" = x""; then
264 infodir="${sharedir}/info"
266 if test x"$tccdir" = x""; then
267 tccdir="${libdir}/tcc"
269 if test x"$includedir" = x""; then
270 includedir="${prefix}/include"
272 fi # mingw32
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 --ar=AR create archives using AR [$ar]
299 --extra-cflags= specify compiler flags [$CFLAGS]
300 --extra-ldflags= specify linker options []
301 --cpu=CPU CPU [$cpu]
302 --strip-binaries strip symbol tables from resulting binaries
303 --debug include debug info with resulting binaries
304 --disable-static make libtcc.so instead of libtcc.a
305 --enable-static make libtcc.a instead of libtcc.dll (win32)
306 --disable-rpath disable use of -rpath with the above
307 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
308 --enable-cross build cross compilers
309 --with-selinux use mmap for executable memory (with tcc -run)
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
314 --triplet=... specify system library/include directory triplet
315 --config-uClibc,-musl,-mingw32... enable system specific configurations
317 #echo "NOTE: The object files are build at the place where configure is launched"
318 exit 1
321 if test -z "$cross_prefix" ; then
322 CONFTEST=./conftest$EXESUF
323 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
324 echo "configure: error: '$cc' failed to compile conftest.c."
325 else
326 gcc_major="$($CONFTEST version)"
327 gcc_minor="$($CONFTEST minor)"
328 gcc_name="$($CONFTEST compiler)"
330 bigendian="$($CONFTEST bigendian)"
331 if test "$mingw32" = "no" ; then
333 if test -z "$triplet"; then
334 tt="$($CONFTEST triplet)"
335 if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
336 triplet="$tt"
340 if test -z "$triplet"; then
341 if test $cpu = "x86_64" -o $cpu = "aarch64" -o $cpu = "riscv64" ; then
342 if test -f "/usr/lib64/crti.o" ; then
343 tcc_lddir="lib64"
348 if test "$cpu" = "arm" ; then
349 if test "${triplet%eabihf}" != "$triplet" ; then
350 confvars="$confvars arm_eabihf arm_vfp"
351 elif test "${triplet%eabi}" != "$triplet" ; then
352 confvars="$confvars arm_eabi"
354 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
355 confvars="$confvars arm_vfp"
359 if test "$suggest" = "yes"; then
360 if test -f "/lib/ld-uClibc.so.0" ; then
361 echo "Perhaps you want ./configure --config-uClibc"
363 if test -f "/lib/ld-musl-$cpu.so.1"; then
364 echo "Perhaps you want ./configure --config-musl"
368 else
369 # if cross compiling, cannot launch a program, so make a static guess
370 case $cpu in
371 ppc|mips|s390) bigendian=yes;;
372 esac
375 if test "$bigendian" = "yes" ; then
376 confvars="$confvars BIGENDIAN"
379 # a final configuration tuning
380 if ! echo "$cc" | grep -q "tcc"; then
381 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
382 # we want -Wno- but gcc does not always reject unknown -Wno- options
383 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
384 if $cc --version 2>&1 | grep -q "clang"; then
385 OPT1="$OPT1 -fheinous-gnu-extensions"
386 OPT2="$OPT2 -Wstring-plus-int"
388 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
389 for o in $OPT1; do # enable these options
390 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
391 done
392 for o in $OPT2; do # disable these options
393 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
394 done
395 # cat cc_msg.txt
396 # echo $CFLAGS
397 rm -f cc_msg.txt a.out
400 fcho() { if test -n "$2"; then echo "$1$2"; fi }
402 fcho "Binary directory " "$bindir"
403 fcho "TinyCC directory " "$tccdir"
404 fcho "Library directory " "$libdir"
405 fcho "Include directory " "$includedir"
406 fcho "Manual directory " "$mandir"
407 fcho "Info directory " "$infodir"
408 fcho "Doc directory " "$docdir"
409 fcho "Target root prefix " "$sysroot"
410 fcho "/usr/include dir " "$tcc_usrinclude"
411 echo "Source path $source_path"
412 echo "C compiler $cc ($gcc_major.$gcc_minor)"
413 echo "Target OS $targetos"
414 echo "CPU $cpu"
415 fcho "Triplet " "$triplet"
416 fcho "Config " "${confvars# }"
417 echo "Creating config.mak and config.h"
419 cat >config.mak <<EOF
420 # Automatically generated by configure - do not modify
421 prefix=$prefix
422 bindir=\$(DESTDIR)$bindir
423 tccdir=\$(DESTDIR)$tccdir
424 libdir=\$(DESTDIR)$libdir
425 includedir=\$(DESTDIR)$includedir
426 mandir=\$(DESTDIR)$mandir
427 infodir=\$(DESTDIR)$infodir
428 docdir=\$(DESTDIR)$docdir
429 CC=$cc
430 GCC_MAJOR=$gcc_major
431 GCC_MINOR=$gcc_minor
432 AR=$ar
433 STRIP=$strip -s -R .comment -R .note
434 CFLAGS=$CFLAGS
435 LDFLAGS=$LDFLAGS
436 LIBSUF=$LIBSUF
437 EXESUF=$EXESUF
438 DLLSUF=$DLLSUF
441 print_inc() {
442 if test -n "$2"; then
443 echo "#ifndef $1" >> $TMPH
444 echo "# define $1 \"$2\"" >> $TMPH
445 echo "#endif" >> $TMPH
449 print_mak() {
450 if test -n "$2"; then
451 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
455 print_mak_int() {
456 if test -n "$2"; then
457 echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
461 echo "/* Automatically generated by configure - do not modify */" > $TMPH
463 print_inc CONFIG_SYSROOT "$sysroot"
464 print_inc CONFIG_TCCDIR "$tccdir"
465 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
466 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
467 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
468 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
469 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
470 print_mak CONFIG_LDDIR "$tcc_lddir"
471 print_mak CONFIG_TRIPLET "$triplet"
472 print_mak_int TCC_CPU_VERSION "$cpuver"
474 if test "$cpu" = "aarch64" ; then
475 echo "ARCH=arm64" >> config.mak
476 else
477 echo "ARCH=$cpu" >> config.mak
479 echo "TARGETOS=$targetos" >> config.mak
481 for v in $confvars ; do
482 if test "${v%=*}" = "$v"; then
483 echo "CONFIG_$v=yes" >> config.mak
484 else
485 echo "CONFIG_$v" >> config.mak
487 done
489 version=`head $source_path/VERSION`
490 echo "VERSION = $version" >> config.mak
491 echo "#define TCC_VERSION \"$version\"" >> $TMPH
492 echo "@set VERSION $version" > config.texi
494 if test "$source_path_used" = "yes" ; then
495 case $source_path in
496 /*) echo "TOPSRC=$source_path";;
497 *) echo "TOPSRC=\$(TOP)/$source_path";;
498 esac >>config.mak
499 else
500 echo 'TOPSRC=$(TOP)' >>config.mak
502 cat >>$TMPH <<EOF
503 #define GCC_MAJOR $gcc_major
504 #define GCC_MINOR $gcc_minor
507 diff $TMPH config.h >/dev/null 2>&1
508 if test $? -ne 0 ; then
509 mv -f $TMPH config.h
510 else
511 echo "config.h is unchanged"
514 rm -f $TMPN* $CONFTEST
516 # ---------------------------------------------------------------------------
517 # build tree in object directory if source path is different from current one
519 fn_makelink()
521 tgt=$1/$2
522 case $2 in
523 */*) dn=${2%/*}
524 test -d $dn || mkdir -p $dn
525 case $1 in
526 /*) ;;
527 *) while test $dn ; do
528 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
529 done
531 esac
533 esac
535 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
538 if test "$source_path_used" = "yes" ; then
539 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
540 for f in $FILES ; do
541 fn_makelink $source_path $f
542 done
545 # ---------------------------------------------------------------------------