Fix test90 for 32 bits targets
[tinycc.git] / configure
blob6fe824827640d34e373243d58765f4fa9e16622e
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 bigendian="no"
33 mingw32="no"
34 LIBSUF=".a"
35 EXESUF=""
36 DLLSUF=".so"
37 tcc_usrinclude=""
38 tcc_sysincludepaths=""
39 tcc_libpaths=""
40 tcc_crtprefix=""
41 tcc_elfinterp=""
42 triplet=
43 tcc_lddir=
44 confvars=
45 suggest="yes"
46 gcc_major=0
47 gcc_minor=0
48 cc_name="gcc"
49 ar_set=
50 darwin=
51 cpuver=
52 dwarf=
54 # use CC from environment when set
55 test -n "$CC" && cc="$CC"
57 # OS specific
58 cpu=`uname -m`
59 cpu_sys="$cpu"
60 targetos=`uname`
61 if test "$targetos" = "Linux" ; then
62 test "$(uname -o)" = "Android" && targetos=Android
65 case $targetos in
66 Darwin)
67 darwin=yes
68 dwarf=4
69 confvars="$confvars OSX"
70 cc=`which cc`
71 cc=`readlink $cc || echo clang`
72 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
73 DLLSUF=".dylib"
75 Windows_NT|MINGW*|MSYS*|CYGWIN*)
76 mingw32=yes
77 targetos=WIN32
79 DragonFly|OpenBSD|FreeBSD|NetBSD)
80 confvars="$confvars BSD ldl=no"
82 Android)
83 confvars="$confvars Android pie new-dtags"
84 if test -n "$TERMUX_VERSION"; then
85 prefix="$PREFIX" # "/data/data/com.termux/files/usr"
86 sysroot="$PREFIX"
87 test "$cpu" = "aarch64" -o "$cpu" = "x86_64" && S="64" || S=""
88 tcc_sysincludepaths="{B}/include:{R}/include/\\\"CONFIG_TRIPLET\\\":{R}/include"
89 tcc_libpaths="{B}:{R}/lib:/system/lib${S}"
90 tcc_crtprefix="{R}/lib"
91 tcc_elfinterp="/system/bin/linker${S}"
92 use_triplet="yes"
93 tcc_switches="-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
98 esac
100 # find source path
101 source_path=${0%configure}
102 source_path=${source_path%/}
103 source_path_used="yes"
104 if test -z "$source_path" -o "$source_path" = "." ; then
105 source_path=`pwd`
106 source_path_used="no"
109 for opt do
110 eval opt=\"$opt\"
111 case "$opt" in
112 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2-`
114 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2-`
116 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2-`
118 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2-`
120 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2-`
122 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2-`
124 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2-`
126 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2-`
128 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2-`
130 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2-`
132 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2-`
134 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2-`
136 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2-`
138 --cc=*) cc=`echo $opt | cut -d '=' -f 2-`
140 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set="yes"
142 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
144 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
146 --extra-libs=*) extralibs="${opt#--extra-libs=}"
148 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2-`
150 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2-`
152 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2-`
154 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2-`
156 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2-`
158 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
160 --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
162 --enable-cross) confvars="$confvars cross"
164 --disable-static) confvars="$confvars static=no"
166 --enable-static) confvars="$confvars static"
168 --disable-rpath) confvars="$confvars rpath=no"
170 --debug) confvars="$confvars debug"
172 --with-libgcc) confvars="$confvars libgcc"
174 --with-selinux) confvars="$confvars selinux"
176 --tcc-switches=*) tcc_switches=`echo $opt | cut -d '=' -f 2-`
178 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
180 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
182 --help|-h) show_help="yes"
184 *) echo "configure: WARNING: unrecognized option $opt"
186 esac
187 done
189 cc="${cross_prefix}${cc}"
190 ar="${cross_prefix}${ar}"
192 # Checking for CFLAGS
193 test -z "$CFLAGS" && CFLAGS="-Wall -O2"
195 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
196 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
197 CFLAGS="$CFLAGS -arch $cpu"
198 LDFLAGS="$LDFLAGS -arch $cpu"
201 case "$cpu" in
202 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
203 cpu="i386"
205 x86_64|amd64|x86-64)
206 cpu="x86_64"
208 evbarm)
209 case "`uname -p`" in
210 aarch64|arm64)
211 cpu="arm64"
213 earmv*)
214 cpu="arm"
216 esac
218 aarch64|arm64|evbarm)
219 cpu="arm64"
221 arm*)
222 case "$cpu" in
223 arm|armv4l)
224 cpuver=4
226 armv5tel|armv5tejl)
227 cpuver=5
229 armv6j|armv6l)
230 cpuver=6
232 armv7|armv7a|armv7l)
233 cpuver=7
235 esac
236 cpu="arm"
238 alpha)
239 cpu="alpha"
241 "Power Macintosh"|ppc|ppc64)
242 cpu="ppc"
244 mips)
245 cpu="mips"
247 s390)
248 cpu="s390"
250 riscv64)
251 cpu="riscv64"
254 echo "Unsupported CPU"
255 exit 1
257 esac
259 if test "$mingw32" = "yes" ; then
260 if test "$source_path_used" = "no"; then
261 source_path="."
263 test -z "$prefix" && prefix="C:/Program Files/tcc"
264 test -z "$tccdir" && tccdir="${prefix}" && tccdir_auto="yes"
265 test -z "$bindir" && bindir="${tccdir}"
266 test -z "$docdir" && docdir="${tccdir}/doc"
267 test -z "$libdir" && libdir="${tccdir}/libtcc"
268 confvars="$confvars WIN32"
269 LIBSUF=".lib"
270 EXESUF=".exe"
271 DLLSUF=".dll"
272 else
273 if test -z "$prefix" ; then
274 prefix="/usr/local"
276 if test -z "$sharedir" ; then
277 sharedir="${prefix}/share"
279 if test x"$execprefix" = x""; then
280 execprefix="${prefix}"
282 if test x"$libdir" = x""; then
283 libdir="${execprefix}/lib"
285 if test x"$bindir" = x""; then
286 bindir="${execprefix}/bin"
288 if test x"$docdir" = x""; then
289 docdir="${sharedir}/doc"
291 if test x"$mandir" = x""; then
292 mandir="${sharedir}/man"
294 if test x"$infodir" = x""; then
295 infodir="${sharedir}/info"
297 if test x"$tccdir" = x""; then
298 tccdir="${libdir}/tcc"
300 if test x"$includedir" = x""; then
301 includedir="${prefix}/include"
303 fi # mingw32
305 if test x"$show_help" = "xyes" ; then
306 cat << EOF
307 Usage: configure [options]
308 Options: [defaults in brackets after descriptions]
310 Standard options:
311 --help print this message
312 --prefix=PREFIX install in PREFIX [$prefix]
313 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
314 [same as prefix]
315 --bindir=DIR user executables in DIR [EPREFIX/bin]
316 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
317 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
318 --includedir=DIR C header files in DIR [PREFIX/include]
319 --sharedir=DIR documentation root DIR [PREFIX/share]
320 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
321 --mandir=DIR man documentation in DIR [SHAREDIR/man]
322 --infodir=DIR info documentation in DIR [SHAREDIR/info]
324 Advanced options (experts only):
325 --source-path=PATH path of source code [$source_path]
326 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
327 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
328 --cc=CC use C compiler CC [$cc]
329 --ar=AR create archives using AR [$ar]
330 --extra-cflags= specify compiler flags [$CFLAGS]
331 --extra-ldflags= specify linker options [$LDFLAGS]
332 --cpu=CPU CPU [$cpu]
334 --debug include debug info with resulting binaries
335 --disable-static make libtcc.so instead of libtcc.a
336 --enable-static make libtcc.a instead of libtcc.dll (win32)
337 --disable-rpath disable use of -rpath with libtcc.so
338 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
339 --with-selinux use mmap for executable memory (tcc -run)
340 --enable-cross build cross compilers (see also 'make help')
342 --sysincludepaths=... specify system include paths, colon separated
343 --libpaths=... specify system library paths, colon separated
344 --crtprefix=... specify locations of crt?.o, colon separated
345 --elfinterp=... specify elf interpreter
346 --triplet=... specify system library/include directory triplet
347 --tcc-switches=... specify implicit switches passed to tcc
349 --config-uClibc,-musl enable system specific configurations
350 --config-mingw32 build on windows using msys, busybox, etc.
351 --config-backtrace=no disable stack backtraces (with -run or -bt)
352 --config-bcheck=no disable bounds checker (-b)
353 --config-predefs=no do not compile tccdefs.h, instead just include
354 --config-new_macho=no Use apple old macho object format
355 --config-codesign Use codesign on apple to sign executables
356 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
358 exit 1
361 if test -z "$cross_prefix" ; then
362 CONFTEST=./conftest$EXESUF
363 if ! $cc -o $CONFTEST $source_path/conftest.c ; then
364 echo "configure: error: '$cc' failed to compile conftest.c."
365 else
366 cc_name="$($CONFTEST compiler)"
367 gcc_major="$($CONFTEST version)"
368 gcc_minor="$($CONFTEST minor)"
369 bigendian="$($CONFTEST bigendian)"
370 _triplet="$($CONFTEST triplet)"
372 if test "$mingw32" = "no" ; then
374 if test -z "$triplet" -a -n "$_triplet"; then
375 if test -f "/usr/lib/$_triplet/crti.o" -o -n "$use_triplet" ; then
376 triplet="$_triplet"
380 if test -z "$triplet"; then
381 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
382 if test -f "/usr/lib64/crti.o" ; then
383 tcc_lddir="lib64"
388 if test "$cpu" = "arm" ; then
389 if test "${triplet%eabihf}" != "$triplet" ; then
390 confvars="$confvars arm_eabihf arm_vfp"
391 elif test "${triplet%eabi}" != "$triplet" ; then
392 confvars="$confvars arm_eabi arm_vfp"
393 elif test "${_triplet%eabihf}" != "$_triplet" ; then
394 confvars="$confvars arm_eabihf arm_vfp"
395 elif test "${_triplet%eabi}" != "$_triplet" ; then
396 confvars="$confvars arm_eabi arm_vfp"
397 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
398 confvars="$confvars arm_vfp"
402 if test "$suggest" = "yes"; then
403 if test -f "/lib/ld-uClibc.so.0" ; then
404 echo "Perhaps you want ./configure --config-uClibc"
406 if test -f "/lib/ld-musl-$cpu.so.1"; then
407 echo "Perhaps you want ./configure --config-musl"
410 else # mingw32 = yes
411 if test "$cc_name" = "gcc"; then
412 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
413 test -z "$LDFLAGS" && LDFLAGS="-static"
416 else
417 # if cross compiling, cannot launch a program, so make a static guess
418 case $cpu in
419 ppc|mips|s390) bigendian=yes;;
420 esac
423 if test "$bigendian" = "yes" ; then
424 confvars="$confvars BIGENDIAN"
427 # a final configuration tuning
428 if test "$cc_name" != "tcc"; then
429 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
430 # we want -Wno- but gcc does not always reject unknown -Wno- options
431 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
432 OPT2="$OPT2 -Wstringop-truncation"
433 if test "$cc_name" = "clang"; then
434 OPT1="$OPT1 -fheinous-gnu-extensions"
435 OPT2="$OPT2 -Wstring-plus-int"
437 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
438 for o in $OPT1; do # enable these options
439 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
440 done
441 for o in $OPT2; do # disable these options
442 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
443 done
444 # cat cc_msg.txt
445 # echo $CFLAGS
446 rm -f cc_msg.txt a.out
447 else # cc is tcc
448 test "$ar_set" || ar="$cc -ar"
451 fcho() { if test -n "$2"; then echo "$1$2"; fi }
453 fcho "Binary directory " "$bindir"
454 fcho "TinyCC directory " "$tccdir"
455 fcho "Library directory " "$libdir"
456 fcho "Include directory " "$includedir"
457 fcho "Manual directory " "$mandir"
458 fcho "Info directory " "$infodir"
459 fcho "Doc directory " "$docdir"
460 fcho "Target root prefix " "$sysroot"
461 fcho "/usr/include dir " "$tcc_usrinclude"
462 echo "Source path $source_path"
463 echo "C compiler $cc ($gcc_major.$gcc_minor)"
464 echo "Target OS $targetos"
465 echo "CPU $cpu"
466 fcho "Triplet " "$triplet"
467 fcho "Config " "${confvars# }"
468 echo "Creating config.mak and config.h"
470 cat >config.mak <<EOF
471 # Automatically generated by configure - do not modify
472 prefix=$prefix
473 bindir=\$(DESTDIR)$bindir
474 tccdir=\$(DESTDIR)$tccdir
475 libdir=\$(DESTDIR)$libdir
476 includedir=\$(DESTDIR)$includedir
477 mandir=\$(DESTDIR)$mandir
478 infodir=\$(DESTDIR)$infodir
479 docdir=\$(DESTDIR)$docdir
480 CC=$cc
481 CC_NAME=$cc_name
482 GCC_MAJOR=$gcc_major
483 GCC_MINOR=$gcc_minor
484 AR=$ar
485 CFLAGS=$CFLAGS
486 LDFLAGS=$LDFLAGS
487 LIBSUF=$LIBSUF
488 EXESUF=$EXESUF
489 DLLSUF=$DLLSUF
492 print_inc() {
493 local v="$2"
494 if test -n "$v"; then
495 test "$3" = "num" || v="\"$v\""
496 echo "#ifndef $1" >> $TMPH
497 echo "# define $1 $v" >> $TMPH
498 echo "#endif" >> $TMPH
502 print_mak() {
503 local v="$2"
504 if test -n "$v"; then
505 test "$3" = "num" || v="\"\\\"$v\\\"\""
506 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
510 echo "/* Automatically generated by configure - do not modify */" > $TMPH
512 print_inc CONFIG_SYSROOT "$sysroot"
513 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
514 print_inc DWARF_VERSION "$dwarf" num
515 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
516 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
517 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
518 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
519 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
520 print_mak CONFIG_TCC_SWITCHES "$tcc_switches"
521 print_mak CONFIG_LDDIR "$tcc_lddir"
522 print_mak CONFIG_TRIPLET "$triplet"
523 print_mak TCC_CPU_VERSION "$cpuver" num
525 echo "ARCH=$cpu" >> config.mak
526 echo "TARGETOS=$targetos" >> config.mak
528 predefs="1"
529 for v in $confvars ; do
530 test "$v" = "predefs=no" && predefs=""
531 if test "${v%=*}" = "$v"; then
532 echo "CONFIG_$v=yes" >> config.mak
533 else
534 echo "CONFIG_$v" >> config.mak
536 done
537 print_inc CONFIG_TCC_PREDEFS "$predefs" num
539 version=`head $source_path/VERSION`
540 echo "VERSION = $version" >> config.mak
541 echo "#define TCC_VERSION \"$version\"" >> $TMPH
542 echo "@set VERSION $version" > config.texi
544 if test "$source_path_used" = "yes" ; then
545 case $source_path in
546 /*) echo "TOPSRC=$source_path";;
547 *) echo "TOPSRC=\$(TOP)/$source_path";;
548 esac >>config.mak
549 else
550 echo 'TOPSRC=$(TOP)' >>config.mak
552 cat >>$TMPH <<EOF
553 #define GCC_MAJOR $gcc_major
554 #define GCC_MINOR $gcc_minor
555 #define CC_NAME CC_${cc_name}
558 diff $TMPH config.h >/dev/null 2>&1
559 if test $? -ne 0 ; then
560 mv -f $TMPH config.h
561 else
562 echo "config.h is unchanged"
565 rm -f $TMPN* $CONFTEST
567 # ---------------------------------------------------------------------------
568 # build tree in object directory if source path is different from current one
570 fn_makelink()
572 tgt=$1/$2
573 case $2 in
574 */*) dn=${2%/*}
575 test -d $dn || mkdir -p $dn
576 case $1 in
577 /*) ;;
578 *) while test $dn ; do
579 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
580 done
582 esac
584 esac
586 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
589 if test "$source_path_used" = "yes" ; then
590 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
591 for f in $FILES ; do
592 fn_makelink $source_path $f
593 done
596 # ---------------------------------------------------------------------------