22fbfbe755c80d91055a8bfae970799b046538af
[tinycc.git] / configure
blob22fbfbe755c80d91055a8bfae970799b046538af
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 triplet="$($CONFTEST triplet)"
300 if test -f "/usr/lib/$triplet/crti.o" ; then
301 tcc_lddir="lib/$triplet"
302 multiarch_triplet="$triplet"
303 elif test -f "/usr/lib64/crti.o" ; then
304 tcc_lddir="lib64"
307 # gr: FIXME
308 # ldd $CONFTEST gives (ubuntu 8)
309 # linux-gate.so.1 => (0xb7fc3000)
310 # libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e37000)
311 # /lib/ld-linux.so.2 (0xb7fa9000)
312 # result is crap:
313 # CONFIG_LDDIR="lib/tls/i686/cmov"
314 # CONFIG_MUADIR="tls/i686/cmov"
316 # multiarch_triplet=${libc_dir#*/}
317 # multiarch_triplet=${multiarch_triplet%/}
318 # tcc_lddir="${libc_dir%%/*}"
319 # if test -n "$multiarch_triplet" ; then
320 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
321 # fi
323 # gr: maybe for after the release:
324 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
325 # #echo "elfinterp $tcc_elfinterp"
329 else
330 # if cross compiling, cannot launch a program, so make a static guess
331 case $cpu in
332 powerpc|mips|s390) bigendian=yes;;
333 esac
336 # gr: maybe for after the release:
337 # run compiler to see if it supports FLAG, if yes add to CFLAGS
338 #cc_option() {
339 # if $cc $CFLAGS $1 -S -o /dev/null -xc conftest.c >/dev/null 2>&1; then
340 # CFLAGS="$CFLAGS $1"; else if test -n "$2"; then
341 # CFLAGS="$CFLAGS $2"; fi; fi
343 #cc_option -fno-strict-aliasing
344 #cc_option -Wno-pointer-sign
345 #cc_option -Wno-sign-compare
346 #cc_option -Wno-unused-result -D_FORTIFY_SOURCE=0
348 cat <<EOF
349 Binary directory $bindir
350 TinyCC directory $tccdir
351 Library directory $libdir
352 Include directory $includedir
353 Manual directory $mandir
354 Info directory $infodir
355 Doc directory $docdir
356 Target root prefix $sysroot
357 Source path $source_path
358 C compiler $cc
359 Target OS $targetos
360 CPU $cpu
361 Big Endian $bigendian
362 gprof enabled $gprof
363 cross compilers $build_cross
364 use libgcc $use_libgcc
367 echo "Creating config.mak and config.h"
369 cat >config.mak <<EOF
370 # Automatically generated by configure - do not modify
371 prefix=$prefix
372 bindir=\$(DESTDIR)$bindir
373 tccdir=\$(DESTDIR)$tccdir
374 libdir=\$(DESTDIR)$libdir
375 ln_libdir=$libdir
376 includedir=\$(DESTDIR)$includedir
377 mandir=\$(DESTDIR)$mandir
378 infodir=\$(DESTDIR)$infodir
379 docdir=\$(DESTDIR)$docdir
380 CC=$cc
381 GCC_MAJOR=$gcc_major
382 GCC_MINOR=$gcc_minor
383 HOST_CC=$host_cc
384 AR=$ar
385 STRIP=$strip -s -R .comment -R .note
386 CFLAGS=$CFLAGS
387 LDFLAGS=$LDFLAGS
388 LIBSUF=$LIBSUF
389 EXESUF=$EXESUF
392 print_def() {
393 if test -n "$2"; then
394 echo "#ifndef $1" >> $TMPH
395 echo "# define $1 \"$2\"" >> $TMPH
396 echo "#endif" >> $TMPH
400 echo "/* Automatically generated by configure - do not modify */" > $TMPH
402 print_def CONFIG_SYSROOT "$sysroot"
403 print_def CONFIG_TCCDIR "$tccdir"
404 print_def CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
405 print_def CONFIG_TCC_LIBPATHS "$tcc_libpaths"
406 print_def CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
407 print_def CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
408 print_def CONFIG_MULTIARCHDIR "$multiarch_triplet"
409 print_def CONFIG_LDDIR "$tcc_lddir"
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 if test "$noldl" = "yes" ; then
444 echo "CONFIG_NOLDL=yes" >> config.mak
446 if test "$mingw32" = "yes" ; then
447 echo "CONFIG_WIN32=yes" >> config.mak
448 echo "#define CONFIG_WIN32 1" >> $TMPH
450 if test "$cygwin" = "yes" ; then
451 echo "#ifndef _WIN32" >> $TMPH
452 echo "# define _WIN32" >> $TMPH
453 echo "#endif" >> $TMPH
454 echo "AR=ar" >> config.mak
456 if test "$bigendian" = "yes" ; then
457 echo "WORDS_BIGENDIAN=yes" >> config.mak
458 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
460 if test "$gprof" = "yes" ; then
461 echo "TARGET_GPROF=yes" >> config.mak
462 echo "#define HAVE_GPROF 1" >> $TMPH
464 if test "$build_cross" = "yes" ; then
465 echo "CONFIG_CROSS=yes" >> config.mak
467 if test "$disable_static" = "yes" ; then
468 echo "DISABLE_STATIC=yes" >> config.mak
470 if test "$disable_rpath" = "yes" ; then
471 echo "DISABLE_RPATH=yes" >> config.mak
473 if test "$strip_binaries" = "yes" ; then
474 echo "STRIP_BINARIES=yes" >> config.mak
476 if test "$use_libgcc" = "yes" ; then
477 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
478 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
480 if test "$have_selinux" = "yes" ; then
481 echo "#define HAVE_SELINUX" >> $TMPH
482 echo "HAVE_SELINUX=yes" >> config.mak
485 version=`head $source_path/VERSION`
486 echo "VERSION=$version" >>config.mak
487 echo "#define TCC_VERSION \"$version\"" >> $TMPH
488 echo "@set VERSION $version" > config.texi
489 echo "SRC_PATH=$source_path" >>config.mak
491 if test "$source_path_used" = "yes" ; then
492 case $source_path in
493 /*) echo "top_srcdir=$source_path";;
494 *) echo "top_srcdir=\$(TOP)/$source_path";;
495 esac >>config.mak
496 else
497 echo 'top_srcdir=$(TOP)' >>config.mak
499 echo 'top_builddir=$(TOP)' >>config.mak
501 diff $TMPH config.h >/dev/null 2>&1
502 if test $? -ne 0 ; then
503 mv -f $TMPH config.h
504 else
505 echo "config.h is unchanged"
508 rm -f $TMPN* $CONFTEST
510 # ---------------------------------------------------------------------------
511 # build tree in object directory if source path is different from current one
513 fn_makelink()
515 tgt=$1/$2
516 case $2 in
517 */*) dn=${2%/*}
518 test -d $dn || mkdir -p $dn
519 case $1 in
520 /*) ;;
521 *) while test $dn ; do
522 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
523 done
525 esac
527 esac
528 ln -sfn $tgt $2
531 if test "$source_path_used" = "yes" ; then
532 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
533 for f in $FILES ; do
534 fn_makelink $source_path $f
535 done
538 # ---------------------------------------------------------------------------