tccpp: faster next()
[tinycc.git] / configure
blob5d21bcf3660a3284fb2558c3269c570b0aa3e506
1 #!/bin/sh
3 # tcc configure script (c) 2003 Fabrice Bellard
5 # set temporary file name
6 # if test ! -z "$TMPDIR" ; then
7 # TMPDIR1="${TMPDIR}"
8 # elif test ! -z "$TEMPDIR" ; then
9 # TMPDIR1="${TEMPDIR}"
10 # else
11 # TMPDIR1="/tmp"
12 # fi
14 # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
16 TMPN="./conftest-$$"
17 TMPH=$TMPN.h
19 # default parameters
20 prefix=""
21 execprefix=""
22 bindir=""
23 libdir=""
24 tccdir=""
25 includedir=""
26 mandir=""
27 infodir=""
28 sysroot=""
29 cross_prefix=""
30 cc="gcc"
31 ar="ar"
32 strip="strip"
33 bigendian="no"
34 mingw32="no"
35 LIBSUF=".a"
36 EXESUF=""
37 DLLSUF=".so"
38 tcc_sysincludepaths=""
39 tcc_libpaths=""
40 tcc_crtprefix=""
41 tcc_elfinterp=""
42 triplet=
43 tcc_lddir=
44 confvars=
45 suggest="yes"
46 cpu=
47 cpuver=
48 gcc_major=0
49 gcc_minor=0
51 # OS specific
52 targetos=`uname`
53 case $targetos in
54 Darwin)
55 confvars="$confvars OSX"
56 DLLSUF=".dylib"
58 Windows_NT|MINGW*|MSYS*|CYGWIN*)
59 mingw32=yes
61 DragonFly|OpenBSD|FreeBSD|NetBSD)
62 confvars="$confvars ldl=no"
66 esac
68 # find source path
69 source_path=${0%configure}
70 source_path=${source_path%/}
71 source_path_used="yes"
72 if test -z "$source_path" -o "$source_path" = "." ; then
73 source_path=`pwd`
74 source_path_used="no"
77 for opt do
78 eval opt=\"$opt\"
79 case "$opt" in
80 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
82 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
84 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
86 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
88 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
90 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
92 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
94 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
96 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
98 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
100 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
102 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
104 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
106 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
108 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
110 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
112 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
114 --extra-libs=*) extralibs="${opt#--extra-libs=}"
116 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
118 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
120 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
122 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
124 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
126 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
128 --enable-cross) confvars="$confvars cross"
130 --disable-static) confvars="$confvars static=no"
132 --enable-static) confvars="$confvars static"
134 --disable-rpath) confvars="$confvars rpath=no"
136 --strip-binaries) confvars="$confvars strip"
138 --debug) confvars="$confvars strip=no"
140 --with-libgcc) confvars="$confvars libgcc"
142 --with-selinux) confvars="$confvars selinux"
144 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
146 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
148 --help|-h) show_help="yes"
150 *) echo "configure: WARNING: unrecognized option $opt"
152 esac
153 done
155 cc="${cross_prefix}${cc}"
156 ar="${cross_prefix}${ar}"
157 strip="${cross_prefix}${strip}"
159 if test -z "$cpu" ; then
160 if test -n "$ARCH" ; then
161 cpu="$ARCH"
162 else
163 cpu=`uname -m`
167 case "$cpu" in
168 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
169 cpu="i386"
171 x86_64|amd64|x86-64)
172 cpu="x86_64"
174 arm*)
175 case "$cpu" in
176 arm|armv4l)
177 cpuver=4
179 armv5tel|armv5tejl)
180 cpuver=5
182 armv6j|armv6l)
183 cpuver=6
185 armv7a|armv7l)
186 cpuver=7
188 esac
189 cpu="arm"
191 aarch64)
192 cpu="aarch64"
194 alpha)
195 cpu="alpha"
197 "Power Macintosh"|ppc|ppc64)
198 cpu="ppc"
200 mips)
201 cpu="mips"
203 s390)
204 cpu="s390"
206 riscv64)
207 cpu="riscv64"
210 echo "Unsupported CPU"
211 exit 1
213 esac
215 # Checking for CFLAGS
216 if test -z "$CFLAGS"; then
217 CFLAGS="-Wall -O2"
220 if test "$mingw32" = "yes" ; then
221 if test "$source_path_used" = "no"; then
222 source_path="."
224 if test "${cc%% *}" = "gcc"; then
225 test -z "$LDFLAGS" && LDFLAGS="-static"
227 test -z "$prefix" && prefix="C:/Program Files/tcc"
228 test -z "$tccdir" && tccdir="${prefix}"
229 test -z "$bindir" && bindir="${tccdir}"
230 test -z "$docdir" && docdir="${tccdir}/doc"
231 test -z "$libdir" && libdir="${tccdir}/libtcc"
232 confvars="$confvars WIN32"
233 LIBSUF=".lib"
234 EXESUF=".exe"
235 DLLSUF=".dll"
236 else
237 if test -z "$prefix" ; then
238 prefix="/usr/local"
240 if test -z "$sharedir" ; then
241 sharedir="${prefix}/share"
243 if test x"$execprefix" = x""; then
244 execprefix="${prefix}"
246 if test x"$libdir" = x""; then
247 libdir="${execprefix}/lib"
249 if test x"$bindir" = x""; then
250 bindir="${execprefix}/bin"
252 if test x"$docdir" = x""; then
253 docdir="${sharedir}/doc"
255 if test x"$mandir" = x""; then
256 mandir="${sharedir}/man"
258 if test x"$infodir" = x""; then
259 infodir="${sharedir}/info"
261 if test x"$tccdir" = x""; then
262 tccdir="${libdir}/tcc"
264 if test x"$includedir" = x""; then
265 includedir="${prefix}/include"
267 fi # mingw32
269 if test x"$show_help" = "xyes" ; then
270 cat << EOF
271 Usage: configure [options]
272 Options: [defaults in brackets after descriptions]
274 Standard options:
275 --help print this message
276 --prefix=PREFIX install in PREFIX [$prefix]
277 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
278 [same as prefix]
279 --bindir=DIR user executables in DIR [EPREFIX/bin]
280 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
281 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
282 --includedir=DIR C header files in DIR [PREFIX/include]
283 --sharedir=DIR documentation root DIR [PREFIX/share]
284 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
285 --mandir=DIR man documentation in DIR [SHAREDIR/man]
286 --infodir=DIR info documentation in DIR [SHAREDIR/info]
288 Advanced options (experts only):
289 --source-path=PATH path of source code [$source_path]
290 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
291 --sysroot=PREFIX prepend PREFIX to library/include paths []
292 --cc=CC use C compiler CC [$cc]
293 --ar=AR create archives using AR [$ar]
294 --extra-cflags= specify compiler flags [$CFLAGS]
295 --extra-ldflags= specify linker options []
296 --cpu=CPU CPU [$cpu]
297 --strip-binaries strip symbol tables from resulting binaries
298 --debug include debug info with resulting binaries
299 --disable-static make libtcc.so instead of libtcc.a
300 --enable-static make libtcc.a instead of libtcc.dll (win32)
301 --disable-rpath disable use of -rpath with the above
302 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
303 --enable-cross build cross compilers
304 --with-selinux use mmap for executable memory (with tcc -run)
305 --sysincludepaths=... specify system include paths, colon separated
306 --libpaths=... specify system library paths, colon separated
307 --crtprefix=... specify locations of crt?.o, colon separated
308 --elfinterp=... specify elf interpreter
309 --triplet=... specify system library/include directory triplet
310 --config-uClibc,-musl,-mingw32... enable system specific configurations
312 #echo "NOTE: The object files are build at the place where configure is launched"
313 exit 1
316 if test -z "$cross_prefix" ; then
317 CONFTEST=./conftest$EXESUF
318 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
319 echo "configure: error: '$cc' failed to compile conftest.c."
320 else
321 gcc_major="$($CONFTEST version)"
322 gcc_minor="$($CONFTEST minor)"
324 bigendian="$($CONFTEST bigendian)"
325 if test "$mingw32" = "no" ; then
327 if test -z "$triplet"; then
328 tt="$($CONFTEST triplet)"
329 if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
330 triplet="$tt"
334 if test -z "$triplet"; then
335 if test $cpu = "x86_64" -o $cpu = "aarch64" -o $cpu = "riscv64" ; then
336 if test -f "/usr/lib64/crti.o" ; then
337 tcc_lddir="lib64"
342 if test "$cpu" = "arm" ; then
343 if test "${triplet%eabihf}" != "$triplet" ; then
344 confvars="$confvars arm_eabihf arm_vfp"
345 elif test "${triplet%eabi}" != "$triplet" ; then
346 confvars="$confvars arm_eabi"
348 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
349 confvars="$confvars arm_vfp"
353 if test "$suggest" = "yes"; then
354 if test -f "/lib/ld-uClibc.so.0" ; then
355 echo "Perhaps you want ./configure --config-uClibc"
357 if test -f "/lib/ld-musl-$cpu.so.1"; then
358 echo "Perhaps you want ./configure --config-musl"
362 else
363 # if cross compiling, cannot launch a program, so make a static guess
364 case $cpu in
365 ppc|mips|s390) bigendian=yes;;
366 esac
369 if test "$bigendian" = "yes" ; then
370 confvars="$confvars BIGENDIAN"
373 # a final configuration tuning
374 if ! echo "$cc" | grep -q "tcc"; then
375 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
376 # we want -Wno- but gcc does not always reject unknown -Wno- options
377 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
378 if echo "$cc" | grep -q "clang"; then
379 OPT1="$OPT1 -fheinous-gnu-extensions"
380 OPT2="$OPT2 -Wstring-plus-int"
382 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
383 for o in $OPT1; do # enable these options
384 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
385 done
386 for o in $OPT2; do # disable these options
387 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
388 done
389 # cat cc_msg.txt
390 # echo $CFLAGS
391 rm -f cc_msg.txt a.out
394 fcho() { if test -n "$2"; then echo "$1$2"; fi }
396 fcho "Binary directory " "$bindir"
397 fcho "TinyCC directory " "$tccdir"
398 fcho "Library directory " "$libdir"
399 fcho "Include directory " "$includedir"
400 fcho "Manual directory " "$mandir"
401 fcho "Info directory " "$infodir"
402 fcho "Doc directory " "$docdir"
403 fcho "Target root prefix " "$sysroot"
404 echo "Source path $source_path"
405 echo "C compiler $cc ($gcc_major.$gcc_minor)"
406 echo "Target OS $targetos"
407 echo "CPU $cpu"
408 fcho "Triplet " "$triplet"
409 fcho "Config " "${confvars# }"
410 echo "Creating config.mak and config.h"
412 cat >config.mak <<EOF
413 # Automatically generated by configure - do not modify
414 prefix=$prefix
415 bindir=\$(DESTDIR)$bindir
416 tccdir=\$(DESTDIR)$tccdir
417 libdir=\$(DESTDIR)$libdir
418 includedir=\$(DESTDIR)$includedir
419 mandir=\$(DESTDIR)$mandir
420 infodir=\$(DESTDIR)$infodir
421 docdir=\$(DESTDIR)$docdir
422 CC=$cc
423 GCC_MAJOR=$gcc_major
424 GCC_MINOR=$gcc_minor
425 AR=$ar
426 STRIP=$strip -s -R .comment -R .note
427 CFLAGS=$CFLAGS
428 LDFLAGS=$LDFLAGS
429 LIBSUF=$LIBSUF
430 EXESUF=$EXESUF
431 DLLSUF=$DLLSUF
434 print_inc() {
435 if test -n "$2"; then
436 echo "#ifndef $1" >> $TMPH
437 echo "# define $1 \"$2\"" >> $TMPH
438 echo "#endif" >> $TMPH
442 print_mak() {
443 if test -n "$2"; then
444 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
448 print_mak_int() {
449 if test -n "$2"; then
450 echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
454 echo "/* Automatically generated by configure - do not modify */" > $TMPH
456 print_inc CONFIG_SYSROOT "$sysroot"
457 print_inc CONFIG_TCCDIR "$tccdir"
458 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
459 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
460 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
461 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
462 print_mak CONFIG_LDDIR "$tcc_lddir"
463 print_mak CONFIG_TRIPLET "$triplet"
464 print_mak_int TCC_CPU_VERSION "$cpuver"
466 if test "$cpu" = "aarch64" ; then
467 echo "ARCH=arm64" >> config.mak
468 else
469 echo "ARCH=$cpu" >> config.mak
471 echo "TARGETOS=$targetos" >> config.mak
473 for v in $confvars ; do
474 if test "${v%=*}" = "$v"; then
475 echo "CONFIG_$v=yes" >> config.mak
476 else
477 echo "CONFIG_$v" >> config.mak
479 done
481 version=`head $source_path/VERSION`
482 echo "VERSION = $version" >> config.mak
483 echo "#define TCC_VERSION \"$version\"" >> $TMPH
484 echo "@set VERSION $version" > config.texi
486 if test "$source_path_used" = "yes" ; then
487 case $source_path in
488 /*) echo "TOPSRC=$source_path";;
489 *) echo "TOPSRC=\$(TOP)/$source_path";;
490 esac >>config.mak
491 else
492 echo 'TOPSRC=$(TOP)' >>config.mak
494 cat >>$TMPH <<EOF
495 #define GCC_MAJOR $gcc_major
496 #define GCC_MINOR $gcc_minor
499 diff $TMPH config.h >/dev/null 2>&1
500 if test $? -ne 0 ; then
501 mv -f $TMPH config.h
502 else
503 echo "config.h is unchanged"
506 rm -f $TMPN* $CONFTEST
508 # ---------------------------------------------------------------------------
509 # build tree in object directory if source path is different from current one
511 fn_makelink()
513 tgt=$1/$2
514 case $2 in
515 */*) dn=${2%/*}
516 test -d $dn || mkdir -p $dn
517 case $1 in
518 /*) ;;
519 *) while test $dn ; do
520 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
521 done
523 esac
525 esac
527 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
530 if test "$source_path_used" = "yes" ; then
531 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
532 for f in $FILES ; do
533 fn_makelink $source_path $f
534 done
537 # ---------------------------------------------------------------------------