Add support for KfreeBSD 64bits
[tinycc.git] / configure
blob6a7fae55f9fece06d323a98628466cfcc5d86d2a
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=
47 confvars=
49 cpu=`uname -m`
51 # OS specific
52 targetos=`uname -s`
53 case $targetos in
54 MINGW32*) mingw32=yes;;
55 DragonFly) noldl=yes;;
56 OpenBSD) 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 case "$cpu" in
72 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
73 cpu="x86"
75 x86_64)
76 cpu="x86-64"
78 arm*)
79 case "$cpu" in
80 arm|armv4l)
81 cpuver=4
83 armv5tel|armv5tejl)
84 cpuver=5
86 armv6j|armv6l)
87 cpuver=6
89 armv7a|armv7l)
90 cpuver=7
92 esac
93 cpu="armv4l"
95 alpha)
96 cpu="alpha"
98 "Power Macintosh"|ppc|ppc64)
99 cpu="powerpc"
101 mips)
102 cpu="mips"
104 s390)
105 cpu="s390"
108 cpu="unknown"
110 esac
112 for opt do
113 eval opt=\"$opt\"
114 case "$opt" in
115 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
117 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
119 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
121 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
123 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
125 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
127 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
129 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
131 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
133 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
135 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
137 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
139 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
141 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
143 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
145 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
147 --extra-libs=*) extralibs=${opt#--extra-libs=}
149 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
151 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
153 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
155 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
157 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
159 --enable-gprof) gprof="yes"
161 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
163 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
165 --enable-cross) build_cross="yes"
167 --disable-static) disable_static="yes"
169 --disable-rpath) disable_rpath="yes"
171 --strip-binaries) strip_binaries="yes"
173 --with-libgcc) use_libgcc="yes"
175 --with-selinux) have_selinux="yes"
177 --help|-h) show_help="yes"
179 *) echo "configure: WARNING: unrecognized option $opt"
181 esac
182 done
184 # Checking for CFLAGS
185 if test -z "$CFLAGS"; then
186 CFLAGS="-Wall -g -O2"
189 if test "$mingw32" = "yes" ; then
190 if test x"$tccdir" = x""; then
191 tccdir="tcc"
193 if test -z "$prefix" ; then
194 prefix="C:/Program Files/${tccdir}"
196 if test -z "$sharedir" ; then
197 sharedir="${prefix}"
199 execprefix="$prefix"
200 bindir="${prefix}"
201 tccdir="${prefix}"
202 libdir="${prefix}/lib"
203 docdir="${sharedir}/doc"
204 mandir="${sharedir}/man"
205 infodir="${sharedir}/info"
206 LIBSUF=".lib"
207 EXESUF=".exe"
208 else
209 if test -z "$prefix" ; then
210 prefix="/usr/local"
212 if test -z "$sharedir" ; then
213 sharedir="${prefix}/share"
215 if test x"$execprefix" = x""; then
216 execprefix="${prefix}"
218 if test x"$libdir" = x""; then
219 libdir="${execprefix}/lib"
221 if test x"$bindir" = x""; then
222 bindir="${execprefix}/bin"
224 if test x"$tccdir" = x""; then
225 tccdir="tcc"
227 if test x"$docdir" = x""; then
228 docdir="${sharedir}/doc/${tccdir}"
230 if test x"$mandir" = x""; then
231 mandir="${sharedir}/man"
233 if test x"$infodir" = x""; then
234 infodir="${sharedir}/info"
236 tccdir="${libdir}/${tccdir}"
237 fi # mingw32
239 if test x"$includedir" = x""; then
240 includedir="${prefix}/include"
243 if test x"$show_help" = "xyes" ; then
244 cat << EOF
245 Usage: configure [options]
246 Options: [defaults in brackets after descriptions]
248 Standard options:
249 --help print this message
250 --prefix=PREFIX install in PREFIX [$prefix]
251 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
252 [same as prefix]
253 --bindir=DIR user executables in DIR [EPREFIX/bin]
254 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
255 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
256 --includedir=DIR C header files in DIR [PREFIX/include]
257 --sharedir=DIR documentation root DIR [PREFIX/share]
258 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
259 --mandir=DIR man documentation in DIR [SHAREDIR/man]
260 --infodir=DIR info documentation in DIR [SHAREDIR/info]
262 Advanced options (experts only):
263 --source-path=PATH path of source code [$source_path]
264 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
265 --sysroot=PREFIX prepend PREFIX to library/include paths []
266 --cc=CC use C compiler CC [$cc]
267 --extra-cflags= specify compiler flags [$CFLAGS]
268 --extra-ldflags= specify linker options []
269 --strip-binaries strip symbol tables from resulting binaries
270 --disable-static make libtcc.so instead of libtcc.a
271 --disable-rpath disable use of -rpath with the above
272 --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a
273 --enable-mingw32 build windows version on linux with mingw32
274 --enable-cygwin build windows version on windows with cygwin
275 --enable-cross build cross compilers
276 --with-selinux use mmap for exec mem [needs writable /tmp]
277 --sysincludepaths=... specify system include paths, colon separated
278 --libpaths=... specify system library paths, colon separated
279 --crtprefix=... specify locations of crt?.o, colon separated
280 --elfinterp=... specify elf interpreter
282 #echo "NOTE: The object files are build at the place where configure is launched"
283 exit 1
286 cc="${cross_prefix}${cc}"
287 ar="${cross_prefix}${ar}"
288 strip="${cross_prefix}${strip}"
290 CONFTEST=./conftest$EXESUF
292 if test -z "$cross_prefix" ; then
293 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
294 echo "configure: error: '$cc' failed to compile conftest.c."
295 else
296 bigendian="$($CONFTEST bigendian)"
297 gcc_major="$($CONFTEST version)"
298 gcc_minor="$($CONFTEST minor)"
299 if test "$mingw32" = "no" ; then
300 triplet="$($CONFTEST triplet)"
301 if test -f "/usr/lib/$triplet/crti.o" ; then
302 tcc_lddir="lib/$triplet"
303 multiarch_triplet="$triplet"
304 elif test -f "/usr/lib64/crti.o" ; then
305 tcc_lddir="lib64"
308 if test "$cpu" = "armv4l" ; then
309 if test "${triplet%eabihf}" != "$triplet" ; then
310 confvars="$confvars arm_eabihf"
311 elif test "${triplet%eabi}" != "$triplet" ; then
312 confvars="$confvars arm_eabi"
314 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
315 confvars="$confvars arm_vfp"
319 # multiarch_triplet=${libc_dir#*/}
320 # multiarch_triplet=${multiarch_triplet%/}
321 # tcc_lddir="${libc_dir%%/*}"
322 # if test -n "$multiarch_triplet" ; then
323 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
324 # fi
326 if test -f "/lib/ld-uClibc.so.0" ; then
327 confvars="$confvars uClibc"
329 # gr: maybe for after the release:
330 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
331 # echo "elfinterp $tcc_elfinterp"
335 else
336 # if cross compiling, cannot launch a program, so make a static guess
337 case $cpu in
338 powerpc|mips|s390) bigendian=yes;;
339 esac
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_inc() {
387 if test -n "$2"; then
388 echo "#ifndef $1" >> $TMPH
389 echo "# define $1 \"$2\"" >> $TMPH
390 echo "#endif" >> $TMPH
393 print_mak() {
394 if test -n "$2"; then
395 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
399 echo "/* Automatically generated by configure - do not modify */" > $TMPH
401 print_inc CONFIG_SYSROOT "$sysroot"
402 print_inc CONFIG_TCCDIR "$tccdir"
403 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
404 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
405 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
406 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
407 print_mak CONFIG_LDDIR "$tcc_lddir"
408 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
410 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
411 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
413 if test "$cpu" = "x86" ; then
414 echo "ARCH=i386" >> config.mak
415 echo "#define HOST_I386 1" >> $TMPH
416 elif test "$cpu" = "x86-64" ; then
417 echo "ARCH=x86-64" >> config.mak
418 echo "#define HOST_X86_64 1" >> $TMPH
419 elif test "$cpu" = "armv4l" ; then
420 echo "ARCH=arm" >> config.mak
421 echo "#define HOST_ARM 1" >> $TMPH
422 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
423 elif test "$cpu" = "powerpc" ; then
424 echo "ARCH=ppc" >> config.mak
425 echo "#define HOST_PPC 1" >> $TMPH
426 elif test "$cpu" = "mips" ; then
427 echo "ARCH=mips" >> config.mak
428 echo "#define HOST_MIPS 1" >> $TMPH
429 elif test "$cpu" = "s390" ; then
430 echo "ARCH=s390" >> config.mak
431 echo "#define HOST_S390 1" >> $TMPH
432 elif test "$cpu" = "alpha" ; then
433 echo "ARCH=alpha" >> config.mak
434 echo "#define HOST_ALPHA 1" >> $TMPH
435 else
436 echo "Unsupported CPU"
437 exit 1
440 echo "TARGETOS=$targetos" >> config.mak
442 for v in $confvars ; do
443 echo "CONFIG_$v=yes" >> config.mak
444 done
445 if test "$noldl" = "yes" ; then
446 echo "CONFIG_NOLDL=yes" >> config.mak
448 if test "$mingw32" = "yes" ; then
449 echo "CONFIG_WIN32=yes" >> config.mak
450 echo "#define CONFIG_WIN32 1" >> $TMPH
452 if test "$cygwin" = "yes" ; then
453 echo "#ifndef _WIN32" >> $TMPH
454 echo "# define _WIN32" >> $TMPH
455 echo "#endif" >> $TMPH
456 echo "AR=ar" >> config.mak
458 if test "$bigendian" = "yes" ; then
459 echo "WORDS_BIGENDIAN=yes" >> config.mak
460 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
462 if test "$gprof" = "yes" ; then
463 echo "TARGET_GPROF=yes" >> config.mak
464 echo "#define HAVE_GPROF 1" >> $TMPH
466 if test "$build_cross" = "yes" ; then
467 echo "CONFIG_CROSS=yes" >> config.mak
469 if test "$disable_static" = "yes" ; then
470 echo "DISABLE_STATIC=yes" >> config.mak
472 if test "$disable_rpath" = "yes" ; then
473 echo "DISABLE_RPATH=yes" >> config.mak
475 if test "$strip_binaries" = "yes" ; then
476 echo "STRIP_BINARIES=yes" >> config.mak
478 if test "$use_libgcc" = "yes" ; then
479 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
480 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
482 if test "$have_selinux" = "yes" ; then
483 echo "#define HAVE_SELINUX" >> $TMPH
484 echo "HAVE_SELINUX=yes" >> config.mak
487 version=`head $source_path/VERSION`
488 echo "VERSION=$version" >>config.mak
489 echo "#define TCC_VERSION \"$version\"" >> $TMPH
490 echo "@set VERSION $version" > config.texi
491 echo "SRC_PATH=$source_path" >>config.mak
493 if test "$source_path_used" = "yes" ; then
494 case $source_path in
495 /*) echo "top_srcdir=$source_path";;
496 *) echo "top_srcdir=\$(TOP)/$source_path";;
497 esac >>config.mak
498 else
499 echo 'top_srcdir=$(TOP)' >>config.mak
501 echo 'top_builddir=$(TOP)' >>config.mak
503 diff $TMPH config.h >/dev/null 2>&1
504 if test $? -ne 0 ; then
505 mv -f $TMPH config.h
506 else
507 echo "config.h is unchanged"
510 rm -f $TMPN* $CONFTEST
512 # ---------------------------------------------------------------------------
513 # build tree in object directory if source path is different from current one
515 fn_makelink()
517 tgt=$1/$2
518 case $2 in
519 */*) dn=${2%/*}
520 test -d $dn || mkdir -p $dn
521 case $1 in
522 /*) ;;
523 *) while test $dn ; do
524 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
525 done
527 esac
529 esac
530 ln -sfn $tgt $2
533 if test "$source_path_used" = "yes" ; then
534 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
535 for f in $FILES ; do
536 fn_makelink $source_path $f
537 done
540 # ---------------------------------------------------------------------------