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
=""
56 # use CC/AR from environment when set
57 test -n "$CC" && cc
="$CC"
58 test -n "$AR" && ar="$AR"
60 # set default CFLAGS if unset in environment
61 test -z "$CFLAGS" && CFLAGS
="-Wall -O2"
64 source_path
=${0%configure}
65 source_path
=${source_path%/}
70 --prefix=*) prefix
=`echo $opt | cut -d '=' -f 2-`
72 --exec-prefix=*) execprefix
=`echo $opt | cut -d '=' -f 2-`
74 --tccdir=*) tccdir
=`echo $opt | cut -d '=' -f 2-`
76 --bindir=*) bindir
=`echo $opt | cut -d '=' -f 2-`
78 --libdir=*) libdir
=`echo $opt | cut -d '=' -f 2-`
80 --includedir=*) includedir
=`echo $opt | cut -d '=' -f 2-`
82 --sharedir=*) sharedir
=`echo $opt | cut -d '=' -f 2-`
84 --mandir=*) mandir
=`echo $opt | cut -d '=' -f 2-`
86 --infodir=*) infodir
=`echo $opt | cut -d '=' -f 2-`
88 --docdir=*) docdir
=`echo $opt | cut -d '=' -f 2-`
90 --sysroot=*) sysroot
=`echo $opt | cut -d '=' -f 2-`
92 --targetos=*) targetos
=`echo $opt | cut -d '=' -f 2-`
94 --source-path=*) source_path
=`echo $opt | cut -d '=' -f 2-`
96 --cross-prefix=*) cross_prefix
=`echo $opt | cut -d '=' -f 2-`
98 --cc=*) cc
=`echo $opt | cut -d '=' -f 2-`
100 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set
="yes"
102 --extra-cflags=*) CFLAGS
="${opt#--extra-cflags=}"
104 --extra-ldflags=*) LDFLAGS
="${opt#--extra-ldflags=}"
106 --extra-libs=*) extralibs
="${opt#--extra-libs=}"
108 --sysincludepaths=*) tcc_sysincludepaths
=`echo $opt | cut -d '=' -f 2-`
110 --libpaths=*) tcc_libpaths
=`echo $opt | cut -d '=' -f 2-`
112 --crtprefix=*) tcc_crtprefix
=`echo $opt | cut -d '=' -f 2-`
114 --elfinterp=*) tcc_elfinterp
=`echo $opt | cut -d '=' -f 2-`
116 --triplet=*) triplet
=`echo $opt | cut -d '=' -f 2-`
118 --cpu=*) cpu
=`echo $opt | cut -d '=' -f 2-`
120 --dwarf=*) dwarf
=`echo $opt | cut -d '=' -f 2-`
122 --enable-cross) confvars
="$confvars cross"
124 --disable-static) confvars
="$confvars static=no"
126 --enable-static) confvars
="$confvars static"
128 --disable-rpath) confvars
="$confvars rpath=no"
130 --debug) confvars
="$confvars debug"
132 --with-libgcc) confvars
="$confvars libgcc"
134 --with-selinux) confvars
="$confvars selinux"
136 --tcc-switches=*) tcc_switches
=`echo $opt | cut -d '=' -f 2-`
138 --config-mingw32*) mingw32
=$
(echo "$opt=yes" | cut
-d '=' -f 2)
140 --config-*) confvars
="$confvars ${opt#--config-}"; suggest
="no"
142 --help|
-h) show_help
="yes"
144 *) echo "configure: WARNING: unrecognized option $opt"
151 Usage: configure [options]
152 Options: [defaults in brackets after descriptions]
155 --help print this message
156 --prefix=PREFIX install in PREFIX [$prefix]
157 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
159 --bindir=DIR user executables in DIR [EPREFIX/bin]
160 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
161 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
162 --includedir=DIR C header files in DIR [PREFIX/include]
163 --sharedir=DIR documentation root DIR [PREFIX/share]
164 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
165 --mandir=DIR man documentation in DIR [SHAREDIR/man]
166 --infodir=DIR info documentation in DIR [SHAREDIR/info]
168 Advanced options (experts only):
169 --source-path=PATH path of source code [$source_path]
170 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
171 --cc=CC use C compiler CC [$cc]
172 --ar=AR create archives using AR [$ar]
173 --extra-cflags= specify compiler flags [$CFLAGS]
174 --extra-ldflags= specify linker options [$LDFLAGS]
176 --debug include debug info with resulting binaries
177 --disable-static make libtcc.so instead of libtcc.a
178 --enable-static make libtcc.a instead of libtcc.dll (win32)
179 --disable-rpath disable use of -rpath with libtcc.so
180 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
181 --with-selinux use mmap for executable memory (tcc -run)
182 --enable-cross build cross compilers (see also 'make help')
184 --sysincludepaths=... specify system include paths, colon separated
185 --libpaths=... specify system library paths, colon separated
186 --crtprefix=... specify locations of crt?.o, colon separated
187 --elfinterp=... specify elf interpreter
188 --triplet=... specify system library/include directory triplet
189 --tcc-switches=... specify implicit switches passed to tcc
191 --config-uClibc,-musl enable system specific configurations
192 --config-mingw32 build on windows using msys, busybox, etc.
193 --config-backtrace=no disable stack backtraces (with -run or -bt)
194 --config-bcheck=no disable bounds checker (-b)
195 --config-predefs=no do not compile tccdefs.h, instead just include
196 --config-new_macho=no|yes Force apple object format (autodetect osx <= 10)
197 --config-codesign=no do not use codesign on apple to sign executables
198 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
200 Cross build options (experimental):
201 --cpu=CPU target CPU [$cpu]
202 --targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos]
203 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
208 default
() # set variable unless already set
212 test -z "$v" && eval $1=\"$2\"
215 default_conf
() # add to confvars unless already present
218 test "${confvars%$v*}" = "${confvars}" && confvars
="$confvars $1"
221 if test -z "$source_path" -o "$source_path" = "." ; then
223 source_path_used
="no"
225 source_path_used
="yes"
232 Windows_NT|MINGW
*|MSYS
*|CYGWIN
*)
236 if test "$(uname -o)" = "Android"; then
238 if test -n "$TERMUX_VERSION"; then
245 if test "$mingw32" = "yes"; then
246 default targetos WIN32
248 default targetos
"$buildos"
252 default cpu
"$cpu_sys"
255 # check for crpss build
256 if test "$cpu_set" != "$cpu_sys" \
257 -o "$targetos" != "$buildos" \
258 -o -n "$cross_prefix" ; then
260 cc
="${cross_prefix}${cc}"
261 ar="${cross_prefix}${ar}"
265 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386
)
281 aarch64|arm64|evbarm
)
304 "Power Macintosh"|ppc|ppc64
)
317 echo "Unsupported CPU"
325 confvars
="$confvars OSX"
326 default_conf
"codesign"
328 if test -z "$build_cross"; then
330 cc
=`readlink $cc || echo clang`
331 tcc_usrinclude
="`xcrun --show-sdk-path`/usr/include"
332 if test "${confvars%new_macho*}" = "${confvars}"; then
333 # if new_macho was not specified and (known) ver <= 10, use old (=no)
334 osxver
=$
(sw_vers
-productVersion 2>/dev
/null
) # X.Y.Z
335 osxver
=${osxver%%.*} # major version (or empty on sw_vers error)
336 [ "${osxver:-11}" -ge 11 ] || confvars
="$confvars new_macho=no"
339 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
340 if test "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
341 CFLAGS
="$CFLAGS -arch $cpu"
342 LDFLAGS
="$LDFLAGS -arch $cpu"
345 DragonFly|OpenBSD|FreeBSD|NetBSD
)
346 confvars
="$confvars BSD ldl=no"
349 if test "$targetos" = "Termux"; then
351 default sysroot
"/data/data/com.termux/files/usr"
353 default sysroot
"/usr"
355 default prefix
"${sysroot}"
356 confvars
="$confvars Android new-dtags rpath=no"
357 test "${cpu}" != "i386" && confvars
="$confvars pie"
358 default_conf
"static=no"
359 if test "${cpu}" = "arm"; then
360 default triplet
"arm-linux-androideabi"
363 default triplet
"${cpu_set}-linux-android"
365 test "${cpu%64}" != "${cpu}" && S
="64" || S
=""
366 default tcc_sysincludepaths
"{B}/include:{R}/include:{R}/include/${triplet}"
367 default tcc_libpaths
"{B}:{R}/lib:/system/lib${S}"
368 default tcc_crtprefix
"{R}/lib"
369 default tcc_elfinterp
"/system/bin/linker${S}"
370 default tcc_switches
"-Wl,-rpath=$sysroot/lib"
374 confvars
="$confvars WIN32"
375 default prefix
"C:/Program Files/tcc"
376 default tccdir
"${prefix}"
377 default bindir
"${tccdir}"
378 default docdir
"${tccdir}/doc"
379 default libdir
"${tccdir}/libtcc"
380 test "$tccdir" = "$bindir" && tccdir_auto
="yes"
384 if test "$source_path_used" = "no"; then
392 if test "$mingw32" = "no"; then
393 default prefix
"/usr/local"
394 default execprefix
"${prefix}"
395 default libdir
"${execprefix}/lib"
396 default bindir
"${execprefix}/bin"
397 default tccdir
"${libdir}/tcc"
398 default includedir
"${prefix}/include"
399 default sharedir
"${prefix}/share"
400 default docdir
"${sharedir}/doc"
401 default mandir
"${sharedir}/man"
402 default infodir
"${sharedir}/info"
405 if test x
"$show_help" = "xyes" ; then
409 if test -z "$build_cross"; then
410 CONFTEST
=.
/conftest
$EXESUF
411 if ! $cc -o $CONFTEST $source_path/conftest.c
; then
412 echo "configure: error: '$cc' failed to compile conftest.c."
414 cc_name
="$($CONFTEST compiler)"
415 gcc_major
="$($CONFTEST version)"
416 gcc_minor
="$($CONFTEST minor)"
417 bigendian
="$($CONFTEST bigendian)"
418 _triplet
="$($CONFTEST triplet)"
420 if test "$mingw32" = "no" ; then
421 if test -z "$triplet" -a -n "$_triplet"; then
422 if test -f "/usr/lib/$_triplet/crti.o"; then
426 if test -z "$triplet"; then
427 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
428 if test -f "/usr/lib64/crti.o" ; then
433 if test "$suggest" = "yes"; then
434 if test -f "/lib/ld-uClibc.so.0" ; then
435 echo "Perhaps you want ./configure --config-uClibc"
437 if test -f "/lib/ld-musl-$cpu.so.1"; then
438 echo "Perhaps you want ./configure --config-musl"
443 # can only make guesses about compiler and target
444 if test "${cc%tcc*}" != "$cc"; then
446 elif test "${cc%clang*}" != "$cc"; then
450 ppc|mips|s390
) bigendian
=yes;;
454 default triplet
"$cpu_set-linux-gnu"
458 if test "$bigendian" = "yes" ; then
459 confvars
="$confvars BIGENDIAN"
462 if test "$mingw32" = "yes" -a "$cc_name" = "gcc"; then
463 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
464 default LDFLAGS
"-static"
467 if test "$cpu" = "arm"; then
468 if test "${triplet%eabihf}" != "$triplet" ; then
469 confvars
="$confvars arm_eabihf arm_vfp"
470 elif test "${triplet%eabi}" != "$triplet" ; then
471 confvars
="$confvars arm_eabi arm_vfp"
472 elif test -z "$build_cross"; then
473 if test "${_triplet%eabihf}" != "$_triplet" ; then
474 confvars
="$confvars arm_eabihf arm_vfp"
475 elif test "${_triplet%eabi}" != "$_triplet" ; then
476 confvars
="$confvars arm_eabi arm_vfp"
477 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
; then
478 confvars
="$confvars arm_vfp"
483 if test -n "$dwarf"; then
484 confvars
="$confvars dwarf=$dwarf"
487 # a final configuration tuning
488 if test "$cc_name" != "tcc"; then
489 OPT1
="-Wdeclaration-after-statement -fno-strict-aliasing"
490 # we want -Wno- but gcc does not always reject unknown -Wno- options
491 OPT2
="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
492 OPT2
="$OPT2 -Wstringop-truncation"
493 if test "$cc_name" = "clang"; then
494 OPT1
="$OPT1 -fheinous-gnu-extensions"
495 OPT2
="$OPT2 -Wstring-plus-int -Wdeprecated-declarations"
497 $cc $OPT1 $OPT2 -o a.out
-c -xc - < /dev
/null
> cc_msg.txt
2>&1
498 for o
in $OPT1; do # enable these options
499 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS $o"; fi
501 for o
in $OPT2; do # disable these options
502 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS -Wno-${o#-W*}"; fi
506 rm -f cc_msg.txt a.out
508 test "$ar_set" ||
ar="$cc -ar"
511 fcho
() { if test -n "$2"; then echo "$1$2"; fi }
513 fcho
"Binary directory " "$bindir"
514 fcho
"TinyCC directory " "$tccdir"
515 fcho
"Library directory " "$libdir"
516 fcho
"Include directory " "$includedir"
517 fcho
"Manual directory " "$mandir"
518 fcho
"Info directory " "$infodir"
519 fcho
"Doc directory " "$docdir"
520 fcho
"Target root prefix " "$sysroot"
521 fcho
"/usr/include dir " "$tcc_usrinclude"
522 echo "Source path $source_path"
523 echo "Build OS $(uname -m -s)"
524 echo "C compiler $cc ($gcc_major.$gcc_minor)"
525 echo "Target OS $targetos"
527 fcho
"Triplet " "$triplet"
528 fcho
"Libs " "$tcc_libpaths"
529 fcho
"Sysinclude " "$tcc_sysincludepaths"
530 fcho
"Crt " "$tcc_crtprefix"
531 fcho
"Elfinterp " "$tcc_elfinterp"
532 fcho
"Switches " "$tcc_switches"
533 fcho
"Config " "${confvars# }"
534 echo "Creating config.mak and config.h"
536 cat >config.mak
<<EOF
537 # Automatically generated by configure - do not modify
539 bindir=\$(DESTDIR)$bindir
540 tccdir=\$(DESTDIR)$tccdir
541 libdir=\$(DESTDIR)$libdir
542 includedir=\$(DESTDIR)$includedir
543 mandir=\$(DESTDIR)$mandir
544 infodir=\$(DESTDIR)$infodir
545 docdir=\$(DESTDIR)$docdir
560 if test -n "$v"; then
561 test "$3" = "num" || v
="\"$v\""
562 echo "#ifndef $1" >> $TMPH
563 echo "# define $1 $v" >> $TMPH
564 echo "#endif" >> $TMPH
570 if test -n "$v"; then
571 test "$3" = "num" || v
="\"\\\"$v\\\"\""
572 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
576 echo "/* Automatically generated by configure - do not modify */" > $TMPH
578 print_inc CONFIG_SYSROOT
"$sysroot"
579 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR
"$tccdir"
580 print_inc DWARF_VERSION
"$dwarf" num
581 print_mak CONFIG_USR_INCLUDE
"$tcc_usrinclude"
582 print_mak CONFIG_TCC_SYSINCLUDEPATHS
"$tcc_sysincludepaths"
583 print_mak CONFIG_TCC_LIBPATHS
"$tcc_libpaths"
584 print_mak CONFIG_TCC_CRTPREFIX
"$tcc_crtprefix"
585 print_mak CONFIG_TCC_ELFINTERP
"$tcc_elfinterp"
586 print_mak CONFIG_TCC_SWITCHES
"$tcc_switches"
587 print_mak CONFIG_LDDIR
"$tcc_lddir"
588 print_mak CONFIG_TRIPLET
"$triplet"
589 print_mak TCC_CPU_VERSION
"$cpuver" num
591 echo "ARCH=$cpu" >> config.mak
592 echo "TARGETOS=$targetos" >> config.mak
593 echo "BUILDOS=$buildos" >> config.mak
596 for v
in $confvars ; do
597 test "$v" = "predefs=no" && predefs
=""
598 if test "${v%=*}" = "$v"; then
599 echo "CONFIG_$v=yes" >> config.mak
601 echo "CONFIG_$v" >> config.mak
604 print_inc CONFIG_TCC_PREDEFS
"$predefs" num
606 version
=`head $source_path/VERSION`
607 echo "VERSION = $version" >> config.mak
608 echo "#define TCC_VERSION \"$version\"" >> $TMPH
609 echo "@set VERSION $version" > config.texi
611 if test "$source_path_used" = "yes" ; then
613 /*) echo "TOPSRC=$source_path";;
614 *) echo "TOPSRC=\$(TOP)/$source_path";;
617 echo 'TOPSRC=$(TOP)' >>config.mak
620 #define GCC_MAJOR $gcc_major
621 #define GCC_MINOR $gcc_minor
622 #define CC_NAME CC_${cc_name}
625 diff $TMPH config.h
>/dev
/null
2>&1
626 if test $?
-ne 0 ; then
629 echo "config.h is unchanged"
632 rm -f $TMPN* $CONFTEST
634 # ---------------------------------------------------------------------------
635 # build tree in object directory if source path is different from current one
642 test -d $dn || mkdir
-p $dn
645 *) while test $dn ; do
646 tgt
=..
/$tgt; dn
=${dn#${dn%%/*}}; dn=${dn#/}
653 ln -sfn $tgt $2 ||
( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
656 if test "$source_path_used" = "yes" ; then
657 FILES
="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
659 fn_makelink
$source_path $f
663 # ---------------------------------------------------------------------------