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"
59 test -n "CFLAGS" && CFLAGS
="-Wall -O2"
62 source_path
=${0%configure}
63 source_path
=${source_path%/}
68 --prefix=*) prefix
=`echo $opt | cut -d '=' -f 2-`
70 --exec-prefix=*) execprefix
=`echo $opt | cut -d '=' -f 2-`
72 --tccdir=*) tccdir
=`echo $opt | cut -d '=' -f 2-`
74 --bindir=*) bindir
=`echo $opt | cut -d '=' -f 2-`
76 --libdir=*) libdir
=`echo $opt | cut -d '=' -f 2-`
78 --includedir=*) includedir
=`echo $opt | cut -d '=' -f 2-`
80 --sharedir=*) sharedir
=`echo $opt | cut -d '=' -f 2-`
82 --mandir=*) mandir
=`echo $opt | cut -d '=' -f 2-`
84 --infodir=*) infodir
=`echo $opt | cut -d '=' -f 2-`
86 --docdir=*) docdir
=`echo $opt | cut -d '=' -f 2-`
88 --sysroot=*) sysroot
=`echo $opt | cut -d '=' -f 2-`
90 --targetos=*) targetos
=`echo $opt | cut -d '=' -f 2-`
92 --source-path=*) source_path
=`echo $opt | cut -d '=' -f 2-`
94 --cross-prefix=*) cross_prefix
=`echo $opt | cut -d '=' -f 2-`
96 --cc=*) cc
=`echo $opt | cut -d '=' -f 2-`
98 --ar=*) ar=`echo $opt | cut -d '=' -f 2-` ; ar_set
="yes"
100 --extra-cflags=*) CFLAGS
="${opt#--extra-cflags=}"
102 --extra-ldflags=*) LDFLAGS
="${opt#--extra-ldflags=}"
104 --extra-libs=*) extralibs
="${opt#--extra-libs=}"
106 --sysincludepaths=*) tcc_sysincludepaths
=`echo $opt | cut -d '=' -f 2-`
108 --libpaths=*) tcc_libpaths
=`echo $opt | cut -d '=' -f 2-`
110 --crtprefix=*) tcc_crtprefix
=`echo $opt | cut -d '=' -f 2-`
112 --elfinterp=*) tcc_elfinterp
=`echo $opt | cut -d '=' -f 2-`
114 --triplet=*) triplet
=`echo $opt | cut -d '=' -f 2-`
116 --cpu=*) cpu
=`echo $opt | cut -d '=' -f 2-`
118 --dwarf=*) dwarf
=`echo $opt | cut -d '=' -f 2-`
120 --enable-cross) confvars
="$confvars cross"
122 --disable-static) confvars
="$confvars static=no"
124 --enable-static) confvars
="$confvars static"
126 --disable-rpath) confvars
="$confvars rpath=no"
128 --debug) confvars
="$confvars debug"
130 --with-libgcc) confvars
="$confvars libgcc"
132 --with-selinux) confvars
="$confvars selinux"
134 --tcc-switches=*) tcc_switches
=`echo $opt | cut -d '=' -f 2-`
136 --config-mingw32*) mingw32
=$
(echo "$opt=yes" | cut
-d '=' -f 2)
138 --config-*) confvars
="$confvars ${opt#--config-}"; suggest
="no"
140 --help|
-h) show_help
="yes"
142 *) echo "configure: WARNING: unrecognized option $opt"
149 Usage: configure [options]
150 Options: [defaults in brackets after descriptions]
153 --help print this message
154 --prefix=PREFIX install in PREFIX [$prefix]
155 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
157 --bindir=DIR user executables in DIR [EPREFIX/bin]
158 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
159 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
160 --includedir=DIR C header files in DIR [PREFIX/include]
161 --sharedir=DIR documentation root DIR [PREFIX/share]
162 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
163 --mandir=DIR man documentation in DIR [SHAREDIR/man]
164 --infodir=DIR info documentation in DIR [SHAREDIR/info]
166 Advanced options (experts only):
167 --source-path=PATH path of source code [$source_path]
168 --sysroot=PREFIX prepend PREFIX to library/include paths [$sysroot]
169 --cc=CC use C compiler CC [$cc]
170 --ar=AR create archives using AR [$ar]
171 --extra-cflags= specify compiler flags [$CFLAGS]
172 --extra-ldflags= specify linker options [$LDFLAGS]
174 --debug include debug info with resulting binaries
175 --disable-static make libtcc.so instead of libtcc.a
176 --enable-static make libtcc.a instead of libtcc.dll (win32)
177 --disable-rpath disable use of -rpath with libtcc.so
178 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
179 --with-selinux use mmap for executable memory (tcc -run)
180 --enable-cross build cross compilers (see also 'make help')
182 --sysincludepaths=... specify system include paths, colon separated
183 --libpaths=... specify system library paths, colon separated
184 --crtprefix=... specify locations of crt?.o, colon separated
185 --elfinterp=... specify elf interpreter
186 --triplet=... specify system library/include directory triplet
187 --tcc-switches=... specify implicit switches passed to tcc
189 --config-uClibc,-musl enable system specific configurations
190 --config-mingw32 build on windows using msys, busybox, etc.
191 --config-backtrace=no disable stack backtraces (with -run or -bt)
192 --config-bcheck=no disable bounds checker (-b)
193 --config-predefs=no do not compile tccdefs.h, instead just include
194 --config-new_macho=no|yes Force apple object format (autodetect osx <= 10)
195 --config-codesign=no do not use codesign on apple to sign executables
196 --dwarf=x Use dwarf debug info instead of stabs (x=2..5)
198 Cross build options (experimental):
199 --cpu=CPU target CPU [$cpu]
200 --targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos]
201 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
206 default
() # set variable unless already set
210 test -z "$v" && eval $1=\"$2\"
213 default_conf
() # add to confvars unless already present
216 test "${confvars%$v*}" = "${confvars}" && confvars
="$confvars $1"
219 if test -z "$source_path" -o "$source_path" = "." ; then
221 source_path_used
="no"
223 source_path_used
="yes"
230 Windows_NT|MINGW
*|MSYS
*|CYGWIN
*)
234 if test "$(uname -o)" = "Android"; then
236 if test -n "$TERMUX_VERSION"; then
243 if test "$mingw32" = "yes"; then
244 default targetos WIN32
246 default targetos
"$buildos"
250 default cpu
"$cpu_sys"
253 # check for crpss build
254 if test "$cpu_set" != "$cpu_sys" \
255 -o "$targetos" != "$buildos" \
256 -o -n "$cross_prefix" ; then
258 cc
="${cross_prefix}${cc}"
259 ar="${cross_prefix}${ar}"
263 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386
)
279 aarch64|arm64|evbarm
)
302 "Power Macintosh"|ppc|ppc64
)
315 echo "Unsupported CPU"
323 confvars
="$confvars OSX"
324 default_conf
"codesign"
326 if test -z "$build_cross"; then
328 cc
=`readlink $cc || echo clang`
329 tcc_usrinclude
="`xcrun --show-sdk-path`/usr/include"
330 if test "${confvars%new_macho*}" = "${confvars}"; then
331 # if new_macho was not specified and (known) ver <= 10, use old (=no)
332 osxver
=$
(sw_vers
-productVersion 2>/dev
/null
) # X.Y.Z
333 osxver
=${osxver%%.*} # major version (or empty on sw_vers error)
334 [ "${osxver:-11}" -ge 11 ] || confvars
="$confvars new_macho=no"
337 # on OSX M1 with --cpu=x86_64, build a tcc to run under rosetta entirely
338 if test "$cpu" = "x86_64" -a "$cpu_sys" = "arm64"; then
339 CFLAGS
="$CFLAGS -arch $cpu"
340 LDFLAGS
="$LDFLAGS -arch $cpu"
343 DragonFly|OpenBSD|FreeBSD|NetBSD
)
344 confvars
="$confvars BSD ldl=no"
347 if test "$targetos" = "Termux"; then
349 default sysroot
"/data/data/com.termux/files/usr"
351 default sysroot
"/usr"
353 default prefix
"${sysroot}"
354 confvars
="$confvars Android new-dtags rpath=no"
355 test "${cpu}" != "i386" && confvars
="$confvars pie"
356 default_conf
"static=no"
357 if test "${cpu}" = "arm"; then
358 default triplet
"arm-linux-androideabi"
361 default triplet
"${cpu_set}-linux-android"
363 test "${cpu%64}" != "${cpu}" && S
="64" || S
=""
364 default tcc_sysincludepaths
"{B}/include:{R}/include:{R}/include/${triplet}"
365 default tcc_libpaths
"{B}:{R}/lib:/system/lib${S}"
366 default tcc_crtprefix
"{R}/lib"
367 default tcc_elfinterp
"/system/bin/linker${S}"
368 default tcc_switches
"-Wl,-rpath=$sysroot/lib"
372 confvars
="$confvars WIN32"
373 default prefix
"C:/Program Files/tcc"
374 default tccdir
"${prefix}"
375 default bindir
"${tccdir}"
376 default docdir
"${tccdir}/doc"
377 default libdir
"${tccdir}/libtcc"
378 test "$tccdir" = "$bindir" && tccdir_auto
="yes"
382 if test "$source_path_used" = "no"; then
390 if test "$mingw32" = "no"; then
391 default prefix
"/usr/local"
392 default execprefix
"${prefix}"
393 default libdir
"${execprefix}/lib"
394 default bindir
"${execprefix}/bin"
395 default tccdir
"${libdir}/tcc"
396 default includedir
"${prefix}/include"
397 default sharedir
"${prefix}/share"
398 default docdir
"${sharedir}/doc"
399 default mandir
"${sharedir}/man"
400 default infodir
"${sharedir}/info"
403 if test x
"$show_help" = "xyes" ; then
407 if test -z "$build_cross"; then
408 CONFTEST
=.
/conftest
$EXESUF
409 if ! $cc -o $CONFTEST $source_path/conftest.c
; then
410 echo "configure: error: '$cc' failed to compile conftest.c."
412 cc_name
="$($CONFTEST compiler)"
413 gcc_major
="$($CONFTEST version)"
414 gcc_minor
="$($CONFTEST minor)"
415 bigendian
="$($CONFTEST bigendian)"
416 _triplet
="$($CONFTEST triplet)"
418 if test "$mingw32" = "no" ; then
419 if test -z "$triplet" -a -n "$_triplet"; then
420 if test -f "/usr/lib/$_triplet/crti.o"; then
424 if test -z "$triplet"; then
425 if test $cpu = "x86_64" -o $cpu = "arm64" -o $cpu = "riscv64" ; then
426 if test -f "/usr/lib64/crti.o" ; then
431 if test "$suggest" = "yes"; then
432 if test -f "/lib/ld-uClibc.so.0" ; then
433 echo "Perhaps you want ./configure --config-uClibc"
435 if test -f "/lib/ld-musl-$cpu.so.1"; then
436 echo "Perhaps you want ./configure --config-musl"
441 # can only make guesses about compiler and target
442 if test "${cc%tcc*}" != "$cc"; then
444 elif test "${cc%clang*}" != "$cc"; then
448 ppc|mips|s390
) bigendian
=yes;;
452 default triplet
"$cpu_set-linux-gnu"
456 if test "$bigendian" = "yes" ; then
457 confvars
="$confvars BIGENDIAN"
460 if test "$mingw32" = "yes" -a "$cc_name" = "gcc"; then
461 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
462 default LDFLAGS
"-static"
465 if test "$cpu" = "arm"; then
466 if test "${triplet%eabihf}" != "$triplet" ; then
467 confvars
="$confvars arm_eabihf arm_vfp"
468 elif test "${triplet%eabi}" != "$triplet" ; then
469 confvars
="$confvars arm_eabi arm_vfp"
470 elif test -z "$build_cross"; then
471 if test "${_triplet%eabihf}" != "$_triplet" ; then
472 confvars
="$confvars arm_eabihf arm_vfp"
473 elif test "${_triplet%eabi}" != "$_triplet" ; then
474 confvars
="$confvars arm_eabi arm_vfp"
475 elif grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc
/cpuinfo
; then
476 confvars
="$confvars arm_vfp"
481 if test -n "$dwarf"; then
482 confvars
="$confvars dwarf=$dwarf"
485 # a final configuration tuning
486 if test "$cc_name" != "tcc"; then
487 OPT1
="-Wdeclaration-after-statement -fno-strict-aliasing"
488 # we want -Wno- but gcc does not always reject unknown -Wno- options
489 OPT2
="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
490 OPT2
="$OPT2 -Wstringop-truncation"
491 if test "$cc_name" = "clang"; then
492 OPT1
="$OPT1 -fheinous-gnu-extensions"
493 OPT2
="$OPT2 -Wstring-plus-int -Wdeprecated-declarations"
495 $cc $OPT1 $OPT2 -o a.out
-c -xc - < /dev
/null
> cc_msg.txt
2>&1
496 for o
in $OPT1; do # enable these options
497 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS $o"; fi
499 for o
in $OPT2; do # disable these options
500 if ! grep -q -- $o cc_msg.txt
; then CFLAGS
="$CFLAGS -Wno-${o#-W*}"; fi
504 rm -f cc_msg.txt a.out
506 test "$ar_set" ||
ar="$cc -ar"
509 fcho
() { if test -n "$2"; then echo "$1$2"; fi }
511 fcho
"Binary directory " "$bindir"
512 fcho
"TinyCC directory " "$tccdir"
513 fcho
"Library directory " "$libdir"
514 fcho
"Include directory " "$includedir"
515 fcho
"Manual directory " "$mandir"
516 fcho
"Info directory " "$infodir"
517 fcho
"Doc directory " "$docdir"
518 fcho
"Target root prefix " "$sysroot"
519 fcho
"/usr/include dir " "$tcc_usrinclude"
520 echo "Source path $source_path"
521 echo "Build OS $(uname -m -s)"
522 echo "C compiler $cc ($gcc_major.$gcc_minor)"
523 echo "Target OS $targetos"
525 fcho
"Triplet " "$triplet"
526 fcho
"Libs " "$tcc_libpaths"
527 fcho
"Sysinclude " "$tcc_sysincludepaths"
528 fcho
"Crt " "$tcc_crtprefix"
529 fcho
"Elfinterp " "$tcc_elfinterp"
530 fcho
"Switches " "$tcc_switches"
531 fcho
"Config " "${confvars# }"
532 echo "Creating config.mak and config.h"
534 cat >config.mak
<<EOF
535 # Automatically generated by configure - do not modify
537 bindir=\$(DESTDIR)$bindir
538 tccdir=\$(DESTDIR)$tccdir
539 libdir=\$(DESTDIR)$libdir
540 includedir=\$(DESTDIR)$includedir
541 mandir=\$(DESTDIR)$mandir
542 infodir=\$(DESTDIR)$infodir
543 docdir=\$(DESTDIR)$docdir
558 if test -n "$v"; then
559 test "$3" = "num" || v
="\"$v\""
560 echo "#ifndef $1" >> $TMPH
561 echo "# define $1 $v" >> $TMPH
562 echo "#endif" >> $TMPH
568 if test -n "$v"; then
569 test "$3" = "num" || v
="\"\\\"$v\\\"\""
570 echo "NATIVE_DEFINES+=-D$1=$v" >> config.mak
574 echo "/* Automatically generated by configure - do not modify */" > $TMPH
576 print_inc CONFIG_SYSROOT
"$sysroot"
577 test "$tccdir_auto" = "yes" || print_inc CONFIG_TCCDIR
"$tccdir"
578 print_inc DWARF_VERSION
"$dwarf" num
579 print_mak CONFIG_USR_INCLUDE
"$tcc_usrinclude"
580 print_mak CONFIG_TCC_SYSINCLUDEPATHS
"$tcc_sysincludepaths"
581 print_mak CONFIG_TCC_LIBPATHS
"$tcc_libpaths"
582 print_mak CONFIG_TCC_CRTPREFIX
"$tcc_crtprefix"
583 print_mak CONFIG_TCC_ELFINTERP
"$tcc_elfinterp"
584 print_mak CONFIG_TCC_SWITCHES
"$tcc_switches"
585 print_mak CONFIG_LDDIR
"$tcc_lddir"
586 print_mak CONFIG_TRIPLET
"$triplet"
587 print_mak TCC_CPU_VERSION
"$cpuver" num
589 echo "ARCH=$cpu" >> config.mak
590 echo "TARGETOS=$targetos" >> config.mak
591 echo "BUILDOS=$buildos" >> config.mak
594 for v
in $confvars ; do
595 test "$v" = "predefs=no" && predefs
=""
596 if test "${v%=*}" = "$v"; then
597 echo "CONFIG_$v=yes" >> config.mak
599 echo "CONFIG_$v" >> config.mak
602 print_inc CONFIG_TCC_PREDEFS
"$predefs" num
604 version
=`head $source_path/VERSION`
605 echo "VERSION = $version" >> config.mak
606 echo "#define TCC_VERSION \"$version\"" >> $TMPH
607 echo "@set VERSION $version" > config.texi
609 if test "$source_path_used" = "yes" ; then
611 /*) echo "TOPSRC=$source_path";;
612 *) echo "TOPSRC=\$(TOP)/$source_path";;
615 echo 'TOPSRC=$(TOP)' >>config.mak
618 #define GCC_MAJOR $gcc_major
619 #define GCC_MINOR $gcc_minor
620 #define CC_NAME CC_${cc_name}
623 diff $TMPH config.h
>/dev
/null
2>&1
624 if test $?
-ne 0 ; then
627 echo "config.h is unchanged"
630 rm -f $TMPN* $CONFTEST
632 # ---------------------------------------------------------------------------
633 # build tree in object directory if source path is different from current one
640 test -d $dn || mkdir
-p $dn
643 *) while test $dn ; do
644 tgt
=..
/$tgt; dn
=${dn#${dn%%/*}}; dn=${dn#/}
651 ln -sfn $tgt $2 ||
( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
654 if test "$source_path_used" = "yes" ; then
655 FILES
="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
657 fn_makelink
$source_path $f
661 # ---------------------------------------------------------------------------