win64: fix resource file support
[tinycc.git] / configure
blobf6df9adae9d1af3b392d8d47b11f653c9f4cc022
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 alpha)
103 cpu="alpha"
105 "Power Macintosh"|ppc|ppc64)
106 cpu="powerpc"
108 mips)
109 cpu="mips"
111 s390)
112 cpu="s390"
115 echo "Unsupported CPU: $cpu"
116 exit 1
118 esac
121 for opt do
122 eval opt=\"$opt\"
123 case "$opt" in
124 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
126 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
128 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
130 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
132 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
134 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
136 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
138 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
140 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
142 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
144 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
146 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
148 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
150 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
152 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
154 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
156 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
158 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
160 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
162 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
164 --extra-libs=*) extralibs=${opt#--extra-libs=}
166 --cpu=*) build_cpu=`echo $opt | cut -d '=' -f 2`
168 --enable-gprof) gprof="yes"
170 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
172 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
174 --enable-cross) build_cross="yes"
176 --enable-assert) enable_assert="yes"
178 --disable-static) disable_static="yes"
180 --disable-rpath) disable_rpath="yes"
182 --strip-binaries) strip_binaries="yes"
184 --with-libgcc) use_libgcc="yes"
186 --with-selinux) have_selinux="yes"
188 --help|-h) show_help="yes"
190 *) echo "configure: WARNING: unrecognized option $opt"
192 esac
193 done
195 classify_cpu "$cpu"
197 # Checking for CFLAGS
198 if test -z "$CFLAGS"; then
199 CFLAGS="-Wall -g -O2"
202 if test "$mingw32" = "yes" ; then
203 if test x"$tccdir" = x""; then
204 tccdir="tcc"
206 if test -z "$prefix" ; then
207 prefix="C:/Program Files/${tccdir}"
209 if test -z "$sharedir" ; then
210 sharedir="${prefix}"
212 execprefix="$prefix"
213 bindir="${prefix}"
214 tccdir="${prefix}"
215 libdir="${prefix}/lib"
216 docdir="${sharedir}/doc"
217 mandir="${sharedir}/man"
218 infodir="${sharedir}/info"
219 LIBSUF=".lib"
220 EXESUF=".exe"
221 else
222 if test -z "$prefix" ; then
223 prefix="/usr/local"
225 if test -z "$sharedir" ; then
226 sharedir="${prefix}/share"
228 if test x"$execprefix" = x""; then
229 execprefix="${prefix}"
231 if test x"$libdir" = x""; then
232 libdir="${execprefix}/lib"
234 if test x"$bindir" = x""; then
235 bindir="${execprefix}/bin"
237 if test x"$tccdir" = x""; then
238 tccdir="tcc"
240 if test x"$docdir" = x""; then
241 docdir="${sharedir}/doc/${tccdir}"
243 if test x"$mandir" = x""; then
244 mandir="${sharedir}/man"
246 if test x"$infodir" = x""; then
247 infodir="${sharedir}/info"
249 tccdir="${libdir}/${tccdir}"
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 --extra-cflags= specify compiler flags [$CFLAGS]
281 --extra-ldflags= specify linker options []
282 --cpu=CPU CPU [$cpu]
283 --strip-binaries strip symbol tables from resulting binaries
284 --disable-static make libtcc.so instead of libtcc.a
285 --disable-rpath disable use of -rpath with the above
286 --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
287 --enable-mingw32 build windows version on linux with mingw32
288 --enable-cygwin build windows version on windows with cygwin
289 --enable-cross build cross compilers
290 --enable-assert enable debug assertions
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 -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"
344 # gr: maybe for after the release:
345 # tcc_elfinterp="$(ldd $CONFTEST | grep 'ld.*.so' | sed 's,\s*\(\S\+\).*,\1,')"
346 # echo "elfinterp $tcc_elfinterp"
350 else
351 # if cross compiling, cannot launch a program, so make a static guess
352 case $cpu in
353 powerpc|mips|s390) bigendian=yes;;
354 esac
357 cat <<EOF
358 Binary directory $bindir
359 TinyCC directory $tccdir
360 Library directory $libdir
361 Include directory $includedir
362 Manual directory $mandir
363 Info directory $infodir
364 Doc directory $docdir
365 Target root prefix $sysroot
366 Source path $source_path
367 C compiler $cc
368 Build CPU $cpu
369 Target OS $targetos
370 Big Endian $bigendian
371 gprof enabled $gprof
372 cross compilers $build_cross
373 use libgcc $use_libgcc
376 echo "Creating config.mak and config.h"
378 cat >config.mak <<EOF
379 # Automatically generated by configure - do not modify
380 prefix=$prefix
381 bindir=\$(DESTDIR)$bindir
382 tccdir=\$(DESTDIR)$tccdir
383 libdir=\$(DESTDIR)$libdir
384 ln_libdir=$libdir
385 includedir=\$(DESTDIR)$includedir
386 mandir=\$(DESTDIR)$mandir
387 infodir=\$(DESTDIR)$infodir
388 docdir=\$(DESTDIR)$docdir
389 CC=$cc
390 GCC_MAJOR=$gcc_major
391 GCC_MINOR=$gcc_minor
392 HOST_CC=$host_cc
393 AR=$ar
394 STRIP=$strip -s -R .comment -R .note
395 CFLAGS=$CFLAGS
396 LDFLAGS=$LDFLAGS
397 LIBSUF=$LIBSUF
398 EXESUF=$EXESUF
401 print_inc() {
402 if test -n "$2"; then
403 echo "#ifndef $1" >> $TMPH
404 echo "# define $1 \"$2\"" >> $TMPH
405 echo "#endif" >> $TMPH
408 print_mak() {
409 if test -n "$2"; then
410 echo "NATIVE_DEFINES+=-D$1=\"\\\"$2\\\"\"" >> config.mak
414 echo "/* Automatically generated by configure - do not modify */" > $TMPH
416 print_inc CONFIG_SYSROOT "$sysroot"
417 print_inc CONFIG_TCCDIR "$tccdir"
418 print_mak CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
419 print_mak CONFIG_TCC_LIBPATHS "$tcc_libpaths"
420 print_mak CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
421 print_mak CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
422 print_mak CONFIG_LDDIR "$tcc_lddir"
423 print_mak CONFIG_MULTIARCHDIR "$multiarch_triplet"
425 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
426 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
428 if test "$cpu" = "x86" ; then
429 echo "ARCH=i386" >> config.mak
430 echo "#define HOST_I386 1" >> $TMPH
431 elif test "$cpu" = "x86-64" ; then
432 echo "ARCH=x86-64" >> config.mak
433 echo "#define HOST_X86_64 1" >> $TMPH
434 elif test "$cpu" = "armv4l" ; then
435 echo "ARCH=arm" >> config.mak
436 echo "#define HOST_ARM 1" >> $TMPH
437 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
438 elif test "$cpu" = "powerpc" ; then
439 echo "ARCH=ppc" >> config.mak
440 echo "#define HOST_PPC 1" >> $TMPH
441 elif test "$cpu" = "mips" ; then
442 echo "ARCH=mips" >> config.mak
443 echo "#define HOST_MIPS 1" >> $TMPH
444 elif test "$cpu" = "s390" ; then
445 echo "ARCH=s390" >> config.mak
446 echo "#define HOST_S390 1" >> $TMPH
447 elif test "$cpu" = "alpha" ; then
448 echo "ARCH=alpha" >> config.mak
449 echo "#define HOST_ALPHA 1" >> $TMPH
450 else
451 echo "Unsupported CPU"
452 exit 1
455 echo "TARGETOS=$targetos" >> config.mak
457 for v in $confvars ; do
458 echo "CONFIG_$v=yes" >> config.mak
459 done
460 if test "$noldl" = "yes" ; then
461 echo "CONFIG_NOLDL=yes" >> config.mak
463 if test "$mingw32" = "yes" ; then
464 echo "CONFIG_WIN32=yes" >> config.mak
465 echo "#define CONFIG_WIN32 1" >> $TMPH
467 if test "$cygwin" = "yes" ; then
468 echo "#ifndef _WIN32" >> $TMPH
469 echo "# define _WIN32" >> $TMPH
470 echo "#endif" >> $TMPH
471 echo "AR=ar" >> config.mak
473 if test "$bigendian" = "yes" ; then
474 echo "WORDS_BIGENDIAN=yes" >> config.mak
475 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
477 if test "$gprof" = "yes" ; then
478 echo "TARGET_GPROF=yes" >> config.mak
479 echo "#define HAVE_GPROF 1" >> $TMPH
481 if test "$build_cross" = "yes" ; then
482 echo "CONFIG_CROSS=yes" >> config.mak
484 if test "$disable_static" = "yes" ; then
485 echo "DISABLE_STATIC=yes" >> config.mak
487 if test "$disable_rpath" = "yes" ; then
488 echo "DISABLE_RPATH=yes" >> config.mak
490 if test "$strip_binaries" = "yes" ; then
491 echo "STRIP_BINARIES=yes" >> config.mak
493 if test "$use_libgcc" = "yes" ; then
494 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
495 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
497 if test "$have_selinux" = "yes" ; then
498 echo "#define HAVE_SELINUX" >> $TMPH
499 echo "HAVE_SELINUX=yes" >> config.mak
501 if test "$enable_assert" = "yes" ; then
502 echo "#define CONFIG_TCC_ASSERT" >> $TMPH
505 version=`head $source_path/VERSION`
506 echo "VERSION=$version" >>config.mak
507 echo "#define TCC_VERSION \"$version\"" >> $TMPH
508 echo "@set VERSION $version" > config.texi
509 echo "SRC_PATH=$source_path" >>config.mak
511 if test "$source_path_used" = "yes" ; then
512 case $source_path in
513 /*) echo "top_srcdir=$source_path";;
514 *) echo "top_srcdir=\$(TOP)/$source_path";;
515 esac >>config.mak
516 else
517 echo 'top_srcdir=$(TOP)' >>config.mak
519 echo 'top_builddir=$(TOP)' >>config.mak
521 diff $TMPH config.h >/dev/null 2>&1
522 if test $? -ne 0 ; then
523 mv -f $TMPH config.h
524 else
525 echo "config.h is unchanged"
528 rm -f $TMPN* $CONFTEST
530 # ---------------------------------------------------------------------------
531 # build tree in object directory if source path is different from current one
533 fn_makelink()
535 tgt=$1/$2
536 case $2 in
537 */*) dn=${2%/*}
538 test -d $dn || mkdir -p $dn
539 case $1 in
540 /*) ;;
541 *) while test $dn ; do
542 tgt=../$tgt; dn=${dn#${dn%%/*}}; dn=${dn#/}
543 done
545 esac
547 esac
548 ln -sfn $tgt $2
551 if test "$source_path_used" = "yes" ; then
552 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
553 for f in $FILES ; do
554 fn_makelink $source_path $f
555 done
558 # ---------------------------------------------------------------------------