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