arm64: Improve constant generation, with tests.
[tinycc.git] / configure
blobc75d46018e54f1f0576c12b608af46e2c7d34d6e
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 enable_assert="no"
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 host_cc="gcc"
35 ar="ar"
36 strip="strip"
37 cygwin="no"
38 gprof="no"
39 bigendian="no"
40 mingw32="no"
41 LIBSUF=".a"
42 EXESUF=""
43 tcc_sysincludepaths=""
44 tcc_libpaths=""
45 tcc_crtprefix=""
46 tcc_elfinterp=""
47 tcc_lddir=
48 confvars=
50 cpu=`uname -m`
52 # OS specific
53 targetos=`uname -s`
54 case $targetos in
55 MINGW32*) 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 classify_cpu ()
76 cpu="$1"
78 case "$cpu" in
79 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
80 cpu="x86"
82 x86_64|amd64)
83 cpu="x86-64"
85 arm*)
86 case "$cpu" in
87 arm|armv4l)
88 cpuver=4
90 armv5tel|armv5tejl)
91 cpuver=5
93 armv6j|armv6l)
94 cpuver=6
96 armv7a|armv7l)
97 cpuver=7
99 esac
100 cpu="armv4l"
102 aarch64)
103 cpu="aarch64"
105 alpha)
106 cpu="alpha"
108 "Power Macintosh"|ppc|ppc64)
109 cpu="powerpc"
111 mips)
112 cpu="mips"
114 s390)
115 cpu="s390"
118 echo "Unsupported CPU: $cpu"
119 exit 1
121 esac
124 for opt do
125 eval opt=\"$opt\"
126 case "$opt" in
127 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
129 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
131 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
133 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
135 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
137 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
139 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
141 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
143 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
145 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
147 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
149 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
151 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
153 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
155 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
157 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
159 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
161 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
163 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
165 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
167 --extra-libs=*) extralibs=${opt#--extra-libs=}
169 --cpu=*) build_cpu=`echo $opt | cut -d '=' -f 2`
171 --enable-gprof) gprof="yes"
173 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
175 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
177 --enable-cross) build_cross="yes"
179 --enable-assert) enable_assert="yes"
181 --disable-static) disable_static="yes"
183 --disable-rpath) disable_rpath="yes"
185 --strip-binaries) strip_binaries="yes"
187 --with-libgcc) use_libgcc="yes"
189 --with-selinux) have_selinux="yes"
191 --help|-h) show_help="yes"
193 *) echo "configure: WARNING: unrecognized option $opt"
195 esac
196 done
198 classify_cpu "$cpu"
200 # Checking for CFLAGS
201 if test -z "$CFLAGS"; then
202 CFLAGS="-Wall -g -O2"
205 if test "$mingw32" = "yes" ; then
206 if test x"$tccdir" = x""; then
207 tccdir="tcc"
209 if test -z "$prefix" ; then
210 prefix="C:/Program Files/${tccdir}"
212 if test -z "$sharedir" ; then
213 sharedir="${prefix}"
215 execprefix="$prefix"
216 bindir="${prefix}"
217 tccdir="${prefix}"
218 libdir="${prefix}/lib"
219 docdir="${sharedir}/doc"
220 mandir="${sharedir}/man"
221 infodir="${sharedir}/info"
222 LIBSUF=".lib"
223 EXESUF=".exe"
224 else
225 if test -z "$prefix" ; then
226 prefix="/usr/local"
228 if test -z "$sharedir" ; then
229 sharedir="${prefix}/share"
231 if test x"$execprefix" = x""; then
232 execprefix="${prefix}"
234 if test x"$libdir" = x""; then
235 libdir="${execprefix}/lib"
237 if test x"$bindir" = x""; then
238 bindir="${execprefix}/bin"
240 if test x"$tccdir" = x""; then
241 tccdir="tcc"
243 if test x"$docdir" = x""; then
244 docdir="${sharedir}/doc/${tccdir}"
246 if test x"$mandir" = x""; then
247 mandir="${sharedir}/man"
249 if test x"$infodir" = x""; then
250 infodir="${sharedir}/info"
252 tccdir="${libdir}/${tccdir}"
253 fi # mingw32
255 if test x"$includedir" = x""; then
256 includedir="${prefix}/include"
259 if test x"$show_help" = "xyes" ; then
260 cat << EOF
261 Usage: configure [options]
262 Options: [defaults in brackets after descriptions]
264 Standard options:
265 --help print this message
266 --prefix=PREFIX install in PREFIX [$prefix]
267 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
268 [same as prefix]
269 --bindir=DIR user executables in DIR [EPREFIX/bin]
270 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
271 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
272 --includedir=DIR C header files in DIR [PREFIX/include]
273 --sharedir=DIR documentation root DIR [PREFIX/share]
274 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
275 --mandir=DIR man documentation in DIR [SHAREDIR/man]
276 --infodir=DIR info documentation in DIR [SHAREDIR/info]
278 Advanced options (experts only):
279 --source-path=PATH path of source code [$source_path]
280 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
281 --sysroot=PREFIX prepend PREFIX to library/include paths []
282 --cc=CC use C compiler CC [$cc]
283 --extra-cflags= specify compiler flags [$CFLAGS]
284 --extra-ldflags= specify linker options []
285 --cpu=CPU CPU [$cpu]
286 --strip-binaries strip symbol tables from resulting binaries
287 --disable-static make libtcc.so instead of libtcc.a
288 --disable-rpath disable use of -rpath with the above
289 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
290 --enable-mingw32 build windows version on linux with mingw32
291 --enable-cygwin build windows version on windows with cygwin
292 --enable-cross build cross compilers
293 --enable-assert enable debug assertions
294 --with-selinux use mmap for exec mem [needs writable /tmp]
295 --sysincludepaths=... specify system include paths, colon separated
296 --libpaths=... specify system library paths, colon separated
297 --crtprefix=... specify locations of crt?.o, colon separated
298 --elfinterp=... specify elf interpreter
300 #echo "NOTE: The object files are build at the place where configure is launched"
301 exit 1
304 cc="${cross_prefix}${cc}"
305 ar="${cross_prefix}${ar}"
306 strip="${cross_prefix}${strip}"
308 CONFTEST=./conftest$EXESUF
310 if test -z "$cross_prefix" ; then
311 if ! $cc -o $CONFTEST $source_path/conftest.c 2>/dev/null ; then
312 echo "configure: error: '$cc' failed to compile conftest.c."
313 else
314 bigendian="$($CONFTEST bigendian)"
315 gcc_major="$($CONFTEST version)"
316 gcc_minor="$($CONFTEST minor)"
317 if test "$mingw32" = "no" ; then
318 triplet="$($CONFTEST triplet)"
319 if test -f "/usr/lib/$triplet/crti.o" ; then
320 tcc_lddir="lib"
321 multiarch_triplet="$triplet"
322 elif test -f "/usr/lib64/crti.o" ; then
323 tcc_lddir="lib64"
326 if test "$cpu" = "armv4l" ; then
327 if test "${triplet%eabihf}" != "$triplet" ; then
328 confvars="$confvars arm_eabihf"
329 elif test "${triplet%eabi}" != "$triplet" ; then
330 confvars="$confvars arm_eabi"
332 if grep -s -q "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo ; then
333 confvars="$confvars arm_vfp"
337 # multiarch_triplet=${libc_dir#*/}
338 # multiarch_triplet=${multiarch_triplet%/}
339 # tcc_lddir="${libc_dir%%/*}"
340 # if test -n "$multiarch_triplet" ; then
341 # tcc_lddir="$tcc_lddir/$multiarch_triplet"
342 # fi
344 if test -f "/lib/ld-uClibc.so.0" ; then
345 confvars="$confvars uClibc"
347 # gr: maybe for after the release:
348 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
349 # echo "elfinterp $tcc_elfinterp"
353 else
354 # if cross compiling, cannot launch a program, so make a static guess
355 case $cpu in
356 powerpc|mips|s390) bigendian=yes;;
357 esac
360 cat <<EOF
361 Binary directory $bindir
362 TinyCC directory $tccdir
363 Library directory $libdir
364 Include directory $includedir
365 Manual directory $mandir
366 Info directory $infodir
367 Doc directory $docdir
368 Target root prefix $sysroot
369 Source path $source_path
370 C compiler $cc
371 Build CPU $cpu
372 Target OS $targetos
373 Big Endian $bigendian
374 gprof enabled $gprof
375 cross compilers $build_cross
376 use libgcc $use_libgcc
379 echo "Creating config.mak and config.h"
381 cat >config.mak <<EOF
382 # Automatically generated by configure - do not modify
383 prefix=$prefix
384 bindir=\$(DESTDIR)$bindir
385 tccdir=\$(DESTDIR)$tccdir
386 libdir=\$(DESTDIR)$libdir
387 ln_libdir=$libdir
388 includedir=\$(DESTDIR)$includedir
389 mandir=\$(DESTDIR)$mandir
390 infodir=\$(DESTDIR)$infodir
391 docdir=\$(DESTDIR)$docdir
392 CC=$cc
393 GCC_MAJOR=$gcc_major
394 GCC_MINOR=$gcc_minor
395 HOST_CC=$host_cc
396 AR=$ar
397 STRIP=$strip -s -R .comment -R .note
398 CFLAGS=$CFLAGS
399 LDFLAGS=$LDFLAGS
400 LIBSUF=$LIBSUF
401 EXESUF=$EXESUF
404 print_inc() {
405 if test -n "$2"; then
406 echo "#ifndef $1" >> $TMPH
407 echo "# define $1 \"$2\"" >> $TMPH
408 echo "#endif" >> $TMPH
411 print_mak() {
412 if test -n "$2"; then
413 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
417 echo "/* Automatically generated by configure - do not modify */" > $TMPH
419 print_inc CONFIG_SYSROOT "$sysroot"
420 print_inc CONFIG_TCCDIR "$tccdir"
421 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
422 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
423 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
424 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
425 print_mak CONFIG_LDDIR "$tcc_lddir"
426 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
428 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
429 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
431 if test "$cpu" = "x86" ; then
432 echo "ARCH=i386" >> config.mak
433 echo "#define HOST_I386 1" >> $TMPH
434 elif test "$cpu" = "x86-64" ; then
435 echo "ARCH=x86-64" >> config.mak
436 echo "#define HOST_X86_64 1" >> $TMPH
437 elif test "$cpu" = "armv4l" ; then
438 echo "ARCH=arm" >> config.mak
439 echo "#define HOST_ARM 1" >> $TMPH
440 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
441 elif test "$cpu" = "aarch64" ; then
442 echo "ARCH=arm64" >> config.mak
443 echo "#define HOST_ARM64 1" >> $TMPH
444 elif test "$cpu" = "powerpc" ; then
445 echo "ARCH=ppc" >> config.mak
446 echo "#define HOST_PPC 1" >> $TMPH
447 elif test "$cpu" = "mips" ; then
448 echo "ARCH=mips" >> config.mak
449 echo "#define HOST_MIPS 1" >> $TMPH
450 elif test "$cpu" = "s390" ; then
451 echo "ARCH=s390" >> config.mak
452 echo "#define HOST_S390 1" >> $TMPH
453 elif test "$cpu" = "alpha" ; then
454 echo "ARCH=alpha" >> config.mak
455 echo "#define HOST_ALPHA 1" >> $TMPH
456 else
457 echo "Unsupported CPU"
458 exit 1
461 echo "TARGETOS=$targetos" >> config.mak
463 for v in $confvars ; do
464 echo "CONFIG_$v=yes" >> config.mak
465 done
466 if test "$noldl" = "yes" ; then
467 echo "CONFIG_NOLDL=yes" >> config.mak
469 if test "$mingw32" = "yes" ; then
470 echo "CONFIG_WIN32=yes" >> config.mak
471 echo "#define CONFIG_WIN32 1" >> $TMPH
473 if test "$cygwin" = "yes" ; then
474 echo "#ifndef _WIN32" >> $TMPH
475 echo "# define _WIN32" >> $TMPH
476 echo "#endif" >> $TMPH
477 echo "AR=ar" >> config.mak
479 if test "$bigendian" = "yes" ; then
480 echo "WORDS_BIGENDIAN=yes" >> config.mak
481 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
483 if test "$gprof" = "yes" ; then
484 echo "TARGET_GPROF=yes" >> config.mak
485 echo "#define HAVE_GPROF 1" >> $TMPH
487 if test "$build_cross" = "yes" ; then
488 echo "CONFIG_CROSS=yes" >> config.mak
490 if test "$disable_static" = "yes" ; then
491 echo "DISABLE_STATIC=yes" >> config.mak
493 if test "$disable_rpath" = "yes" ; then
494 echo "DISABLE_RPATH=yes" >> config.mak
496 if test "$strip_binaries" = "yes" ; then
497 echo "STRIP_BINARIES=yes" >> config.mak
499 if test "$use_libgcc" = "yes" ; then
500 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
501 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
503 if test "$have_selinux" = "yes" ; then
504 echo "#define HAVE_SELINUX" >> $TMPH
505 echo "HAVE_SELINUX=yes" >> config.mak
507 if test "$enable_assert" = "yes" ; then
508 echo "#define CONFIG_TCC_ASSERT" >> $TMPH
511 version=`head $source_path/VERSION`
512 echo "VERSION=$version" >>config.mak
513 echo "#define TCC_VERSION \"$version\"" >> $TMPH
514 echo "@set VERSION $version" > config.texi
515 echo "SRC_PATH=$source_path" >>config.mak
517 if test "$source_path_used" = "yes" ; then
518 case $source_path in
519 /*) echo "top_srcdir=$source_path";;
520 *) echo "top_srcdir=\$(TOP)/$source_path";;
521 esac >>config.mak
522 else
523 echo 'top_srcdir=$(TOP)' >>config.mak
525 echo 'top_builddir=$(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
554 ln -sfn $tgt $2
557 if test "$source_path_used" = "yes" ; then
558 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
559 for f in $FILES ; do
560 fn_makelink $source_path $f
561 done
564 # ---------------------------------------------------------------------------