Flush caches before -running program
[tinycc.git] / configure
blob72d48af15b5da8aee196f1268d1fb15a78672d92
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 FreeBSD) noldl=yes;;
58 *) ;;
59 esac
61 # find source path
62 # XXX: we assume an absolute path is given when launching configure,
63 # except in './configure' case.
64 source_path=${0%configure}
65 source_path=${source_path%/}
66 source_path_used="yes"
67 if test -z "$source_path" -o "$source_path" = "." ; then
68 source_path=`pwd`
69 source_path_used="no"
72 case "$cpu" in
73 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
74 cpu="x86"
76 x86_64|amd64)
77 cpu="x86-64"
79 arm*)
80 case "$cpu" in
81 arm|armv4l)
82 cpuver=4
84 armv5tel|armv5tejl)
85 cpuver=5
87 armv6j|armv6l)
88 cpuver=6
90 armv7a|armv7l)
91 cpuver=7
93 esac
94 cpu="armv4l"
96 alpha)
97 cpu="alpha"
99 "Power Macintosh"|ppc|ppc64)
100 cpu="powerpc"
102 mips)
103 cpu="mips"
105 s390)
106 cpu="s390"
109 cpu="unknown"
111 esac
113 for opt do
114 eval opt=\"$opt\"
115 case "$opt" in
116 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
118 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
120 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
122 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
124 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
126 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
128 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
130 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
132 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
134 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
136 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
138 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
140 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
142 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
144 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
146 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
148 --extra-libs=*) extralibs=${opt#--extra-libs=}
150 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
152 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
154 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
156 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
158 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
160 --enable-gprof) gprof="yes"
162 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
164 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
166 --enable-cross) build_cross="yes"
168 --disable-static) disable_static="yes"
170 --disable-rpath) disable_rpath="yes"
172 --strip-binaries) strip_binaries="yes"
174 --with-libgcc) use_libgcc="yes"
176 --with-selinux) have_selinux="yes"
178 --help|-h) show_help="yes"
180 *) echo "configure: WARNING: unrecognized option $opt"
182 esac
183 done
185 # Checking for CFLAGS
186 if test -z "$CFLAGS"; then
187 CFLAGS="-Wall -g -O2"
190 if test "$mingw32" = "yes" ; then
191 if test x"$tccdir" = x""; then
192 tccdir="tcc"
194 if test -z "$prefix" ; then
195 prefix="C:/Program Files/${tccdir}"
197 if test -z "$sharedir" ; then
198 sharedir="${prefix}"
200 execprefix="$prefix"
201 bindir="${prefix}"
202 tccdir="${prefix}"
203 libdir="${prefix}/lib"
204 docdir="${sharedir}/doc"
205 mandir="${sharedir}/man"
206 infodir="${sharedir}/info"
207 LIBSUF=".lib"
208 EXESUF=".exe"
209 else
210 if test -z "$prefix" ; then
211 prefix="/usr/local"
213 if test -z "$sharedir" ; then
214 sharedir="${prefix}/share"
216 if test x"$execprefix" = x""; then
217 execprefix="${prefix}"
219 if test x"$libdir" = x""; then
220 libdir="${execprefix}/lib"
222 if test x"$bindir" = x""; then
223 bindir="${execprefix}/bin"
225 if test x"$tccdir" = x""; then
226 tccdir="tcc"
228 if test x"$docdir" = x""; then
229 docdir="${sharedir}/doc/${tccdir}"
231 if test x"$mandir" = x""; then
232 mandir="${sharedir}/man"
234 if test x"$infodir" = x""; then
235 infodir="${sharedir}/info"
237 tccdir="${libdir}/${tccdir}"
238 fi # mingw32
240 if test x"$includedir" = x""; then
241 includedir="${prefix}/include"
244 if test x"$show_help" = "xyes" ; then
245 cat << EOF
246 Usage: configure [options]
247 Options: [defaults in brackets after descriptions]
249 Standard options:
250 --help print this message
251 --prefix=PREFIX install in PREFIX [$prefix]
252 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
253 [same as prefix]
254 --bindir=DIR user executables in DIR [EPREFIX/bin]
255 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
256 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
257 --includedir=DIR C header files in DIR [PREFIX/include]
258 --sharedir=DIR documentation root DIR [PREFIX/share]
259 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
260 --mandir=DIR man documentation in DIR [SHAREDIR/man]
261 --infodir=DIR info documentation in DIR [SHAREDIR/info]
263 Advanced options (experts only):
264 --source-path=PATH path of source code [$source_path]
265 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
266 --sysroot=PREFIX prepend PREFIX to library/include paths []
267 --cc=CC use C compiler CC [$cc]
268 --extra-cflags= specify compiler flags [$CFLAGS]
269 --extra-ldflags= specify linker options []
270 --strip-binaries strip symbol tables from resulting binaries
271 --disable-static make libtcc.so instead of libtcc.a
272 --disable-rpath disable use of -rpath with the above
273 --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a
274 --enable-mingw32 build windows version on linux with mingw32
275 --enable-cygwin build windows version on windows with cygwin
276 --enable-cross build cross compilers
277 --with-selinux use mmap for exec mem [needs writable /tmp]
278 --sysincludepaths=... specify system include paths, colon separated
279 --libpaths=... specify system library paths, colon separated
280 --crtprefix=... specify locations of crt?.o, colon separated
281 --elfinterp=... specify elf interpreter
283 #echo "NOTE: The object files are build at the place where configure is launched"
284 exit 1
287 cc="${cross_prefix}${cc}"
288 ar="${cross_prefix}${ar}"
289 strip="${cross_prefix}${strip}"
291 CONFTEST=./conftest$EXESUF
293 if test -z "$cross_prefix" ; then
294 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
295 echo "configure: error: '$cc' failed to compile conftest.c."
296 else
297 bigendian="$($CONFTEST bigendian)"
298 gcc_major="$($CONFTEST version)"
299 gcc_minor="$($CONFTEST minor)"
300 if test "$mingw32" = "no" ; then
301 triplet="$($CONFTEST triplet)"
302 if test -f "/usr/lib/$triplet/crti.o" ; then
303 tcc_lddir="lib/$triplet"
304 multiarch_triplet="$triplet"
305 elif test -f "/usr/lib64/crti.o" ; then
306 tcc_lddir="lib64"
309 if test "$cpu" = "armv4l" ; then
310 if test "${triplet%eabihf}" != "$triplet" ; then
311 confvars="$confvars arm_eabihf"
312 elif test "${triplet%eabi}" != "$triplet" ; then
313 confvars="$confvars arm_eabi"
315 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
316 confvars="$confvars arm_vfp"
320 # multiarch_triplet=${libc_dir#*/}
321 # multiarch_triplet=${multiarch_triplet%/}
322 # tcc_lddir="${libc_dir%%/*}"
323 # if test -n "$multiarch_triplet" ; then
324 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
325 # fi
327 if test -f "/lib/ld-uClibc.so.0" ; then
328 confvars="$confvars uClibc"
330 # gr: maybe for after the release:
331 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
332 # echo "elfinterp $tcc_elfinterp"
336 else
337 # if cross compiling, cannot launch a program, so make a static guess
338 case $cpu in
339 powerpc|mips|s390) bigendian=yes;;
340 esac
343 cat <<EOF
344 Binary directory $bindir
345 TinyCC directory $tccdir
346 Library directory $libdir
347 Include directory $includedir
348 Manual directory $mandir
349 Info directory $infodir
350 Doc directory $docdir
351 Target root prefix $sysroot
352 Source path $source_path
353 C compiler $cc
354 Target OS $targetos
355 CPU $cpu
356 Big Endian $bigendian
357 gprof enabled $gprof
358 cross compilers $build_cross
359 use libgcc $use_libgcc
362 echo "Creating config.mak and config.h"
364 cat >config.mak <<EOF
365 # Automatically generated by configure - do not modify
366 prefix=$prefix
367 bindir=\$(DESTDIR)$bindir
368 tccdir=\$(DESTDIR)$tccdir
369 libdir=\$(DESTDIR)$libdir
370 ln_libdir=$libdir
371 includedir=\$(DESTDIR)$includedir
372 mandir=\$(DESTDIR)$mandir
373 infodir=\$(DESTDIR)$infodir
374 docdir=\$(DESTDIR)$docdir
375 CC=$cc
376 GCC_MAJOR=$gcc_major
377 GCC_MINOR=$gcc_minor
378 HOST_CC=$host_cc
379 AR=$ar
380 STRIP=$strip -s -R .comment -R .note
381 CFLAGS=$CFLAGS
382 LDFLAGS=$LDFLAGS
383 LIBSUF=$LIBSUF
384 EXESUF=$EXESUF
387 print_inc() {
388 if test -n "$2"; then
389 echo "#ifndef $1" >> $TMPH
390 echo "# define $1 \"$2\"" >> $TMPH
391 echo "#endif" >> $TMPH
394 print_mak() {
395 if test -n "$2"; then
396 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
400 echo "/* Automatically generated by configure - do not modify */" > $TMPH
402 print_inc CONFIG_SYSROOT "$sysroot"
403 print_inc CONFIG_TCCDIR "$tccdir"
404 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
405 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
406 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
407 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
408 print_mak CONFIG_LDDIR "$tcc_lddir"
409 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
411 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
412 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
414 if test "$cpu" = "x86" ; then
415 echo "ARCH=i386" >> config.mak
416 echo "#define HOST_I386 1" >> $TMPH
417 elif test "$cpu" = "x86-64" ; then
418 echo "ARCH=x86-64" >> config.mak
419 echo "#define HOST_X86_64 1" >> $TMPH
420 elif test "$cpu" = "armv4l" ; then
421 echo "ARCH=arm" >> config.mak
422 echo "#define HOST_ARM 1" >> $TMPH
423 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
424 elif test "$cpu" = "powerpc" ; then
425 echo "ARCH=ppc" >> config.mak
426 echo "#define HOST_PPC 1" >> $TMPH
427 elif test "$cpu" = "mips" ; then
428 echo "ARCH=mips" >> config.mak
429 echo "#define HOST_MIPS 1" >> $TMPH
430 elif test "$cpu" = "s390" ; then
431 echo "ARCH=s390" >> config.mak
432 echo "#define HOST_S390 1" >> $TMPH
433 elif test "$cpu" = "alpha" ; then
434 echo "ARCH=alpha" >> config.mak
435 echo "#define HOST_ALPHA 1" >> $TMPH
436 else
437 echo "Unsupported CPU"
438 exit 1
441 echo "TARGETOS=$targetos" >> config.mak
443 for v in $confvars ; do
444 echo "CONFIG_$v=yes" >> config.mak
445 done
446 if test "$noldl" = "yes" ; then
447 echo "CONFIG_NOLDL=yes" >> config.mak
449 if test "$mingw32" = "yes" ; then
450 echo "CONFIG_WIN32=yes" >> config.mak
451 echo "#define CONFIG_WIN32 1" >> $TMPH
453 if test "$cygwin" = "yes" ; then
454 echo "#ifndef _WIN32" >> $TMPH
455 echo "# define _WIN32" >> $TMPH
456 echo "#endif" >> $TMPH
457 echo "AR=ar" >> config.mak
459 if test "$bigendian" = "yes" ; then
460 echo "WORDS_BIGENDIAN=yes" >> config.mak
461 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
463 if test "$gprof" = "yes" ; then
464 echo "TARGET_GPROF=yes" >> config.mak
465 echo "#define HAVE_GPROF 1" >> $TMPH
467 if test "$build_cross" = "yes" ; then
468 echo "CONFIG_CROSS=yes" >> config.mak
470 if test "$disable_static" = "yes" ; then
471 echo "DISABLE_STATIC=yes" >> config.mak
473 if test "$disable_rpath" = "yes" ; then
474 echo "DISABLE_RPATH=yes" >> config.mak
476 if test "$strip_binaries" = "yes" ; then
477 echo "STRIP_BINARIES=yes" >> config.mak
479 if test "$use_libgcc" = "yes" ; then
480 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
481 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
483 if test "$have_selinux" = "yes" ; then
484 echo "#define HAVE_SELINUX" >> $TMPH
485 echo "HAVE_SELINUX=yes" >> config.mak
488 version=`head $source_path/VERSION`
489 echo "VERSION=$version" >>config.mak
490 echo "#define TCC_VERSION \"$version\"" >> $TMPH
491 echo "@set VERSION $version" > config.texi
492 echo "SRC_PATH=$source_path" >>config.mak
494 if test "$source_path_used" = "yes" ; then
495 case $source_path in
496 /*) echo "top_srcdir=$source_path";;
497 *) echo "top_srcdir=\$(TOP)/$source_path";;
498 esac >>config.mak
499 else
500 echo 'top_srcdir=$(TOP)' >>config.mak
502 echo 'top_builddir=$(TOP)' >>config.mak
504 diff $TMPH config.h >/dev/null 2>&1
505 if test $? -ne 0 ; then
506 mv -f $TMPH config.h
507 else
508 echo "config.h is unchanged"
511 rm -f $TMPN* $CONFTEST
513 # ---------------------------------------------------------------------------
514 # build tree in object directory if source path is different from current one
516 fn_makelink()
518 tgt=$1/$2
519 case $2 in
520 */*) dn=${2%/*}
521 test -d $dn || mkdir -p $dn
522 case $1 in
523 /*) ;;
524 *) while test $dn ; do
525 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
526 done
528 esac
530 esac
531 ln -sfn $tgt $2
534 if test "$source_path_used" = "yes" ; then
535 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
536 for f in $FILES ; do
537 fn_makelink $source_path $f
538 done
541 # ---------------------------------------------------------------------------