tccpp_new/delete and other cleanups
[tinycc.git] / configure
blob003f53873960cad5e4d5d2fe15e11f9dbaeea02c
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 ar="ar"
34 strip="strip"
35 cygwin="no"
36 gprof="no"
37 bigendian="no"
38 mingw32="no"
39 LIBSUF=".a"
40 EXESUF=""
41 tcc_sysincludepaths=""
42 tcc_libpaths=""
43 tcc_crtprefix=""
44 tcc_elfinterp=""
45 tcc_lddir=
46 confvars=
47 cpu=
49 # OS specific
50 targetos=`uname`
51 case $targetos in
52 MINGW*) mingw32=yes;;
53 MSYS*) mingw32=yes;;
54 DragonFly) noldl=yes;;
55 OpenBSD) noldl=yes;;
56 FreeBSD) noldl=yes;;
57 NetBSD) 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 for opt do
73 eval opt=\"$opt\"
74 case "$opt" in
75 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
77 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
79 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
81 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
83 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
85 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
87 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
89 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
91 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
93 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
95 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
97 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
99 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
101 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
103 --ar=*) ar=`echo $opt | cut -d '=' -f 2`
105 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
107 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
109 --extra-libs=*) extralibs="${opt#--extra-libs=}"
111 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
113 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
115 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
117 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
119 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
121 --enable-gprof) gprof="yes"
123 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
125 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
127 --enable-cross) build_cross="yes"
129 --disable-static) disable_static="yes"
131 --disable-rpath) disable_rpath="yes"
133 --strip-binaries) strip_binaries="yes"
135 --with-libgcc) use_libgcc="yes"
137 --with-selinux) have_selinux="yes"
139 --help|-h) show_help="yes"
141 *) echo "configure: WARNING: unrecognized option $opt"
143 esac
144 done
146 if test -z "$cpu" ; then
147 if test -n "$ARCH" ; then
148 cpu="$ARCH"
149 else
150 cpu=`uname -m`
154 case "$cpu" in
155 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
156 cpu="x86"
158 x86_64|amd64)
159 cpu="x86-64"
161 arm*)
162 case "$cpu" in
163 arm|armv4l)
164 cpuver=4
166 armv5tel|armv5tejl)
167 cpuver=5
169 armv6j|armv6l)
170 cpuver=6
172 armv7a|armv7l)
173 cpuver=7
175 esac
176 cpu="armv4l"
178 aarch64)
179 cpu="aarch64"
181 alpha)
182 cpu="alpha"
184 "Power Macintosh"|ppc|ppc64)
185 cpu="powerpc"
187 mips)
188 cpu="mips"
190 s390)
191 cpu="s390"
194 cpu="unknown"
196 esac
198 # Checking for CFLAGS
199 if test -z "$CFLAGS"; then
200 CFLAGS="-Wall -g -O2"
203 if test "$mingw32" = "yes" ; then
204 if test x"$tccdir" = x""; then
205 tccdir="tcc"
207 if test -z "$prefix" ; then
208 prefix="C:/Program Files/${tccdir}"
210 if test -z "$sharedir" ; then
211 sharedir="${prefix}"
213 execprefix="$prefix"
214 bindir="${prefix}"
215 tccdir="${prefix}"
216 libdir="${prefix}/lib"
217 docdir="${sharedir}/doc"
218 mandir="${sharedir}/man"
219 infodir="${sharedir}/info"
220 LIBSUF=".lib"
221 EXESUF=".exe"
222 else
223 if test -z "$prefix" ; then
224 prefix="/usr/local"
226 if test -z "$sharedir" ; then
227 sharedir="${prefix}/share"
229 if test x"$execprefix" = x""; then
230 execprefix="${prefix}"
232 if test x"$libdir" = x""; then
233 libdir="${execprefix}/lib"
235 if test x"$bindir" = x""; then
236 bindir="${execprefix}/bin"
238 if test x"$docdir" = x""; then
239 docdir="${sharedir}/doc"
241 if test x"$mandir" = x""; then
242 mandir="${sharedir}/man"
244 if test x"$infodir" = x""; then
245 infodir="${sharedir}/info"
247 if test x"$tccdir" = x""; then
248 tccdir="${libdir}/tcc"
250 fi # mingw32
252 if test x"$includedir" = x""; then
253 includedir="${prefix}/include"
256 if test x"$show_help" = "xyes" ; then
257 cat << EOF
258 Usage: configure [options]
259 Options: [defaults in brackets after descriptions]
261 Standard options:
262 --help print this message
263 --prefix=PREFIX install in PREFIX [$prefix]
264 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
265 [same as prefix]
266 --bindir=DIR user executables in DIR [EPREFIX/bin]
267 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
268 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
269 --includedir=DIR C header files in DIR [PREFIX/include]
270 --sharedir=DIR documentation root DIR [PREFIX/share]
271 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
272 --mandir=DIR man documentation in DIR [SHAREDIR/man]
273 --infodir=DIR info documentation in DIR [SHAREDIR/info]
275 Advanced options (experts only):
276 --source-path=PATH path of source code [$source_path]
277 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
278 --sysroot=PREFIX prepend PREFIX to library/include paths []
279 --cc=CC use C compiler CC [$cc]
280 --ar=AR create archives using AR [$ar]
281 --extra-cflags= specify compiler flags [$CFLAGS]
282 --extra-ldflags= specify linker options []
283 --cpu=CPU CPU [$cpu]
284 --strip-binaries strip symbol tables from resulting binaries
285 --disable-static make libtcc.so instead of libtcc.a
286 --disable-rpath disable use of -rpath with the above
287 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
288 --enable-mingw32 build windows version on linux with mingw32
289 --enable-cygwin build windows version on windows with cygwin
290 --enable-cross build cross compilers
291 --with-selinux use mmap for exec mem [needs writable /tmp]
292 --sysincludepaths=... specify system include paths, colon separated
293 --libpaths=... specify system library paths, colon separated
294 --crtprefix=... specify locations of crt?.o, colon separated
295 --elfinterp=... specify elf interpreter
297 #echo "NOTE: The object files are build at the place where configure is launched"
298 exit 1
301 cc="${cross_prefix}${cc}"
302 ar="${cross_prefix}${ar}"
303 strip="${cross_prefix}${strip}"
305 CONFTEST=./conftest$EXESUF
307 if test -z "$cross_prefix" ; then
308 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
309 echo "configure: error: '$cc' failed to compile conftest.c."
310 else
311 bigendian="$($CONFTEST bigendian)"
312 gcc_major="$($CONFTEST version)"
313 gcc_minor="$($CONFTEST minor)"
314 if test "$mingw32" = "no" ; then
315 triplet="$($CONFTEST triplet)"
316 if test -f "/usr/lib/$triplet/crti.o" ; then
317 tcc_lddir="lib"
318 multiarch_triplet="$triplet"
319 elif test "$cpu" != "x86" -a -f "/usr/lib64/crti.o" ; then
320 tcc_lddir="lib64"
323 if test "$cpu" = "armv4l" ; then
324 if test "${triplet%eabihf}" != "$triplet" ; then
325 confvars="$confvars arm_eabihf"
326 elif test "${triplet%eabi}" != "$triplet" ; then
327 confvars="$confvars arm_eabi"
329 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
330 confvars="$confvars arm_vfp"
334 # multiarch_triplet=${libc_dir#*/}
335 # multiarch_triplet=${multiarch_triplet%/}
336 # tcc_lddir="${libc_dir%%/*}"
337 # if test -n "$multiarch_triplet" ; then
338 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
339 # fi
341 if test -f "/lib/ld-uClibc.so.0" ; then
342 confvars="$confvars uClibc"
345 # if test -z "$tcc_elfinterp" ; then
346 # tcc_elfinterp="$(ldd $CONFTEST | grep '/ld-.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
347 # fi
351 else
352 # if cross compiling, cannot launch a program, so make a static guess
353 case $cpu in
354 powerpc|mips|s390) bigendian=yes;;
355 esac
358 # a final configuration tuning
359 $cc -v --help > cc_help.txt 2>&1
360 W_OPTIONS="declaration-after-statement"
361 for i in $W_OPTIONS; do
362 O_PRESENT="$(grep -- -W$i cc_help.txt)"
363 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -W$i"; fi
364 done
365 W_OPTIONS="deprecated-declarations strict-aliasing pointer-sign sign-compare unused-result uninitialized"
366 for i in $W_OPTIONS; do
367 O_PRESENT="$(grep -- -W$i cc_help.txt)"
368 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -Wno-$i"; fi
369 done
370 F_OPTIONS="strict-aliasing"
371 for i in $F_OPTIONS; do
372 O_PRESENT="$(grep -- -f$i cc_help.txt)"
373 if test -n "$O_PRESENT"; then CFLAGS="$CFLAGS -fno-$i"; fi
374 done
375 rm -f cc_help.txt
377 echo "Binary directory $bindir"
378 echo "TinyCC directory $tccdir"
379 echo "Library directory $libdir"
380 echo "Include directory $includedir"
381 echo "Manual directory $mandir"
382 echo "Info directory $infodir"
383 echo "Doc directory $docdir"
384 echo "Target root prefix $sysroot"
385 echo "Source path $source_path"
386 echo "C compiler $cc"
387 echo "Target OS $targetos"
388 echo "CPU $cpu"
389 echo "Big Endian $bigendian"
390 echo "gprof enabled $gprof"
391 echo "cross compilers $build_cross"
392 echo "use libgcc $use_libgcc"
394 echo "Creating config.mak and config.h"
396 cat >config.mak <<EOF
397 # Automatically generated by configure - do not modify
398 prefix=$prefix
399 bindir=\$(DESTDIR)$bindir
400 tccdir=\$(DESTDIR)$tccdir
401 libdir=\$(DESTDIR)$libdir
402 ln_libdir=$libdir
403 includedir=\$(DESTDIR)$includedir
404 mandir=\$(DESTDIR)$mandir
405 infodir=\$(DESTDIR)$infodir
406 docdir=\$(DESTDIR)$docdir
407 CC=$cc
408 GCC_MAJOR=$gcc_major
409 GCC_MINOR=$gcc_minor
410 AR=$ar
411 STRIP=$strip -s -R .comment -R .note
412 CFLAGS=$CFLAGS
413 LDFLAGS=$LDFLAGS
414 LIBSUF=$LIBSUF
415 EXESUF=$EXESUF
418 print_inc() {
419 if test -n "$2"; then
420 echo "#ifndef $1" >> $TMPH
421 echo "# define $1 \"$2\"" >> $TMPH
422 echo "#endif" >> $TMPH
425 print_mak() {
426 if test -n "$2"; then
427 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
431 echo "/* Automatically generated by configure - do not modify */" > $TMPH
433 print_inc CONFIG_SYSROOT "$sysroot"
434 print_inc CONFIG_TCCDIR "$tccdir"
435 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
436 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
437 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
438 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
439 print_mak CONFIG_LDDIR "$tcc_lddir"
440 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
442 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
443 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
445 if test "$cpu" = "x86" ; then
446 echo "ARCH=i386" >> config.mak
447 elif test "$cpu" = "x86-64" ; then
448 echo "ARCH=x86-64" >> config.mak
449 elif test "$cpu" = "armv4l" ; then
450 echo "ARCH=arm" >> config.mak
451 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
452 elif test "$cpu" = "aarch64" ; then
453 echo "ARCH=arm64" >> config.mak
454 elif test "$cpu" = "powerpc" ; then
455 echo "ARCH=ppc" >> config.mak
456 elif test "$cpu" = "mips" ; then
457 echo "ARCH=mips" >> config.mak
458 elif test "$cpu" = "s390" ; then
459 echo "ARCH=s390" >> config.mak
460 elif test "$cpu" = "alpha" ; then
461 echo "ARCH=alpha" >> config.mak
462 else
463 echo "Unsupported CPU"
464 exit 1
467 echo "TARGETOS=$targetos" >> config.mak
469 for v in $confvars ; do
470 echo "CONFIG_$v=yes" >> config.mak
471 done
472 if test "$noldl" = "yes" ; then
473 echo "CONFIG_NOLDL=yes" >> config.mak
475 if test "$mingw32" = "yes" ; then
476 echo "CONFIG_WIN32=yes" >> config.mak
478 if test "$cygwin" = "yes" ; then
479 echo "#ifndef _WIN32" >> $TMPH
480 echo "# define _WIN32" >> $TMPH
481 echo "#endif" >> $TMPH
482 echo "AR=ar" >> config.mak
484 if test "$bigendian" = "yes" ; then
485 echo "WORDS_BIGENDIAN=yes" >> config.mak
486 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
488 if test "$gprof" = "yes" ; then
489 echo "TARGET_GPROF=yes" >> config.mak
490 echo "#define HAVE_GPROF 1" >> $TMPH
492 if test "$build_cross" = "yes" ; then
493 echo "CONFIG_CROSS=yes" >> config.mak
495 if test "$disable_static" = "yes" ; then
496 echo "DISABLE_STATIC=yes" >> config.mak
498 if test "$disable_rpath" = "yes" ; then
499 echo "DISABLE_RPATH=yes" >> config.mak
501 if test "$strip_binaries" = "yes" ; then
502 echo "STRIP_BINARIES=yes" >> config.mak
504 if test "$use_libgcc" = "yes" ; then
505 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
506 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
508 if test "$have_selinux" = "yes" ; then
509 echo "#define HAVE_SELINUX" >> $TMPH
510 echo "HAVE_SELINUX=yes" >> config.mak
513 version=`head $source_path/VERSION`
514 echo "VERSION = $version" >> config.mak
515 echo "#define TCC_VERSION \"$version\"" >> $TMPH
516 echo "@set VERSION $version" > config.texi
518 if test "$source_path_used" = "yes" ; then
519 case $source_path in
520 /*) echo "TOPSRC=$source_path";;
521 *) echo "TOPSRC=\$(TOP)/$source_path";;
522 esac >>config.mak
523 else
524 echo 'TOPSRC=$(TOP)' >>config.mak
527 diff $TMPH config.h >/dev/null 2>&1
528 if test $? -ne 0 ; then
529 mv -f $TMPH config.h
530 else
531 echo "config.h is unchanged"
534 rm -f $TMPN* $CONFTEST
536 # ---------------------------------------------------------------------------
537 # build tree in object directory if source path is different from current one
539 fn_makelink()
541 tgt=$1/$2
542 case $2 in
543 */*) dn=${2%/*}
544 test -d $dn || mkdir -p $dn
545 case $1 in
546 /*) ;;
547 *) while test $dn ; do
548 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
549 done
551 esac
553 esac
555 ln -sfn $tgt $2 || ( echo "ln failed. Using cp instead."; cp -f $1/$2 $2 )
558 if test "$source_path_used" = "yes" ; then
559 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile tests/pp/Makefile"
560 for f in $FILES ; do
561 fn_makelink $source_path $f
562 done
565 # ---------------------------------------------------------------------------