riscv: Avoid some compiler warnings
[tinycc/nsauzede.git] / configure
blobe7735a4eeb257505c92462ae6d6a71ece675ac47
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 cpu=
51 cpuver=
52 dwarf=
53 targetos=
54 build_cross=
56 # use CC/AR from environment when set
57 test -n "$CC" && cc="$CC"
58 test -n "$AR" && ar="$AR"
59 test -n "CFLAGS" && CFLAGS="-Wall -O2"
61 # find source path
62 source_path=${0%configure}
63 source_path=${source_path%/}
65 for opt do
66 eval opt=\"$opt\"
67 case "$opt" in
68 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2-`
70 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2-`
72 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2-`
74 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2-`
76 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2-`
78 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2-`
80 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2-`
82 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2-`
84 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2-`
86 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2-`
88 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2-`
90 --targetos=*) targetos=`echo $opt | cut -d '=' -f 2-`
92 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2-`
94 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2-`
96 --cc=*) cc=`echo $opt | cut -d '=' -f 2-`
98 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set="yes"
100 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
102 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
104 --extra-libs=*) extralibs="${opt#--extra-libs=}"
106 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2-`
108 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2-`
110 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2-`
112 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2-`
114 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2-`
116 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
118 --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
120 --enable-cross) confvars="$confvars cross"
122 --disable-static) confvars="$confvars static=no"
124 --enable-static) confvars="$confvars static"
126 --disable-rpath) confvars="$confvars rpath=no"
128 --debug) confvars="$confvars debug"
130 --with-libgcc) confvars="$confvars libgcc"
132 --with-selinux) confvars="$confvars selinux"
134 --tcc-switches=*) tcc_switches=`echo $opt | cut -d '=' -f 2-`
136 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
138 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
140 --help|-h) show_help="yes"
142 *) echo "configure: WARNING: unrecognized option $opt"
144 esac
145 done
147 show_help() {
148 cat << EOF
149 Usage: configure [options]
150 Options: [defaults in brackets after descriptions]
152 Standard options:
153 --help print this message
154 --prefix=PREFIX install in PREFIX [$prefix]
155 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
156 [same as prefix]
157 --bindir=DIR user executables in DIR [EPREFIX/bin]
158 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
159 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
160 --includedir=DIR C header files in DIR [PREFIX/include]
161 --sharedir=DIR documentation root DIR [PREFIX/share]
162 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
163 --mandir=DIR man documentation in DIR [SHAREDIR/man]
164 --infodir=DIR info documentation in DIR [SHAREDIR/info]
166 Advanced options (experts only):
167 --source-path=PATH path of source code [$source_path]
168 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
169 --cc=CC use C compiler CC [$cc]
170 --ar=AR create archives using AR [$ar]
171 --extra-cflags= specify compiler flags [$CFLAGS]
172 --extra-ldflags= specify linker options [$LDFLAGS]
174 --debug include debug info with resulting binaries
175 --disable-static make libtcc.so instead of libtcc.a
176 --enable-static make libtcc.a instead of libtcc.dll (win32)
177 --disable-rpath disable use of -rpath with libtcc.so
178 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
179 --with-selinux use mmap for executable memory (tcc -run)
180 --enable-cross build cross compilers (see also 'make help')
182 --sysincludepaths=... specify system include paths, colon separated
183 --libpaths=... specify system library paths, colon separated
184 --crtprefix=... specify locations of crt?.o, colon separated
185 --elfinterp=... specify elf interpreter
186 --triplet=... specify system library/include directory triplet
187 --tcc-switches=... specify implicit switches passed to tcc
189 --config-uClibc,-musl enable system specific configurations
190 --config-mingw32 build on windows using msys, busybox, etc.
191 --config-backtrace=no disable stack backtraces (with -run or -bt)
192 --config-bcheck=no disable bounds checker (-b)
193 --config-predefs=no do not compile tccdefs.h, instead just include
194 --config-new_macho=no|yes Force apple object format (autodetect osx <= 10)
195 --config-codesign=no do not use codesign on apple to sign executables
196 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
198 Cross build options (experimental):
199 --cpu=CPU target CPU [$cpu]
200 --targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos]
201 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
203 exit 1
206 default() # set variable unless already set
208 local v
209 eval v=\"\$$1\"
210 test -z "$v" && eval $1=\"$2\"
213 default_conf() # add to confvars unless already present
215 local v=${1%=*}
216 test "${confvars%$v*}" = "${confvars}" && confvars="$confvars $1"
219 if test -z "$source_path" -o "$source_path" = "." ; then
220 source_path=$(pwd)
221 source_path_used="no"
222 else
223 source_path_used="yes"
226 # OS specific
227 buildos=$(uname)
229 case $buildos in
230 Windows_NT|MINGW*|MSYS*|CYGWIN*)
231 buildos="WIN32"
233 Linux)
234 if test "$(uname -o)" = "Android"; then
235 buildos=Android
236 if test -n "$TERMUX_VERSION"; then
237 buildos=Termux
241 esac
243 if test "$mingw32" = "yes"; then
244 default targetos WIN32
245 else
246 default targetos "$buildos"
249 cpu_sys=$(uname -m)
250 default cpu "$cpu_sys"
251 cpu_set="$cpu"
253 # check for crpss build
254 if test "$cpu_set" != "$cpu_sys" \
255 -o "$targetos" != "$buildos" \
256 -o -n "$cross_prefix" ; then
257 build_cross="yes"
258 cc="${cross_prefix}${cc}"
259 ar="${cross_prefix}${ar}"
262 case "$cpu" in
263 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
264 cpu="i386"
266 x86_64|amd64|x86-64)
267 cpu="x86_64"
269 evbarm)
270 case "`uname -p`" in
271 aarch64|arm64)
272 cpu="arm64"
274 earmv*)
275 cpu="arm"
277 esac
279 aarch64|arm64|evbarm)
280 cpu="arm64"
282 arm*)
283 case "$cpu" in
284 arm|armv4l)
285 cpuver=4
287 armv5tel|armv5tejl)
288 cpuver=5
290 armv6j|armv6l)
291 cpuver=6
293 armv7|armv7a|armv7l)
294 cpuver=7
296 esac
297 cpu="arm"
299 alpha)
300 cpu="alpha"
302 "Power Macintosh"|ppc|ppc64)
303 cpu="ppc"
305 mips)
306 cpu="mips"
308 s390)
309 cpu="s390"
311 riscv64)
312 cpu="riscv64"
315 echo "Unsupported CPU"
316 exit 1
318 esac
320 case $targetos in
321 Darwin)
322 dwarf=4
323 confvars="$confvars OSX"
324 default_conf "codesign"
325 DLLSUF=".dylib"
326 if test -z "$build_cross"; then
327 cc=`command -v cc`
328 cc=`readlink $cc || echo clang`
329 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
330 if test "${confvars%new_macho*}" = "${confvars}"; then
331 # if new_macho was not specified and (known) ver <= 10, use old (=no)
332 osxver=$(sw_vers -productVersion 2>/dev/null) # X.Y.Z
333 osxver=${osxver%%.*} # major version (or empty on sw_vers error)
334 [ "${osxver:-11}" -ge 11 ] || confvars="$confvars new_macho=no"
337 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
338 if test "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
339 CFLAGS="$CFLAGS -arch $cpu"
340 LDFLAGS="$LDFLAGS -arch $cpu"
343 DragonFly|OpenBSD|FreeBSD|NetBSD)
344 confvars="$confvars BSD ldl=no"
346 Android|Termux)
347 if test "$targetos" = "Termux"; then
348 targetos=Android
349 default sysroot "/data/data/com.termux/files/usr"
350 else
351 default sysroot "/usr"
353 default prefix "${sysroot}"
354 confvars="$confvars Android new-dtags rpath=no"
355 test "${cpu}" != "i386" && confvars="$confvars pie"
356 default_conf "static=no"
357 if test "${cpu}" = "arm"; then
358 default triplet "arm-linux-androideabi"
359 cpuver=7
360 else
361 default triplet "${cpu_set}-linux-android"
363 test "${cpu%64}" != "${cpu}" && S="64" || S=""
364 default tcc_sysincludepaths "{B}/include:{R}/include:{R}/include/${triplet}"
365 default tcc_libpaths "{B}:{R}/lib:/system/lib${S}"
366 default tcc_crtprefix "{R}/lib"
367 default tcc_elfinterp "/system/bin/linker${S}"
368 default tcc_switches "-Wl,-rpath=$sysroot/lib"
370 WIN32)
371 mingw32="yes"
372 confvars="$confvars WIN32"
373 default prefix "C:/Program Files/tcc"
374 default tccdir "${prefix}"
375 default bindir "${tccdir}"
376 default docdir "${tccdir}/doc"
377 default libdir "${tccdir}/libtcc"
378 test "$tccdir" = "$bindir" && tccdir_auto="yes"
379 LIBSUF=".lib"
380 EXESUF=".exe"
381 DLLSUF=".dll"
382 if test "$source_path_used" = "no"; then
383 source_path="."
388 esac
390 if test "$mingw32" = "no"; then
391 default prefix "/usr/local"
392 default execprefix "${prefix}"
393 default libdir "${execprefix}/lib"
394 default bindir "${execprefix}/bin"
395 default tccdir "${libdir}/tcc"
396 default includedir "${prefix}/include"
397 default sharedir "${prefix}/share"
398 default docdir "${sharedir}/doc"
399 default mandir "${sharedir}/man"
400 default infodir "${sharedir}/info"
403 if test x"$show_help" = "xyes" ; then
404 show_help
407 if test -z "$build_cross"; then
408 CONFTEST=./conftest$EXESUF
409 if ! $cc -o $CONFTEST $source_path/conftest.c ; then
410 echo "configure: error: '$cc' failed to compile conftest.c."
411 else
412 cc_name="$($CONFTEST compiler)"
413 gcc_major="$($CONFTEST version)"
414 gcc_minor="$($CONFTEST minor)"
415 bigendian="$($CONFTEST bigendian)"
416 _triplet="$($CONFTEST triplet)"
418 if test "$mingw32" = "no" ; then
419 if test -z "$triplet" -a -n "$_triplet"; then
420 if test -f "/usr/lib/$_triplet/crti.o"; then
421 triplet="$_triplet"
424 if test -z "$triplet"; then
425 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
426 if test -f "/usr/lib64/crti.o" ; then
427 tcc_lddir="lib64"
431 if test "$suggest" = "yes"; then
432 if test -f "/lib/ld-uClibc.so.0" ; then
433 echo "Perhaps you want ./configure --config-uClibc"
435 if test -f "/lib/ld-musl-$cpu.so.1"; then
436 echo "Perhaps you want ./configure --config-musl"
440 else
441 # can only make guesses about compiler and target
442 if test "${cc%tcc*}" != "$cc"; then
443 cc_name="tcc"
444 elif test "${cc%clang*}" != "$cc"; then
445 cc_name="clang"
447 case $cpu in
448 ppc|mips|s390) bigendian=yes;;
449 esac
450 case $targetos in
451 Linux)
452 default triplet "$cpu_set-linux-gnu"
453 esac
456 if test "$bigendian" = "yes" ; then
457 confvars="$confvars BIGENDIAN"
460 if test "$mingw32" = "yes" -a "$cc_name" = "gcc"; then
461 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
462 default LDFLAGS "-static"
465 if test "$cpu" = "arm"; then
466 if test "${triplet%eabihf}" != "$triplet" ; then
467 confvars="$confvars arm_eabihf arm_vfp"
468 elif test "${triplet%eabi}" != "$triplet" ; then
469 confvars="$confvars arm_eabi arm_vfp"
470 elif test -z "$build_cross"; then
471 if test "${_triplet%eabihf}" != "$_triplet" ; then
472 confvars="$confvars arm_eabihf arm_vfp"
473 elif test "${_triplet%eabi}" != "$_triplet" ; then
474 confvars="$confvars arm_eabi arm_vfp"
475 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
476 confvars="$confvars arm_vfp"
481 if test -n "$dwarf"; then
482 confvars="$confvars dwarf=$dwarf"
485 # a final configuration tuning
486 if test "$cc_name" != "tcc"; then
487 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
488 # we want -Wno- but gcc does not always reject unknown -Wno- options
489 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
490 OPT2="$OPT2 -Wstringop-truncation"
491 if test "$cc_name" = "clang"; then
492 OPT1="$OPT1 -fheinous-gnu-extensions"
493 OPT2="$OPT2 -Wstring-plus-int -Wdeprecated-declarations"
495 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
496 for o in $OPT1; do # enable these options
497 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
498 done
499 for o in $OPT2; do # disable these options
500 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
501 done
502 # cat cc_msg.txt
503 # echo $CFLAGS
504 rm -f cc_msg.txt a.out
505 else # cc is tcc
506 test "$ar_set" || ar="$cc -ar"
509 fcho() { if test -n "$2"; then echo "$1$2"; fi }
511 fcho "Binary directory " "$bindir"
512 fcho "TinyCC directory " "$tccdir"
513 fcho "Library directory " "$libdir"
514 fcho "Include directory " "$includedir"
515 fcho "Manual directory " "$mandir"
516 fcho "Info directory " "$infodir"
517 fcho "Doc directory " "$docdir"
518 fcho "Target root prefix " "$sysroot"
519 fcho "/usr/include dir " "$tcc_usrinclude"
520 echo "Source path $source_path"
521 echo "Build OS $(uname -m -s)"
522 echo "C compiler $cc ($gcc_major.$gcc_minor)"
523 echo "Target OS $targetos"
524 echo "CPU $cpu"
525 fcho "Triplet " "$triplet"
526 fcho "Libs " "$tcc_libpaths"
527 fcho "Sysinclude " "$tcc_sysincludepaths"
528 fcho "Crt " "$tcc_crtprefix"
529 fcho "Elfinterp " "$tcc_elfinterp"
530 fcho "Switches " "$tcc_switches"
531 fcho "Config " "${confvars# }"
532 echo "Creating config.mak and config.h"
534 cat >config.mak <<EOF
535 # Automatically generated by configure - do not modify
536 prefix=$prefix
537 bindir=\$(DESTDIR)$bindir
538 tccdir=\$(DESTDIR)$tccdir
539 libdir=\$(DESTDIR)$libdir
540 includedir=\$(DESTDIR)$includedir
541 mandir=\$(DESTDIR)$mandir
542 infodir=\$(DESTDIR)$infodir
543 docdir=\$(DESTDIR)$docdir
544 CC=$cc
545 CC_NAME=$cc_name
546 GCC_MAJOR=$gcc_major
547 GCC_MINOR=$gcc_minor
548 AR=$ar
549 CFLAGS=$CFLAGS
550 LDFLAGS=$LDFLAGS
551 LIBSUF=$LIBSUF
552 EXESUF=$EXESUF
553 DLLSUF=$DLLSUF
556 print_inc() {
557 local v="$2"
558 if test -n "$v"; then
559 test "$3" = "num" || v="\"$v\""
560 echo "#ifndef $1" >> $TMPH
561 echo "# define $1 $v" >> $TMPH
562 echo "#endif" >> $TMPH
566 print_mak() {
567 local v="$2"
568 if test -n "$v"; then
569 test "$3" = "num" || v="\"\\\"$v\\\"\""
570 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
574 echo "/* Automatically generated by configure - do not modify */" > $TMPH
576 print_inc CONFIG_SYSROOT "$sysroot"
577 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
578 print_inc DWARF_VERSION "$dwarf" num
579 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
580 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
581 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
582 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
583 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
584 print_mak CONFIG_TCC_SWITCHES "$tcc_switches"
585 print_mak CONFIG_LDDIR "$tcc_lddir"
586 print_mak CONFIG_TRIPLET "$triplet"
587 print_mak TCC_CPU_VERSION "$cpuver" num
589 echo "ARCH=$cpu" >> config.mak
590 echo "TARGETOS=$targetos" >> config.mak
591 echo "BUILDOS=$buildos" >> config.mak
593 predefs="1"
594 for v in $confvars ; do
595 test "$v" = "predefs=no" && predefs=""
596 if test "${v%=*}" = "$v"; then
597 echo "CONFIG_$v=yes" >> config.mak
598 else
599 echo "CONFIG_$v" >> config.mak
601 done
602 print_inc CONFIG_TCC_PREDEFS "$predefs" num
604 version=`head $source_path/VERSION`
605 echo "VERSION = $version" >> config.mak
606 echo "#define TCC_VERSION \"$version\"" >> $TMPH
607 echo "@set VERSION $version" > config.texi
609 if test "$source_path_used" = "yes" ; then
610 case $source_path in
611 /*) echo "TOPSRC=$source_path";;
612 *) echo "TOPSRC=\$(TOP)/$source_path";;
613 esac >>config.mak
614 else
615 echo 'TOPSRC=$(TOP)' >>config.mak
617 cat >>$TMPH <<EOF
618 #define GCC_MAJOR $gcc_major
619 #define GCC_MINOR $gcc_minor
620 #define CC_NAME CC_${cc_name}
623 diff $TMPH config.h >/dev/null 2>&1
624 if test $? -ne 0 ; then
625 mv -f $TMPH config.h
626 else
627 echo "config.h is unchanged"
630 rm -f $TMPN* $CONFTEST
632 # ---------------------------------------------------------------------------
633 # build tree in object directory if source path is different from current one
635 fn_makelink()
637 tgt=$1/$2
638 case $2 in
639 */*) dn=${2%/*}
640 test -d $dn || mkdir -p $dn
641 case $1 in
642 /*) ;;
643 *) while test $dn ; do
644 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
645 done
647 esac
649 esac
651 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
654 if test "$source_path_used" = "yes" ; then
655 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
656 for f in $FILES ; do
657 fn_makelink $source_path $f
658 done
661 # ---------------------------------------------------------------------------