- make clang accept unportable code in libtcc1.c
[tinycc.git] / configure
blob1f4a17dfcb41ca905c3a7e9c3b4c1745c0f1d7a3
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 build_cross="no"
21 use_libgcc="no"
22 prefix=""
23 execprefix=""
24 bindir=""
25 libdir=""
26 tccdir=""
27 includedir=""
28 mandir=""
29 infodir=""
30 sysroot=""
31 cross_prefix=""
32 cc="gcc"
33 host_cc="gcc"
34 ar="ar"
35 strip="strip"
36 cygwin="no"
37 gprof="no"
38 bigendian="no"
39 mingw32="no"
40 LIBSUF=".a"
41 EXESUF=""
42 tcc_sysincludepaths=""
43 tcc_libpaths=""
44 tcc_crtprefix=""
45 tcc_elfinterp=""
46 tcc_lddir=
48 cpu=`uname -m`
50 # OS specific
51 targetos=`uname -s`
52 case $targetos in
53 MINGW32*) mingw32=yes;;
54 DragonFly) noldl=yes;;
55 OpenBSD) noldl=yes;;
56 *) ;;
57 esac
59 # find source path
60 # XXX: we assume an absolute path is given when launching configure,
61 # except in './configure' case.
62 source_path=${0%configure}
63 source_path=${source_path%/}
64 source_path_used="yes"
65 if test -z "$source_path" -o "$source_path" = "." ; then
66 source_path=`pwd`
67 source_path_used="no"
70 case "$cpu" in
71 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
72 cpu="x86"
74 x86_64)
75 cpu="x86-64"
77 arm*)
78 case "$cpu" in
79 arm|armv4l)
80 cpuver=4
82 armv5tel|armv5tejl)
83 cpuver=5
85 armv6j|armv6l)
86 cpuver=6
88 armv7a|armv7l)
89 cpuver=7
91 esac
92 cpu="armv4l"
94 alpha)
95 cpu="alpha"
97 "Power Macintosh"|ppc|ppc64)
98 cpu="powerpc"
100 mips)
101 cpu="mips"
103 s390)
104 cpu="s390"
107 cpu="unknown"
109 esac
111 for opt do
112 eval opt=\"$opt\"
113 case "$opt" in
114 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
116 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
118 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
120 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
122 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
124 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
126 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
128 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
130 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
132 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
134 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
136 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
138 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
140 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
142 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
144 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
146 --extra-libs=*) extralibs=${opt#--extra-libs=}
148 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
150 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
152 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
154 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
156 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
158 --enable-gprof) gprof="yes"
160 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
162 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
164 --enable-cross) build_cross="yes"
166 --disable-static) disable_static="yes"
168 --disable-rpath) disable_rpath="yes"
170 --strip-binaries) strip_binaries="yes"
172 --with-libgcc) use_libgcc="yes"
174 --with-selinux) have_selinux="yes"
176 --help|-h) show_help="yes"
178 *) echo "configure: WARNING: unrecognized option $opt"
180 esac
181 done
183 # Checking for CFLAGS
184 if test -z "$CFLAGS"; then
185 CFLAGS="-Wall -g -O2"
188 if test "$mingw32" = "yes" ; then
189 if test x"$tccdir" = x""; then
190 tccdir="tcc"
192 if test -z "$prefix" ; then
193 prefix="C:/Program Files/${tccdir}"
195 if test -z "$sharedir" ; then
196 sharedir="${prefix}"
198 execprefix="$prefix"
199 bindir="${prefix}"
200 tccdir="${prefix}"
201 libdir="${prefix}/lib"
202 docdir="${sharedir}/doc"
203 mandir="${sharedir}/man"
204 infodir="${sharedir}/info"
205 LIBSUF=".lib"
206 EXESUF=".exe"
207 else
208 if test -z "$prefix" ; then
209 prefix="/usr/local"
211 if test -z "$sharedir" ; then
212 sharedir="${prefix}/share"
214 if test x"$execprefix" = x""; then
215 execprefix="${prefix}"
217 if test x"$libdir" = x""; then
218 libdir="${execprefix}/lib"
220 if test x"$bindir" = x""; then
221 bindir="${execprefix}/bin"
223 if test x"$tccdir" = x""; then
224 tccdir="tcc"
226 if test x"$docdir" = x""; then
227 docdir="${sharedir}/doc/${tccdir}"
229 if test x"$mandir" = x""; then
230 mandir="${sharedir}/man"
232 if test x"$infodir" = x""; then
233 infodir="${sharedir}/info"
235 tccdir="${libdir}/${tccdir}"
236 fi # mingw32
238 if test x"$includedir" = x""; then
239 includedir="${prefix}/include"
242 if test x"$show_help" = "xyes" ; then
243 cat << EOF
244 Usage: configure [options]
245 Options: [defaults in brackets after descriptions]
247 Standard options:
248 --help print this message
249 --prefix=PREFIX install in PREFIX [$prefix]
250 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
251 [same as prefix]
252 --bindir=DIR user executables in DIR [EPREFIX/bin]
253 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
254 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
255 --includedir=DIR C header files in DIR [PREFIX/include]
256 --sharedir=DIR documentation root DIR [PREFIX/share]
257 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
258 --mandir=DIR man documentation in DIR [SHAREDIR/man]
259 --infodir=DIR info documentation in DIR [SHAREDIR/info]
261 Advanced options (experts only):
262 --source-path=PATH path of source code [$source_path]
263 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
264 --sysroot=PREFIX prepend PREFIX to library/include paths []
265 --cc=CC use C compiler CC [$cc]
266 --extra-cflags= specify compiler flags [$CFLAGS]
267 --extra-ldflags= specify linker options []
268 --strip-binaries strip symbol tables from resulting binaries
269 --disable-static make libtcc.so instead of libtcc.a
270 --disable-rpath disable use of -rpath with the above
271 --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a
272 --enable-mingw32 build windows version on linux with mingw32
273 --enable-cygwin build windows version on windows with cygwin
274 --enable-cross build cross compilers
275 --with-selinux use mmap for exec mem [needs writable /tmp]
276 --sysincludepaths=... specify system include paths, colon separated
277 --libpaths=... specify system library paths, colon separated
278 --crtprefix=... specify locations of crt?.o, colon separated
279 --elfinterp=... specify elf interpreter
281 #echo "NOTE: The object files are build at the place where configure is launched"
282 exit 1
285 cc="${cross_prefix}${cc}"
286 ar="${cross_prefix}${ar}"
287 strip="${cross_prefix}${strip}"
289 CONFTEST=./conftest$EXESUF
291 if test -z "$cross_prefix" ; then
292 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
293 echo "configure: error: '$cc' failed to compile conftest.c."
294 else
295 bigendian="$($CONFTEST bigendian)"
296 gcc_major="$($CONFTEST version)"
297 gcc_minor="$($CONFTEST minor)"
298 if test "$mingw32" = "no" ; then
299 libc_dir="$(ldd $CONFTEST | grep libc.so | sed 's|[^/]*/\(.*/\)[^/]*|\1|')"
301 # gr: FIXME
302 # ldd $CONFTEST gives (ubuntu 8)
303 # linux-gate.so.1 => (0xb7fc3000)
304 # libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e37000)
305 # /lib/ld-linux.so.2 (0xb7fa9000)
306 # result is crap:
307 # CONFIG_LDDIR="lib/tls/i686/cmov"
308 # CONFIG_MUADIR="tls/i686/cmov"
310 multiarch_triplet=${libc_dir#*/}
311 multiarch_triplet=${multiarch_triplet%/}
312 tcc_lddir="${libc_dir%%/*}"
313 if test -n "$multiarch_triplet" ; then
314 tcc_lddir="$tcc_lddir/$multiarch_triplet"
317 # gr: maybe for after the release:
318 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
319 # #echo "elfinterp $tcc_elfinterp"
323 else
324 # if cross compiling, cannot launch a program, so make a static guess
325 case $cpu in
326 powerpc|mips|s390) bigendian=yes;;
327 esac
330 # gr: maybe for after the release:
331 # run compiler to see if it supports FLAG, if yes add to CFLAGS
332 #cc_option() {
333 # if $cc $CFLAGS $1 -S -o /dev/null -xc conftest.c >/dev/null 2>&1; then
334 # CFLAGS="$CFLAGS $1"; else if test -n "$2"; then
335 # CFLAGS="$CFLAGS $2"; fi; fi
337 #cc_option -fno-strict-aliasing
338 #cc_option -Wno-pointer-sign
339 #cc_option -Wno-sign-compare
340 #cc_option -Wno-unused-result -D_FORTIFY_SOURCE=0
342 cat <<EOF
343 Binary directory $bindir
344 TinyCC directory $tccdir
345 Library directory $libdir
346 Include directory $includedir
347 Manual directory $mandir
348 Info directory $infodir
349 Doc directory $docdir
350 Target root prefix $sysroot
351 Source path $source_path
352 C compiler $cc
353 Target OS $targetos
354 CPU $cpu
355 Big Endian $bigendian
356 gprof enabled $gprof
357 cross compilers $build_cross
358 use libgcc $use_libgcc
361 echo "Creating config.mak and config.h"
363 cat >config.mak <<EOF
364 # Automatically generated by configure - do not modify
365 prefix=$prefix
366 bindir=\$(DESTDIR)$bindir
367 tccdir=\$(DESTDIR)$tccdir
368 libdir=\$(DESTDIR)$libdir
369 ln_libdir=$libdir
370 includedir=\$(DESTDIR)$includedir
371 mandir=\$(DESTDIR)$mandir
372 infodir=\$(DESTDIR)$infodir
373 docdir=\$(DESTDIR)$docdir
374 CC=$cc
375 GCC_MAJOR=$gcc_major
376 GCC_MINOR=$gcc_minor
377 HOST_CC=$host_cc
378 AR=$ar
379 STRIP=$strip -s -R .comment -R .note
380 CFLAGS=$CFLAGS
381 LDFLAGS=$LDFLAGS
382 LIBSUF=$LIBSUF
383 EXESUF=$EXESUF
386 print_def() {
387 if test -n "$2"; then
388 echo "#ifndef $1" >> $TMPH
389 echo "# define $1 \"$2\"" >> $TMPH
390 echo "#endif" >> $TMPH
394 echo "/* Automatically generated by configure - do not modify */" > $TMPH
396 print_def CONFIG_SYSROOT "$sysroot"
397 print_def CONFIG_TCCDIR "$tccdir"
398 print_def CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
399 print_def CONFIG_TCC_LIBPATHS "$tcc_libpaths"
400 print_def CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
401 print_def CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
402 print_def CONFIG_MULTIARCHDIR "$multiarch_triplet"
403 print_def CONFIG_LDDIR "$tcc_lddir"
405 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
406 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
408 if test "$cpu" = "x86" ; then
409 echo "ARCH=i386" >> config.mak
410 echo "#define HOST_I386 1" >> $TMPH
411 elif test "$cpu" = "x86-64" ; then
412 echo "ARCH=x86-64" >> config.mak
413 echo "#define HOST_X86_64 1" >> $TMPH
414 elif test "$cpu" = "armv4l" ; then
415 echo "ARCH=arm" >> config.mak
416 echo "#define HOST_ARM 1" >> $TMPH
417 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
418 elif test "$cpu" = "powerpc" ; then
419 echo "ARCH=ppc" >> config.mak
420 echo "#define HOST_PPC 1" >> $TMPH
421 elif test "$cpu" = "mips" ; then
422 echo "ARCH=mips" >> config.mak
423 echo "#define HOST_MIPS 1" >> $TMPH
424 elif test "$cpu" = "s390" ; then
425 echo "ARCH=s390" >> config.mak
426 echo "#define HOST_S390 1" >> $TMPH
427 elif test "$cpu" = "alpha" ; then
428 echo "ARCH=alpha" >> config.mak
429 echo "#define HOST_ALPHA 1" >> $TMPH
430 else
431 echo "Unsupported CPU"
432 exit 1
435 echo "TARGETOS=$targetos" >> config.mak
437 if test "$noldl" = "yes" ; then
438 echo "CONFIG_NOLDL=yes" >> config.mak
440 if test "$mingw32" = "yes" ; then
441 echo "CONFIG_WIN32=yes" >> config.mak
442 echo "#define CONFIG_WIN32 1" >> $TMPH
444 if test "$cygwin" = "yes" ; then
445 echo "#ifndef _WIN32" >> $TMPH
446 echo "# define _WIN32" >> $TMPH
447 echo "#endif" >> $TMPH
448 echo "AR=ar" >> config.mak
450 if test "$bigendian" = "yes" ; then
451 echo "WORDS_BIGENDIAN=yes" >> config.mak
452 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
454 if test "$gprof" = "yes" ; then
455 echo "TARGET_GPROF=yes" >> config.mak
456 echo "#define HAVE_GPROF 1" >> $TMPH
458 if test "$build_cross" = "yes" ; then
459 echo "CONFIG_CROSS=yes" >> config.mak
461 if test "$disable_static" = "yes" ; then
462 echo "DISABLE_STATIC=yes" >> config.mak
464 if test "$disable_rpath" = "yes" ; then
465 echo "DISABLE_RPATH=yes" >> config.mak
467 if test "$strip_binaries" = "yes" ; then
468 echo "STRIP_BINARIES=yes" >> config.mak
470 if test "$use_libgcc" = "yes" ; then
471 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
472 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
474 if test "$have_selinux" = "yes" ; then
475 echo "#define HAVE_SELINUX" >> $TMPH
476 echo "HAVE_SELINUX=yes" >> config.mak
479 version=`head $source_path/VERSION`
480 echo "VERSION=$version" >>config.mak
481 echo "#define TCC_VERSION \"$version\"" >> $TMPH
482 echo "@set VERSION $version" > config.texi
483 echo "SRC_PATH=$source_path" >>config.mak
485 if test "$source_path_used" = "yes" ; then
486 case $source_path in
487 /*) echo "top_srcdir=$source_path";;
488 *) echo "top_srcdir=\$(TOP)/$source_path";;
489 esac >>config.mak
490 else
491 echo 'top_srcdir=$(TOP)' >>config.mak
493 echo 'top_builddir=$(TOP)' >>config.mak
495 diff $TMPH config.h >/dev/null 2>&1
496 if test $? -ne 0 ; then
497 mv -f $TMPH config.h
498 else
499 echo "config.h is unchanged"
502 rm -f $TMPN* $CONFTEST
504 # ---------------------------------------------------------------------------
505 # build tree in object directory if source path is different from current one
507 fn_makelink()
509 tgt=$1/$2
510 case $2 in
511 */*) dn=${2%/*}
512 test -d $dn || mkdir -p $dn
513 case $1 in
514 /*) ;;
515 *) while test $dn ; do
516 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
517 done
519 esac
521 esac
522 ln -sfn $tgt $2
525 if test "$source_path_used" = "yes" ; then
526 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
527 for f in $FILES ; do
528 fn_makelink $source_path $f
529 done
532 # ---------------------------------------------------------------------------