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
68 confvars
="$confvars OSX dll=no"
70 cc
=`readlink $cc || echo clang`
71 tcc_usrinclude
="`xcrun --show-sdk-path`/usr/include"
74 Windows_NT|MINGW
*|MSYS
*|CYGWIN
*)
78 DragonFly|OpenBSD|FreeBSD|NetBSD
)
79 confvars
="$confvars BSD ldl=no"
82 confvars
="$confvars Android pie new-dtags"
83 if test -n "$TERMUX_VERSION"; then
84 prefix
="$PREFIX" # "/data/data/com.termux/files/usr"
86 test "$cpu" = "aarch64" -o "$cpu" = "x86_64" && S
="64" || S
=""
87 tcc_sysincludepaths
="{B}/include:{R}/include/\\\"CONFIG_TRIPLET\\\":{R}/include"
88 tcc_libpaths
="{B}:{R}/lib:/system/lib${S}"
89 tcc_crtprefix
="{R}/lib"
90 tcc_elfinterp
="/system/bin/linker${S}"
92 tcc_switches
="-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
100 source_path
=${0%configure}
101 source_path
=${source_path%/}
102 source_path_used
="yes"
103 if test -z "$source_path" -o "$source_path" = "." ; then
105 source_path_used
="no"
111 --prefix=*) prefix
=`echo $opt | cut -d '=' -f 2-`
113 --exec-prefix=*) execprefix
=`echo $opt | cut -d '=' -f 2-`
115 --tccdir=*) tccdir
=`echo $opt | cut -d '=' -f 2-`
117 --bindir=*) bindir
=`echo $opt | cut -d '=' -f 2-`
119 --libdir=*) libdir
=`echo $opt | cut -d '=' -f 2-`
121 --includedir=*) includedir
=`echo $opt | cut -d '=' -f 2-`
123 --sharedir=*) sharedir
=`echo $opt | cut -d '=' -f 2-`
125 --mandir=*) mandir
=`echo $opt | cut -d '=' -f 2-`
127 --infodir=*) infodir
=`echo $opt | cut -d '=' -f 2-`
129 --docdir=*) docdir
=`echo $opt | cut -d '=' -f 2-`
131 --sysroot=*) sysroot
=`echo $opt | cut -d '=' -f 2-`
133 --source-path=*) source_path
=`echo $opt | cut -d '=' -f 2-`
135 --cross-prefix=*) cross_prefix
=`echo $opt | cut -d '=' -f 2-`
137 --cc=*) cc
=`echo $opt | cut -d '=' -f 2-`
139 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set
="yes"
141 --extra-cflags=*) CFLAGS
="${opt#--extra-cflags=}"
143 --extra-ldflags=*) LDFLAGS
="${opt#--extra-ldflags=}"
145 --extra-libs=*) extralibs
="${opt#--extra-libs=}"
147 --sysincludepaths=*) tcc_sysincludepaths
=`echo $opt | cut -d '=' -f 2-`
149 --libpaths=*) tcc_libpaths
=`echo $opt | cut -d '=' -f 2-`
151 --crtprefix=*) tcc_crtprefix
=`echo $opt | cut -d '=' -f 2-`
153 --elfinterp=*) tcc_elfinterp
=`echo $opt | cut -d '=' -f 2-`
155 --triplet=*) triplet
=`echo $opt | cut -d '=' -f 2-`
157 --cpu=*) cpu
=`echo $opt | cut -d '=' -f 2-`
159 --dwarf=*) dwarf
=`echo $opt | cut -d '=' -f 2-`
161 --enable-cross) confvars
="$confvars cross"
163 --disable-static) confvars
="$confvars static=no"
165 --enable-static) confvars
="$confvars static"
167 --disable-rpath) confvars
="$confvars rpath=no"
169 --debug) confvars
="$confvars debug"
171 --with-libgcc) confvars
="$confvars libgcc"
173 --with-selinux) confvars
="$confvars selinux"
175 --tcc-switches=*) tcc_switches
=`echo $opt | cut -d '=' -f 2-`
177 --config-mingw32*) mingw32
=$
(echo "$opt=yes" | cut
-d '=' -f 2)
179 --config-*) confvars
="$confvars ${opt#--config-}"; suggest
="no"
181 --help|
-h) show_help
="yes"
183 *) echo "configure: WARNING: unrecognized option $opt"
188 cc
="${cross_prefix}${cc}"
189 ar="${cross_prefix}${ar}"
191 # Checking for CFLAGS
192 test -z "$CFLAGS" && CFLAGS
="-Wall -O2"
194 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
195 if test "$darwin" = "yes" -a "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
196 CFLAGS
="$CFLAGS -arch $cpu"
197 LDFLAGS
="$LDFLAGS -arch $cpu"
201 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386
)
217 aarch64|arm64|evbarm
)
240 "Power Macintosh"|ppc|ppc64
)
253 echo "Unsupported CPU"
258 if test "$mingw32" = "yes" ; then
259 if test "$source_path_used" = "no"; then
262 test -z "$prefix" && prefix
="C:/Program Files/tcc"
263 test -z "$tccdir" && tccdir
="${prefix}" && tccdir_auto
="yes"
264 test -z "$bindir" && bindir
="${tccdir}"
265 test -z "$docdir" && docdir
="${tccdir}/doc"
266 test -z "$libdir" && libdir
="${tccdir}/libtcc"
267 confvars
="$confvars WIN32"
272 if test -z "$prefix" ; then
275 if test -z "$sharedir" ; then
276 sharedir
="${prefix}/share"
278 if test x
"$execprefix" = x
""; then
279 execprefix
="${prefix}"
281 if test x
"$libdir" = x
""; then
282 libdir
="${execprefix}/lib"
284 if test x
"$bindir" = x
""; then
285 bindir
="${execprefix}/bin"
287 if test x
"$docdir" = x
""; then
288 docdir
="${sharedir}/doc"
290 if test x
"$mandir" = x
""; then
291 mandir
="${sharedir}/man"
293 if test x
"$infodir" = x
""; then
294 infodir
="${sharedir}/info"
296 if test x
"$tccdir" = x
""; then
297 tccdir
="${libdir}/tcc"
299 if test x
"$includedir" = x
""; then
300 includedir
="${prefix}/include"
304 if test x
"$show_help" = "xyes" ; then
306 Usage: configure [options]
307 Options: [defaults in brackets after descriptions]
310 --help print this message
311 --prefix=PREFIX install in PREFIX [$prefix]
312 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
314 --bindir=DIR user executables in DIR [EPREFIX/bin]
315 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
316 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
317 --includedir=DIR C header files in DIR [PREFIX/include]
318 --sharedir=DIR documentation root DIR [PREFIX/share]
319 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
320 --mandir=DIR man documentation in DIR [SHAREDIR/man]
321 --infodir=DIR info documentation in DIR [SHAREDIR/info]
323 Advanced options (experts only):
324 --source-path=PATH path of source code [$source_path]
325 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
326 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
327 --cc=CC use C compiler CC [$cc]
328 --ar=AR create archives using AR [$ar]
329 --extra-cflags= specify compiler flags [$CFLAGS]
330 --extra-ldflags= specify linker options [$LDFLAGS]
333 --debug include debug info with resulting binaries
334 --disable-static make libtcc.so instead of libtcc.a
335 --enable-static make libtcc.a instead of libtcc.dll (win32)
336 --disable-rpath disable use of -rpath with libtcc.so
337 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
338 --with-selinux use mmap for executable memory (tcc -run)
339 --enable-cross build cross compilers (see also 'make help')
341 --sysincludepaths=... specify system include paths, colon separated
342 --libpaths=... specify system library paths, colon separated
343 --crtprefix=... specify locations of crt?.o, colon separated
344 --elfinterp=... specify elf interpreter
345 --triplet=... specify system library/include directory triplet
346 --tcc-switches=... specify implicit switches passed to tcc
348 --config-uClibc,-musl enable system specific configurations
349 --config-mingw32 build on windows using msys, busybox, etc.
350 --config-backtrace=no disable stack backtraces (with -run or -bt)
351 --config-bcheck=no disable bounds checker (-b)
352 --config-predefs=no do not compile tccdefs.h, instead just include
353 --config-new_macho Use apple new macho object format
354 --config-codesign Use codesign on apple to sign executables
355 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
360 if test -z "$cross_prefix" ; then
361 CONFTEST
=.
/conftest
$EXESUF
362 if ! $cc -o $CONFTEST $source_path/conftest.c
; then
363 echo "configure: error: '$cc' failed to compile conftest.c."
365 cc_name
="$($CONFTEST compiler)"
366 gcc_major
="$($CONFTEST version)"
367 gcc_minor
="$($CONFTEST minor)"
368 bigendian
="$($CONFTEST bigendian)"
369 _triplet
="$($CONFTEST triplet)"
371 if test "$mingw32" = "no" ; then
373 if test -z "$triplet" -a -n "$_triplet"; then
374 if test -f "/usr/lib/$_triplet/crti.o" -o -n "$use_triplet" ; then
379 if test -z "$triplet"; then
380 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
381 if test -f "/usr/lib64/crti.o" ; then
387 if test "$cpu" = "arm" ; then
388 if 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 test "${_triplet%eabihf}" != "$_triplet" ; then
393 confvars
="$confvars arm_eabihf arm_vfp"
394 elif test "${_triplet%eabi}" != "$_triplet" ; then
395 confvars
="$confvars arm_eabi arm_vfp"
396 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
; then
397 confvars
="$confvars arm_vfp"
401 if test "$suggest" = "yes"; then
402 if test -f "/lib/ld-uClibc.so.0" ; then
403 echo "Perhaps you want ./configure --config-uClibc"
405 if test -f "/lib/ld-musl-$cpu.so.1"; then
406 echo "Perhaps you want ./configure --config-musl"
410 if test "$cc_name" = "gcc"; then
411 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
412 test -z "$LDFLAGS" && LDFLAGS
="-static"
416 # if cross compiling, cannot launch a program, so make a static guess
418 ppc|mips|s390
) bigendian
=yes;;
422 if test "$bigendian" = "yes" ; then
423 confvars
="$confvars BIGENDIAN"
426 # a final configuration tuning
427 if test "$cc_name" != "tcc"; then
428 OPT1
="-Wdeclaration-after-statement -fno-strict-aliasing"
429 # we want -Wno- but gcc does not always reject unknown -Wno- options
430 OPT2
="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
431 OPT2
="$OPT2 -Wstringop-truncation"
432 if test "$cc_name" = "clang"; then
433 OPT1
="$OPT1 -fheinous-gnu-extensions"
434 OPT2
="$OPT2 -Wstring-plus-int"
436 $cc $OPT1 $OPT2 -o a.out
-c -xc - < /dev
/null
> cc_msg.txt
2>&1
437 for o
in $OPT1; do # enable these options
438 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS $o"; fi
440 for o
in $OPT2; do # disable these options
441 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS -Wno-${o#-W*}"; fi
445 rm -f cc_msg.txt a.out
447 test "$ar_set" ||
ar="$cc -ar"
450 fcho
() { if test -n "$2"; then echo "$1$2"; fi }
452 fcho
"Binary directory " "$bindir"
453 fcho
"TinyCC directory " "$tccdir"
454 fcho
"Library directory " "$libdir"
455 fcho
"Include directory " "$includedir"
456 fcho
"Manual directory " "$mandir"
457 fcho
"Info directory " "$infodir"
458 fcho
"Doc directory " "$docdir"
459 fcho
"Target root prefix " "$sysroot"
460 fcho
"/usr/include dir " "$tcc_usrinclude"
461 echo "Source path $source_path"
462 echo "C compiler $cc ($gcc_major.$gcc_minor)"
463 echo "Target OS $targetos"
465 fcho
"Triplet " "$triplet"
466 fcho
"Config " "${confvars# }"
467 echo "Creating config.mak and config.h"
469 cat >config.mak
<<EOF
470 # Automatically generated by configure - do not modify
472 bindir=\$(DESTDIR)$bindir
473 tccdir=\$(DESTDIR)$tccdir
474 libdir=\$(DESTDIR)$libdir
475 includedir=\$(DESTDIR)$includedir
476 mandir=\$(DESTDIR)$mandir
477 infodir=\$(DESTDIR)$infodir
478 docdir=\$(DESTDIR)$docdir
493 if test -n "$v"; then
494 test "$3" = "num" || v
="\"$v\""
495 echo "#ifndef $1" >> $TMPH
496 echo "# define $1 $v" >> $TMPH
497 echo "#endif" >> $TMPH
503 if test -n "$v"; then
504 test "$3" = "num" || v
="\"\\\"$v\\\"\""
505 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
509 echo "/* Automatically generated by configure - do not modify */" > $TMPH
511 print_inc CONFIG_SYSROOT
"$sysroot"
512 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR
"$tccdir"
513 print_inc DWARF_VERSION
"$dwarf" num
514 print_mak CONFIG_USR_INCLUDE
"$tcc_usrinclude"
515 print_mak CONFIG_TCC_SYSINCLUDEPATHS
"$tcc_sysincludepaths"
516 print_mak CONFIG_TCC_LIBPATHS
"$tcc_libpaths"
517 print_mak CONFIG_TCC_CRTPREFIX
"$tcc_crtprefix"
518 print_mak CONFIG_TCC_ELFINTERP
"$tcc_elfinterp"
519 print_mak CONFIG_TCC_SWITCHES
"$tcc_switches"
520 print_mak CONFIG_LDDIR
"$tcc_lddir"
521 print_mak CONFIG_TRIPLET
"$triplet"
522 print_mak TCC_CPU_VERSION
"$cpuver" num
524 echo "ARCH=$cpu" >> config.mak
525 echo "TARGETOS=$targetos" >> config.mak
528 for v
in $confvars ; do
529 test "$v" = "predefs=no" && predefs
=""
530 if test "${v%=*}" = "$v"; then
531 echo "CONFIG_$v=yes" >> config.mak
533 echo "CONFIG_$v" >> config.mak
536 print_inc CONFIG_TCC_PREDEFS
"$predefs" num
538 version
=`head $source_path/VERSION`
539 echo "VERSION = $version" >> config.mak
540 echo "#define TCC_VERSION \"$version\"" >> $TMPH
541 echo "@set VERSION $version" > config.texi
543 if test "$source_path_used" = "yes" ; then
545 /*) echo "TOPSRC=$source_path";;
546 *) echo "TOPSRC=\$(TOP)/$source_path";;
549 echo 'TOPSRC=$(TOP)' >>config.mak
552 #define GCC_MAJOR $gcc_major
553 #define GCC_MINOR $gcc_minor
554 #define CC_NAME CC_${cc_name}
557 diff $TMPH config.h
>/dev
/null
2>&1
558 if test $?
-ne 0 ; then
561 echo "config.h is unchanged"
564 rm -f $TMPN* $CONFTEST
566 # ---------------------------------------------------------------------------
567 # build tree in object directory if source path is different from current one
574 test -d $dn || mkdir
-p $dn
577 *) while test $dn ; do
578 tgt
=..
/$tgt; dn
=${dn#${dn%%/*}}; dn=${dn#/}
585 ln -sfn $tgt $2 ||
( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
588 if test "$source_path_used" = "yes" ; then
589 FILES
="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
591 fn_makelink
$source_path $f
595 # ---------------------------------------------------------------------------