Rework expr_infix
[tinycc.git] / configure
blob674619774bc4b905470d7ccca08dd402d93bea35
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 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 --with-libgcc) confvars="$confvars libgcc"
140 --with-selinux) confvars="$confvars selinux"
142 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
144 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
146 --help|-h) show_help="yes"
148 *) echo "configure: WARNING: unrecognized option $opt"
150 esac
151 done
153 cc="${cross_prefix}${cc}"
154 ar="${cross_prefix}${ar}"
155 strip="${cross_prefix}${strip}"
158 PPIF_TEMPLATE="
159 int ppif(void) {
160 #if %s
161 return 0;
162 #else
163 PPIF_FALSE;
164 #endif
168 # Succeeds when preprocessor condition `#if $1` is true.
169 # if $2 is not empty, prints to stderr `checking whether $2... <yes/no>`
170 # Works also when $cc is a cross compiler to any foreign platform.
171 # E.g. ppif "defined(__GNUC__) && (GCC_MAJOR >= 3)"
172 # or ppif "defined(_WIN32)" "target is Windows"
173 ppif() {
174 [ -z "${2-}" ] || printf "checking whether %s... " "$2" >&2
175 printf "$PPIF_TEMPLATE" "$1" > ppif.c \
176 && $cc -o ppif.o -c ppif.c 2>/dev/null
177 ppif_rv=$?
178 rm ppif.c ppif.o 2>/dev/null
179 [ -z "${2-}" ] || { [ 0 = $ppif_rv ] && echo yes || echo no; } >&2
180 return $ppif_rv
184 if test -z "$cpu" ; then
185 if test -n "$ARCH" ; then
186 cpu="$ARCH"
187 elif ppif "defined(__x86_64__)"; then
188 cpu="x86_64"
189 elif ppif "defined(__i386__)"; then
190 cpu="i386"
191 else
192 cpu=`uname -m`
196 case "$cpu" in
197 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
198 cpu="i386"
200 x86_64|amd64|x86-64)
201 cpu="x86_64"
203 arm*)
204 case "$cpu" in
205 arm|armv4l)
206 cpuver=4
208 armv5tel|armv5tejl)
209 cpuver=5
211 armv6j|armv6l)
212 cpuver=6
214 armv7a|armv7l)
215 cpuver=7
217 esac
218 cpu="arm"
220 aarch64)
221 cpu="aarch64"
223 alpha)
224 cpu="alpha"
226 "Power Macintosh"|ppc|ppc64)
227 cpu="ppc"
229 mips)
230 cpu="mips"
232 s390)
233 cpu="s390"
235 riscv64)
236 cpu="riscv64"
239 echo "Unsupported CPU"
240 exit 1
242 esac
244 # Checking for CFLAGS
245 if test -z "$CFLAGS"; then
246 CFLAGS="-Wall -g -O2"
249 if test "$mingw32" = "yes" ; then
250 if test "$source_path_used" = "no"; then
251 source_path="."
253 if test "$cc" = gcc; then
254 test -z "$LDFLAGS" && LDFLAGS="-static"
256 test -z "$prefix" && prefix="C:/Program Files/tcc"
257 test -z "$tccdir" && tccdir="${prefix}"
258 test -z "$bindir" && bindir="${tccdir}"
259 test -z "$docdir" && docdir="${tccdir}/doc"
260 test -z "$libdir" && libdir="${tccdir}/libtcc"
261 confvars="$confvars WIN32"
262 LIBSUF=".lib"
263 EXESUF=".exe"
264 DLLSUF=".dll"
265 else
266 if test -z "$prefix" ; then
267 prefix="/usr/local"
269 if test -z "$sharedir" ; then
270 sharedir="${prefix}/share"
272 if test x"$execprefix" = x""; then
273 execprefix="${prefix}"
275 if test x"$libdir" = x""; then
276 libdir="${execprefix}/lib"
278 if test x"$bindir" = x""; then
279 bindir="${execprefix}/bin"
281 if test x"$docdir" = x""; then
282 docdir="${sharedir}/doc"
284 if test x"$mandir" = x""; then
285 mandir="${sharedir}/man"
287 if test x"$infodir" = x""; then
288 infodir="${sharedir}/info"
290 if test x"$tccdir" = x""; then
291 tccdir="${libdir}/tcc"
293 if test x"$includedir" = x""; then
294 includedir="${prefix}/include"
296 fi # mingw32
298 if test x"$show_help" = "xyes" ; then
299 cat << EOF
300 Usage: configure [options]
301 Options: [defaults in brackets after descriptions]
303 Standard options:
304 --help print this message
305 --prefix=PREFIX install in PREFIX [$prefix]
306 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
307 [same as prefix]
308 --bindir=DIR user executables in DIR [EPREFIX/bin]
309 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
310 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
311 --includedir=DIR C header files in DIR [PREFIX/include]
312 --sharedir=DIR documentation root DIR [PREFIX/share]
313 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
314 --mandir=DIR man documentation in DIR [SHAREDIR/man]
315 --infodir=DIR info documentation in DIR [SHAREDIR/info]
317 Advanced options (experts only):
318 --source-path=PATH path of source code [$source_path]
319 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
320 --sysroot=PREFIX prepend PREFIX to library/include paths []
321 --cc=CC use C compiler CC [$cc]
322 --ar=AR create archives using AR [$ar]
323 --extra-cflags= specify compiler flags [$CFLAGS]
324 --extra-ldflags= specify linker options []
325 --cpu=CPU CPU [$cpu]
326 --strip-binaries strip symbol tables from resulting binaries
327 --disable-static make libtcc.so instead of libtcc.a
328 --enable-static make libtcc.a instead of libtcc.dll (win32)
329 --disable-rpath disable use of -rpath with the above
330 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
331 --enable-cross build cross compilers
332 --with-selinux use mmap for executable memory (with tcc -run)
333 --sysincludepaths=... specify system include paths, colon separated
334 --libpaths=... specify system library paths, colon separated
335 --crtprefix=... specify locations of crt?.o, colon separated
336 --elfinterp=... specify elf interpreter
337 --triplet=... specify system library/include directory triplet
338 --config-uClibc,-musl,-mingw32... enable system specific configurations
340 #echo "NOTE: The object files are build at the place where configure is launched"
341 exit 1
344 if test -z "$cross_prefix" ; then
345 CONFTEST=./conftest$EXESUF
346 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
347 echo "configure: error: '$cc' failed to compile conftest.c."
348 else
349 gcc_major="$($CONFTEST version)"
350 gcc_minor="$($CONFTEST minor)"
352 bigendian="$($CONFTEST bigendian)"
353 if test "$mingw32" = "no" ; then
355 if test -z "$triplet"; then
356 tt="$($CONFTEST triplet)"
357 if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
358 triplet="$tt"
362 if test -z "$triplet"; then
363 if test $cpu = "x86_64" -o $cpu = "aarch64" -o $cpu = "riscv64" ; then
364 if test -f "/usr/lib64/crti.o" ; then
365 tcc_lddir="lib64"
370 if test "$cpu" = "arm" ; then
371 if test "${triplet%eabihf}" != "$triplet" ; then
372 confvars="$confvars arm_eabihf arm_vfp"
373 elif test "${triplet%eabi}" != "$triplet" ; then
374 confvars="$confvars arm_eabi"
376 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
377 confvars="$confvars arm_vfp"
381 if test "$suggest" = "yes"; then
382 if test -f "/lib/ld-uClibc.so.0" ; then
383 echo "Perhaps you want ./configure --config-uClibc"
385 if test -f "/lib/ld-musl-$cpu.so.1"; then
386 echo "Perhaps you want ./configure --config-musl"
390 else
391 # if cross compiling, cannot launch a program, so make a static guess
392 case $cpu in
393 ppc|mips|s390) bigendian=yes;;
394 esac
397 if test "$bigendian" = "yes" ; then
398 confvars="$confvars BIGENDIAN"
401 # a final configuration tuning
402 if ! echo "$cc" | grep -q "tcc"; then
403 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
404 # we want -Wno- but gcc does not always reject unknown -Wno- options
405 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
406 if echo "$cc" | grep -q "clang"; then
407 OPT1="$OPT1 -fheinous-gnu-extensions"
408 OPT2="$OPT2 -Wstring-plus-int"
410 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
411 for o in $OPT1; do # enable these options
412 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
413 done
414 for o in $OPT2; do # disable these options
415 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
416 done
417 # cat cc_msg.txt
418 # echo $CFLAGS
419 rm -f cc_msg.txt a.out
422 fcho() { if test -n "$2"; then echo "$1$2"; fi }
424 fcho "Binary directory " "$bindir"
425 fcho "TinyCC directory " "$tccdir"
426 fcho "Library directory " "$libdir"
427 fcho "Include directory " "$includedir"
428 fcho "Manual directory " "$mandir"
429 fcho "Info directory " "$infodir"
430 fcho "Doc directory " "$docdir"
431 fcho "Target root prefix " "$sysroot"
432 echo "Source path $source_path"
433 echo "C compiler $cc ($gcc_major.$gcc_minor)"
434 echo "Target OS $targetos"
435 echo "CPU $cpu"
436 fcho "Triplet " "$triplet"
437 fcho "Config " "${confvars# }"
438 echo "Creating config.mak and config.h"
440 cat >config.mak <<EOF
441 # Automatically generated by configure - do not modify
442 prefix=$prefix
443 bindir=\$(DESTDIR)$bindir
444 tccdir=\$(DESTDIR)$tccdir
445 libdir=\$(DESTDIR)$libdir
446 includedir=\$(DESTDIR)$includedir
447 mandir=\$(DESTDIR)$mandir
448 infodir=\$(DESTDIR)$infodir
449 docdir=\$(DESTDIR)$docdir
450 CC=$cc
451 GCC_MAJOR=$gcc_major
452 GCC_MINOR=$gcc_minor
453 AR=$ar
454 STRIP=$strip -s -R .comment -R .note
455 CFLAGS=$CFLAGS
456 LDFLAGS=$LDFLAGS
457 LIBSUF=$LIBSUF
458 EXESUF=$EXESUF
459 DLLSUF=$DLLSUF
462 print_inc() {
463 if test -n "$2"; then
464 echo "#ifndef $1" >> $TMPH
465 echo "# define $1 \"$2\"" >> $TMPH
466 echo "#endif" >> $TMPH
470 print_mak() {
471 if test -n "$2"; then
472 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
476 print_mak_int() {
477 if test -n "$2"; then
478 echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
482 echo "/* Automatically generated by configure - do not modify */" > $TMPH
484 print_inc CONFIG_SYSROOT "$sysroot"
485 print_inc CONFIG_TCCDIR "$tccdir"
486 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
487 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
488 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
489 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
490 print_mak CONFIG_LDDIR "$tcc_lddir"
491 print_mak CONFIG_TRIPLET "$triplet"
492 print_mak_int TCC_CPU_VERSION "$cpuver"
494 if test "$cpu" = "aarch64" ; then
495 echo "ARCH=arm64" >> config.mak
496 else
497 echo "ARCH=$cpu" >> config.mak
499 echo "TARGETOS=$targetos" >> config.mak
501 for v in $confvars ; do
502 if test "${v%=*}" = "$v"; then
503 echo "CONFIG_$v=yes" >> config.mak
504 else
505 echo "CONFIG_$v" >> config.mak
507 done
509 version=`head $source_path/VERSION`
510 echo "VERSION = $version" >> config.mak
511 echo "#define TCC_VERSION \"$version\"" >> $TMPH
512 echo "@set VERSION $version" > config.texi
514 if test "$source_path_used" = "yes" ; then
515 case $source_path in
516 /*) echo "TOPSRC=$source_path";;
517 *) echo "TOPSRC=\$(TOP)/$source_path";;
518 esac >>config.mak
519 else
520 echo 'TOPSRC=$(TOP)' >>config.mak
523 diff $TMPH config.h >/dev/null 2>&1
524 if test $? -ne 0 ; then
525 mv -f $TMPH config.h
526 else
527 echo "config.h is unchanged"
530 rm -f $TMPN* $CONFTEST
532 # ---------------------------------------------------------------------------
533 # build tree in object directory if source path is different from current one
535 fn_makelink()
537 tgt=$1/$2
538 case $2 in
539 */*) dn=${2%/*}
540 test -d $dn || mkdir -p $dn
541 case $1 in
542 /*) ;;
543 *) while test $dn ; do
544 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
545 done
547 esac
549 esac
551 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
554 if test "$source_path_used" = "yes" ; then
555 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
556 for f in $FILES ; do
557 fn_makelink $source_path $f
558 done
561 # ---------------------------------------------------------------------------