re-add accidentally deleted printf("\n"); to tests2/97*.c
[tinycc.git] / configure
blob4050570b17482aea4e455d5ba771cf59c2355bad
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_usrinclude=""
39 tcc_sysincludepaths=""
40 tcc_libpaths=""
41 tcc_crtprefix=""
42 tcc_elfinterp=""
43 triplet=
44 tcc_lddir=
45 confvars=
46 suggest="yes"
47 cpu=
48 cpuver=
49 gcc_major=0
50 gcc_minor=0
51 cc_name="gcc"
52 ar_set=
54 # OS specific
55 targetos=`uname`
56 case $targetos in
57 Darwin)
58 confvars="$confvars OSX dll=no"
59 cc=`which cc`
60 cc=`readlink $cc`
61 tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
62 DLLSUF=".dylib"
64 Windows_NT|MINGW*|MSYS*|CYGWIN*)
65 mingw32=yes
66 targetos=WIN32
68 DragonFly|OpenBSD|FreeBSD|NetBSD)
69 confvars="$confvars BSD ldl=no"
73 esac
75 # find source path
76 source_path=${0%configure}
77 source_path=${source_path%/}
78 source_path_used="yes"
79 if test -z "$source_path" -o "$source_path" = "." ; then
80 source_path=`pwd`
81 source_path_used="no"
84 for opt do
85 eval opt=\"$opt\"
86 case "$opt" in
87 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
89 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
91 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
93 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
95 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
97 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
99 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
101 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
103 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
105 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
107 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
109 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
111 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
113 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
115 --ar=*) ar=`echo $opt | cut -d '=' -f 2` ; ar_set="yes"
117 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
119 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
121 --extra-libs=*) extralibs="${opt#--extra-libs=}"
123 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
125 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
127 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
129 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
131 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
133 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
135 --enable-cross) confvars="$confvars cross"
137 --disable-static) confvars="$confvars static=no"
139 --enable-static) confvars="$confvars static"
141 --disable-rpath) confvars="$confvars rpath=no"
143 --strip-binaries) echo deprecate, use 'make install-strip' to strip binaries
145 --debug) confvars="$confvars strip=no"
147 --with-libgcc) confvars="$confvars libgcc"
149 --with-selinux) confvars="$confvars selinux"
151 --config-mingw32*) mingw32=$(echo "$opt=yes" | cut -d '=' -f 2)
153 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
155 --help|-h) show_help="yes"
157 *) echo "configure: WARNING: unrecognized option $opt"
159 esac
160 done
162 cc="${cross_prefix}${cc}"
163 ar="${cross_prefix}${ar}"
164 strip="${cross_prefix}${strip}"
166 if test -z "$cpu" ; then
167 if test -n "$ARCH" ; then
168 cpu="$ARCH"
169 else
170 cpu=`uname -m`
174 case "$cpu" in
175 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
176 cpu="i386"
178 x86_64|amd64|x86-64)
179 cpu="x86_64"
181 evbarm)
182 case "`uname -p`" in
183 aarch64|arm64)
184 cpu="aarch64"
186 earmv*)
187 cpu="arm"
189 esac
191 aarch64|arm64|evbarm)
192 cpu="aarch64"
194 arm*)
195 case "$cpu" in
196 arm|armv4l)
197 cpuver=4
199 armv5tel|armv5tejl)
200 cpuver=5
202 armv6j|armv6l)
203 cpuver=6
205 armv7|armv7a|armv7l)
206 cpuver=7
208 esac
209 cpu="arm"
211 alpha)
212 cpu="alpha"
214 "Power Macintosh"|ppc|ppc64)
215 cpu="ppc"
217 mips)
218 cpu="mips"
220 s390)
221 cpu="s390"
223 riscv64)
224 cpu="riscv64"
227 echo "Unsupported CPU"
228 exit 1
230 esac
232 # Checking for CFLAGS
233 if test -z "$CFLAGS"; then
234 CFLAGS="-Wall -O2"
237 if test "$mingw32" = "yes" ; then
238 if test "$source_path_used" = "no"; then
239 source_path="."
241 test -z "$prefix" && prefix="C:/Program Files/tcc"
242 test -z "$tccdir" && tccdir="${prefix}"
243 test -z "$bindir" && bindir="${tccdir}"
244 test -z "$docdir" && docdir="${tccdir}/doc"
245 test -z "$libdir" && libdir="${tccdir}/libtcc"
246 confvars="$confvars WIN32"
247 LIBSUF=".lib"
248 EXESUF=".exe"
249 DLLSUF=".dll"
250 else
251 if test -z "$prefix" ; then
252 prefix="/usr/local"
254 if test -z "$sharedir" ; then
255 sharedir="${prefix}/share"
257 if test x"$execprefix" = x""; then
258 execprefix="${prefix}"
260 if test x"$libdir" = x""; then
261 libdir="${execprefix}/lib"
263 if test x"$bindir" = x""; then
264 bindir="${execprefix}/bin"
266 if test x"$docdir" = x""; then
267 docdir="${sharedir}/doc"
269 if test x"$mandir" = x""; then
270 mandir="${sharedir}/man"
272 if test x"$infodir" = x""; then
273 infodir="${sharedir}/info"
275 if test x"$tccdir" = x""; then
276 tccdir="${libdir}/tcc"
278 if test x"$includedir" = x""; then
279 includedir="${prefix}/include"
281 fi # mingw32
283 if test x"$show_help" = "xyes" ; then
284 cat << EOF
285 Usage: configure [options]
286 Options: [defaults in brackets after descriptions]
288 Standard options:
289 --help print this message
290 --prefix=PREFIX install in PREFIX [$prefix]
291 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
292 [same as prefix]
293 --bindir=DIR user executables in DIR [EPREFIX/bin]
294 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
295 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
296 --includedir=DIR C header files in DIR [PREFIX/include]
297 --sharedir=DIR documentation root DIR [PREFIX/share]
298 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
299 --mandir=DIR man documentation in DIR [SHAREDIR/man]
300 --infodir=DIR info documentation in DIR [SHAREDIR/info]
302 Advanced options (experts only):
303 --source-path=PATH path of source code [$source_path]
304 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
305 --sysroot=PREFIX prepend PREFIX to library/include paths []
306 --cc=CC use C compiler CC [$cc]
307 --ar=AR create archives using AR [$ar]
308 --extra-cflags= specify compiler flags [$CFLAGS]
309 --extra-ldflags= specify linker options []
310 --cpu=CPU CPU [$cpu]
311 --strip-binaries strip symbol tables from resulting binaries
312 --debug include debug info with resulting binaries
313 --disable-static make libtcc.so instead of libtcc.a
314 --enable-static make libtcc.a instead of libtcc.dll (win32)
315 --disable-rpath disable use of -rpath with the above
316 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
317 --enable-cross build cross compilers
318 --with-selinux use mmap for executable memory (with tcc -run)
319 --sysincludepaths=... specify system include paths, colon separated
320 --libpaths=... specify system library paths, colon separated
321 --crtprefix=... specify locations of crt?.o, colon separated
322 --elfinterp=... specify elf interpreter
323 --triplet=... specify system library/include directory triplet
324 --config-uClibc,-musl,-mingw32... enable system specific configurations
325 --config-bcheck=no/-backtrace=no disable bounds checker/stack backtraces
326 --config-predefs=no do not compile tccdefs.h, instead just include
328 #echo "NOTE: The object files are build at the place where configure is launched"
329 exit 1
332 if test -z "$cross_prefix" ; then
333 CONFTEST=./conftest$EXESUF
334 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
335 echo "configure: error: '$cc' failed to compile conftest.c."
336 else
337 cc_name="$($CONFTEST compiler)"
338 gcc_major="$($CONFTEST version)"
339 gcc_minor="$($CONFTEST minor)"
340 bigendian="$($CONFTEST bigendian)"
341 _triplet="$($CONFTEST triplet)"
343 if test "$mingw32" = "no" ; then
345 if test -z "$triplet"; then
346 if test -n "$_triplet" -a -f "/usr/lib/$_triplet/crti.o" ; then
347 triplet="$_triplet"
351 if test -z "$triplet"; then
352 if test $cpu = "x86_64" -o $cpu = "aarch64" -o $cpu = "riscv64" ; then
353 if test -f "/usr/lib64/crti.o" ; then
354 tcc_lddir="lib64"
359 if test "$cpu" = "arm" ; then
360 if test "${triplet%eabihf}" != "$triplet" ; then
361 confvars="$confvars arm_eabihf arm_vfp"
362 elif test "${triplet%eabi}" != "$triplet" ; then
363 confvars="$confvars arm_eabi arm_vfp"
364 elif test "${_triplet%eabihf}" != "$_triplet" ; then
365 confvars="$confvars arm_eabihf arm_vfp"
366 elif test "${_triplet%eabi}" != "$_triplet" ; then
367 confvars="$confvars arm_eabi arm_vfp"
369 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
370 confvars="$confvars arm_vfp"
374 if test "$suggest" = "yes"; then
375 if test -f "/lib/ld-uClibc.so.0" ; then
376 echo "Perhaps you want ./configure --config-uClibc"
378 if test -f "/lib/ld-musl-$cpu.so.1"; then
379 echo "Perhaps you want ./configure --config-musl"
382 else # mingw32 = yes
383 if test "$cc_name" = "gcc"; then
384 # avoid mingw dependencies such as 'libgcc_s_dw2-1.dll'
385 test -z "$LDFLAGS" && LDFLAGS="-static"
388 else
389 # if cross compiling, cannot launch a program, so make a static guess
390 case $cpu in
391 ppc|mips|s390) bigendian=yes;;
392 esac
395 if test "$bigendian" = "yes" ; then
396 confvars="$confvars BIGENDIAN"
399 # a final configuration tuning
400 if test "$cc_name" != "tcc"; then
401 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
402 # we want -Wno- but gcc does not always reject unknown -Wno- options
403 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
404 if test "$cc_name" = "clang"; then
405 OPT1="$OPT1 -fheinous-gnu-extensions"
406 OPT2="$OPT2 -Wstring-plus-int"
408 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
409 for o in $OPT1; do # enable these options
410 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
411 done
412 for o in $OPT2; do # disable these options
413 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
414 done
415 # cat cc_msg.txt
416 # echo $CFLAGS
417 rm -f cc_msg.txt a.out
418 else # cc is tcc
419 test "$ar_set" || ar="$cc -ar"
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 fcho "/usr/include dir " "$tcc_usrinclude"
433 echo "Source path $source_path"
434 echo "C compiler $cc ($gcc_major.$gcc_minor)"
435 echo "Target OS $targetos"
436 echo "CPU $cpu"
437 fcho "Triplet " "$triplet"
438 fcho "Config " "${confvars# }"
439 echo "Creating config.mak and config.h"
441 cat >config.mak <<EOF
442 # Automatically generated by configure - do not modify
443 prefix=$prefix
444 bindir=\$(DESTDIR)$bindir
445 tccdir=\$(DESTDIR)$tccdir
446 libdir=\$(DESTDIR)$libdir
447 includedir=\$(DESTDIR)$includedir
448 mandir=\$(DESTDIR)$mandir
449 infodir=\$(DESTDIR)$infodir
450 docdir=\$(DESTDIR)$docdir
451 CC=$cc
452 CC_NAME=$cc_name
453 GCC_MAJOR=$gcc_major
454 GCC_MINOR=$gcc_minor
455 AR=$ar
456 STRIP=$strip -s -R .comment -R .note
457 CFLAGS=$CFLAGS
458 LDFLAGS=$LDFLAGS
459 LIBSUF=$LIBSUF
460 EXESUF=$EXESUF
461 DLLSUF=$DLLSUF
464 print_inc() {
465 local v="$2"
466 if test -n "$v"; then
467 test "$3" = "num" || v="\"$v\""
468 echo "#ifndef $1" >> $TMPH
469 echo "# define $1 $v" >> $TMPH
470 echo "#endif" >> $TMPH
474 print_mak() {
475 local v="$2"
476 if test -n "$v"; then
477 test "$3" = "num" || v="\"\\\"$v\\\"\""
478 echo "NATIVE_DEFINES+=-D$1=$v" >> 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_USR_INCLUDE "$tcc_usrinclude"
487 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
488 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
489 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
490 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
491 print_mak CONFIG_LDDIR "$tcc_lddir"
492 print_mak CONFIG_TRIPLET "$triplet"
493 print_mak TCC_CPU_VERSION "$cpuver" num
495 if test "$cpu" = "aarch64" ; then
496 echo "ARCH=arm64" >> config.mak
497 else
498 echo "ARCH=$cpu" >> config.mak
500 echo "TARGETOS=$targetos" >> config.mak
502 predefs="1"
503 for v in $confvars ; do
504 test "$v" = "predefs=no" && predefs=""
505 if test "${v%=*}" = "$v"; then
506 echo "CONFIG_$v=yes" >> config.mak
507 else
508 echo "CONFIG_$v" >> config.mak
510 done
511 print_inc CONFIG_TCC_PREDEFS "$predefs" num
513 version=`head $source_path/VERSION`
514 echo "VERSION = $version" >> config.mak
515 echo "#define TCC_VERSION \"$version\"" >> $TMPH
516 echo "@set VERSION $version" > config.texi
518 if test "$source_path_used" = "yes" ; then
519 case $source_path in
520 /*) echo "TOPSRC=$source_path";;
521 *) echo "TOPSRC=\$(TOP)/$source_path";;
522 esac >>config.mak
523 else
524 echo 'TOPSRC=$(TOP)' >>config.mak
526 cat >>$TMPH <<EOF
527 #define GCC_MAJOR $gcc_major
528 #define GCC_MINOR $gcc_minor
529 #define CC_NAME CC_${cc_name}
532 diff $TMPH config.h >/dev/null 2>&1
533 if test $? -ne 0 ; then
534 mv -f $TMPH config.h
535 else
536 echo "config.h is unchanged"
539 rm -f $TMPN* $CONFTEST
541 # ---------------------------------------------------------------------------
542 # build tree in object directory if source path is different from current one
544 fn_makelink()
546 tgt=$1/$2
547 case $2 in
548 */*) dn=${2%/*}
549 test -d $dn || mkdir -p $dn
550 case $1 in
551 /*) ;;
552 *) while test $dn ; do
553 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
554 done
556 esac
558 esac
560 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
563 if test "$source_path_used" = "yes" ; then
564 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
565 for f in $FILES ; do
566 fn_makelink $source_path $f
567 done
570 # ---------------------------------------------------------------------------