tccpp: allow "0x1e+1" in asm
[tinycc.git] / configure
blobb6a0b2193d014bec776ad70ec1d7cb4cd7b8f5d0
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 ar="ar"
34 strip="strip"
35 cygwin="no"
36 gprof="no"
37 bigendian="no"
38 mingw32="no"
39 LIBSUF=".a"
40 EXESUF=""
41 tcc_sysincludepaths=""
42 tcc_libpaths=""
43 tcc_crtprefix=""
44 tcc_elfinterp=""
45 tcc_lddir=
46 confvars=
47 cpu=
49 # OS specific
50 targetos=`uname`
51 case $targetos in
52 MINGW32*) mingw32=yes;;
53 DragonFly) noldl=yes;;
54 OpenBSD) noldl=yes;;
55 FreeBSD) noldl=yes;;
56 NetBSD) noldl=yes;;
57 *) ;;
58 esac
60 # find source path
61 # XXX: we assume an absolute path is given when launching configure,
62 # except in './configure' case.
63 source_path=${0%configure}
64 source_path=${source_path%/}
65 source_path_used="yes"
66 if test -z "$source_path" -o "$source_path" = "." ; then
67 source_path=`pwd`
68 source_path_used="no"
71 cpu=`uname -m`
72 if test $mingw32=yes; then
73 if test "$PROCESSOR_ARCHITEW6432" = "AMD64" \
74 -o "$PROCESSOR_ARCHITECTURE" = "AMD64"; then
75 cpu="x86_64"
79 case "$cpu" in
80 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
81 cpu="x86"
83 x86_64|amd64)
84 cpu="x86-64"
86 arm*)
87 case "$cpu" in
88 arm|armv4l)
89 cpuver=4
91 armv5tel|armv5tejl)
92 cpuver=5
94 armv6j|armv6l)
95 cpuver=6
97 armv7a|armv7l)
98 cpuver=7
100 esac
101 cpu="armv4l"
103 aarch64)
104 cpu="aarch64"
106 alpha)
107 cpu="alpha"
109 "Power Macintosh"|ppc|ppc64)
110 cpu="powerpc"
112 mips)
113 cpu="mips"
115 s390)
116 cpu="s390"
119 cpu="unknown"
121 esac
123 for opt do
124 eval opt=\"$opt\"
125 case "$opt" in
126 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
128 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
130 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
132 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
134 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
136 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
138 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
140 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
142 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
144 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
146 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
148 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
150 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
152 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
154 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
156 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
158 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
160 --extra-libs=*) extralibs="${opt#--extra-libs=}"
162 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
164 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
166 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
168 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
170 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
172 --enable-gprof) gprof="yes"
174 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
176 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
178 --enable-cross) build_cross="yes"
180 --disable-static) disable_static="yes"
182 --disable-rpath) disable_rpath="yes"
184 --strip-binaries) strip_binaries="yes"
186 --with-libgcc) use_libgcc="yes"
188 --with-selinux) have_selinux="yes"
190 --help|-h) show_help="yes"
192 *) echo "configure: WARNING: unrecognized option $opt"
194 esac
195 done
197 # Checking for CFLAGS
198 if test -z "$CFLAGS"; then
199 CFLAGS="-Wall -g -O2"
200 if test "$mingw32" = "yes" -a "$cpu" = "x86-64"; then
201 CFLAGS="-m64 $CFLAGS"
205 if test "$mingw32" = "yes" ; then
206 if test x"$tccdir" = x""; then
207 tccdir="tcc"
209 if test -z "$prefix" ; then
210 prefix="C:/Program Files/${tccdir}"
212 if test -z "$sharedir" ; then
213 sharedir="${prefix}"
215 execprefix="$prefix"
216 bindir="${prefix}"
217 tccdir="${prefix}"
218 libdir="${prefix}/lib"
219 docdir="${sharedir}/doc"
220 mandir="${sharedir}/man"
221 infodir="${sharedir}/info"
222 LIBSUF=".lib"
223 EXESUF=".exe"
224 else
225 if test -z "$prefix" ; then
226 prefix="/usr/local"
228 if test -z "$sharedir" ; then
229 sharedir="${prefix}/share"
231 if test x"$execprefix" = x""; then
232 execprefix="${prefix}"
234 if test x"$libdir" = x""; then
235 libdir="${execprefix}/lib"
237 if test x"$bindir" = x""; then
238 bindir="${execprefix}/bin"
240 if test x"$tccdir" = x""; then
241 tccdir="tcc"
243 if test x"$docdir" = x""; then
244 docdir="${sharedir}/doc/${tccdir}"
246 if test x"$mandir" = x""; then
247 mandir="${sharedir}/man"
249 if test x"$infodir" = x""; then
250 infodir="${sharedir}/info"
252 tccdir="${libdir}/${tccdir}"
253 fi # mingw32
255 if test x"$includedir" = x""; then
256 includedir="${prefix}/include"
259 if test x"$show_help" = "xyes" ; then
260 cat << EOF
261 Usage: configure [options]
262 Options: [defaults in brackets after descriptions]
264 Standard options:
265 --help print this message
266 --prefix=PREFIX install in PREFIX [$prefix]
267 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
268 [same as prefix]
269 --bindir=DIR user executables in DIR [EPREFIX/bin]
270 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
271 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
272 --includedir=DIR C header files in DIR [PREFIX/include]
273 --sharedir=DIR documentation root DIR [PREFIX/share]
274 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
275 --mandir=DIR man documentation in DIR [SHAREDIR/man]
276 --infodir=DIR info documentation in DIR [SHAREDIR/info]
278 Advanced options (experts only):
279 --source-path=PATH path of source code [$source_path]
280 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
281 --sysroot=PREFIX prepend PREFIX to library/include paths []
282 --cc=CC use C compiler CC [$cc]
283 --ar=AR create archives using AR [$ar]
284 --extra-cflags= specify compiler flags [$CFLAGS]
285 --extra-ldflags= specify linker options []
286 --strip-binaries strip symbol tables from resulting binaries
287 --disable-static make libtcc.so instead of libtcc.a
288 --disable-rpath disable use of -rpath with the above
289 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
290 --enable-mingw32 build windows version on linux with mingw32
291 --enable-cygwin build windows version on windows with cygwin
292 --enable-cross build cross compilers
293 --with-selinux use mmap for exec mem [needs writable /tmp]
294 --sysincludepaths=... specify system include paths, colon separated
295 --libpaths=... specify system library paths, colon separated
296 --crtprefix=... specify locations of crt?.o, colon separated
297 --elfinterp=... specify elf interpreter
299 #echo "NOTE: The object files are build at the place where configure is launched"
300 exit 1
303 cc="${cross_prefix}${cc}"
304 ar="${cross_prefix}${ar}"
305 strip="${cross_prefix}${strip}"
307 CONFTEST=./conftest$EXESUF
309 if test -z "$cross_prefix" ; then
310 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
311 echo "configure: error: '$cc' failed to compile conftest.c."
312 else
313 bigendian="$($CONFTEST bigendian)"
314 gcc_major="$($CONFTEST version)"
315 gcc_minor="$($CONFTEST minor)"
316 if test "$mingw32" = "no" ; then
317 triplet="$($CONFTEST triplet)"
318 if test -f "/usr/lib/$triplet/crti.o" ; then
319 tcc_lddir="lib/$triplet"
320 multiarch_triplet="$triplet"
321 elif test -f "/usr/lib64/crti.o" ; then
322 tcc_lddir="lib64"
325 if test "$cpu" = "armv4l" ; then
326 if test "${triplet%eabihf}" != "$triplet" ; then
327 confvars="$confvars arm_eabihf"
328 elif test "${triplet%eabi}" != "$triplet" ; then
329 confvars="$confvars arm_eabi"
331 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
332 confvars="$confvars arm_vfp"
336 # multiarch_triplet=${libc_dir#*/}
337 # multiarch_triplet=${multiarch_triplet%/}
338 # tcc_lddir="${libc_dir%%/*}"
339 # if test -n "$multiarch_triplet" ; then
340 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
341 # fi
343 if test -f "/lib/ld-uClibc.so.0" ; then
344 confvars="$confvars uClibc"
347 # if test -z "$tcc_elfinterp" ; then
348 # tcc_elfinterp="$(ldd $CONFTEST | grep '/ld-.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
349 # fi
353 else
354 # if cross compiling, cannot launch a program, so make a static guess
355 case $cpu in
356 powerpc|mips|s390) bigendian=yes;;
357 esac
360 # a final configuration tuning
361 $cc -v --help > cc_help.txt 2>&1
362 W_OPTIONS="declaration-after-statement"
363 for i in $W_OPTIONS; do
364 O_PRESENT="$(grep -- -W$i cc_help.txt)"
365 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -W$i"; fi
366 done
367 W_OPTIONS="deprecated-declarations strict-aliasing pointer-sign sign-compare unused-result uninitialized"
368 for i in $W_OPTIONS; do
369 O_PRESENT="$(grep -- -W$i cc_help.txt)"
370 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -Wno-$i"; fi
371 done
372 F_OPTIONS="strict-aliasing"
373 for i in $F_OPTIONS; do
374 O_PRESENT="$(grep -- -f$i cc_help.txt)"
375 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -fno-$i"; fi
376 done
377 rm -f cc_help.txt
379 echo "Binary directory $bindir"
380 echo "TinyCC directory $tccdir"
381 echo "Library directory $libdir"
382 echo "Include directory $includedir"
383 echo "Manual directory $mandir"
384 echo "Info directory $infodir"
385 echo "Doc directory $docdir"
386 echo "Target root prefix $sysroot"
387 echo "Source path $source_path"
388 echo "C compiler $cc"
389 echo "Target OS $targetos"
390 echo "CPU $cpu"
391 echo "Big Endian $bigendian"
392 echo "gprof enabled $gprof"
393 echo "cross compilers $build_cross"
394 echo "use libgcc $use_libgcc"
396 echo "Creating config.mak and config.h"
398 cat >config.mak <<EOF
399 # Automatically generated by configure - do not modify
400 prefix=$prefix
401 bindir=\$(DESTDIR)$bindir
402 tccdir=\$(DESTDIR)$tccdir
403 libdir=\$(DESTDIR)$libdir
404 ln_libdir=$libdir
405 includedir=\$(DESTDIR)$includedir
406 mandir=\$(DESTDIR)$mandir
407 infodir=\$(DESTDIR)$infodir
408 docdir=\$(DESTDIR)$docdir
409 CC=$cc
410 GCC_MAJOR=$gcc_major
411 GCC_MINOR=$gcc_minor
412 AR=$ar
413 STRIP=$strip -s -R .comment -R .note
414 CFLAGS=$CFLAGS
415 LDFLAGS=$LDFLAGS
416 LIBSUF=$LIBSUF
417 EXESUF=$EXESUF
420 print_inc() {
421 if test -n "$2"; then
422 echo "#ifndef $1" >> $TMPH
423 echo "# define $1 \"$2\"" >> $TMPH
424 echo "#endif" >> $TMPH
427 print_mak() {
428 if test -n "$2"; then
429 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
433 echo "/* Automatically generated by configure - do not modify */" > $TMPH
435 print_inc CONFIG_SYSROOT "$sysroot"
436 print_inc CONFIG_TCCDIR "$tccdir"
437 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
438 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
439 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
440 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
441 print_mak CONFIG_LDDIR "$tcc_lddir"
442 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
444 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
445 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
447 if test "$cpu" = "x86" ; then
448 echo "ARCH=i386" >> config.mak
449 elif test "$cpu" = "x86-64" ; then
450 echo "ARCH=x86-64" >> config.mak
451 elif test "$cpu" = "armv4l" ; then
452 echo "ARCH=arm" >> config.mak
453 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
454 elif test "$cpu" = "aarch64" ; then
455 echo "ARCH=arm64" >> config.mak
456 elif test "$cpu" = "powerpc" ; then
457 echo "ARCH=ppc" >> config.mak
458 elif test "$cpu" = "mips" ; then
459 echo "ARCH=mips" >> config.mak
460 elif test "$cpu" = "s390" ; then
461 echo "ARCH=s390" >> config.mak
462 elif test "$cpu" = "alpha" ; then
463 echo "ARCH=alpha" >> config.mak
464 else
465 echo "Unsupported CPU"
466 exit 1
469 echo "TARGETOS=$targetos" >> config.mak
471 for v in $confvars ; do
472 echo "CONFIG_$v=yes" >> config.mak
473 done
474 if test "$noldl" = "yes" ; then
475 echo "CONFIG_NOLDL=yes" >> config.mak
477 if test "$mingw32" = "yes" ; then
478 echo "CONFIG_WIN32=yes" >> config.mak
480 if test "$cygwin" = "yes" ; then
481 echo "#ifndef _WIN32" >> $TMPH
482 echo "# define _WIN32" >> $TMPH
483 echo "#endif" >> $TMPH
484 echo "AR=ar" >> config.mak
486 if test "$bigendian" = "yes" ; then
487 echo "WORDS_BIGENDIAN=yes" >> config.mak
488 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
490 if test "$gprof" = "yes" ; then
491 echo "TARGET_GPROF=yes" >> config.mak
492 echo "#define HAVE_GPROF 1" >> $TMPH
494 if test "$build_cross" = "yes" ; then
495 echo "CONFIG_CROSS=yes" >> config.mak
497 if test "$disable_static" = "yes" ; then
498 echo "DISABLE_STATIC=yes" >> config.mak
500 if test "$disable_rpath" = "yes" ; then
501 echo "DISABLE_RPATH=yes" >> config.mak
503 if test "$strip_binaries" = "yes" ; then
504 echo "STRIP_BINARIES=yes" >> config.mak
506 if test "$use_libgcc" = "yes" ; then
507 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
508 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
510 if test "$have_selinux" = "yes" ; then
511 echo "#define HAVE_SELINUX" >> $TMPH
512 echo "HAVE_SELINUX=yes" >> config.mak
515 version=`head $source_path/VERSION`
516 echo "VERSION = $version" >> config.mak
517 echo "#define TCC_VERSION \"$version\"" >> $TMPH
518 echo "@set VERSION $version" > config.texi
520 if test "$source_path_used" = "yes" ; then
521 case $source_path in
522 /*) echo "TOPSRC=$source_path";;
523 *) echo "TOPSRC=\$(TOP)/$source_path";;
524 esac >>config.mak
525 else
526 echo 'TOPSRC=$(TOP)' >>config.mak
529 diff $TMPH config.h >/dev/null 2>&1
530 if test $? -ne 0 ; then
531 mv -f $TMPH config.h
532 else
533 echo "config.h is unchanged"
536 rm -f $TMPN* $CONFTEST
538 # ---------------------------------------------------------------------------
539 # build tree in object directory if source path is different from current one
541 fn_makelink()
543 tgt=$1/$2
544 case $2 in
545 */*) dn=${2%/*}
546 test -d $dn || mkdir -p $dn
547 case $1 in
548 /*) ;;
549 *) while test $dn ; do
550 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
551 done
553 esac
555 esac
556 if test "$mingw32" = "yes" ; then
557 cmd //c mklink `echo "$2 $tgt" | sed 's,/,\\\\,g'`
558 else
559 ln -sfn $tgt $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 # ---------------------------------------------------------------------------