Even on Darwin, tcc should display Linux
[tinycc.git] / configure
blobd1cb838b928fa5ecf94c108a3f308888cdf65942
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 disable_static=""
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 ar="ar"
35 strip="strip"
36 cygwin="no"
37 gprof="no"
38 bigendian="no"
39 mingw32="no"
40 LIBSUF=".a"
41 EXESUF=""
42 DLLSUF=".so"
43 tcc_sysincludepaths=""
44 tcc_libpaths=""
45 tcc_crtprefix=""
46 tcc_elfinterp=""
47 triplet=
48 tcc_lddir=
49 confvars=
50 cpu=
52 # OS specific
53 targetos=`uname`
54 case $targetos in
55 MINGW*) mingw32=yes;;
56 MSYS*) mingw32=yes;;
57 CYGWIN*) mingw32=yes; cygwin=yes; cross_prefix="mingw32-";;
58 DragonFly) noldl=yes;;
59 OpenBSD) noldl=yes;;
60 FreeBSD) noldl=yes;;
61 NetBSD) noldl=yes;;
62 *) ;;
63 esac
65 # find source path
66 # XXX: we assume an absolute path is given when launching configure,
67 # except in './configure' case.
68 source_path=${0%configure}
69 source_path=${source_path%/}
70 source_path_used="yes"
71 if test -z "$source_path" -o "$source_path" = "." ; then
72 source_path=`pwd`
73 source_path_used="no"
74 # mingw compilers might not understand cygwin paths
75 if test $cygwin = "yes"; then source_path="."; fi
78 for opt do
79 eval opt=\"$opt\"
80 case "$opt" in
81 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
83 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
85 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
87 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
89 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
91 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
93 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
95 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
97 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
99 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
101 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
103 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
105 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
107 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
109 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
111 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
113 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
115 --extra-libs=*) extralibs="${opt#--extra-libs=}"
117 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
119 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
121 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
123 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
125 --triplet=*) triplet=`echo $opt | cut -d '=' -f 2`
127 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
129 --enable-gprof) gprof="yes"
131 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
133 --enable-cross) build_cross="yes"
135 --disable-static) disable_static="yes"
137 --enable-static) disable_static="no"
139 --disable-rpath) disable_rpath="yes"
141 --strip-binaries) strip_binaries="yes"
143 --with-libgcc) use_libgcc="yes"
145 --with-selinux) have_selinux="yes"
147 --help|-h) show_help="yes"
149 *) echo "configure: WARNING: unrecognized option $opt"
151 esac
152 done
154 if test -z "$cpu" ; then
155 if test -n "$ARCH" ; then
156 cpu="$ARCH"
157 else
158 cpu=`uname -m`
162 case "$cpu" in
163 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
164 cpu="x86"
166 x86_64|amd64|x86-64)
167 cpu="x86_64"
169 arm*)
170 case "$cpu" in
171 arm|armv4l)
172 cpuver=4
174 armv5tel|armv5tejl)
175 cpuver=5
177 armv6j|armv6l)
178 cpuver=6
180 armv7a|armv7l)
181 cpuver=7
183 esac
184 cpu="armv4l"
186 aarch64)
187 cpu="aarch64"
189 alpha)
190 cpu="alpha"
192 "Power Macintosh"|ppc|ppc64)
193 cpu="powerpc"
195 mips)
196 cpu="mips"
198 s390)
199 cpu="s390"
202 cpu="unknown"
204 esac
206 # Checking for CFLAGS
207 if test -z "$CFLAGS"; then
208 CFLAGS="-Wall -g -O2"
211 if test "$mingw32" = "yes" ; then
212 if test x"$tccdir" = x""; then
213 tccdir="tcc"
215 if test -z "$prefix" ; then
216 prefix="C:/Program Files/${tccdir}"
218 if test -z "$sharedir" ; then
219 sharedir="${prefix}"
221 execprefix="$prefix"
222 bindir="${prefix}"
223 tccdir="${prefix}"
224 libdir="${prefix}/lib"
225 docdir="${sharedir}/doc"
226 mandir="${sharedir}/man"
227 infodir="${sharedir}/info"
228 LIBSUF=".lib"
229 EXESUF=".exe"
230 DLLSUF=".dll"
231 else
232 if test -z "$prefix" ; then
233 prefix="/usr/local"
235 if test -z "$sharedir" ; then
236 sharedir="${prefix}/share"
238 if test x"$execprefix" = x""; then
239 execprefix="${prefix}"
241 if test x"$libdir" = x""; then
242 libdir="${execprefix}/lib"
244 if test x"$bindir" = x""; then
245 bindir="${execprefix}/bin"
247 if test x"$docdir" = x""; then
248 docdir="${sharedir}/doc"
250 if test x"$mandir" = x""; then
251 mandir="${sharedir}/man"
253 if test x"$infodir" = x""; then
254 infodir="${sharedir}/info"
256 if test x"$tccdir" = x""; then
257 tccdir="${libdir}/tcc"
259 fi # mingw32
261 if test x"$includedir" = x""; then
262 includedir="${prefix}/include"
265 if test x"$show_help" = "xyes" ; then
266 cat << EOF
267 Usage: configure [options]
268 Options: [defaults in brackets after descriptions]
270 Standard options:
271 --help print this message
272 --prefix=PREFIX install in PREFIX [$prefix]
273 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
274 [same as prefix]
275 --bindir=DIR user executables in DIR [EPREFIX/bin]
276 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
277 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
278 --includedir=DIR C header files in DIR [PREFIX/include]
279 --sharedir=DIR documentation root DIR [PREFIX/share]
280 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
281 --mandir=DIR man documentation in DIR [SHAREDIR/man]
282 --infodir=DIR info documentation in DIR [SHAREDIR/info]
284 Advanced options (experts only):
285 --source-path=PATH path of source code [$source_path]
286 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
287 --sysroot=PREFIX prepend PREFIX to library/include paths []
288 --cc=CC use C compiler CC [$cc]
289 --ar=AR create archives using AR [$ar]
290 --extra-cflags= specify compiler flags [$CFLAGS]
291 --extra-ldflags= specify linker options []
292 --cpu=CPU CPU [$cpu]
293 --strip-binaries strip symbol tables from resulting binaries
294 --disable-static make libtcc.so instead of libtcc.a
295 --enable-static make libtcc.a instead of libtcc.dll (win32)
296 --disable-rpath disable use of -rpath with the above
297 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
298 --enable-mingw32 build windows version on linux with mingw32
299 --enable-cross build cross compilers
300 --with-selinux use mmap for executable memory (with tcc -run)
301 --sysincludepaths=... specify system include paths, colon separated
302 --libpaths=... specify system library paths, colon separated
303 --crtprefix=... specify locations of crt?.o, colon separated
304 --elfinterp=... specify elf interpreter
305 --triplet=... specify system library/include directory triplet
307 #echo "NOTE: The object files are build at the place where configure is launched"
308 exit 1
311 cc="${cross_prefix}${cc}"
312 ar="${cross_prefix}${ar}"
313 strip="${cross_prefix}${strip}"
315 CONFTEST=./conftest$EXESUF
316 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
317 echo "configure: error: '$cc' failed to compile conftest.c."
318 else
319 gcc_major="$($CONFTEST version)"
320 gcc_minor="$($CONFTEST minor)"
323 if test -z "$cross_prefix" ; then
324 bigendian="$($CONFTEST bigendian)"
325 if test "$mingw32" = "no" ; then
327 if test -z "$triplet"; then
328 tt="$($CONFTEST triplet)"
329 if test -n "$tt" -a -f "/usr/lib/$tt/crti.o" ; then
330 triplet="$tt"
334 if test -z "$triplet"; then
335 if test $cpu = "x86_64" -o $cpu = "aarch64" ; then
336 if test -f "/usr/lib64/crti.o" ; then
337 tcc_lddir="lib64"
342 if test "$cpu" = "armv4l" ; then
343 if test "${triplet%eabihf}" != "$triplet" ; then
344 confvars="$confvars arm_eabihf"
345 elif test "${triplet%eabi}" != "$triplet" ; then
346 confvars="$confvars arm_eabi"
348 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
349 confvars="$confvars arm_vfp"
353 if test -f "/lib/ld-uClibc.so.0" ; then
354 confvars="$confvars uClibc"
357 else
358 # if cross compiling, cannot launch a program, so make a static guess
359 case $cpu in
360 powerpc|mips|s390) bigendian=yes;;
361 esac
364 # a final configuration tuning
365 $cc -v --help > cc_help.txt 2>&1
366 W_OPTIONS="declaration-after-statement"
367 for i in $W_OPTIONS; do
368 O_PRESENT="$(grep -- -W$i cc_help.txt)"
369 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -W$i"; fi
370 done
371 W_OPTIONS="pointer-sign sign-compare unused-result"
372 for i in $W_OPTIONS; do
373 O_PRESENT="$(grep -- -W$i cc_help.txt)"
374 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -Wno-$i"; fi
375 done
376 F_OPTIONS="strict-aliasing"
377 for i in $F_OPTIONS; do
378 O_PRESENT="$(grep -- -f$i cc_help.txt)"
379 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -fno-$i"; fi
380 done
381 rm -f cc_help.txt
383 fcho() { if test -n "$2"; then echo "$1$2"; else echo "$1-"; fi }
385 echo "Binary directory $bindir"
386 echo "TinyCC directory $tccdir"
387 echo "Library directory $libdir"
388 echo "Include directory $includedir"
389 echo "Manual directory $mandir"
390 echo "Info directory $infodir"
391 echo "Doc directory $docdir"
392 fcho "Target root prefix " "$sysroot"
393 echo "Source path $source_path"
394 echo "C compiler $cc"
395 echo "Target OS $targetos"
396 echo "CPU $cpu"
397 echo "Big Endian $bigendian"
398 echo "Profiling $gprof"
399 echo "Cross compilers $build_cross"
400 echo "Use libgcc $use_libgcc"
401 fcho "Triplet " "$triplet"
403 echo "Creating config.mak and config.h"
405 cat >config.mak <<EOF
406 # Automatically generated by configure - do not modify
407 prefix=$prefix
408 bindir=\$(DESTDIR)$bindir
409 tccdir=\$(DESTDIR)$tccdir
410 libdir=\$(DESTDIR)$libdir
411 includedir=\$(DESTDIR)$includedir
412 mandir=\$(DESTDIR)$mandir
413 infodir=\$(DESTDIR)$infodir
414 docdir=\$(DESTDIR)$docdir
415 CC=$cc
416 GCC_MAJOR=$gcc_major
417 GCC_MINOR=$gcc_minor
418 AR=$ar
419 STRIP=$strip -s -R .comment -R .note
420 CFLAGS=$CFLAGS
421 LDFLAGS=$LDFLAGS
422 LIBSUF=$LIBSUF
423 EXESUF=$EXESUF
424 DLLSUF=$DLLSUF
427 print_inc() {
428 if test -n "$2"; then
429 echo "#ifndef $1" >> $TMPH
430 echo "# define $1 \"$2\"" >> $TMPH
431 echo "#endif" >> $TMPH
434 print_mak() {
435 if test -n "$2"; then
436 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
440 echo "/* Automatically generated by configure - do not modify */" > $TMPH
442 print_inc CONFIG_SYSROOT "$sysroot"
443 print_inc CONFIG_TCCDIR "$tccdir"
444 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
445 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
446 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
447 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
448 print_mak CONFIG_LDDIR "$tcc_lddir"
449 print_mak CONFIG_TRIPLET "$triplet"
451 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
452 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
454 if test "$cpu" = "x86" ; then
455 echo "ARCH=i386" >> config.mak
456 elif test "$cpu" = "x86_64" ; then
457 echo "ARCH=x86_64" >> config.mak
458 elif test "$cpu" = "armv4l" ; then
459 echo "ARCH=arm" >> config.mak
460 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
461 elif test "$cpu" = "aarch64" ; then
462 echo "ARCH=arm64" >> config.mak
463 elif test "$cpu" = "powerpc" ; then
464 echo "ARCH=ppc" >> config.mak
465 elif test "$cpu" = "mips" ; then
466 echo "ARCH=mips" >> config.mak
467 elif test "$cpu" = "s390" ; then
468 echo "ARCH=s390" >> config.mak
469 elif test "$cpu" = "alpha" ; then
470 echo "ARCH=alpha" >> config.mak
471 else
472 echo "Unsupported CPU"
473 exit 1
476 echo "TARGETOS=$targetos" >> config.mak
478 for v in $confvars ; do
479 echo "CONFIG_$v=yes" >> config.mak
480 done
481 if test "$noldl" = "yes" ; then
482 echo "CONFIG_NOLDL=yes" >> config.mak
484 if test "$mingw32" = "yes" ; then
485 echo "CONFIG_WIN32=yes" >> config.mak
487 if test "$bigendian" = "yes" ; then
488 echo "WORDS_BIGENDIAN=yes" >> config.mak
489 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
491 if test "$gprof" = "yes" ; then
492 echo "TARGET_GPROF=yes" >> config.mak
493 echo "#define HAVE_GPROF 1" >> $TMPH
495 if test "$build_cross" = "yes" ; then
496 echo "CONFIG_CROSS=yes" >> config.mak
498 if test -n "$disable_static" ; then
499 echo "DISABLE_STATIC=$disable_static" >> config.mak
501 if test "$disable_rpath" = "yes" ; then
502 echo "DISABLE_RPATH=yes" >> config.mak
504 if test "$strip_binaries" = "yes" ; then
505 echo "STRIP_BINARIES=yes" >> config.mak
507 if test "$use_libgcc" = "yes" ; then
508 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
509 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
511 if test "$have_selinux" = "yes" ; then
512 echo "#define HAVE_SELINUX" >> $TMPH
513 echo "HAVE_SELINUX=yes" >> config.mak
516 version=`head $source_path/VERSION`
517 echo "VERSION = $version" >> config.mak
518 echo "#define TCC_VERSION \"$version\"" >> $TMPH
519 echo "@set VERSION $version" > config.texi
521 if test "$source_path_used" = "yes" ; then
522 case $source_path in
523 /*) echo "TOPSRC=$source_path";;
524 *) echo "TOPSRC=\$(TOP)/$source_path";;
525 esac >>config.mak
526 else
527 echo 'TOPSRC=$(TOP)' >>config.mak
530 diff $TMPH config.h >/dev/null 2>&1
531 if test $? -ne 0 ; then
532 mv -f $TMPH config.h
533 else
534 echo "config.h is unchanged"
537 rm -f $TMPN* $CONFTEST
539 # ---------------------------------------------------------------------------
540 # build tree in object directory if source path is different from current one
542 fn_makelink()
544 tgt=$1/$2
545 case $2 in
546 */*) dn=${2%/*}
547 test -d $dn || mkdir -p $dn
548 case $1 in
549 /*) ;;
550 *) while test $dn ; do
551 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
552 done
554 esac
556 esac
558 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
561 if test "$source_path_used" = "yes" ; then
562 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
563 for f in $FILES ; do
564 fn_makelink $source_path $f
565 done
568 # ---------------------------------------------------------------------------