mutiples fix for _Generic
[tinycc.git] / configure
blob4a337e755c0a97f3ef2db3e40f767c1e29f0b17d
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 confvars="$confvars WIN32"
60 mingw32=yes
62 DragonFly|OpenBSD|FreeBSD|NetBSD)
63 confvars="$confvars ldl=no"
67 esac
69 # find source path
70 source_path=${0%configure}
71 source_path=${source_path%/}
72 source_path_used="yes"
73 if test -z "$source_path" -o "$source_path" = "." ; then
74 source_path=`pwd`
75 source_path_used="no"
78 for opt do
79 eval opt=\"$opt\"
80 case "$opt" in
81 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
83 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
85 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
87 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
89 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
91 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
93 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
95 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
97 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
99 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
101 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
103 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
105 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
107 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
109 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
111 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
113 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
115 --extra-libs=*) extralibs="${opt#--extra-libs=}"
117 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
119 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
121 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
123 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
125 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
127 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
129 --enable-mingw32) confvars="$confvars WIN32"; mingw32="yes"
131 --enable-cross) confvars="$confvars cross"
133 --disable-static) confvars="$confvars static=no"
135 --enable-static) confvars="$confvars static"
137 --disable-rpath) confvars="$confvars rpath=no"
139 --strip-binaries) confvars="$confvars strip"
141 --with-libgcc) confvars="$confvars libgcc"
143 --with-selinux) confvars="$confvars selinux"
145 --config-*) confvars="$confvars ${opt#--config-}"; suggest="no"
147 --help|-h) show_help="yes"
149 *) echo "configure: WARNING: unrecognized option $opt"
151 esac
152 done
154 if test -z "$cpu" ; then
155 if test -n "$ARCH" ; then
156 cpu="$ARCH"
157 else
158 cpu=`uname -m`
162 case "$cpu" in
163 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
164 cpu="i386"
166 x86_64|amd64|x86-64)
167 cpu="x86_64"
169 arm*)
170 case "$cpu" in
171 arm|armv4l)
172 cpuver=4
174 armv5tel|armv5tejl)
175 cpuver=5
177 armv6j|armv6l)
178 cpuver=6
180 armv7a|armv7l)
181 cpuver=7
183 esac
184 cpu="arm"
186 aarch64)
187 cpu="aarch64"
189 alpha)
190 cpu="alpha"
192 "Power Macintosh"|ppc|ppc64)
193 cpu="ppc"
195 mips)
196 cpu="mips"
198 s390)
199 cpu="s390"
202 echo "Unsupported CPU"
203 exit 1
205 esac
207 # Checking for CFLAGS
208 if test -z "$CFLAGS"; then
209 CFLAGS="-Wall -g -O2"
212 if test "$mingw32" = "yes" ; then
213 if test "$source_path_used" = "no"; then
214 source_path="."
216 if test "$cc" = gcc; then
217 test -z "$LDFLAGS" && LDFLAGS="-static"
219 if test x"$tccdir" = x""; then
220 tccdir="tcc"
222 if test -z "$prefix" ; then
223 prefix="C:/Program Files/${tccdir}"
225 if test -z "$sharedir" ; then
226 sharedir="${prefix}"
228 execprefix="$prefix"
229 bindir="${prefix}"
230 tccdir="${prefix}"
231 libdir="${prefix}/lib"
232 docdir="${sharedir}/doc"
233 mandir="${sharedir}/man"
234 infodir="${sharedir}/info"
235 LIBSUF=".lib"
236 EXESUF=".exe"
237 DLLSUF=".dll"
238 else
239 if test -z "$prefix" ; then
240 prefix="/usr/local"
242 if test -z "$sharedir" ; then
243 sharedir="${prefix}/share"
245 if test x"$execprefix" = x""; then
246 execprefix="${prefix}"
248 if test x"$libdir" = x""; then
249 libdir="${execprefix}/lib"
251 if test x"$bindir" = x""; then
252 bindir="${execprefix}/bin"
254 if test x"$docdir" = x""; then
255 docdir="${sharedir}/doc"
257 if test x"$mandir" = x""; then
258 mandir="${sharedir}/man"
260 if test x"$infodir" = x""; then
261 infodir="${sharedir}/info"
263 if test x"$tccdir" = x""; then
264 tccdir="${libdir}/tcc"
266 fi # mingw32
268 if test x"$includedir" = x""; then
269 includedir="${prefix}/include"
272 if test x"$show_help" = "xyes" ; then
273 cat << EOF
274 Usage: configure [options]
275 Options: [defaults in brackets after descriptions]
277 Standard options:
278 --help print this message
279 --prefix=PREFIX install in PREFIX [$prefix]
280 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
281 [same as prefix]
282 --bindir=DIR user executables in DIR [EPREFIX/bin]
283 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
284 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
285 --includedir=DIR C header files in DIR [PREFIX/include]
286 --sharedir=DIR documentation root DIR [PREFIX/share]
287 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
288 --mandir=DIR man documentation in DIR [SHAREDIR/man]
289 --infodir=DIR info documentation in DIR [SHAREDIR/info]
291 Advanced options (experts only):
292 --source-path=PATH path of source code [$source_path]
293 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
294 --sysroot=PREFIX prepend PREFIX to library/include paths []
295 --cc=CC use C compiler CC [$cc]
296 --ar=AR create archives using AR [$ar]
297 --extra-cflags= specify compiler flags [$CFLAGS]
298 --extra-ldflags= specify linker options []
299 --cpu=CPU CPU [$cpu]
300 --strip-binaries strip symbol tables from resulting binaries
301 --disable-static make libtcc.so instead of libtcc.a
302 --enable-static make libtcc.a instead of libtcc.dll (win32)
303 --disable-rpath disable use of -rpath with the above
304 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
305 --enable-mingw32 build windows version on linux with mingw32
306 --enable-cross build cross compilers
307 --with-selinux use mmap for executable memory (with tcc -run)
308 --sysincludepaths=... specify system include paths, colon separated
309 --libpaths=... specify system library paths, colon separated
310 --crtprefix=... specify locations of crt?.o, colon separated
311 --elfinterp=... specify elf interpreter
312 --triplet=... specify system library/include directory triplet
313 --config-uClibc,-musl... enable specific configuration for some systems
315 #echo "NOTE: The object files are build at the place where configure is launched"
316 exit 1
319 cc="${cross_prefix}${cc}"
320 ar="${cross_prefix}${ar}"
321 strip="${cross_prefix}${strip}"
323 CONFTEST=./conftest$EXESUF
324 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
325 echo "configure: error: '$cc' failed to compile conftest.c."
326 else
327 gcc_major="$($CONFTEST version)"
328 gcc_minor="$($CONFTEST minor)"
331 if test -z "$cross_prefix" ; then
332 bigendian="$($CONFTEST bigendian)"
333 if test "$mingw32" = "no" ; then
335 if test -z "$triplet"; then
336 tt="$($CONFTEST triplet)"
337 if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
338 triplet="$tt"
342 if test -z "$triplet"; then
343 if test $cpu = "x86_64" -o $cpu = "aarch64" ; then
344 if test -f "/usr/lib64/crti.o" ; then
345 tcc_lddir="lib64"
350 if test "$cpu" = "arm" ; then
351 if test "${triplet%eabihf}" != "$triplet" ; then
352 confvars="$confvars arm_eabihf"
353 elif test "${triplet%eabi}" != "$triplet" ; then
354 confvars="$confvars arm_eabi"
356 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
357 confvars="$confvars arm_vfp"
361 if test "$suggest" = "yes"; then
362 if test -f "/lib/ld-uClibc.so.0" ; then
363 echo "Perhaps you want ./configure --config-uClibc"
365 if test -f "/lib/ld-musl-$cpu.so.1"; then
366 echo "Perhaps you want ./configure --config-musl"
370 else
371 # if cross compiling, cannot launch a program, so make a static guess
372 case $cpu in
373 ppc|mips|s390) bigendian=yes;;
374 esac
377 if test "$bigendian" = "yes" ; then
378 confvars="$confvars BIGENDIAN"
381 # a final configuration tuning
382 if ! echo "$cc" | grep -q "tcc"; then
383 OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
384 # we want -Wno- but gcc does not always reject unknown -Wno- options
385 OPT2="-Wpointer-sign -Wsign-compare -Wunused-result"
386 if echo "$cc" | grep -q "clang"; then
387 OPT1="$OPT1 -fheinous-gnu-extensions"
388 OPT2="$OPT2 -Wstring-plus-int"
390 $cc $OPT1 $OPT2 -o a.out -c -xc - < /dev/null > cc_msg.txt 2>&1
391 for o in $OPT1; do # enable these options
392 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS $o"; fi
393 done
394 for o in $OPT2; do # disable these options
395 if ! grep -q -- $o cc_msg.txt; then CFLAGS="$CFLAGS -Wno-${o#-W*}"; fi
396 done
397 # cat cc_msg.txt
398 # echo $CFLAGS
399 rm -f cc_msg.txt a.out
402 fcho() { if test -n "$2"; then echo "$1$2"; fi }
404 echo "Binary directory $bindir"
405 echo "TinyCC directory $tccdir"
406 echo "Library directory $libdir"
407 echo "Include directory $includedir"
408 echo "Manual directory $mandir"
409 echo "Info directory $infodir"
410 echo "Doc directory $docdir"
411 fcho "Target root prefix " "$sysroot"
412 echo "Source path $source_path"
413 echo "C compiler $cc"
414 echo "Target OS $targetos"
415 echo "CPU $cpu"
416 fcho "Triplet " "$triplet"
417 fcho "Config " "${confvars# }"
418 echo "Creating config.mak and config.h"
420 cat >config.mak <<EOF
421 # Automatically generated by configure - do not modify
422 prefix=$prefix
423 bindir=\$(DESTDIR)$bindir
424 tccdir=\$(DESTDIR)$tccdir
425 libdir=\$(DESTDIR)$libdir
426 includedir=\$(DESTDIR)$includedir
427 mandir=\$(DESTDIR)$mandir
428 infodir=\$(DESTDIR)$infodir
429 docdir=\$(DESTDIR)$docdir
430 CC=$cc
431 GCC_MAJOR=$gcc_major
432 GCC_MINOR=$gcc_minor
433 AR=$ar
434 STRIP=$strip -s -R .comment -R .note
435 CFLAGS=$CFLAGS
436 LDFLAGS=$LDFLAGS
437 LIBSUF=$LIBSUF
438 EXESUF=$EXESUF
439 DLLSUF=$DLLSUF
442 print_inc() {
443 if test -n "$2"; then
444 echo "#ifndef $1" >> $TMPH
445 echo "# define $1 \"$2\"" >> $TMPH
446 echo "#endif" >> $TMPH
450 print_mak() {
451 if test -n "$2"; then
452 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
456 print_mak_int() {
457 if test -n "$2"; then
458 echo "NATIVE_DEFINES+=-D$1=$2" >> config.mak
462 echo "/* Automatically generated by configure - do not modify */" > $TMPH
464 print_inc CONFIG_SYSROOT "$sysroot"
465 print_inc CONFIG_TCCDIR "$tccdir"
466 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
467 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
468 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
469 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
470 print_mak CONFIG_LDDIR "$tcc_lddir"
471 print_mak CONFIG_TRIPLET "$triplet"
472 print_mak_int TCC_CPU_VERSION "$cpuver"
474 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
475 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
476 if test "$cpu" = "aarch64" ; then
477 echo "ARCH=arm64" >> config.mak
478 else
479 echo "ARCH=$cpu" >> config.mak
481 echo "TARGETOS=$targetos" >> config.mak
483 for v in $confvars ; do
484 if test "${v%=*}" = "$v"; then
485 echo "CONFIG_$v=yes" >> config.mak
486 else
487 echo "CONFIG_$v" >> config.mak
489 done
491 version=`head $source_path/VERSION`
492 echo "VERSION = $version" >> config.mak
493 echo "#define TCC_VERSION \"$version\"" >> $TMPH
494 echo "@set VERSION $version" > config.texi
496 if test "$source_path_used" = "yes" ; then
497 case $source_path in
498 /*) echo "TOPSRC=$source_path";;
499 *) echo "TOPSRC=\$(TOP)/$source_path";;
500 esac >>config.mak
501 else
502 echo 'TOPSRC=$(TOP)' >>config.mak
505 diff $TMPH config.h >/dev/null 2>&1
506 if test $? -ne 0 ; then
507 mv -f $TMPH config.h
508 else
509 echo "config.h is unchanged"
512 rm -f $TMPN* $CONFTEST
514 # ---------------------------------------------------------------------------
515 # build tree in object directory if source path is different from current one
517 fn_makelink()
519 tgt=$1/$2
520 case $2 in
521 */*) dn=${2%/*}
522 test -d $dn || mkdir -p $dn
523 case $1 in
524 /*) ;;
525 *) while test $dn ; do
526 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
527 done
529 esac
531 esac
533 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
536 if test "$source_path_used" = "yes" ; then
537 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
538 for f in $FILES ; do
539 fn_makelink $source_path $f
540 done
543 # ---------------------------------------------------------------------------