riscv64-tok.h: update with more instructions from the spec
[tinycc.git] / configure
blob6ec98f38ddcac3054b81b98f5947e3b9f3b3ded9
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=`command -v cc`
71 cc=`readlink $cc || echo clang`
72 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
73 DLLSUF=".dylib"
74 case $* in *--config-new_macho*) ;; *)
75 # if new_macho was not specified and (known) ver <= 10, use old (=no)
76 osxver=$(sw_vers -productVersion 2>/dev/null) # X.Y.Z
77 osxver=${osxver%%.*} # major version (or empty on sw_vers error)
78 [ "${osxver:-11}" -ge 11 ] || confvars="$confvars new_macho=no"
79 esac
81 Windows_NT|MINGW*|MSYS*|CYGWIN*)
82 mingw32=yes
83 targetos=WIN32
85 DragonFly|OpenBSD|FreeBSD|NetBSD)
86 confvars="$confvars BSD ldl=no"
88 Android)
89 confvars="$confvars Android pie new-dtags"
90 if test -n "$TERMUX_VERSION"; then
91 prefix="$PREFIX" # "/data/data/com.termux/files/usr"
92 sysroot="$PREFIX"
93 test "$cpu" = "aarch64" -o "$cpu" = "x86_64" && S="64" || S=""
94 tcc_sysincludepaths="{B}/include:{R}/include/\\\"CONFIG_TRIPLET\\\":{R}/include"
95 tcc_libpaths="{B}:{R}/lib:/system/lib${S}"
96 tcc_crtprefix="{R}/lib"
97 tcc_elfinterp="/system/bin/linker${S}"
98 use_triplet="yes"
99 tcc_switches="-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
104 esac
106 # find source path
107 source_path=${0%configure}
108 source_path=${source_path%/}
109 source_path_used="yes"
110 if test -z "$source_path" -o "$source_path" = "." ; then
111 source_path=`pwd`
112 source_path_used="no"
115 for opt do
116 eval opt=\"$opt\"
117 case "$opt" in
118 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2-`
120 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2-`
122 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2-`
124 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2-`
126 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2-`
128 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2-`
130 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2-`
132 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2-`
134 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2-`
136 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2-`
138 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2-`
140 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2-`
142 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2-`
144 --cc=*) cc=`echo $opt | cut -d '=' -f 2-`
146 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set="yes"
148 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
150 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
152 --extra-libs=*) extralibs="${opt#--extra-libs=}"
154 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2-`
156 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2-`
158 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2-`
160 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2-`
162 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2-`
164 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
166 --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
168 --enable-cross) confvars="$confvars cross"
170 --disable-static) confvars="$confvars static=no"
172 --enable-static) confvars="$confvars static"
174 --disable-rpath) confvars="$confvars rpath=no"
176 --debug) confvars="$confvars debug"
178 --with-libgcc) confvars="$confvars libgcc"
180 --with-selinux) confvars="$confvars selinux"
182 --tcc-switches=*) tcc_switches=`echo $opt | cut -d '=' -f 2-`
184 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
186 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
188 --help|-h) show_help="yes"
190 *) echo "configure: WARNING: unrecognized option $opt"
192 esac
193 done
195 cc="${cross_prefix}${cc}"
196 ar="${cross_prefix}${ar}"
198 # Checking for CFLAGS
199 test -z "$CFLAGS" && CFLAGS="-Wall -O2"
201 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
202 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
203 CFLAGS="$CFLAGS -arch $cpu"
204 LDFLAGS="$LDFLAGS -arch $cpu"
207 case "$cpu" in
208 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
209 cpu="i386"
211 x86_64|amd64|x86-64)
212 cpu="x86_64"
214 evbarm)
215 case "`uname -p`" in
216 aarch64|arm64)
217 cpu="arm64"
219 earmv*)
220 cpu="arm"
222 esac
224 aarch64|arm64|evbarm)
225 cpu="arm64"
227 arm*)
228 case "$cpu" in
229 arm|armv4l)
230 cpuver=4
232 armv5tel|armv5tejl)
233 cpuver=5
235 armv6j|armv6l)
236 cpuver=6
238 armv7|armv7a|armv7l)
239 cpuver=7
241 esac
242 cpu="arm"
244 alpha)
245 cpu="alpha"
247 "Power Macintosh"|ppc|ppc64)
248 cpu="ppc"
250 mips)
251 cpu="mips"
253 s390)
254 cpu="s390"
256 riscv64)
257 cpu="riscv64"
260 echo "Unsupported CPU"
261 exit 1
263 esac
265 if test "$mingw32" = "yes" ; then
266 if test "$source_path_used" = "no"; then
267 source_path="."
269 test -z "$prefix" && prefix="C:/Program Files/tcc"
270 test -z "$tccdir" && tccdir="${prefix}" && tccdir_auto="yes"
271 test -z "$bindir" && bindir="${tccdir}"
272 test -z "$docdir" && docdir="${tccdir}/doc"
273 test -z "$libdir" && libdir="${tccdir}/libtcc"
274 confvars="$confvars WIN32"
275 LIBSUF=".lib"
276 EXESUF=".exe"
277 DLLSUF=".dll"
278 else
279 if test -z "$prefix" ; then
280 prefix="/usr/local"
282 if test -z "$sharedir" ; then
283 sharedir="${prefix}/share"
285 if test x"$execprefix" = x""; then
286 execprefix="${prefix}"
288 if test x"$libdir" = x""; then
289 libdir="${execprefix}/lib"
291 if test x"$bindir" = x""; then
292 bindir="${execprefix}/bin"
294 if test x"$docdir" = x""; then
295 docdir="${sharedir}/doc"
297 if test x"$mandir" = x""; then
298 mandir="${sharedir}/man"
300 if test x"$infodir" = x""; then
301 infodir="${sharedir}/info"
303 if test x"$tccdir" = x""; then
304 tccdir="${libdir}/tcc"
306 if test x"$includedir" = x""; then
307 includedir="${prefix}/include"
309 fi # mingw32
311 if test x"$show_help" = "xyes" ; then
312 cat << EOF
313 Usage: configure [options]
314 Options: [defaults in brackets after descriptions]
316 Standard options:
317 --help print this message
318 --prefix=PREFIX install in PREFIX [$prefix]
319 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
320 [same as prefix]
321 --bindir=DIR user executables in DIR [EPREFIX/bin]
322 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
323 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
324 --includedir=DIR C header files in DIR [PREFIX/include]
325 --sharedir=DIR documentation root DIR [PREFIX/share]
326 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
327 --mandir=DIR man documentation in DIR [SHAREDIR/man]
328 --infodir=DIR info documentation in DIR [SHAREDIR/info]
330 Advanced options (experts only):
331 --source-path=PATH path of source code [$source_path]
332 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
333 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
334 --cc=CC use C compiler CC [$cc]
335 --ar=AR create archives using AR [$ar]
336 --extra-cflags= specify compiler flags [$CFLAGS]
337 --extra-ldflags= specify linker options [$LDFLAGS]
338 --cpu=CPU CPU [$cpu]
340 --debug include debug info with resulting binaries
341 --disable-static make libtcc.so instead of libtcc.a
342 --enable-static make libtcc.a instead of libtcc.dll (win32)
343 --disable-rpath disable use of -rpath with libtcc.so
344 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
345 --with-selinux use mmap for executable memory (tcc -run)
346 --enable-cross build cross compilers (see also 'make help')
348 --sysincludepaths=... specify system include paths, colon separated
349 --libpaths=... specify system library paths, colon separated
350 --crtprefix=... specify locations of crt?.o, colon separated
351 --elfinterp=... specify elf interpreter
352 --triplet=... specify system library/include directory triplet
353 --tcc-switches=... specify implicit switches passed to tcc
355 --config-uClibc,-musl enable system specific configurations
356 --config-mingw32 build on windows using msys, busybox, etc.
357 --config-backtrace=no disable stack backtraces (with -run or -bt)
358 --config-bcheck=no disable bounds checker (-b)
359 --config-predefs=no do not compile tccdefs.h, instead just include
360 --config-new_macho=no|yes Force apple object format (autodetect osx <= 10)
361 --config-codesign Use codesign on apple to sign executables
362 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
364 exit 1
367 if test -z "$cross_prefix" ; then
368 CONFTEST=./conftest$EXESUF
369 if ! $cc -o $CONFTEST $source_path/conftest.c ; then
370 echo "configure: error: '$cc' failed to compile conftest.c."
371 else
372 cc_name="$($CONFTEST compiler)"
373 gcc_major="$($CONFTEST version)"
374 gcc_minor="$($CONFTEST minor)"
375 bigendian="$($CONFTEST bigendian)"
376 _triplet="$($CONFTEST triplet)"
378 if test "$mingw32" = "no" ; then
380 if test -z "$triplet" -a -n "$_triplet"; then
381 if test -f "/usr/lib/$_triplet/crti.o" -o -n "$use_triplet" ; then
382 triplet="$_triplet"
386 if test -z "$triplet"; then
387 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
388 if test -f "/usr/lib64/crti.o" ; then
389 tcc_lddir="lib64"
394 if test "$cpu" = "arm" ; then
395 if test "${triplet%eabihf}" != "$triplet" ; then
396 confvars="$confvars arm_eabihf arm_vfp"
397 elif test "${triplet%eabi}" != "$triplet" ; then
398 confvars="$confvars arm_eabi arm_vfp"
399 elif test "${_triplet%eabihf}" != "$_triplet" ; then
400 confvars="$confvars arm_eabihf arm_vfp"
401 elif test "${_triplet%eabi}" != "$_triplet" ; then
402 confvars="$confvars arm_eabi arm_vfp"
403 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
404 confvars="$confvars arm_vfp"
408 if test "$suggest" = "yes"; then
409 if test -f "/lib/ld-uClibc.so.0" ; then
410 echo "Perhaps you want ./configure --config-uClibc"
412 if test -f "/lib/ld-musl-$cpu.so.1"; then
413 echo "Perhaps you want ./configure --config-musl"
416 else # mingw32 = yes
417 if test "$cc_name" = "gcc"; then
418 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
419 test -z "$LDFLAGS" && LDFLAGS="-static"
422 else
423 # if cross compiling, cannot launch a program, so make a static guess
424 case $cpu in
425 ppc|mips|s390) bigendian=yes;;
426 esac
429 if test "$bigendian" = "yes" ; then
430 confvars="$confvars BIGENDIAN"
433 # a final configuration tuning
434 if test "$cc_name" != "tcc"; then
435 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
436 # we want -Wno- but gcc does not always reject unknown -Wno- options
437 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
438 OPT2="$OPT2 -Wstringop-truncation"
439 if test "$cc_name" = "clang"; then
440 OPT1="$OPT1 -fheinous-gnu-extensions"
441 OPT2="$OPT2 -Wstring-plus-int"
443 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
444 for o in $OPT1; do # enable these options
445 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
446 done
447 for o in $OPT2; do # disable these options
448 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
449 done
450 # cat cc_msg.txt
451 # echo $CFLAGS
452 rm -f cc_msg.txt a.out
453 else # cc is tcc
454 test "$ar_set" || ar="$cc -ar"
457 fcho() { if test -n "$2"; then echo "$1$2"; fi }
459 fcho "Binary directory " "$bindir"
460 fcho "TinyCC directory " "$tccdir"
461 fcho "Library directory " "$libdir"
462 fcho "Include directory " "$includedir"
463 fcho "Manual directory " "$mandir"
464 fcho "Info directory " "$infodir"
465 fcho "Doc directory " "$docdir"
466 fcho "Target root prefix " "$sysroot"
467 fcho "/usr/include dir " "$tcc_usrinclude"
468 echo "Source path $source_path"
469 echo "C compiler $cc ($gcc_major.$gcc_minor)"
470 echo "Target OS $targetos"
471 echo "CPU $cpu"
472 fcho "Triplet " "$triplet"
473 fcho "Config " "${confvars# }"
474 echo "Creating config.mak and config.h"
476 cat >config.mak <<EOF
477 # Automatically generated by configure - do not modify
478 prefix=$prefix
479 bindir=\$(DESTDIR)$bindir
480 tccdir=\$(DESTDIR)$tccdir
481 libdir=\$(DESTDIR)$libdir
482 includedir=\$(DESTDIR)$includedir
483 mandir=\$(DESTDIR)$mandir
484 infodir=\$(DESTDIR)$infodir
485 docdir=\$(DESTDIR)$docdir
486 CC=$cc
487 CC_NAME=$cc_name
488 GCC_MAJOR=$gcc_major
489 GCC_MINOR=$gcc_minor
490 AR=$ar
491 CFLAGS=$CFLAGS
492 LDFLAGS=$LDFLAGS
493 LIBSUF=$LIBSUF
494 EXESUF=$EXESUF
495 DLLSUF=$DLLSUF
498 print_inc() {
499 local v="$2"
500 if test -n "$v"; then
501 test "$3" = "num" || v="\"$v\""
502 echo "#ifndef $1" >> $TMPH
503 echo "# define $1 $v" >> $TMPH
504 echo "#endif" >> $TMPH
508 print_mak() {
509 local v="$2"
510 if test -n "$v"; then
511 test "$3" = "num" || v="\"\\\"$v\\\"\""
512 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
516 echo "/* Automatically generated by configure - do not modify */" > $TMPH
518 print_inc CONFIG_SYSROOT "$sysroot"
519 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
520 print_inc DWARF_VERSION "$dwarf" num
521 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
522 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
523 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
524 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
525 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
526 print_mak CONFIG_TCC_SWITCHES "$tcc_switches"
527 print_mak CONFIG_LDDIR "$tcc_lddir"
528 print_mak CONFIG_TRIPLET "$triplet"
529 print_mak TCC_CPU_VERSION "$cpuver" num
531 echo "ARCH=$cpu" >> config.mak
532 echo "TARGETOS=$targetos" >> config.mak
534 predefs="1"
535 for v in $confvars ; do
536 test "$v" = "predefs=no" && predefs=""
537 if test "${v%=*}" = "$v"; then
538 echo "CONFIG_$v=yes" >> config.mak
539 else
540 echo "CONFIG_$v" >> config.mak
542 done
543 print_inc CONFIG_TCC_PREDEFS "$predefs" num
545 version=`head $source_path/VERSION`
546 echo "VERSION = $version" >> config.mak
547 echo "#define TCC_VERSION \"$version\"" >> $TMPH
548 echo "@set VERSION $version" > config.texi
550 if test "$source_path_used" = "yes" ; then
551 case $source_path in
552 /*) echo "TOPSRC=$source_path";;
553 *) echo "TOPSRC=\$(TOP)/$source_path";;
554 esac >>config.mak
555 else
556 echo 'TOPSRC=$(TOP)' >>config.mak
558 cat >>$TMPH <<EOF
559 #define GCC_MAJOR $gcc_major
560 #define GCC_MINOR $gcc_minor
561 #define CC_NAME CC_${cc_name}
564 diff $TMPH config.h >/dev/null 2>&1
565 if test $? -ne 0 ; then
566 mv -f $TMPH config.h
567 else
568 echo "config.h is unchanged"
571 rm -f $TMPN* $CONFTEST
573 # ---------------------------------------------------------------------------
574 # build tree in object directory if source path is different from current one
576 fn_makelink()
578 tgt=$1/$2
579 case $2 in
580 */*) dn=${2%/*}
581 test -d $dn || mkdir -p $dn
582 case $1 in
583 /*) ;;
584 *) while test $dn ; do
585 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
586 done
588 esac
590 esac
592 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
595 if test "$source_path_used" = "yes" ; then
596 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
597 for f in $FILES ; do
598 fn_makelink $source_path $f
599 done
602 # ---------------------------------------------------------------------------