riscv64-asm.c: asm_emit_j: correct check of immediate
[tinycc.git] / configure
blob799973b10edbdbce75e48446d31e6d3efe8796fc
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"
60 # find source path
61 source_path=${0%configure}
62 source_path=${source_path%/}
64 for opt do
65 eval opt=\"$opt\"
66 case "$opt" in
67 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2-`
69 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2-`
71 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2-`
73 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2-`
75 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2-`
77 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2-`
79 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2-`
81 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2-`
83 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2-`
85 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2-`
87 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2-`
89 --targetos=*) targetos=`echo $opt | cut -d '=' -f 2-`
91 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2-`
93 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2-`
95 --cc=*) cc=`echo $opt | cut -d '=' -f 2-`
97 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set="yes"
99 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
101 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
103 --extra-libs=*) extralibs="${opt#--extra-libs=}"
105 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2-`
107 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2-`
109 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2-`
111 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2-`
113 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2-`
115 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
117 --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
119 --enable-cross) confvars="$confvars cross"
121 --disable-static) confvars="$confvars static=no"
123 --enable-static) confvars="$confvars static"
125 --disable-rpath) confvars="$confvars rpath=no"
127 --debug) confvars="$confvars debug"
129 --with-libgcc) confvars="$confvars libgcc"
131 --with-selinux) confvars="$confvars selinux"
133 --tcc-switches=*) tcc_switches=`echo $opt | cut -d '=' -f 2-`
135 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
137 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
139 --help|-h) show_help="yes"
141 *) echo "configure: WARNING: unrecognized option $opt"
143 esac
144 done
146 show_help() {
147 cat << EOF
148 Usage: configure [options]
149 Options: [defaults in brackets after descriptions]
151 Standard options:
152 --help print this message
153 --prefix=PREFIX install in PREFIX [$prefix]
154 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
155 [same as prefix]
156 --bindir=DIR user executables in DIR [EPREFIX/bin]
157 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
158 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
159 --includedir=DIR C header files in DIR [PREFIX/include]
160 --sharedir=DIR documentation root DIR [PREFIX/share]
161 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
162 --mandir=DIR man documentation in DIR [SHAREDIR/man]
163 --infodir=DIR info documentation in DIR [SHAREDIR/info]
165 Advanced options (experts only):
166 --source-path=PATH path of source code [$source_path]
167 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
168 --cc=CC use C compiler CC [$cc]
169 --ar=AR create archives using AR [$ar]
170 --extra-cflags= specify compiler flags [$CFLAGS]
171 --extra-ldflags= specify linker options [$LDFLAGS]
173 --debug include debug info with resulting binaries
174 --disable-static make libtcc.so instead of libtcc.a
175 --enable-static make libtcc.a instead of libtcc.dll (win32)
176 --disable-rpath disable use of -rpath with libtcc.so
177 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
178 --with-selinux use mmap for executable memory (tcc -run)
179 --enable-cross build cross compilers (see also 'make help')
181 --sysincludepaths=... specify system include paths, colon separated
182 --libpaths=... specify system library paths, colon separated
183 --crtprefix=... specify locations of crt?.o, colon separated
184 --elfinterp=... specify elf interpreter
185 --triplet=... specify system library/include directory triplet
186 --tcc-switches=... specify implicit switches passed to tcc
188 --config-uClibc,-musl enable system specific configurations
189 --config-mingw32 build on windows using msys, busybox, etc.
190 --config-backtrace=no disable stack backtraces (with -run or -bt)
191 --config-bcheck=no disable bounds checker (-b)
192 --config-predefs=no do not compile tccdefs.h, instead just include
193 --config-new_macho=no|yes Force apple object format (autodetect osx <= 10)
194 --config-codesign=no do not use codesign on apple to sign executables
195 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
197 Cross build options (experimental):
198 --cpu=CPU target CPU [$cpu]
199 --targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos]
200 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
202 exit 1
205 default() # set variable unless already set
207 local v
208 eval v=\"\$$1\"
209 test -z "$v" && eval $1=\"$2\"
212 default_conf() # add to confvars unless already present
214 local v=${1%=*}
215 test "${confvars%$v*}" = "${confvars}" && confvars="$confvars $1"
218 if test -z "$source_path" -o "$source_path" = "." ; then
219 source_path=$(pwd)
220 source_path_used="no"
221 else
222 source_path_used="yes"
225 # OS specific
226 buildos=$(uname)
228 case $buildos in
229 Windows_NT|MINGW*|MSYS*|CYGWIN*)
230 buildos="WIN32"
232 Linux)
233 if test "$(uname -o)" = "Android"; then
234 buildos=Android
235 if test -n "$TERMUX_VERSION"; then
236 buildos=Termux
240 esac
242 if test "$mingw32" = "yes"; then
243 default targetos WIN32
244 else
245 default targetos "$buildos"
248 cpu_sys=$(uname -m)
249 default cpu "$cpu_sys"
250 cpu_set="$cpu"
252 # check for crpss build
253 if test "$cpu_set" != "$cpu_sys" \
254 -o "$targetos" != "$buildos" \
255 -o -n "$cross_prefix" ; then
256 build_cross="yes"
257 cc="${cross_prefix}${cc}"
258 ar="${cross_prefix}${ar}"
261 case "$cpu" in
262 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
263 cpu="i386"
265 x86_64|amd64|x86-64)
266 cpu="x86_64"
268 evbarm)
269 case "`uname -p`" in
270 aarch64|arm64)
271 cpu="arm64"
273 earmv*)
274 cpu="arm"
276 esac
278 aarch64|arm64|evbarm)
279 cpu="arm64"
281 arm*)
282 case "$cpu" in
283 arm|armv4l)
284 cpuver=4
286 armv5tel|armv5tejl)
287 cpuver=5
289 armv6j|armv6l)
290 cpuver=6
292 armv7|armv7a|armv7l)
293 cpuver=7
295 esac
296 cpu="arm"
298 alpha)
299 cpu="alpha"
301 "Power Macintosh"|ppc|ppc64)
302 cpu="ppc"
304 mips)
305 cpu="mips"
307 s390)
308 cpu="s390"
310 riscv64)
311 cpu="riscv64"
314 echo "Unsupported CPU"
315 exit 1
317 esac
319 case $targetos in
320 Darwin)
321 dwarf=4
322 confvars="$confvars OSX"
323 default_conf "codesign"
324 DLLSUF=".dylib"
325 if test -z "$build_cross"; then
326 cc=`command -v cc`
327 cc=`readlink $cc || echo clang`
328 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
329 if test "${confvars%new_macho*}" = "${confvars}"; then
330 # if new_macho was not specified and (known) ver <= 10, use old (=no)
331 osxver=$(sw_vers -productVersion 2>/dev/null) # X.Y.Z
332 osxver=${osxver%%.*} # major version (or empty on sw_vers error)
333 [ "${osxver:-11}" -ge 11 ] || confvars="$confvars new_macho=no"
336 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
337 if test "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
338 CFLAGS="$CFLAGS -arch $cpu"
339 LDFLAGS="$LDFLAGS -arch $cpu"
342 DragonFly|OpenBSD|FreeBSD|NetBSD)
343 confvars="$confvars BSD ldl=no"
345 Android|Termux)
346 if test "$targetos" = "Termux"; then
347 targetos=Android
348 default sysroot "/data/data/com.termux/files/usr"
349 else
350 default sysroot "/usr"
352 default prefix "${sysroot}"
353 confvars="$confvars Android new-dtags rpath=no"
354 test "${cpu}" != "i386" && confvars="$confvars pie"
355 default_conf "static=no"
356 if test "${cpu}" = "arm"; then
357 default triplet "arm-linux-androideabi"
358 cpuver=7
359 else
360 default triplet "${cpu_set}-linux-android"
362 test "${cpu%64}" != "${cpu}" && S="64" || S=""
363 default tcc_sysincludepaths "{B}/include:{R}/include:{R}/include/${triplet}"
364 default tcc_libpaths "{B}:{R}/lib:/system/lib${S}"
365 default tcc_crtprefix "{R}/lib"
366 default tcc_elfinterp "/system/bin/linker${S}"
367 default tcc_switches "-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
369 WIN32)
370 mingw32="yes"
371 confvars="$confvars WIN32"
372 default prefix "C:/Program Files/tcc"
373 default tccdir "${prefix}"
374 default bindir "${tccdir}"
375 default docdir "${tccdir}/doc"
376 default libdir "${tccdir}/libtcc"
377 test "$tccdir" = "$bindir" && tccdir_auto="yes"
378 LIBSUF=".lib"
379 EXESUF=".exe"
380 DLLSUF=".dll"
381 if test "$source_path_used" = "no"; then
382 source_path="."
387 esac
389 if test "$mingw32" = "no"; then
390 default prefix "/usr/local"
391 default execprefix "${prefix}"
392 default libdir "${execprefix}/lib"
393 default bindir "${execprefix}/bin"
394 default tccdir "${libdir}/tcc"
395 default includedir "${prefix}/include"
396 default sharedir "${prefix}/share"
397 default docdir "${sharedir}/doc"
398 default mandir "${sharedir}/man"
399 default infodir "${sharedir}/info"
402 # set default CFLAGS
403 default CFLAGS "-Wall -O2"
405 if test "$mingw32" = "yes" -a "$cc_name" = "gcc"; then
406 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
407 default LDFLAGS "-static"
410 if test x"$show_help" = "xyes" ; then
411 show_help
414 if test -z "$build_cross"; then
415 CONFTEST=./conftest$EXESUF
416 if ! $cc -o $CONFTEST $source_path/conftest.c ; then
417 echo "configure: error: '$cc' failed to compile conftest.c."
418 else
419 cc_name="$($CONFTEST compiler)"
420 gcc_major="$($CONFTEST version)"
421 gcc_minor="$($CONFTEST minor)"
422 bigendian="$($CONFTEST bigendian)"
423 _triplet="$($CONFTEST triplet)"
425 if test "$mingw32" = "no" ; then
426 if test -z "$triplet" -a -n "$_triplet"; then
427 if test -f "/usr/lib/$_triplet/crti.o"; then
428 triplet="$_triplet"
431 if test -z "$triplet"; then
432 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
433 if test -f "/usr/lib64/crti.o" ; then
434 tcc_lddir="lib64"
438 if test "$suggest" = "yes"; then
439 if test -f "/lib/ld-uClibc.so.0" ; then
440 echo "Perhaps you want ./configure --config-uClibc"
442 if test -f "/lib/ld-musl-$cpu.so.1"; then
443 echo "Perhaps you want ./configure --config-musl"
447 else
448 # can only make guesses about compiler and target
449 if test "${cc%tcc*}" != "$cc"; then
450 cc_name="tcc"
451 elif test "${cc%clang*}" != "$cc"; then
452 cc_name="clang"
454 case $cpu in
455 ppc|mips|s390) bigendian=yes;;
456 esac
457 case $targetos in
458 Linux)
459 default triplet "$cpu_set-linux-gnu"
460 esac
463 if test "$bigendian" = "yes" ; then
464 confvars="$confvars BIGENDIAN"
467 if test "$cpu" = "arm"; then
468 if test "${triplet%eabihf}" != "$triplet" ; then
469 confvars="$confvars arm_eabihf arm_vfp"
470 elif test "${triplet%eabi}" != "$triplet" ; then
471 confvars="$confvars arm_eabi arm_vfp"
472 elif test -z "$build_cross"; then
473 if test "${_triplet%eabihf}" != "$_triplet" ; then
474 confvars="$confvars arm_eabihf arm_vfp"
475 elif test "${_triplet%eabi}" != "$_triplet" ; then
476 confvars="$confvars arm_eabi arm_vfp"
477 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
478 confvars="$confvars arm_vfp"
483 # a final configuration tuning
484 if test "$cc_name" != "tcc"; then
485 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
486 # we want -Wno- but gcc does not always reject unknown -Wno- options
487 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
488 OPT2="$OPT2 -Wstringop-truncation"
489 if test "$cc_name" = "clang"; then
490 OPT1="$OPT1 -fheinous-gnu-extensions"
491 OPT2="$OPT2 -Wstring-plus-int -Wdeprecated-declarations"
493 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
494 for o in $OPT1; do # enable these options
495 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
496 done
497 for o in $OPT2; do # disable these options
498 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
499 done
500 # cat cc_msg.txt
501 # echo $CFLAGS
502 rm -f cc_msg.txt a.out
503 else # cc is tcc
504 test "$ar_set" || ar="$cc -ar"
507 fcho() { if test -n "$2"; then echo "$1$2"; fi }
509 fcho "Binary directory " "$bindir"
510 fcho "TinyCC directory " "$tccdir"
511 fcho "Library directory " "$libdir"
512 fcho "Include directory " "$includedir"
513 fcho "Manual directory " "$mandir"
514 fcho "Info directory " "$infodir"
515 fcho "Doc directory " "$docdir"
516 fcho "Target root prefix " "$sysroot"
517 fcho "/usr/include dir " "$tcc_usrinclude"
518 echo "Source path $source_path"
519 echo "C compiler $cc ($gcc_major.$gcc_minor)"
520 echo "Target OS $targetos"
521 echo "CPU $cpu"
522 fcho "Triplet " "$triplet"
523 fcho "Libs " "$tcc_libpaths"
524 fcho "Sysinclude " "$tcc_sysincludepaths"
525 fcho "Crt " "$tcc_crtprefix"
526 fcho "Elfinterp " "$tcc_elfinterp"
527 fcho "Switches " "$tcc_switches"
528 fcho "Config " "${confvars# }"
529 echo "Creating config.mak and config.h"
531 cat >config.mak <<EOF
532 # Automatically generated by configure - do not modify
533 prefix=$prefix
534 bindir=\$(DESTDIR)$bindir
535 tccdir=\$(DESTDIR)$tccdir
536 libdir=\$(DESTDIR)$libdir
537 includedir=\$(DESTDIR)$includedir
538 mandir=\$(DESTDIR)$mandir
539 infodir=\$(DESTDIR)$infodir
540 docdir=\$(DESTDIR)$docdir
541 CC=$cc
542 CC_NAME=$cc_name
543 GCC_MAJOR=$gcc_major
544 GCC_MINOR=$gcc_minor
545 AR=$ar
546 CFLAGS=$CFLAGS
547 LDFLAGS=$LDFLAGS
548 LIBSUF=$LIBSUF
549 EXESUF=$EXESUF
550 DLLSUF=$DLLSUF
553 print_inc() {
554 local v="$2"
555 if test -n "$v"; then
556 test "$3" = "num" || v="\"$v\""
557 echo "#ifndef $1" >> $TMPH
558 echo "# define $1 $v" >> $TMPH
559 echo "#endif" >> $TMPH
563 print_mak() {
564 local v="$2"
565 if test -n "$v"; then
566 test "$3" = "num" || v="\"\\\"$v\\\"\""
567 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
571 echo "/* Automatically generated by configure - do not modify */" > $TMPH
573 print_inc CONFIG_SYSROOT "$sysroot"
574 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
575 print_inc DWARF_VERSION "$dwarf" num
576 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
577 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
578 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
579 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
580 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
581 print_mak CONFIG_TCC_SWITCHES "$tcc_switches"
582 print_mak CONFIG_LDDIR "$tcc_lddir"
583 print_mak CONFIG_TRIPLET "$triplet"
584 print_mak TCC_CPU_VERSION "$cpuver" num
586 echo "ARCH=$cpu" >> config.mak
587 echo "TARGETOS=$targetos" >> config.mak
588 echo "BUILDOS=$buildos" >> config.mak
590 predefs="1"
591 for v in $confvars ; do
592 test "$v" = "predefs=no" && predefs=""
593 if test "${v%=*}" = "$v"; then
594 echo "CONFIG_$v=yes" >> config.mak
595 else
596 echo "CONFIG_$v" >> config.mak
598 done
599 print_inc CONFIG_TCC_PREDEFS "$predefs" num
601 version=`head $source_path/VERSION`
602 echo "VERSION = $version" >> config.mak
603 echo "#define TCC_VERSION \"$version\"" >> $TMPH
604 echo "@set VERSION $version" > config.texi
606 if test "$targetos" = "Darwin"; then
607 # On macOS, -current_version and -compatibility_version must not contain letters.
608 macos_dylib_version=`echo $version | sed 's/[^0-9.]//g'`
609 echo "MACOS_DYLIB_VERSION = $macos_dylib_version" >> config.mak
612 if test "$source_path_used" = "yes" ; then
613 case $source_path in
614 /*) echo "TOPSRC=$source_path";;
615 *) echo "TOPSRC=\$(TOP)/$source_path";;
616 esac >>config.mak
617 else
618 echo 'TOPSRC=$(TOP)' >>config.mak
620 cat >>$TMPH <<EOF
621 #define GCC_MAJOR $gcc_major
622 #define GCC_MINOR $gcc_minor
623 #define CC_NAME CC_${cc_name}
626 diff $TMPH config.h >/dev/null 2>&1
627 if test $? -ne 0 ; then
628 mv -f $TMPH config.h
629 else
630 echo "config.h is unchanged"
633 rm -f $TMPN* $CONFTEST
635 # ---------------------------------------------------------------------------
636 # build tree in object directory if source path is different from current one
638 fn_makelink()
640 tgt=$1/$2
641 case $2 in
642 */*) dn=${2%/*}
643 test -d $dn || mkdir -p $dn
644 case $1 in
645 /*) ;;
646 *) while test $dn ; do
647 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
648 done
650 esac
652 esac
654 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
657 if test "$source_path_used" = "yes" ; then
658 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
659 for f in $FILES ; do
660 fn_makelink $source_path $f
661 done
664 # ---------------------------------------------------------------------------