dce: Don't force unreachable case label to be live
[tinycc.git] / configure
blob008794513dd272cebc822fb44bda7b6aa4e8b6f3
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 test "$(uname -o)" = "Android" && targetos=Android
63 case $targetos in
64 Darwin)
65 darwin=yes
66 confvars="$confvars OSX dll=no"
67 cc=`which cc`
68 cc=`readlink $cc || echo clang`
69 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
70 DLLSUF=".dylib"
72 Windows_NT|MINGW*|MSYS*|CYGWIN*)
73 mingw32=yes
74 targetos=WIN32
76 DragonFly|OpenBSD|FreeBSD|NetBSD)
77 confvars="$confvars BSD ldl=no"
79 Android)
80 confvars="$confvars Android pie new-dtags"
81 if test -n "$TERMUX_VERSION"; then
82 prefix="$PREFIX" # "/data/data/com.termux/files/usr"
83 sysroot="$PREFIX"
84 test "$cpu" = "aarch64" -o "$cpu" = "x86_64" && S="64" || S=""
85 tcc_sysincludepaths="{B}/include:{R}/include/\\\"CONFIG_TRIPLET\\\":{R}/include"
86 tcc_libpaths="{B}:{R}/lib:/system/lib${S}"
87 tcc_crtprefix="{R}/lib"
88 tcc_elfinterp="/system/bin/linker${S}"
89 use_triplet="yes"
90 tcc_switches="-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
95 esac
97 # find source path
98 source_path=${0%configure}
99 source_path=${source_path%/}
100 source_path_used="yes"
101 if test -z "$source_path" -o "$source_path" = "." ; then
102 source_path=`pwd`
103 source_path_used="no"
106 for opt do
107 eval opt=\"$opt\"
108 case "$opt" in
109 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2-`
111 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2-`
113 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2-`
115 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2-`
117 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2-`
119 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2-`
121 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2-`
123 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2-`
125 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2-`
127 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2-`
129 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2-`
131 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2-`
133 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2-`
135 --cc=*) cc=`echo $opt | cut -d '=' -f 2-`
137 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set="yes"
139 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
141 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
143 --extra-libs=*) extralibs="${opt#--extra-libs=}"
145 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2-`
147 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2-`
149 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2-`
151 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2-`
153 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2-`
155 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
157 --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
159 --enable-cross) confvars="$confvars cross"
161 --disable-static) confvars="$confvars static=no"
163 --enable-static) confvars="$confvars static"
165 --disable-rpath) confvars="$confvars rpath=no"
167 --debug) confvars="$confvars debug"
169 --with-libgcc) confvars="$confvars libgcc"
171 --with-selinux) confvars="$confvars selinux"
173 --tcc-switches=*) tcc_switches=`echo $opt | cut -d '=' -f 2-`
175 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
177 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
179 --help|-h) show_help="yes"
181 *) echo "configure: WARNING: unrecognized option $opt"
183 esac
184 done
186 cc="${cross_prefix}${cc}"
187 ar="${cross_prefix}${ar}"
189 # Checking for CFLAGS
190 test -z "$CFLAGS" && CFLAGS="-Wall -O2"
192 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
193 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
194 CFLAGS="$CFLAGS -arch $cpu"
195 LDFLAGS="$LDFLAGS -arch $cpu"
198 case "$cpu" in
199 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
200 cpu="i386"
202 x86_64|amd64|x86-64)
203 cpu="x86_64"
205 evbarm)
206 case "`uname -p`" in
207 aarch64|arm64)
208 cpu="arm64"
210 earmv*)
211 cpu="arm"
213 esac
215 aarch64|arm64|evbarm)
216 cpu="arm64"
218 arm*)
219 case "$cpu" in
220 arm|armv4l)
221 cpuver=4
223 armv5tel|armv5tejl)
224 cpuver=5
226 armv6j|armv6l)
227 cpuver=6
229 armv7|armv7a|armv7l)
230 cpuver=7
232 esac
233 cpu="arm"
235 alpha)
236 cpu="alpha"
238 "Power Macintosh"|ppc|ppc64)
239 cpu="ppc"
241 mips)
242 cpu="mips"
244 s390)
245 cpu="s390"
247 riscv64)
248 cpu="riscv64"
251 echo "Unsupported CPU"
252 exit 1
254 esac
256 if test "$mingw32" = "yes" ; then
257 if test "$source_path_used" = "no"; then
258 source_path="."
260 test -z "$prefix" && prefix="C:/Program Files/tcc"
261 test -z "$tccdir" && tccdir="${prefix}" && tccdir_auto="yes"
262 test -z "$bindir" && bindir="${tccdir}"
263 test -z "$docdir" && docdir="${tccdir}/doc"
264 test -z "$libdir" && libdir="${tccdir}/libtcc"
265 confvars="$confvars WIN32"
266 LIBSUF=".lib"
267 EXESUF=".exe"
268 DLLSUF=".dll"
269 else
270 if test -z "$prefix" ; then
271 prefix="/usr/local"
273 if test -z "$sharedir" ; then
274 sharedir="${prefix}/share"
276 if test x"$execprefix" = x""; then
277 execprefix="${prefix}"
279 if test x"$libdir" = x""; then
280 libdir="${execprefix}/lib"
282 if test x"$bindir" = x""; then
283 bindir="${execprefix}/bin"
285 if test x"$docdir" = x""; then
286 docdir="${sharedir}/doc"
288 if test x"$mandir" = x""; then
289 mandir="${sharedir}/man"
291 if test x"$infodir" = x""; then
292 infodir="${sharedir}/info"
294 if test x"$tccdir" = x""; then
295 tccdir="${libdir}/tcc"
297 if test x"$includedir" = x""; then
298 includedir="${prefix}/include"
300 fi # mingw32
302 if test x"$show_help" = "xyes" ; then
303 cat << EOF
304 Usage: configure [options]
305 Options: [defaults in brackets after descriptions]
307 Standard options:
308 --help print this message
309 --prefix=PREFIX install in PREFIX [$prefix]
310 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
311 [same as prefix]
312 --bindir=DIR user executables in DIR [EPREFIX/bin]
313 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
314 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
315 --includedir=DIR C header files in DIR [PREFIX/include]
316 --sharedir=DIR documentation root DIR [PREFIX/share]
317 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
318 --mandir=DIR man documentation in DIR [SHAREDIR/man]
319 --infodir=DIR info documentation in DIR [SHAREDIR/info]
321 Advanced options (experts only):
322 --source-path=PATH path of source code [$source_path]
323 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
324 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
325 --cc=CC use C compiler CC [$cc]
326 --ar=AR create archives using AR [$ar]
327 --extra-cflags= specify compiler flags [$CFLAGS]
328 --extra-ldflags= specify linker options [$LDFLAGS]
329 --cpu=CPU CPU [$cpu]
331 --debug include debug info with resulting binaries
332 --disable-static make libtcc.so instead of libtcc.a
333 --enable-static make libtcc.a instead of libtcc.dll (win32)
334 --disable-rpath disable use of -rpath with libtcc.so
335 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
336 --with-selinux use mmap for executable memory (tcc -run)
337 --enable-cross build cross compilers (see also 'make help')
339 --sysincludepaths=... specify system include paths, colon separated
340 --libpaths=... specify system library paths, colon separated
341 --crtprefix=... specify locations of crt?.o, colon separated
342 --elfinterp=... specify elf interpreter
343 --triplet=... specify system library/include directory triplet
344 --tcc-switches=... specify implicit switches passed to tcc
346 --config-uClibc,-musl enable system specific configurations
347 --config-mingw32 build on windows using msys, busybox, etc.
348 --config-backtrace=no disable stack backtraces (with -run or -bt)
349 --config-bcheck=no disable bounds checker (-b)
350 --config-predefs=no do not compile tccdefs.h, instead just include
351 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
353 exit 1
356 if test -z "$cross_prefix" ; then
357 CONFTEST=./conftest$EXESUF
358 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
359 echo "configure: error: '$cc' failed to compile conftest.c."
360 else
361 cc_name="$($CONFTEST compiler)"
362 gcc_major="$($CONFTEST version)"
363 gcc_minor="$($CONFTEST minor)"
364 bigendian="$($CONFTEST bigendian)"
365 _triplet="$($CONFTEST triplet)"
367 if test "$mingw32" = "no" ; then
369 if test -z "$triplet" -a -n "$_triplet"; then
370 if test -f "/usr/lib/$_triplet/crti.o" -o -n "$use_triplet" ; then
371 triplet="$_triplet"
375 if test -z "$triplet"; then
376 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
377 if test -f "/usr/lib64/crti.o" ; then
378 tcc_lddir="lib64"
383 if test "$cpu" = "arm" ; then
384 if test "${triplet%eabihf}" != "$triplet" ; then
385 confvars="$confvars arm_eabihf arm_vfp"
386 elif test "${triplet%eabi}" != "$triplet" ; then
387 confvars="$confvars arm_eabi arm_vfp"
388 elif test "${_triplet%eabihf}" != "$_triplet" ; then
389 confvars="$confvars arm_eabihf arm_vfp"
390 elif test "${_triplet%eabi}" != "$_triplet" ; then
391 confvars="$confvars arm_eabi arm_vfp"
392 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
393 confvars="$confvars arm_vfp"
397 if test "$suggest" = "yes"; then
398 if test -f "/lib/ld-uClibc.so.0" ; then
399 echo "Perhaps you want ./configure --config-uClibc"
401 if test -f "/lib/ld-musl-$cpu.so.1"; then
402 echo "Perhaps you want ./configure --config-musl"
405 else # mingw32 = yes
406 if test "$cc_name" = "gcc"; then
407 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
408 test -z "$LDFLAGS" && LDFLAGS="-static"
411 else
412 # if cross compiling, cannot launch a program, so make a static guess
413 case $cpu in
414 ppc|mips|s390) bigendian=yes;;
415 esac
418 if test "$bigendian" = "yes" ; then
419 confvars="$confvars BIGENDIAN"
422 # a final configuration tuning
423 if test "$cc_name" != "tcc"; then
424 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
425 # we want -Wno- but gcc does not always reject unknown -Wno- options
426 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
427 OPT2="$OPT2 -Wstringop-truncation"
428 if test "$cc_name" = "clang"; then
429 OPT1="$OPT1 -fheinous-gnu-extensions"
430 OPT2="$OPT2 -Wstring-plus-int"
432 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
433 for o in $OPT1; do # enable these options
434 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
435 done
436 for o in $OPT2; do # disable these options
437 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
438 done
439 # cat cc_msg.txt
440 # echo $CFLAGS
441 rm -f cc_msg.txt a.out
442 else # cc is tcc
443 test "$ar_set" || ar="$cc -ar"
446 fcho() { if test -n "$2"; then echo "$1$2"; fi }
448 fcho "Binary directory " "$bindir"
449 fcho "TinyCC directory " "$tccdir"
450 fcho "Library directory " "$libdir"
451 fcho "Include directory " "$includedir"
452 fcho "Manual directory " "$mandir"
453 fcho "Info directory " "$infodir"
454 fcho "Doc directory " "$docdir"
455 fcho "Target root prefix " "$sysroot"
456 fcho "/usr/include dir " "$tcc_usrinclude"
457 echo "Source path $source_path"
458 echo "C compiler $cc ($gcc_major.$gcc_minor)"
459 echo "Target OS $targetos"
460 echo "CPU $cpu"
461 fcho "Triplet " "$triplet"
462 fcho "Config " "${confvars# }"
463 echo "Creating config.mak and config.h"
465 cat >config.mak <<EOF
466 # Automatically generated by configure - do not modify
467 prefix=$prefix
468 bindir=\$(DESTDIR)$bindir
469 tccdir=\$(DESTDIR)$tccdir
470 libdir=\$(DESTDIR)$libdir
471 includedir=\$(DESTDIR)$includedir
472 mandir=\$(DESTDIR)$mandir
473 infodir=\$(DESTDIR)$infodir
474 docdir=\$(DESTDIR)$docdir
475 CC=$cc
476 CC_NAME=$cc_name
477 GCC_MAJOR=$gcc_major
478 GCC_MINOR=$gcc_minor
479 AR=$ar
480 CFLAGS=$CFLAGS
481 LDFLAGS=$LDFLAGS
482 LIBSUF=$LIBSUF
483 EXESUF=$EXESUF
484 DLLSUF=$DLLSUF
487 print_inc() {
488 local v="$2"
489 if test -n "$v"; then
490 test "$3" = "num" || v="\"$v\""
491 echo "#ifndef $1" >> $TMPH
492 echo "# define $1 $v" >> $TMPH
493 echo "#endif" >> $TMPH
497 print_mak() {
498 local v="$2"
499 if test -n "$v"; then
500 test "$3" = "num" || v="\"\\\"$v\\\"\""
501 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
505 echo "/* Automatically generated by configure - do not modify */" > $TMPH
507 print_inc CONFIG_SYSROOT "$sysroot"
508 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
509 print_inc DWARF_VERSION "$dwarf" num
510 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
511 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
512 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
513 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
514 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
515 print_mak CONFIG_TCC_SWITCHES "$tcc_switches"
516 print_mak CONFIG_LDDIR "$tcc_lddir"
517 print_mak CONFIG_TRIPLET "$triplet"
518 print_mak TCC_CPU_VERSION "$cpuver" num
520 echo "ARCH=$cpu" >> config.mak
521 echo "TARGETOS=$targetos" >> config.mak
523 predefs="1"
524 for v in $confvars ; do
525 test "$v" = "predefs=no" && predefs=""
526 if test "${v%=*}" = "$v"; then
527 echo "CONFIG_$v=yes" >> config.mak
528 else
529 echo "CONFIG_$v" >> config.mak
531 done
532 print_inc CONFIG_TCC_PREDEFS "$predefs" num
534 version=`head $source_path/VERSION`
535 echo "VERSION = $version" >> config.mak
536 echo "#define TCC_VERSION \"$version\"" >> $TMPH
537 echo "@set VERSION $version" > config.texi
539 if test "$source_path_used" = "yes" ; then
540 case $source_path in
541 /*) echo "TOPSRC=$source_path";;
542 *) echo "TOPSRC=\$(TOP)/$source_path";;
543 esac >>config.mak
544 else
545 echo 'TOPSRC=$(TOP)' >>config.mak
547 cat >>$TMPH <<EOF
548 #define GCC_MAJOR $gcc_major
549 #define GCC_MINOR $gcc_minor
550 #define CC_NAME CC_${cc_name}
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
581 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
584 if test "$source_path_used" = "yes" ; then
585 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
586 for f in $FILES ; do
587 fn_makelink $source_path $f
588 done
591 # ---------------------------------------------------------------------------