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"
61 source_path
=${0%configure}
62 source_path
=${source_path%/}
67 --prefix=*) prefix
=`echo $opt | cut -d '=' -f 2-`
69 --exec-prefix=*) execprefix
=`echo $opt | cut -d '=' -f 2-`
71 --tccdir=*) tccdir
=`echo $opt | cut -d '=' -f 2-`
73 --bindir=*) bindir
=`echo $opt | cut -d '=' -f 2-`
75 --libdir=*) libdir
=`echo $opt | cut -d '=' -f 2-`
77 --includedir=*) includedir
=`echo $opt | cut -d '=' -f 2-`
79 --sharedir=*) sharedir
=`echo $opt | cut -d '=' -f 2-`
81 --mandir=*) mandir
=`echo $opt | cut -d '=' -f 2-`
83 --infodir=*) infodir
=`echo $opt | cut -d '=' -f 2-`
85 --docdir=*) docdir
=`echo $opt | cut -d '=' -f 2-`
87 --sysroot=*) sysroot
=`echo $opt | cut -d '=' -f 2-`
89 --targetos=*) targetos
=`echo $opt | cut -d '=' -f 2-`
91 --source-path=*) source_path
=`echo $opt | cut -d '=' -f 2-`
93 --cross-prefix=*) cross_prefix
=`echo $opt | cut -d '=' -f 2-`
95 --cc=*) cc
=`echo $opt | cut -d '=' -f 2-`
97 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set
="yes"
99 --extra-cflags=*) CFLAGS
="${opt#--extra-cflags=}"
101 --extra-ldflags=*) LDFLAGS
="${opt#--extra-ldflags=}"
103 --extra-libs=*) extralibs
="${opt#--extra-libs=}"
105 --sysincludepaths=*) tcc_sysincludepaths
=`echo $opt | cut -d '=' -f 2-`
107 --libpaths=*) tcc_libpaths
=`echo $opt | cut -d '=' -f 2-`
109 --crtprefix=*) tcc_crtprefix
=`echo $opt | cut -d '=' -f 2-`
111 --elfinterp=*) tcc_elfinterp
=`echo $opt | cut -d '=' -f 2-`
113 --triplet=*) triplet
=`echo $opt | cut -d '=' -f 2-`
115 --cpu=*) cpu
=`echo $opt | cut -d '=' -f 2-`
117 --dwarf=*) dwarf
=`echo $opt | cut -d '=' -f 2-`
119 --enable-cross) confvars
="$confvars cross"
121 --disable-static) confvars
="$confvars static=no"
123 --enable-static) confvars
="$confvars static"
125 --disable-rpath) confvars
="$confvars rpath=no"
127 --debug) confvars
="$confvars debug"
129 --with-libgcc) confvars
="$confvars libgcc"
131 --with-selinux) confvars
="$confvars selinux"
133 --tcc-switches=*) tcc_switches
=`echo $opt | cut -d '=' -f 2-`
135 --config-mingw32*) mingw32
=$
(echo "$opt=yes" | cut
-d '=' -f 2)
137 --config-*) confvars
="$confvars ${opt#--config-}"; suggest
="no"
139 --help|
-h) show_help
="yes"
141 *) echo "configure: WARNING: unrecognized option $opt"
148 Usage: configure [options]
149 Options: [defaults in brackets after descriptions]
152 --help print this message
153 --prefix=PREFIX install in PREFIX [$prefix]
154 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
156 --bindir=DIR user executables in DIR [EPREFIX/bin]
157 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
158 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
159 --includedir=DIR C header files in DIR [PREFIX/include]
160 --sharedir=DIR documentation root DIR [PREFIX/share]
161 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
162 --mandir=DIR man documentation in DIR [SHAREDIR/man]
163 --infodir=DIR info documentation in DIR [SHAREDIR/info]
165 Advanced options (experts only):
166 --source-path=PATH path of source code [$source_path]
167 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
168 --cc=CC use C compiler CC [$cc]
169 --ar=AR create archives using AR [$ar]
170 --extra-cflags= specify compiler flags [$CFLAGS]
171 --extra-ldflags= specify linker options [$LDFLAGS]
173 --debug include debug info with resulting binaries
174 --disable-static make libtcc.so instead of libtcc.a
175 --enable-static make libtcc.a instead of libtcc.dll (win32)
176 --disable-rpath disable use of -rpath with libtcc.so
177 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
178 --with-selinux use mmap for executable memory (tcc -run)
179 --enable-cross build cross compilers (see also 'make help')
181 --sysincludepaths=... specify system include paths, colon separated
182 --libpaths=... specify system library paths, colon separated
183 --crtprefix=... specify locations of crt?.o, colon separated
184 --elfinterp=... specify elf interpreter
185 --triplet=... specify system library/include directory triplet
186 --tcc-switches=... specify implicit switches passed to tcc
188 --config-uClibc,-musl enable system specific configurations
189 --config-mingw32 build on windows using msys, busybox, etc.
190 --config-backtrace=no disable stack backtraces (with -run or -bt)
191 --config-bcheck=no disable bounds checker (-b)
192 --config-predefs=no do not compile tccdefs.h, instead just include
193 --config-new_macho=no|yes Force apple object format (autodetect osx <= 10)
194 --config-codesign=no do not use codesign on apple to sign executables
195 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
197 Cross build options (experimental):
198 --cpu=CPU target CPU [$cpu]
199 --targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos]
200 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
205 default
() # set variable unless already set
209 test -z "$v" && eval $1=\"$2\"
212 default_conf
() # add to confvars unless already present
215 test "${confvars%$v*}" = "${confvars}" && confvars
="$confvars $1"
218 if test -z "$source_path" -o "$source_path" = "." ; then
220 source_path_used
="no"
222 source_path_used
="yes"
229 Windows_NT|MINGW
*|MSYS
*|CYGWIN
*)
233 if test "$(uname -o)" = "Android"; then
235 if test -n "$TERMUX_VERSION"; then
242 if test "$mingw32" = "yes"; then
243 default targetos WIN32
245 default targetos
"$buildos"
249 default cpu
"$cpu_sys"
252 # check for crpss build
253 if test "$cpu_set" != "$cpu_sys" \
254 -o "$targetos" != "$buildos" \
255 -o -n "$cross_prefix" ; then
257 cc
="${cross_prefix}${cc}"
258 ar="${cross_prefix}${ar}"
262 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386
)
278 aarch64|arm64|evbarm
)
301 "Power Macintosh"|ppc|ppc64
)
314 echo "Unsupported CPU"
322 confvars
="$confvars OSX"
323 default_conf
"codesign"
325 if test -z "$build_cross"; then
327 cc
=`readlink $cc || echo clang`
328 tcc_usrinclude
="`xcrun --show-sdk-path`/usr/include"
329 if test "${confvars%new_macho*}" = "${confvars}"; then
330 # if new_macho was not specified and (known) ver <= 10, use old (=no)
331 osxver
=$
(sw_vers
-productVersion 2>/dev
/null
) # X.Y.Z
332 osxver
=${osxver%%.*} # major version (or empty on sw_vers error)
333 [ "${osxver:-11}" -ge 11 ] || confvars
="$confvars new_macho=no"
336 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
337 if test "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
338 CFLAGS
="$CFLAGS -arch $cpu"
339 LDFLAGS
="$LDFLAGS -arch $cpu"
342 DragonFly|OpenBSD|FreeBSD|NetBSD
)
343 confvars
="$confvars BSD ldl=no"
346 if test "$targetos" = "Termux"; then
348 default sysroot
"/data/data/com.termux/files/usr"
350 default sysroot
"/usr"
352 default prefix
"${sysroot}"
353 confvars
="$confvars Android new-dtags rpath=no"
354 test "${cpu}" != "i386" && confvars
="$confvars pie"
355 default_conf
"static=no"
356 if test "${cpu}" = "arm"; then
357 default triplet
"arm-linux-androideabi"
360 default triplet
"${cpu_set}-linux-android"
362 test "${cpu%64}" != "${cpu}" && S
="64" || S
=""
363 default tcc_sysincludepaths
"{B}/include:{R}/include:{R}/include/${triplet}"
364 default tcc_libpaths
"{B}:{R}/lib:/system/lib${S}"
365 default tcc_crtprefix
"{R}/lib"
366 default tcc_elfinterp
"/system/bin/linker${S}"
367 default tcc_switches
"-Wl,-rpath=$sysroot/lib,-section-alignment=0x1000"
371 confvars
="$confvars WIN32"
372 default prefix
"C:/Program Files/tcc"
373 default tccdir
"${prefix}"
374 default bindir
"${tccdir}"
375 default docdir
"${tccdir}/doc"
376 default libdir
"${tccdir}/libtcc"
377 test "$tccdir" = "$bindir" && tccdir_auto
="yes"
381 if test "$source_path_used" = "no"; then
389 if test "$mingw32" = "no"; then
390 default prefix
"/usr/local"
391 default execprefix
"${prefix}"
392 default libdir
"${execprefix}/lib"
393 default bindir
"${execprefix}/bin"
394 default tccdir
"${libdir}/tcc"
395 default includedir
"${prefix}/include"
396 default sharedir
"${prefix}/share"
397 default docdir
"${sharedir}/doc"
398 default mandir
"${sharedir}/man"
399 default infodir
"${sharedir}/info"
403 default CFLAGS
"-Wall -O2"
405 if test "$mingw32" = "yes" -a "$cc_name" = "gcc"; then
406 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
407 default LDFLAGS
"-static"
410 if test x
"$show_help" = "xyes" ; then
414 if test -z "$build_cross"; then
415 CONFTEST
=.
/conftest
$EXESUF
416 if ! $cc -o $CONFTEST $source_path/conftest.c
; then
417 echo "configure: error: '$cc' failed to compile conftest.c."
419 cc_name
="$($CONFTEST compiler)"
420 gcc_major
="$($CONFTEST version)"
421 gcc_minor
="$($CONFTEST minor)"
422 bigendian
="$($CONFTEST bigendian)"
423 _triplet
="$($CONFTEST triplet)"
425 if test "$mingw32" = "no" ; then
426 if test -z "$triplet" -a -n "$_triplet"; then
427 if test -f "/usr/lib/$_triplet/crti.o"; then
431 if test -z "$triplet"; then
432 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
433 if test -f "/usr/lib64/crti.o" ; then
438 if test "$suggest" = "yes"; then
439 if test -f "/lib/ld-uClibc.so.0" ; then
440 echo "Perhaps you want ./configure --config-uClibc"
442 if test -f "/lib/ld-musl-$cpu.so.1"; then
443 echo "Perhaps you want ./configure --config-musl"
448 # can only make guesses about compiler and target
449 if test "${cc%tcc*}" != "$cc"; then
451 elif test "${cc%clang*}" != "$cc"; then
455 ppc|mips|s390
) bigendian
=yes;;
459 default triplet
"$cpu_set-linux-gnu"
463 if test "$bigendian" = "yes" ; then
464 confvars
="$confvars BIGENDIAN"
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 # a final configuration tuning
484 if test "$cc_name" != "tcc"; then
485 OPT1
="-Wdeclaration-after-statement -fno-strict-aliasing"
486 # we want -Wno- but gcc does not always reject unknown -Wno- options
487 OPT2
="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
488 OPT2
="$OPT2 -Wstringop-truncation"
489 if test "$cc_name" = "clang"; then
490 OPT1
="$OPT1 -fheinous-gnu-extensions"
491 OPT2
="$OPT2 -Wstring-plus-int -Wdeprecated-declarations"
493 $cc $OPT1 $OPT2 -o a.out
-c -xc - < /dev
/null
> cc_msg.txt
2>&1
494 for o
in $OPT1; do # enable these options
495 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS $o"; fi
497 for o
in $OPT2; do # disable these options
498 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS -Wno-${o#-W*}"; fi
502 rm -f cc_msg.txt a.out
504 test "$ar_set" ||
ar="$cc -ar"
507 fcho
() { if test -n "$2"; then echo "$1$2"; fi }
509 fcho
"Binary directory " "$bindir"
510 fcho
"TinyCC directory " "$tccdir"
511 fcho
"Library directory " "$libdir"
512 fcho
"Include directory " "$includedir"
513 fcho
"Manual directory " "$mandir"
514 fcho
"Info directory " "$infodir"
515 fcho
"Doc directory " "$docdir"
516 fcho
"Target root prefix " "$sysroot"
517 fcho
"/usr/include dir " "$tcc_usrinclude"
518 echo "Source path $source_path"
519 echo "C compiler $cc ($gcc_major.$gcc_minor)"
520 echo "Target OS $targetos"
522 fcho
"Triplet " "$triplet"
523 fcho
"Libs " "$tcc_libpaths"
524 fcho
"Sysinclude " "$tcc_sysincludepaths"
525 fcho
"Crt " "$tcc_crtprefix"
526 fcho
"Elfinterp " "$tcc_elfinterp"
527 fcho
"Switches " "$tcc_switches"
528 fcho
"Config " "${confvars# }"
529 echo "Creating config.mak and config.h"
531 cat >config.mak
<<EOF
532 # Automatically generated by configure - do not modify
534 bindir=\$(DESTDIR)$bindir
535 tccdir=\$(DESTDIR)$tccdir
536 libdir=\$(DESTDIR)$libdir
537 includedir=\$(DESTDIR)$includedir
538 mandir=\$(DESTDIR)$mandir
539 infodir=\$(DESTDIR)$infodir
540 docdir=\$(DESTDIR)$docdir
555 if test -n "$v"; then
556 test "$3" = "num" || v
="\"$v\""
557 echo "#ifndef $1" >> $TMPH
558 echo "# define $1 $v" >> $TMPH
559 echo "#endif" >> $TMPH
565 if test -n "$v"; then
566 test "$3" = "num" || v
="\"\\\"$v\\\"\""
567 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
571 echo "/* Automatically generated by configure - do not modify */" > $TMPH
573 print_inc CONFIG_SYSROOT
"$sysroot"
574 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR
"$tccdir"
575 print_inc DWARF_VERSION
"$dwarf" num
576 print_mak CONFIG_USR_INCLUDE
"$tcc_usrinclude"
577 print_mak CONFIG_TCC_SYSINCLUDEPATHS
"$tcc_sysincludepaths"
578 print_mak CONFIG_TCC_LIBPATHS
"$tcc_libpaths"
579 print_mak CONFIG_TCC_CRTPREFIX
"$tcc_crtprefix"
580 print_mak CONFIG_TCC_ELFINTERP
"$tcc_elfinterp"
581 print_mak CONFIG_TCC_SWITCHES
"$tcc_switches"
582 print_mak CONFIG_LDDIR
"$tcc_lddir"
583 print_mak CONFIG_TRIPLET
"$triplet"
584 print_mak TCC_CPU_VERSION
"$cpuver" num
586 echo "ARCH=$cpu" >> config.mak
587 echo "TARGETOS=$targetos" >> config.mak
588 echo "BUILDOS=$buildos" >> config.mak
591 for v
in $confvars ; do
592 test "$v" = "predefs=no" && predefs
=""
593 if test "${v%=*}" = "$v"; then
594 echo "CONFIG_$v=yes" >> config.mak
596 echo "CONFIG_$v" >> config.mak
599 print_inc CONFIG_TCC_PREDEFS
"$predefs" num
601 version
=`head $source_path/VERSION`
602 echo "VERSION = $version" >> config.mak
603 echo "#define TCC_VERSION \"$version\"" >> $TMPH
604 echo "@set VERSION $version" > config.texi
606 if test "$targetos" = "Darwin"; then
607 # On macOS, -current_version and -compatibility_version must not contain letters.
608 macos_dylib_version
=`echo $version | sed 's/[^0-9.]//g'`
609 echo "MACOS_DYLIB_VERSION = $macos_dylib_version" >> config.mak
612 if test "$source_path_used" = "yes" ; then
614 /*) echo "TOPSRC=$source_path";;
615 *) echo "TOPSRC=\$(TOP)/$source_path";;
618 echo 'TOPSRC=$(TOP)' >>config.mak
621 #define GCC_MAJOR $gcc_major
622 #define GCC_MINOR $gcc_minor
623 #define CC_NAME CC_${cc_name}
626 diff $TMPH config.h
>/dev
/null
2>&1
627 if test $?
-ne 0 ; then
630 echo "config.h is unchanged"
633 rm -f $TMPN* $CONFTEST
635 # ---------------------------------------------------------------------------
636 # build tree in object directory if source path is different from current one
643 test -d $dn || mkdir
-p $dn
646 *) while test $dn ; do
647 tgt
=..
/$tgt; dn
=${dn#${dn%%/*}}; dn=${dn#/}
654 ln -sfn $tgt $2 ||
( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
657 if test "$source_path_used" = "yes" ; then
658 FILES
="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
660 fn_makelink
$source_path $f
664 # ---------------------------------------------------------------------------