correction for the previous commit
[tinycc.git] / configure
blobd33092adae9fc59ce447892c216dc5544e9427d3
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 enable_assert="no"
23 prefix=""
24 execprefix=""
25 bindir=""
26 libdir=""
27 tccdir=""
28 includedir=""
29 mandir=""
30 infodir=""
31 sysroot=""
32 cross_prefix=""
33 cc="gcc"
34 host_cc="gcc"
35 ar="ar"
36 strip="strip"
37 cygwin="no"
38 gprof="no"
39 bigendian="no"
40 mingw32="no"
41 LIBSUF=".a"
42 EXESUF=""
43 tcc_sysincludepaths=""
44 tcc_libpaths=""
45 tcc_crtprefix=""
46 tcc_elfinterp=""
47 tcc_lddir=
48 confvars=
49 cpu=
50 host_os=Linux
52 # OS specific
53 targetos=`uname -s`
54 case $targetos in
55 MINGW32*) mingw32=yes; host_os=Windows; ;;
56 DragonFly) noldl=yes;;
57 OpenBSD) noldl=yes;;
58 FreeBSD) noldl=yes;;
59 NetBSD) noldl=yes;;
60 *) ;;
61 esac
63 # find source path
64 # XXX: we assume an absolute path is given when launching configure,
65 # except in './configure' case.
66 source_path=${0%configure}
67 source_path=${source_path%/}
68 source_path_used="yes"
69 if test -z "$source_path" -o "$source_path" = "." ; then
70 source_path=`pwd`
71 source_path_used="no"
74 classify_cpu ()
76 cpu="$1"
78 case "$cpu" in
79 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
80 cpu="x86"
82 x86_64|amd64)
83 cpu="x86-64"
85 arm*)
86 case "$cpu" in
87 arm|armv4l)
88 cpuver=4
90 armv5tel|armv5tejl)
91 cpuver=5
93 armv6j|armv6l)
94 cpuver=6
96 armv7a|armv7l)
97 cpuver=7
99 esac
100 cpu="armv4l"
102 aarch64)
103 cpu="aarch64"
105 alpha)
106 cpu="alpha"
108 "Power Macintosh"|ppc|ppc64)
109 cpu="powerpc"
111 mips)
112 cpu="mips"
114 s390)
115 cpu="s390"
118 echo "Unsupported CPU: $cpu"
119 exit 1
121 esac
124 for opt do
125 eval opt=\"$opt\"
126 case "$opt" in
127 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
129 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
131 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
133 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
135 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
137 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
139 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
141 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
143 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
145 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
147 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
149 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
151 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
153 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
155 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
157 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
159 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
161 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
163 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
165 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
167 --extra-libs=*) extralibs=${opt#--extra-libs=}
169 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
171 --enable-gprof) gprof="yes"
173 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
175 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
177 --enable-tcc32-mingw) mingw32="yes" ; cross_prefix="i386-win-" ; cpu=x86; cc=tcc
179 --enable-tcc64-mingw) mingw32="yes" ; cross_prefix="x86_64-win-" ; cpu=x86_64; cc=tcc
181 --enable-cross) build_cross="yes"
183 --enable-assert) enable_assert="yes"
185 --disable-static) disable_static="yes"
187 --disable-rpath) disable_rpath="yes"
189 --strip-binaries) strip_binaries="yes"
191 --with-libgcc) use_libgcc="yes"
193 --with-selinux) have_selinux="yes"
195 --help|-h) show_help="yes"
197 *) echo "configure: WARNING: unrecognized option $opt"
199 esac
200 done
202 if test -z "$cpu" ; then
203 if test -n "$ARCH" ; then
204 cpu="$ARCH"
205 else
206 cpu=`uname -m`
209 classify_cpu "$cpu"
211 # Checking for CFLAGS
212 if test -z "$CFLAGS"; then
213 CFLAGS="-Wall -g -O2"
216 if test "$mingw32" = "yes" ; then
217 if test x"$tccdir" = x""; then
218 tccdir="tcc"
220 if test -z "$prefix" ; then
221 prefix="C:/Program Files/${tccdir}"
223 if test -z "$sharedir" ; then
224 sharedir="${prefix}"
226 execprefix="$prefix"
227 bindir="${prefix}"
228 tccdir="${prefix}"
229 libdir="${prefix}/lib"
230 docdir="${sharedir}/doc"
231 mandir="${sharedir}/man"
232 infodir="${sharedir}/info"
233 LIBSUF=".lib"
234 EXESUF=".exe"
235 else
236 if test -z "$prefix" ; then
237 prefix="/usr/local"
239 if test -z "$sharedir" ; then
240 sharedir="${prefix}/share"
242 if test x"$execprefix" = x""; then
243 execprefix="${prefix}"
245 if test x"$tccdir" = x""; then
246 tccdir="tcc"
248 if test x"$libdir" = x""; then
249 libdir="${execprefix}/lib"
250 if test -n "${tccdir}"; then
251 tccdir="${libdir}/${tccdir}"
252 else
253 tccdir="${libdir}"
255 if test "$cpu" = "x86-64"; then
256 libdir="${execprefix}/lib64"
258 else
259 tccdir="${libdir}/${tccdir}"
261 if test x"$bindir" = x""; then
262 bindir="${execprefix}/bin"
264 if test x"$docdir" = x""; then
265 docdir="${sharedir}/doc/${tccdir}"
267 if test x"$mandir" = x""; then
268 mandir="${sharedir}/man"
270 if test x"$infodir" = x""; then
271 infodir="${sharedir}/info"
273 fi # mingw32
275 if test x"$includedir" = x""; then
276 includedir="${prefix}/include"
279 if test x"$show_help" = "xyes" ; then
280 cat << EOF
281 Usage: configure [options]
282 Options: [defaults in brackets after descriptions]
284 Standard options:
285 --help print this message
286 --prefix=PREFIX install in PREFIX [$prefix]
287 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
288 [same as prefix]
289 --bindir=DIR user executables in DIR [EPREFIX/bin]
290 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
291 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
292 --includedir=DIR C header files in DIR [PREFIX/include]
293 --sharedir=DIR documentation root DIR [PREFIX/share]
294 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
295 --mandir=DIR man documentation in DIR [SHAREDIR/man]
296 --infodir=DIR info documentation in DIR [SHAREDIR/info]
298 Advanced options (experts only):
299 --source-path=PATH path of source code [$source_path]
300 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
301 --sysroot=PREFIX prepend PREFIX to library/include paths []
302 --cc=CC use C compiler CC [$cc]
303 --extra-cflags= specify compiler flags [$CFLAGS]
304 --extra-ldflags= specify linker options []
305 --cpu=CPU CPU [$cpu]
306 --strip-binaries strip symbol tables from resulting binaries
307 --disable-static make libtcc.so instead of libtcc.a
308 --disable-rpath disable use of -rpath with the above
309 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
310 --enable-tcc64-mingw build windows version on linux with x86_64-win-tcc
311 --enable-tcc32-mingw build windows version on linux with i386-win-tcc
312 --enable-mingw32 build windows version on linux with mingw32
313 --enable-cygwin build windows version on windows with cygwin
314 --enable-cross build cross compilers
315 --enable-assert enable debug assertions
316 --with-selinux use mmap for exec mem [needs writable /tmp]
317 --sysincludepaths=... specify system include paths, colon separated
318 --libpaths=... specify system library paths, colon separated
319 --crtprefix=... specify locations of crt?.o, colon separated
320 --elfinterp=... specify elf interpreter
322 #echo "NOTE: The object files are build at the place where configure is launched"
323 exit 1
326 if test "$cc" != "tcc"; then
327 ar="${cross_prefix}${ar}"
329 cc="${cross_prefix}${cc}"
330 strip="${cross_prefix}${strip}"
332 CONFTEST=./conftest$EXESUF
334 if test -z "$cross_prefix" ; then
335 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
336 echo "configure: error: '$cc' failed to compile conftest.c."
337 else
338 bigendian="$($CONFTEST bigendian)"
339 gcc_major="$($CONFTEST version)"
340 gcc_minor="$($CONFTEST minor)"
341 if test "$mingw32" = "no" ; then
342 triplet="$($CONFTEST triplet)"
343 if test -f "/usr/lib/$triplet/crti.o" ; then
344 tcc_lddir="lib"
345 multiarch_triplet="$triplet"
346 elif test "$cpu" != "x86" -a -f "/usr/lib64/crti.o" ; then
347 tcc_lddir="lib64"
350 if test "$cpu" = "armv4l" ; 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 # multiarch_triplet=${libc_dir#*/}
362 # multiarch_triplet=${multiarch_triplet%/}
363 # tcc_lddir="${libc_dir%%/*}"
364 # if test -n "$multiarch_triplet" ; then
365 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
366 # fi
368 if test -f "/lib/ld-uClibc.so.0" ; then
369 confvars="$confvars uClibc"
371 # gr: maybe for after the release:
372 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
373 # echo "elfinterp $tcc_elfinterp"
377 else
378 # if cross compiling, cannot launch a program, so make a static guess
379 case $cpu in
380 powerpc|mips|s390) bigendian=yes;;
381 esac
384 # a final configuration tuning
385 W_OPTIONS="deprecated-declarations strict-aliasing pointer-sign sign-compare unused-result uninitialized"
386 for i in $W_OPTIONS; do
387 O_PRESENT="$($cc -v --help 2>&1 | grep -- -W$i)"
388 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -Wno-$i"; fi
389 done
390 F_OPTIONS="strict-aliasing"
391 for i in $F_OPTIONS; do
392 O_PRESENT="$($cc -v --help 2>&1 | grep -- -f$i)"
393 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -fno-$i"; fi
394 done
395 if test -z "$tcc_lddir" -a "$cpu" = "x86-64"; then tcc_lddir="lib64"; fi
397 echo "Binary directory $bindir"
398 echo "TinyCC directory $tccdir"
399 echo "Library directory $libdir"
400 echo "Include directory $includedir"
401 echo "Manual directory $mandir"
402 echo "Info directory $infodir"
403 echo "Doc directory $docdir"
404 echo "Target root prefix $sysroot"
405 echo "Source path $source_path"
406 echo "C compiler $cc"
407 echo "cross compilers $build_cross"
408 if test "$build_cross" = "no"; then
409 echo "Target CPU $cpu"
411 echo "Host OS $host_os"
412 echo "Target OS $targetos"
413 echo "Big Endian $bigendian"
414 echo "gprof enabled $gprof"
415 echo "use libgcc $use_libgcc"
417 echo "Creating config.mak and config.h"
419 cat >config.mak <<EOF
420 # Automatically generated by configure - do not modify
421 prefix=$prefix
422 bindir=\$(DESTDIR)$bindir
423 tccdir=\$(DESTDIR)$tccdir
424 libdir=\$(DESTDIR)$libdir
425 ln_libdir=$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 HOST_CC=$host_cc
434 AR=$ar
435 STRIP=$strip -s -R .comment -R .note
436 CFLAGS=$CFLAGS
437 LDFLAGS=$LDFLAGS
438 LIBSUF=$LIBSUF
439 EXESUF=$EXESUF
440 HOST_OS=$host_os
442 if test "$mingw32" = "yes"; then
443 cat >>config.mak <<EOF
444 XCC=$cc
445 XAR=$ar
449 print_inc() {
450 if test -n "$2"; then
451 echo "#ifndef $1" >> $TMPH
452 echo "# define $1 \"$2\"" >> $TMPH
453 echo "#endif" >> $TMPH
456 print_mak() {
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_inc CONFIG_LDDIR "$tcc_lddir"
467 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
468 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
469 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
470 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
471 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
473 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
474 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
476 if test "$cpu" = "x86" ; then
477 echo "ARCH=i386" >> config.mak
478 elif test "$cpu" = "x86-64" ; then
479 echo "ARCH=x86-64" >> config.mak
480 elif test "$cpu" = "armv4l" ; then
481 echo "ARCH=arm" >> config.mak
482 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
483 elif test "$cpu" = "aarch64" ; then
484 echo "ARCH=arm64" >> config.mak
485 elif test "$cpu" = "powerpc" ; then
486 echo "ARCH=ppc" >> config.mak
487 elif test "$cpu" = "mips" ; then
488 echo "ARCH=mips" >> config.mak
489 elif test "$cpu" = "s390" ; then
490 echo "ARCH=s390" >> config.mak
491 elif test "$cpu" = "alpha" ; then
492 echo "ARCH=alpha" >> config.mak
493 else
494 echo "Unsupported CPU"
495 exit 1
498 echo "TARGETOS=$targetos" >> config.mak
500 for v in $confvars ; do
501 echo "CONFIG_$v=yes" >> config.mak
502 done
503 if test "$noldl" = "yes" ; then
504 echo "CONFIG_NOLDL=yes" >> config.mak
506 if test "$mingw32" = "yes" ; then
507 echo "CONFIG_WIN32=yes" >> config.mak
508 echo "#define CONFIG_WIN32 1" >> $TMPH
510 if test "$cygwin" = "yes" ; then
511 echo "#ifndef _WIN32" >> $TMPH
512 echo "# define _WIN32" >> $TMPH
513 echo "#endif" >> $TMPH
514 echo "AR=ar" >> config.mak
516 if test "$bigendian" = "yes" ; then
517 echo "WORDS_BIGENDIAN=yes" >> config.mak
518 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
520 if test "$gprof" = "yes" ; then
521 echo "TARGET_GPROF=yes" >> config.mak
522 echo "#define HAVE_GPROF 1" >> $TMPH
524 if test "$build_cross" = "yes" ; then
525 echo "CONFIG_CROSS=yes" >> config.mak
527 if test "$disable_static" = "yes" ; then
528 echo "DISABLE_STATIC=yes" >> config.mak
530 if test "$disable_rpath" = "yes" ; then
531 echo "DISABLE_RPATH=yes" >> config.mak
533 if test "$strip_binaries" = "yes" ; then
534 echo "STRIP_BINARIES=yes" >> config.mak
536 if test "$use_libgcc" = "yes" ; then
537 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
538 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
540 if test "$have_selinux" = "yes" ; then
541 echo "#define HAVE_SELINUX" >> $TMPH
542 echo "HAVE_SELINUX=yes" >> config.mak
544 if test "$enable_assert" = "yes" ; then
545 echo "#define CONFIG_TCC_ASSERT" >> $TMPH
548 version=`head $source_path/VERSION`
549 echo "VERSION=$version" >>config.mak
550 echo "#define TCC_VERSION \"$version\"" >> $TMPH
551 echo "@set VERSION $version" > config.texi
552 echo "SRC_PATH=$source_path" >>config.mak
554 if test "$source_path_used" = "yes" ; then
555 case $source_path in
556 /*) echo "top_srcdir=$source_path";;
557 *) echo "top_srcdir=\$(TOP)/$source_path";;
558 esac >>config.mak
559 else
560 echo 'top_srcdir=$(TOP)' >>config.mak
562 echo 'top_builddir=$(TOP)' >>config.mak
564 diff $TMPH config.h >/dev/null 2>&1
565 if test $? -ne 0 ; then
566 mv -f $TMPH config.h
567 else
568 echo "config.h is unchanged"
571 rm -f $TMPN* $CONFTEST
573 # ---------------------------------------------------------------------------
574 # build tree in object directory if source path is different from current one
576 fn_makelink()
578 tgt=$1/$2
579 case $2 in
580 */*) dn=${2%/*}
581 test -d $dn || mkdir -p $dn
582 case $1 in
583 /*) ;;
584 *) while test $dn ; do
585 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
586 done
588 esac
590 esac
591 ln -sfn $tgt $2
594 if test "$source_path_used" = "yes" ; then
595 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
596 for f in $FILES ; do
597 fn_makelink $source_path $f
598 done
601 # ---------------------------------------------------------------------------