tccelf: avoid lookup of _GLOBAL_OFFSET_TABLE_
[tinycc.git] / configure
blobcd96ea3088a861773f4c50bb6ed6f3684bf8c77a
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 test -z "$CC" && CC="gcc"
31 test -z "$cc" && cc="$CC"
32 ar="ar"
33 bigendian="no"
34 mingw32="no"
35 LIBSUF=".a"
36 EXESUF=""
37 DLLSUF=".so"
38 tcc_usrinclude=""
39 tcc_sysincludepaths=""
40 tcc_libpaths=""
41 tcc_crtprefix=""
42 tcc_elfinterp=""
43 triplet=
44 tcc_lddir=
45 confvars=
46 suggest="yes"
47 gcc_major=0
48 gcc_minor=0
49 cc_name="$cc"
50 ar_set=
51 darwin=
52 cpu=
53 cpuver=
54 dwarf=
56 # OS specific
57 cpu_sys=`uname -m`
58 targetos=`uname`
60 case $targetos in
61 Darwin)
62 darwin=yes
63 confvars="$confvars OSX dll=no"
64 cc=`which cc`
65 cc=`readlink $cc || echo clang`
66 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
67 DLLSUF=".dylib"
69 Windows_NT|MINGW*|MSYS*|CYGWIN*)
70 mingw32=yes
71 targetos=WIN32
73 DragonFly|OpenBSD|FreeBSD|NetBSD)
74 confvars="$confvars BSD ldl=no"
78 esac
80 # find source path
81 source_path=${0%configure}
82 source_path=${source_path%/}
83 source_path_used="yes"
84 if test -z "$source_path" -o "$source_path" = "." ; then
85 source_path=`pwd`
86 source_path_used="no"
89 for opt do
90 eval opt=\"$opt\"
91 case "$opt" in
92 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2-`
94 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2-`
96 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2-`
98 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2-`
100 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2-`
102 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2-`
104 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2-`
106 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2-`
108 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2-`
110 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2-`
112 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2-`
114 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2-`
116 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2-`
118 --cc=*) cc=`echo $opt | cut -d '=' -f 2-`
120 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set="yes"
122 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
124 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
126 --extra-libs=*) extralibs="${opt#--extra-libs=}"
128 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2-`
130 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2-`
132 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2-`
134 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2-`
136 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2-`
138 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2-`
140 --dwarf=*) dwarf=`echo $opt | cut -d '=' -f 2-`
142 --enable-cross) confvars="$confvars cross"
144 --disable-static) confvars="$confvars static=no"
146 --enable-static) confvars="$confvars static"
148 --disable-rpath) confvars="$confvars rpath=no"
150 --debug) confvars="$confvars debug"
152 --with-libgcc) confvars="$confvars libgcc"
154 --with-selinux) confvars="$confvars selinux"
156 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
158 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
160 --help|-h) show_help="yes"
162 *) echo "configure: WARNING: unrecognized option $opt"
164 esac
165 done
167 cc="${cross_prefix}${cc}"
168 ar="${cross_prefix}${ar}"
170 # Checking for CFLAGS
171 test -z "$CFLAGS" && CFLAGS="-Wall -O2"
173 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
174 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
175 CFLAGS="$CFLAGS -arch $cpu"
176 LDFLAGS="$LDFLAGS -arch $cpu"
179 # checking for cpu
180 test -z "$cpu" && cpu="$cpu_sys"
182 case "$cpu" in
183 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
184 cpu="i386"
186 x86_64|amd64|x86-64)
187 cpu="x86_64"
189 evbarm)
190 case "`uname -p`" in
191 aarch64|arm64)
192 cpu="arm64"
194 earmv*)
195 cpu="arm"
197 esac
199 aarch64|arm64|evbarm)
200 cpu="arm64"
202 arm*)
203 case "$cpu" in
204 arm|armv4l)
205 cpuver=4
207 armv5tel|armv5tejl)
208 cpuver=5
210 armv6j|armv6l)
211 cpuver=6
213 armv7|armv7a|armv7l)
214 cpuver=7
216 esac
217 cpu="arm"
219 alpha)
220 cpu="alpha"
222 "Power Macintosh"|ppc|ppc64)
223 cpu="ppc"
225 mips)
226 cpu="mips"
228 s390)
229 cpu="s390"
231 riscv64)
232 cpu="riscv64"
235 echo "Unsupported CPU"
236 exit 1
238 esac
240 if test "$mingw32" = "yes" ; then
241 if test "$source_path_used" = "no"; then
242 source_path="."
244 test -z "$prefix" && prefix="C:/Program Files/tcc"
245 test -z "$tccdir" && tccdir="${prefix}" && tccdir_auto="yes"
246 test -z "$bindir" && bindir="${tccdir}"
247 test -z "$docdir" && docdir="${tccdir}/doc"
248 test -z "$libdir" && libdir="${tccdir}/libtcc"
249 confvars="$confvars WIN32"
250 LIBSUF=".lib"
251 EXESUF=".exe"
252 DLLSUF=".dll"
253 else
254 if test -z "$prefix" ; then
255 prefix="/usr/local"
257 if test -z "$sharedir" ; then
258 sharedir="${prefix}/share"
260 if test x"$execprefix" = x""; then
261 execprefix="${prefix}"
263 if test x"$libdir" = x""; then
264 libdir="${execprefix}/lib"
266 if test x"$bindir" = x""; then
267 bindir="${execprefix}/bin"
269 if test x"$docdir" = x""; then
270 docdir="${sharedir}/doc"
272 if test x"$mandir" = x""; then
273 mandir="${sharedir}/man"
275 if test x"$infodir" = x""; then
276 infodir="${sharedir}/info"
278 if test x"$tccdir" = x""; then
279 tccdir="${libdir}/tcc"
281 if test x"$includedir" = x""; then
282 includedir="${prefix}/include"
284 fi # mingw32
286 if test x"$show_help" = "xyes" ; then
287 cat << EOF
288 Usage: configure [options]
289 Options: [defaults in brackets after descriptions]
291 Standard options:
292 --help print this message
293 --prefix=PREFIX install in PREFIX [$prefix]
294 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
295 [same as prefix]
296 --bindir=DIR user executables in DIR [EPREFIX/bin]
297 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
298 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
299 --includedir=DIR C header files in DIR [PREFIX/include]
300 --sharedir=DIR documentation root DIR [PREFIX/share]
301 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
302 --mandir=DIR man documentation in DIR [SHAREDIR/man]
303 --infodir=DIR info documentation in DIR [SHAREDIR/info]
305 Advanced options (experts only):
306 --source-path=PATH path of source code [$source_path]
307 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
308 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
309 --cc=CC use C compiler CC [$cc]
310 --ar=AR create archives using AR [$ar]
311 --extra-cflags= specify compiler flags [$CFLAGS]
312 --extra-ldflags= specify linker options [$LDFLAGS]
313 --cpu=CPU CPU [$cpu]
315 --debug include debug info with resulting binaries
316 --disable-static make libtcc.so instead of libtcc.a
317 --enable-static make libtcc.a instead of libtcc.dll (win32)
318 --disable-rpath disable use of -rpath with libtcc.so
319 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
320 --with-selinux use mmap for executable memory (tcc -run)
321 --enable-cross build cross compilers (see also 'make help')
323 --sysincludepaths=... specify system include paths, colon separated
324 --libpaths=... specify system library paths, colon separated
325 --crtprefix=... specify locations of crt?.o, colon separated
326 --elfinterp=... specify elf interpreter
327 --triplet=... specify system library/include directory triplet
329 --config-uClibc,-musl enable system specific configurations
330 --config-mingw32 build on windows using msys, busybox, etc.
331 --config-backtrace=no disable stack backtraces (with -run or -bt)
332 --config-bcheck=no disable bounds checker (-b)
333 --config-predefs=no do not compile tccdefs.h, instead just include
334 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
336 exit 1
339 if test -z "$cross_prefix" ; then
340 CONFTEST=./conftest$EXESUF
341 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
342 echo "configure: error: '$cc' failed to compile conftest.c."
343 else
344 cc_name="$($CONFTEST compiler)"
345 gcc_major="$($CONFTEST version)"
346 gcc_minor="$($CONFTEST minor)"
347 bigendian="$($CONFTEST bigendian)"
348 _triplet="$($CONFTEST triplet)"
350 if test "$mingw32" = "no" ; then
352 if test -z "$triplet"; then
353 if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then
354 triplet="$_triplet"
358 if test -z "$triplet"; then
359 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
360 if test -f "/usr/lib64/crti.o" ; then
361 tcc_lddir="lib64"
366 if test "$cpu" = "arm" ; then
367 if test "${triplet%eabihf}" != "$triplet" ; then
368 confvars="$confvars arm_eabihf arm_vfp"
369 elif test "${triplet%eabi}" != "$triplet" ; then
370 confvars="$confvars arm_eabi arm_vfp"
371 elif test "${_triplet%eabihf}" != "$_triplet" ; then
372 confvars="$confvars arm_eabihf arm_vfp"
373 elif test "${_triplet%eabi}" != "$_triplet" ; then
374 confvars="$confvars arm_eabi arm_vfp"
376 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
377 confvars="$confvars arm_vfp"
381 if test "$suggest" = "yes"; then
382 if test -f "/lib/ld-uClibc.so.0" ; then
383 echo "Perhaps you want ./configure --config-uClibc"
385 if test -f "/lib/ld-musl-$cpu.so.1"; then
386 echo "Perhaps you want ./configure --config-musl"
389 else # mingw32 = yes
390 if test "$cc_name" = "gcc"; then
391 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
392 test -z "$LDFLAGS" && LDFLAGS="-static"
395 else
396 # if cross compiling, cannot launch a program, so make a static guess
397 case $cpu in
398 ppc|mips|s390) bigendian=yes;;
399 esac
402 if test "$bigendian" = "yes" ; then
403 confvars="$confvars BIGENDIAN"
406 # a final configuration tuning
407 if test "$cc_name" != "tcc"; then
408 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
409 # we want -Wno- but gcc does not always reject unknown -Wno- options
410 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
411 OPT2="$OPT2 -Wstringop-truncation"
412 if test "$cc_name" = "clang"; then
413 OPT1="$OPT1 -fheinous-gnu-extensions"
414 OPT2="$OPT2 -Wstring-plus-int"
416 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
417 for o in $OPT1; do # enable these options
418 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
419 done
420 for o in $OPT2; do # disable these options
421 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
422 done
423 # cat cc_msg.txt
424 # echo $CFLAGS
425 rm -f cc_msg.txt a.out
426 else # cc is tcc
427 test "$ar_set" || ar="$cc -ar"
430 fcho() { if test -n "$2"; then echo "$1$2"; fi }
432 fcho "Binary directory " "$bindir"
433 fcho "TinyCC directory " "$tccdir"
434 fcho "Library directory " "$libdir"
435 fcho "Include directory " "$includedir"
436 fcho "Manual directory " "$mandir"
437 fcho "Info directory " "$infodir"
438 fcho "Doc directory " "$docdir"
439 fcho "Target root prefix " "$sysroot"
440 fcho "/usr/include dir " "$tcc_usrinclude"
441 echo "Source path $source_path"
442 echo "C compiler $cc ($gcc_major.$gcc_minor)"
443 echo "Target OS $targetos"
444 echo "CPU $cpu"
445 fcho "Triplet " "$triplet"
446 fcho "Config " "${confvars# }"
447 echo "Creating config.mak and config.h"
449 cat >config.mak <<EOF
450 # Automatically generated by configure - do not modify
451 prefix=$prefix
452 bindir=\$(DESTDIR)$bindir
453 tccdir=\$(DESTDIR)$tccdir
454 libdir=\$(DESTDIR)$libdir
455 includedir=\$(DESTDIR)$includedir
456 mandir=\$(DESTDIR)$mandir
457 infodir=\$(DESTDIR)$infodir
458 docdir=\$(DESTDIR)$docdir
459 CC=$cc
460 CC_NAME=$cc_name
461 GCC_MAJOR=$gcc_major
462 GCC_MINOR=$gcc_minor
463 AR=$ar
464 CFLAGS=$CFLAGS
465 LDFLAGS=$LDFLAGS
466 LIBSUF=$LIBSUF
467 EXESUF=$EXESUF
468 DLLSUF=$DLLSUF
471 print_inc() {
472 local v="$2"
473 if test -n "$v"; then
474 test "$3" = "num" || v="\"$v\""
475 echo "#ifndef $1" >> $TMPH
476 echo "# define $1 $v" >> $TMPH
477 echo "#endif" >> $TMPH
481 print_mak() {
482 local v="$2"
483 if test -n "$v"; then
484 test "$3" = "num" || v="\"\\\"$v\\\"\""
485 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
489 echo "/* Automatically generated by configure - do not modify */" > $TMPH
491 print_inc CONFIG_SYSROOT "$sysroot"
492 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR "$tccdir"
493 print_inc DWARF_VERSION "$dwarf" num
494 print_mak CONFIG_USR_INCLUDE "$tcc_usrinclude"
495 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
496 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
497 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
498 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
499 print_mak CONFIG_LDDIR "$tcc_lddir"
500 print_mak CONFIG_TRIPLET "$triplet"
501 print_mak TCC_CPU_VERSION "$cpuver" num
503 echo "ARCH=$cpu" >> config.mak
504 echo "TARGETOS=$targetos" >> config.mak
506 predefs="1"
507 for v in $confvars ; do
508 test "$v" = "predefs=no" && predefs=""
509 if test "${v%=*}" = "$v"; then
510 echo "CONFIG_$v=yes" >> config.mak
511 else
512 echo "CONFIG_$v" >> config.mak
514 done
515 print_inc CONFIG_TCC_PREDEFS "$predefs" num
517 version=`head $source_path/VERSION`
518 echo "VERSION = $version" >> config.mak
519 echo "#define TCC_VERSION \"$version\"" >> $TMPH
520 echo "@set VERSION $version" > config.texi
522 if test "$source_path_used" = "yes" ; then
523 case $source_path in
524 /*) echo "TOPSRC=$source_path";;
525 *) echo "TOPSRC=\$(TOP)/$source_path";;
526 esac >>config.mak
527 else
528 echo 'TOPSRC=$(TOP)' >>config.mak
530 cat >>$TMPH <<EOF
531 #define GCC_MAJOR $gcc_major
532 #define GCC_MINOR $gcc_minor
533 #define CC_NAME CC_${cc_name}
536 diff $TMPH config.h >/dev/null 2>&1
537 if test $? -ne 0 ; then
538 mv -f $TMPH config.h
539 else
540 echo "config.h is unchanged"
543 rm -f $TMPN* $CONFTEST
545 # ---------------------------------------------------------------------------
546 # build tree in object directory if source path is different from current one
548 fn_makelink()
550 tgt=$1/$2
551 case $2 in
552 */*) dn=${2%/*}
553 test -d $dn || mkdir -p $dn
554 case $1 in
555 /*) ;;
556 *) while test $dn ; do
557 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
558 done
560 esac
562 esac
564 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
567 if test "$source_path_used" = "yes" ; then
568 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
569 for f in $FILES ; do
570 fn_makelink $source_path $f
571 done
574 # ---------------------------------------------------------------------------