3 # tcc configure script (c) 2003 Fabrice Bellard
5 # set temporary file name
6 # if test ! -z "$TMPDIR" ; then
8 # elif test ! -z "$TEMPDIR" ; then
14 # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
38 tcc_sysincludepaths
=""
54 # use CC from environment when set
55 test -n "$CC" && cc
="$CC"
61 if test "$targetos" = "Linux" ; then
62 test "$(uname -o)" = "Android" && targetos
=Android
69 confvars
="$confvars OSX"
71 cc
=`readlink $cc || echo clang`
72 tcc_usrinclude
="`xcrun --show-sdk-path`/usr/include"
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"
81 Windows_NT|MINGW
*|MSYS
*|CYGWIN
*)
85 DragonFly|OpenBSD|FreeBSD|NetBSD
)
86 confvars
="$confvars BSD ldl=no"
89 confvars
="$confvars Android pie new-dtags"
90 if test -n "$TERMUX_VERSION"; then
91 prefix
="$PREFIX" # "/data/data/com.termux/files/usr"
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}"
99 tcc_switches
="-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
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
112 source_path_used
="no"
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"
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"
208 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386
)
224 aarch64|arm64|evbarm
)
247 "Power Macintosh"|ppc|ppc64
)
260 echo "Unsupported CPU"
265 if test "$mingw32" = "yes" ; then
266 if test "$source_path_used" = "no"; then
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"
279 if test -z "$prefix" ; then
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"
311 if test x
"$show_help" = "xyes" ; then
313 Usage: configure [options]
314 Options: [defaults in brackets after descriptions]
317 --help print this message
318 --prefix=PREFIX install in PREFIX [$prefix]
319 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
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]
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)
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."
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
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
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"
417 if test "$cc_name" = "gcc"; then
418 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
419 test -z "$LDFLAGS" && LDFLAGS
="-static"
423 # if cross compiling, cannot launch a program, so make a static guess
425 ppc|mips|s390
) bigendian
=yes;;
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
447 for o
in $OPT2; do # disable these options
448 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS -Wno-${o#-W*}"; fi
452 rm -f cc_msg.txt a.out
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"
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
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
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
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
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
540 echo "CONFIG_$v" >> config.mak
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
552 /*) echo "TOPSRC=$source_path";;
553 *) echo "TOPSRC=\$(TOP)/$source_path";;
556 echo 'TOPSRC=$(TOP)' >>config.mak
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
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
581 test -d $dn || mkdir
-p $dn
584 *) while test $dn ; do
585 tgt
=..
/$tgt; dn
=${dn#${dn%%/*}}; dn=${dn#/}
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"
598 fn_makelink
$source_path $f
602 # ---------------------------------------------------------------------------