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