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"
75 Windows_NT|MINGW
*|MSYS
*|CYGWIN
*)
79 DragonFly|OpenBSD|FreeBSD|NetBSD
)
80 confvars
="$confvars BSD ldl=no"
83 confvars
="$confvars Android pie new-dtags"
84 if test -n "$TERMUX_VERSION"; then
85 prefix
="$PREFIX" # "/data/data/com.termux/files/usr"
87 test "$cpu" = "aarch64" -o "$cpu" = "x86_64" && S
="64" || S
=""
88 tcc_sysincludepaths
="{B}/include:{R}/include/\\\"CONFIG_TRIPLET\\\":{R}/include"
89 tcc_libpaths
="{B}:{R}/lib:/system/lib${S}"
90 tcc_crtprefix
="{R}/lib"
91 tcc_elfinterp
="/system/bin/linker${S}"
93 tcc_switches
="-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
101 source_path
=${0%configure}
102 source_path
=${source_path%/}
103 source_path_used
="yes"
104 if test -z "$source_path" -o "$source_path" = "." ; then
106 source_path_used
="no"
112 --prefix=*) prefix
=`echo $opt | cut -d '=' -f 2-`
114 --exec-prefix=*) execprefix
=`echo $opt | cut -d '=' -f 2-`
116 --tccdir=*) tccdir
=`echo $opt | cut -d '=' -f 2-`
118 --bindir=*) bindir
=`echo $opt | cut -d '=' -f 2-`
120 --libdir=*) libdir
=`echo $opt | cut -d '=' -f 2-`
122 --includedir=*) includedir
=`echo $opt | cut -d '=' -f 2-`
124 --sharedir=*) sharedir
=`echo $opt | cut -d '=' -f 2-`
126 --mandir=*) mandir
=`echo $opt | cut -d '=' -f 2-`
128 --infodir=*) infodir
=`echo $opt | cut -d '=' -f 2-`
130 --docdir=*) docdir
=`echo $opt | cut -d '=' -f 2-`
132 --sysroot=*) sysroot
=`echo $opt | cut -d '=' -f 2-`
134 --source-path=*) source_path
=`echo $opt | cut -d '=' -f 2-`
136 --cross-prefix=*) cross_prefix
=`echo $opt | cut -d '=' -f 2-`
138 --cc=*) cc
=`echo $opt | cut -d '=' -f 2-`
140 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set
="yes"
142 --extra-cflags=*) CFLAGS
="${opt#--extra-cflags=}"
144 --extra-ldflags=*) LDFLAGS
="${opt#--extra-ldflags=}"
146 --extra-libs=*) extralibs
="${opt#--extra-libs=}"
148 --sysincludepaths=*) tcc_sysincludepaths
=`echo $opt | cut -d '=' -f 2-`
150 --libpaths=*) tcc_libpaths
=`echo $opt | cut -d '=' -f 2-`
152 --crtprefix=*) tcc_crtprefix
=`echo $opt | cut -d '=' -f 2-`
154 --elfinterp=*) tcc_elfinterp
=`echo $opt | cut -d '=' -f 2-`
156 --triplet=*) triplet
=`echo $opt | cut -d '=' -f 2-`
158 --cpu=*) cpu
=`echo $opt | cut -d '=' -f 2-`
160 --dwarf=*) dwarf
=`echo $opt | cut -d '=' -f 2-`
162 --enable-cross) confvars
="$confvars cross"
164 --disable-static) confvars
="$confvars static=no"
166 --enable-static) confvars
="$confvars static"
168 --disable-rpath) confvars
="$confvars rpath=no"
170 --debug) confvars
="$confvars debug"
172 --with-libgcc) confvars
="$confvars libgcc"
174 --with-selinux) confvars
="$confvars selinux"
176 --tcc-switches=*) tcc_switches
=`echo $opt | cut -d '=' -f 2-`
178 --config-mingw32*) mingw32
=$
(echo "$opt=yes" | cut
-d '=' -f 2)
180 --config-*) confvars
="$confvars ${opt#--config-}"; suggest
="no"
182 --help|
-h) show_help
="yes"
184 *) echo "configure: WARNING: unrecognized option $opt"
189 cc
="${cross_prefix}${cc}"
190 ar="${cross_prefix}${ar}"
192 # Checking for CFLAGS
193 test -z "$CFLAGS" && CFLAGS
="-Wall -O2"
195 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
196 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
197 CFLAGS
="$CFLAGS -arch $cpu"
198 LDFLAGS
="$LDFLAGS -arch $cpu"
202 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386
)
218 aarch64|arm64|evbarm
)
241 "Power Macintosh"|ppc|ppc64
)
254 echo "Unsupported CPU"
259 if test "$mingw32" = "yes" ; then
260 if test "$source_path_used" = "no"; then
263 test -z "$prefix" && prefix
="C:/Program Files/tcc"
264 test -z "$tccdir" && tccdir
="${prefix}" && tccdir_auto
="yes"
265 test -z "$bindir" && bindir
="${tccdir}"
266 test -z "$docdir" && docdir
="${tccdir}/doc"
267 test -z "$libdir" && libdir
="${tccdir}/libtcc"
268 confvars
="$confvars WIN32"
273 if test -z "$prefix" ; then
276 if test -z "$sharedir" ; then
277 sharedir
="${prefix}/share"
279 if test x
"$execprefix" = x
""; then
280 execprefix
="${prefix}"
282 if test x
"$libdir" = x
""; then
283 libdir
="${execprefix}/lib"
285 if test x
"$bindir" = x
""; then
286 bindir
="${execprefix}/bin"
288 if test x
"$docdir" = x
""; then
289 docdir
="${sharedir}/doc"
291 if test x
"$mandir" = x
""; then
292 mandir
="${sharedir}/man"
294 if test x
"$infodir" = x
""; then
295 infodir
="${sharedir}/info"
297 if test x
"$tccdir" = x
""; then
298 tccdir
="${libdir}/tcc"
300 if test x
"$includedir" = x
""; then
301 includedir
="${prefix}/include"
305 if test x
"$show_help" = "xyes" ; then
307 Usage: configure [options]
308 Options: [defaults in brackets after descriptions]
311 --help print this message
312 --prefix=PREFIX install in PREFIX [$prefix]
313 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
315 --bindir=DIR user executables in DIR [EPREFIX/bin]
316 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
317 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
318 --includedir=DIR C header files in DIR [PREFIX/include]
319 --sharedir=DIR documentation root DIR [PREFIX/share]
320 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
321 --mandir=DIR man documentation in DIR [SHAREDIR/man]
322 --infodir=DIR info documentation in DIR [SHAREDIR/info]
324 Advanced options (experts only):
325 --source-path=PATH path of source code [$source_path]
326 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
327 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
328 --cc=CC use C compiler CC [$cc]
329 --ar=AR create archives using AR [$ar]
330 --extra-cflags= specify compiler flags [$CFLAGS]
331 --extra-ldflags= specify linker options [$LDFLAGS]
334 --debug include debug info with resulting binaries
335 --disable-static make libtcc.so instead of libtcc.a
336 --enable-static make libtcc.a instead of libtcc.dll (win32)
337 --disable-rpath disable use of -rpath with libtcc.so
338 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
339 --with-selinux use mmap for executable memory (tcc -run)
340 --enable-cross build cross compilers (see also 'make help')
342 --sysincludepaths=... specify system include paths, colon separated
343 --libpaths=... specify system library paths, colon separated
344 --crtprefix=... specify locations of crt?.o, colon separated
345 --elfinterp=... specify elf interpreter
346 --triplet=... specify system library/include directory triplet
347 --tcc-switches=... specify implicit switches passed to tcc
349 --config-uClibc,-musl enable system specific configurations
350 --config-mingw32 build on windows using msys, busybox, etc.
351 --config-backtrace=no disable stack backtraces (with -run or -bt)
352 --config-bcheck=no disable bounds checker (-b)
353 --config-predefs=no do not compile tccdefs.h, instead just include
354 --config-new_macho=no Use apple old macho object format
355 --config-codesign Use codesign on apple to sign executables
356 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
361 if test -z "$cross_prefix" ; then
362 CONFTEST
=.
/conftest
$EXESUF
363 if ! $cc -o $CONFTEST $source_path/conftest.c
; then
364 echo "configure: error: '$cc' failed to compile conftest.c."
366 cc_name
="$($CONFTEST compiler)"
367 gcc_major
="$($CONFTEST version)"
368 gcc_minor
="$($CONFTEST minor)"
369 bigendian
="$($CONFTEST bigendian)"
370 _triplet
="$($CONFTEST triplet)"
372 if test "$mingw32" = "no" ; then
374 if test -z "$triplet" -a -n "$_triplet"; then
375 if test -f "/usr/lib/$_triplet/crti.o" -o -n "$use_triplet" ; then
380 if test -z "$triplet"; then
381 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
382 if test -f "/usr/lib64/crti.o" ; then
388 if test "$cpu" = "arm" ; then
389 if test "${triplet%eabihf}" != "$triplet" ; then
390 confvars
="$confvars arm_eabihf arm_vfp"
391 elif test "${triplet%eabi}" != "$triplet" ; then
392 confvars
="$confvars arm_eabi arm_vfp"
393 elif test "${_triplet%eabihf}" != "$_triplet" ; then
394 confvars
="$confvars arm_eabihf arm_vfp"
395 elif test "${_triplet%eabi}" != "$_triplet" ; then
396 confvars
="$confvars arm_eabi arm_vfp"
397 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
; then
398 confvars
="$confvars arm_vfp"
402 if test "$suggest" = "yes"; then
403 if test -f "/lib/ld-uClibc.so.0" ; then
404 echo "Perhaps you want ./configure --config-uClibc"
406 if test -f "/lib/ld-musl-$cpu.so.1"; then
407 echo "Perhaps you want ./configure --config-musl"
411 if test "$cc_name" = "gcc"; then
412 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
413 test -z "$LDFLAGS" && LDFLAGS
="-static"
417 # if cross compiling, cannot launch a program, so make a static guess
419 ppc|mips|s390
) bigendian
=yes;;
423 if test "$bigendian" = "yes" ; then
424 confvars
="$confvars BIGENDIAN"
427 # a final configuration tuning
428 if test "$cc_name" != "tcc"; then
429 OPT1
="-Wdeclaration-after-statement -fno-strict-aliasing"
430 # we want -Wno- but gcc does not always reject unknown -Wno- options
431 OPT2
="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
432 OPT2
="$OPT2 -Wstringop-truncation"
433 if test "$cc_name" = "clang"; then
434 OPT1
="$OPT1 -fheinous-gnu-extensions"
435 OPT2
="$OPT2 -Wstring-plus-int"
437 $cc $OPT1 $OPT2 -o a.out
-c -xc - < /dev
/null
> cc_msg.txt
2>&1
438 for o
in $OPT1; do # enable these options
439 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS $o"; fi
441 for o
in $OPT2; do # disable these options
442 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS -Wno-${o#-W*}"; fi
446 rm -f cc_msg.txt a.out
448 test "$ar_set" ||
ar="$cc -ar"
451 fcho
() { if test -n "$2"; then echo "$1$2"; fi }
453 fcho
"Binary directory " "$bindir"
454 fcho
"TinyCC directory " "$tccdir"
455 fcho
"Library directory " "$libdir"
456 fcho
"Include directory " "$includedir"
457 fcho
"Manual directory " "$mandir"
458 fcho
"Info directory " "$infodir"
459 fcho
"Doc directory " "$docdir"
460 fcho
"Target root prefix " "$sysroot"
461 fcho
"/usr/include dir " "$tcc_usrinclude"
462 echo "Source path $source_path"
463 echo "C compiler $cc ($gcc_major.$gcc_minor)"
464 echo "Target OS $targetos"
466 fcho
"Triplet " "$triplet"
467 fcho
"Config " "${confvars# }"
468 echo "Creating config.mak and config.h"
470 cat >config.mak
<<EOF
471 # Automatically generated by configure - do not modify
473 bindir=\$(DESTDIR)$bindir
474 tccdir=\$(DESTDIR)$tccdir
475 libdir=\$(DESTDIR)$libdir
476 includedir=\$(DESTDIR)$includedir
477 mandir=\$(DESTDIR)$mandir
478 infodir=\$(DESTDIR)$infodir
479 docdir=\$(DESTDIR)$docdir
494 if test -n "$v"; then
495 test "$3" = "num" || v
="\"$v\""
496 echo "#ifndef $1" >> $TMPH
497 echo "# define $1 $v" >> $TMPH
498 echo "#endif" >> $TMPH
504 if test -n "$v"; then
505 test "$3" = "num" || v
="\"\\\"$v\\\"\""
506 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
510 echo "/* Automatically generated by configure - do not modify */" > $TMPH
512 print_inc CONFIG_SYSROOT
"$sysroot"
513 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR
"$tccdir"
514 print_inc DWARF_VERSION
"$dwarf" num
515 print_mak CONFIG_USR_INCLUDE
"$tcc_usrinclude"
516 print_mak CONFIG_TCC_SYSINCLUDEPATHS
"$tcc_sysincludepaths"
517 print_mak CONFIG_TCC_LIBPATHS
"$tcc_libpaths"
518 print_mak CONFIG_TCC_CRTPREFIX
"$tcc_crtprefix"
519 print_mak CONFIG_TCC_ELFINTERP
"$tcc_elfinterp"
520 print_mak CONFIG_TCC_SWITCHES
"$tcc_switches"
521 print_mak CONFIG_LDDIR
"$tcc_lddir"
522 print_mak CONFIG_TRIPLET
"$triplet"
523 print_mak TCC_CPU_VERSION
"$cpuver" num
525 echo "ARCH=$cpu" >> config.mak
526 echo "TARGETOS=$targetos" >> config.mak
529 for v
in $confvars ; do
530 test "$v" = "predefs=no" && predefs
=""
531 if test "${v%=*}" = "$v"; then
532 echo "CONFIG_$v=yes" >> config.mak
534 echo "CONFIG_$v" >> config.mak
537 print_inc CONFIG_TCC_PREDEFS
"$predefs" num
539 version
=`head $source_path/VERSION`
540 echo "VERSION = $version" >> config.mak
541 echo "#define TCC_VERSION \"$version\"" >> $TMPH
542 echo "@set VERSION $version" > config.texi
544 if test "$source_path_used" = "yes" ; then
546 /*) echo "TOPSRC=$source_path";;
547 *) echo "TOPSRC=\$(TOP)/$source_path";;
550 echo 'TOPSRC=$(TOP)' >>config.mak
553 #define GCC_MAJOR $gcc_major
554 #define GCC_MINOR $gcc_minor
555 #define CC_NAME CC_${cc_name}
558 diff $TMPH config.h
>/dev
/null
2>&1
559 if test $?
-ne 0 ; then
562 echo "config.h is unchanged"
565 rm -f $TMPN* $CONFTEST
567 # ---------------------------------------------------------------------------
568 # build tree in object directory if source path is different from current one
575 test -d $dn || mkdir
-p $dn
578 *) while test $dn ; do
579 tgt
=..
/$tgt; dn
=${dn#${dn%%/*}}; dn=${dn#/}
586 ln -sfn $tgt $2 ||
( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
589 if test "$source_path_used" = "yes" ; then
590 FILES
="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
592 fn_makelink
$source_path $f
596 # ---------------------------------------------------------------------------