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 test "$(uname -o)" = "Android" && targetos
=Android
66 confvars
="$confvars OSX dll=no"
68 cc
=`readlink $cc || echo clang`
69 tcc_usrinclude
="`xcrun --show-sdk-path`/usr/include"
72 Windows_NT|MINGW
*|MSYS
*|CYGWIN
*)
76 DragonFly|OpenBSD|FreeBSD|NetBSD
)
77 confvars
="$confvars BSD ldl=no"
80 confvars
="$confvars Android pie new-dtags"
81 if test -n "$TERMUX_VERSION"; then
82 prefix
="$PREFIX" # "/data/data/com.termux/files/usr"
84 test "$cpu" = "aarch64" -o "$cpu" = "x86_64" && S
="64" || S
=""
85 tcc_sysincludepaths
="{B}/include:{R}/include/\\\"CONFIG_TRIPLET\\\":{R}/include"
86 tcc_libpaths
="{B}:{R}/lib:/system/lib${S}"
87 tcc_crtprefix
="{R}/lib"
88 tcc_elfinterp
="/system/bin/linker${S}"
90 tcc_switches
="-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
98 source_path
=${0%configure}
99 source_path
=${source_path%/}
100 source_path_used
="yes"
101 if test -z "$source_path" -o "$source_path" = "." ; then
103 source_path_used
="no"
109 --prefix=*) prefix
=`echo $opt | cut -d '=' -f 2-`
111 --exec-prefix=*) execprefix
=`echo $opt | cut -d '=' -f 2-`
113 --tccdir=*) tccdir
=`echo $opt | cut -d '=' -f 2-`
115 --bindir=*) bindir
=`echo $opt | cut -d '=' -f 2-`
117 --libdir=*) libdir
=`echo $opt | cut -d '=' -f 2-`
119 --includedir=*) includedir
=`echo $opt | cut -d '=' -f 2-`
121 --sharedir=*) sharedir
=`echo $opt | cut -d '=' -f 2-`
123 --mandir=*) mandir
=`echo $opt | cut -d '=' -f 2-`
125 --infodir=*) infodir
=`echo $opt | cut -d '=' -f 2-`
127 --docdir=*) docdir
=`echo $opt | cut -d '=' -f 2-`
129 --sysroot=*) sysroot
=`echo $opt | cut -d '=' -f 2-`
131 --source-path=*) source_path
=`echo $opt | cut -d '=' -f 2-`
133 --cross-prefix=*) cross_prefix
=`echo $opt | cut -d '=' -f 2-`
135 --cc=*) cc
=`echo $opt | cut -d '=' -f 2-`
137 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set
="yes"
139 --extra-cflags=*) CFLAGS
="${opt#--extra-cflags=}"
141 --extra-ldflags=*) LDFLAGS
="${opt#--extra-ldflags=}"
143 --extra-libs=*) extralibs
="${opt#--extra-libs=}"
145 --sysincludepaths=*) tcc_sysincludepaths
=`echo $opt | cut -d '=' -f 2-`
147 --libpaths=*) tcc_libpaths
=`echo $opt | cut -d '=' -f 2-`
149 --crtprefix=*) tcc_crtprefix
=`echo $opt | cut -d '=' -f 2-`
151 --elfinterp=*) tcc_elfinterp
=`echo $opt | cut -d '=' -f 2-`
153 --triplet=*) triplet
=`echo $opt | cut -d '=' -f 2-`
155 --cpu=*) cpu
=`echo $opt | cut -d '=' -f 2-`
157 --dwarf=*) dwarf
=`echo $opt | cut -d '=' -f 2-`
159 --enable-cross) confvars
="$confvars cross"
161 --disable-static) confvars
="$confvars static=no"
163 --enable-static) confvars
="$confvars static"
165 --disable-rpath) confvars
="$confvars rpath=no"
167 --debug) confvars
="$confvars debug"
169 --with-libgcc) confvars
="$confvars libgcc"
171 --with-selinux) confvars
="$confvars selinux"
173 --tcc-switches=*) tcc_switches
=`echo $opt | cut -d '=' -f 2-`
175 --config-mingw32*) mingw32
=$
(echo "$opt=yes" | cut
-d '=' -f 2)
177 --config-*) confvars
="$confvars ${opt#--config-}"; suggest
="no"
179 --help|
-h) show_help
="yes"
181 *) echo "configure: WARNING: unrecognized option $opt"
186 cc
="${cross_prefix}${cc}"
187 ar="${cross_prefix}${ar}"
189 # Checking for CFLAGS
190 test -z "$CFLAGS" && CFLAGS
="-Wall -O2"
192 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
193 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
194 CFLAGS
="$CFLAGS -arch $cpu"
195 LDFLAGS
="$LDFLAGS -arch $cpu"
199 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386
)
215 aarch64|arm64|evbarm
)
238 "Power Macintosh"|ppc|ppc64
)
251 echo "Unsupported CPU"
256 if test "$mingw32" = "yes" ; then
257 if test "$source_path_used" = "no"; then
260 test -z "$prefix" && prefix
="C:/Program Files/tcc"
261 test -z "$tccdir" && tccdir
="${prefix}" && tccdir_auto
="yes"
262 test -z "$bindir" && bindir
="${tccdir}"
263 test -z "$docdir" && docdir
="${tccdir}/doc"
264 test -z "$libdir" && libdir
="${tccdir}/libtcc"
265 confvars
="$confvars WIN32"
270 if test -z "$prefix" ; then
273 if test -z "$sharedir" ; then
274 sharedir
="${prefix}/share"
276 if test x
"$execprefix" = x
""; then
277 execprefix
="${prefix}"
279 if test x
"$libdir" = x
""; then
280 libdir
="${execprefix}/lib"
282 if test x
"$bindir" = x
""; then
283 bindir
="${execprefix}/bin"
285 if test x
"$docdir" = x
""; then
286 docdir
="${sharedir}/doc"
288 if test x
"$mandir" = x
""; then
289 mandir
="${sharedir}/man"
291 if test x
"$infodir" = x
""; then
292 infodir
="${sharedir}/info"
294 if test x
"$tccdir" = x
""; then
295 tccdir
="${libdir}/tcc"
297 if test x
"$includedir" = x
""; then
298 includedir
="${prefix}/include"
302 if test x
"$show_help" = "xyes" ; then
304 Usage: configure [options]
305 Options: [defaults in brackets after descriptions]
308 --help print this message
309 --prefix=PREFIX install in PREFIX [$prefix]
310 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
312 --bindir=DIR user executables in DIR [EPREFIX/bin]
313 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
314 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
315 --includedir=DIR C header files in DIR [PREFIX/include]
316 --sharedir=DIR documentation root DIR [PREFIX/share]
317 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
318 --mandir=DIR man documentation in DIR [SHAREDIR/man]
319 --infodir=DIR info documentation in DIR [SHAREDIR/info]
321 Advanced options (experts only):
322 --source-path=PATH path of source code [$source_path]
323 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
324 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
325 --cc=CC use C compiler CC [$cc]
326 --ar=AR create archives using AR [$ar]
327 --extra-cflags= specify compiler flags [$CFLAGS]
328 --extra-ldflags= specify linker options [$LDFLAGS]
331 --debug include debug info with resulting binaries
332 --disable-static make libtcc.so instead of libtcc.a
333 --enable-static make libtcc.a instead of libtcc.dll (win32)
334 --disable-rpath disable use of -rpath with libtcc.so
335 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
336 --with-selinux use mmap for executable memory (tcc -run)
337 --enable-cross build cross compilers (see also 'make help')
339 --sysincludepaths=... specify system include paths, colon separated
340 --libpaths=... specify system library paths, colon separated
341 --crtprefix=... specify locations of crt?.o, colon separated
342 --elfinterp=... specify elf interpreter
343 --triplet=... specify system library/include directory triplet
344 --tcc-switches=... specify implicit switches passed to tcc
346 --config-uClibc,-musl enable system specific configurations
347 --config-mingw32 build on windows using msys, busybox, etc.
348 --config-backtrace=no disable stack backtraces (with -run or -bt)
349 --config-bcheck=no disable bounds checker (-b)
350 --config-predefs=no do not compile tccdefs.h, instead just include
351 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
356 if test -z "$cross_prefix" ; then
357 CONFTEST
=.
/conftest
$EXESUF
358 if ! $cc -o $CONFTEST $source_path/conftest.c
2>/dev
/null
; then
359 echo "configure: error: '$cc' failed to compile conftest.c."
361 cc_name
="$($CONFTEST compiler)"
362 gcc_major
="$($CONFTEST version)"
363 gcc_minor
="$($CONFTEST minor)"
364 bigendian
="$($CONFTEST bigendian)"
365 _triplet
="$($CONFTEST triplet)"
367 if test "$mingw32" = "no" ; then
369 if test -z "$triplet" -a -n "$_triplet"; then
370 if test -f "/usr/lib/$_triplet/crti.o" -o -n "$use_triplet" ; then
375 if test -z "$triplet"; then
376 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
377 if test -f "/usr/lib64/crti.o" ; then
383 if test "$cpu" = "arm" ; then
384 if test "${triplet%eabihf}" != "$triplet" ; then
385 confvars
="$confvars arm_eabihf arm_vfp"
386 elif test "${triplet%eabi}" != "$triplet" ; then
387 confvars
="$confvars arm_eabi arm_vfp"
388 elif test "${_triplet%eabihf}" != "$_triplet" ; then
389 confvars
="$confvars arm_eabihf arm_vfp"
390 elif test "${_triplet%eabi}" != "$_triplet" ; then
391 confvars
="$confvars arm_eabi arm_vfp"
392 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
; then
393 confvars
="$confvars arm_vfp"
397 if test "$suggest" = "yes"; then
398 if test -f "/lib/ld-uClibc.so.0" ; then
399 echo "Perhaps you want ./configure --config-uClibc"
401 if test -f "/lib/ld-musl-$cpu.so.1"; then
402 echo "Perhaps you want ./configure --config-musl"
406 if test "$cc_name" = "gcc"; then
407 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
408 test -z "$LDFLAGS" && LDFLAGS
="-static"
412 # if cross compiling, cannot launch a program, so make a static guess
414 ppc|mips|s390
) bigendian
=yes;;
418 if test "$bigendian" = "yes" ; then
419 confvars
="$confvars BIGENDIAN"
422 # a final configuration tuning
423 if test "$cc_name" != "tcc"; then
424 OPT1
="-Wdeclaration-after-statement -fno-strict-aliasing"
425 # we want -Wno- but gcc does not always reject unknown -Wno- options
426 OPT2
="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
427 OPT2
="$OPT2 -Wstringop-truncation"
428 if test "$cc_name" = "clang"; then
429 OPT1
="$OPT1 -fheinous-gnu-extensions"
430 OPT2
="$OPT2 -Wstring-plus-int"
432 $cc $OPT1 $OPT2 -o a.out
-c -xc - < /dev
/null
> cc_msg.txt
2>&1
433 for o
in $OPT1; do # enable these options
434 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS $o"; fi
436 for o
in $OPT2; do # disable these options
437 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS -Wno-${o#-W*}"; fi
441 rm -f cc_msg.txt a.out
443 test "$ar_set" ||
ar="$cc -ar"
446 fcho
() { if test -n "$2"; then echo "$1$2"; fi }
448 fcho
"Binary directory " "$bindir"
449 fcho
"TinyCC directory " "$tccdir"
450 fcho
"Library directory " "$libdir"
451 fcho
"Include directory " "$includedir"
452 fcho
"Manual directory " "$mandir"
453 fcho
"Info directory " "$infodir"
454 fcho
"Doc directory " "$docdir"
455 fcho
"Target root prefix " "$sysroot"
456 fcho
"/usr/include dir " "$tcc_usrinclude"
457 echo "Source path $source_path"
458 echo "C compiler $cc ($gcc_major.$gcc_minor)"
459 echo "Target OS $targetos"
461 fcho
"Triplet " "$triplet"
462 fcho
"Config " "${confvars# }"
463 echo "Creating config.mak and config.h"
465 cat >config.mak
<<EOF
466 # Automatically generated by configure - do not modify
468 bindir=\$(DESTDIR)$bindir
469 tccdir=\$(DESTDIR)$tccdir
470 libdir=\$(DESTDIR)$libdir
471 includedir=\$(DESTDIR)$includedir
472 mandir=\$(DESTDIR)$mandir
473 infodir=\$(DESTDIR)$infodir
474 docdir=\$(DESTDIR)$docdir
489 if test -n "$v"; then
490 test "$3" = "num" || v
="\"$v\""
491 echo "#ifndef $1" >> $TMPH
492 echo "# define $1 $v" >> $TMPH
493 echo "#endif" >> $TMPH
499 if test -n "$v"; then
500 test "$3" = "num" || v
="\"\\\"$v\\\"\""
501 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
505 echo "/* Automatically generated by configure - do not modify */" > $TMPH
507 print_inc CONFIG_SYSROOT
"$sysroot"
508 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR
"$tccdir"
509 print_inc DWARF_VERSION
"$dwarf" num
510 print_mak CONFIG_USR_INCLUDE
"$tcc_usrinclude"
511 print_mak CONFIG_TCC_SYSINCLUDEPATHS
"$tcc_sysincludepaths"
512 print_mak CONFIG_TCC_LIBPATHS
"$tcc_libpaths"
513 print_mak CONFIG_TCC_CRTPREFIX
"$tcc_crtprefix"
514 print_mak CONFIG_TCC_ELFINTERP
"$tcc_elfinterp"
515 print_mak CONFIG_TCC_SWITCHES
"$tcc_switches"
516 print_mak CONFIG_LDDIR
"$tcc_lddir"
517 print_mak CONFIG_TRIPLET
"$triplet"
518 print_mak TCC_CPU_VERSION
"$cpuver" num
520 echo "ARCH=$cpu" >> config.mak
521 echo "TARGETOS=$targetos" >> config.mak
524 for v
in $confvars ; do
525 test "$v" = "predefs=no" && predefs
=""
526 if test "${v%=*}" = "$v"; then
527 echo "CONFIG_$v=yes" >> config.mak
529 echo "CONFIG_$v" >> config.mak
532 print_inc CONFIG_TCC_PREDEFS
"$predefs" num
534 version
=`head $source_path/VERSION`
535 echo "VERSION = $version" >> config.mak
536 echo "#define TCC_VERSION \"$version\"" >> $TMPH
537 echo "@set VERSION $version" > config.texi
539 if test "$source_path_used" = "yes" ; then
541 /*) echo "TOPSRC=$source_path";;
542 *) echo "TOPSRC=\$(TOP)/$source_path";;
545 echo 'TOPSRC=$(TOP)' >>config.mak
548 #define GCC_MAJOR $gcc_major
549 #define GCC_MINOR $gcc_minor
550 #define CC_NAME CC_${cc_name}
553 diff $TMPH config.h
>/dev
/null
2>&1
554 if test $?
-ne 0 ; then
557 echo "config.h is unchanged"
560 rm -f $TMPN* $CONFTEST
562 # ---------------------------------------------------------------------------
563 # build tree in object directory if source path is different from current one
570 test -d $dn || mkdir
-p $dn
573 *) while test $dn ; do
574 tgt
=..
/$tgt; dn
=${dn#${dn%%/*}}; dn=${dn#/}
581 ln -sfn $tgt $2 ||
( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
584 if test "$source_path_used" = "yes" ; then
585 FILES
="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
587 fn_makelink
$source_path $f
591 # ---------------------------------------------------------------------------