win64: va_arg with structures
[tinycc.git] / configure
blobc9bc83a21a5ea0f13126c70c1c99322b78d698ea
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"
14 # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
15 TMPN="./conftest-$$"
17 TMPC=$TMPN.c
18 TMPH=$TMPN.h
19 TMPO=$TMPN.o
20 TMPE=$TMPN
22 # default parameters
23 build_cross="no"
24 use_libgcc="no"
25 prefix=""
26 execprefix=""
27 bindir=""
28 libdir=""
29 tccdir=""
30 includedir=""
31 mandir=""
32 infodir=""
33 sysroot=""
34 cross_prefix=""
35 cc="gcc"
36 host_cc="gcc"
37 ar="ar"
38 strip="strip"
39 cygwin="no"
40 cpu=`uname -m`
41 case "$cpu" in
42 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
43 cpu="x86"
45 x86_64)
46 cpu="x86-64"
48 arm|armv4l|armv5tel|armv5tejl|armv6j|armv7a|armv7l)
49 cpu="armv4l"
51 alpha)
52 cpu="alpha"
54 "Power Macintosh"|ppc|ppc64)
55 cpu="powerpc"
57 mips)
58 cpu="mips"
60 s390)
61 cpu="s390"
64 cpu="unknown"
66 esac
67 gprof="no"
68 bigendian="no"
69 mingw32="no"
70 LIBSUF=".a"
71 EXESUF=""
73 # OS specific
74 targetos=`uname -s`
75 case $targetos in
76 MINGW32*)
77 mingw32="yes"
79 DragonFly)
80 noldl="yes"
82 OpenBSD)
83 noldl="yes"
85 *) ;;
86 esac
88 # find source path
89 # XXX: we assume an absolute path is given when launching configure,
90 # except in './configure' case.
91 source_path=${0%configure}
92 source_path=${source_path%/}
93 source_path_used="yes"
94 if test -z "$source_path" -o "$source_path" = "." ; then
95 source_path=`pwd`
96 source_path_used="no"
99 for opt do
100 case "$opt" in
101 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
103 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
105 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
107 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
109 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
111 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
113 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
115 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
117 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
119 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
121 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
123 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
125 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
127 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
129 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
131 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
133 --extra-libs=*) extralibs=${opt#--extra-libs=}
135 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
137 --enable-gprof) gprof="yes"
139 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
141 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
143 --enable-cross) build_cross="yes"
145 --disable-static) disable_static="yes"
147 --disable-rpath) disable_rpath="yes"
149 --strip-binaries) strip_binaries="yes"
151 --with-libgcc) use_libgcc="yes"
153 --with-selinux) have_selinux="yes"
155 --help|-h) show_help="yes"
157 esac
158 done
160 # Checking for CFLAGS
161 if test -z "$CFLAGS"; then
162 CFLAGS="-Wall -g -O2"
165 cc="${cross_prefix}${cc}"
166 ar="${cross_prefix}${ar}"
167 strip="${cross_prefix}${strip}"
169 if test "$mingw32" = "yes" ; then
170 LIBSUF=".lib"
171 EXESUF=".exe"
174 if test -z "$cross_prefix" ; then
176 # ---
177 # big/little endian test
178 cat > $TMPC << EOF
179 #include <inttypes.h>
180 int main(int argc, char ** argv){
181 volatile uint32_t i=0x01234567;
182 return (*((uint8_t*)(&i))) == 0x67;
186 if $cc -o $TMPE $TMPC 2>/dev/null ; then
187 $TMPE && bigendian="yes"
188 else
189 echo big/little test failed
192 else
194 # if cross compiling, cannot launch a program, so make a static guess
195 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
196 bigendian="yes"
201 # check gcc version
202 cat > $TMPC <<EOF
203 int main(void) {
204 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
205 return 0;
206 #else
207 #error gcc < 3.2
208 #endif
212 gcc_major="2"
213 if $cc -o $TMPO $TMPC 2> /dev/null ; then
214 gcc_major="3"
216 cat > $TMPC <<EOF
217 int main(void) {
218 #if __GNUC__ >= 4
219 return 0;
220 #else
221 #error gcc < 4
222 #endif
226 if $cc -o $TMPO $TMPC 2> /dev/null ; then
227 gcc_major="4"
230 if test x"$show_help" = "xyes" ; then
231 cat << EOF
233 Usage: configure [options]
234 Options: [defaults in brackets after descriptions]
237 echo "Standard options:"
238 echo " --help print this message"
239 echo " --prefix=PREFIX install in PREFIX [$prefix]"
240 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
241 echo " [same as prefix]"
242 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
243 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
244 echo " --tccdir=DIR installation directory [EPREFIX/lib/tcc]"
245 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
246 echo " --sharedir=DIR documentation root DIR [PREFIX]/share"
247 echo " --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]"
248 echo " --mandir=DIR man documentation in DIR [SHAREDIR/man]"
249 echo " --infodir=DIR info documentation in DIR [SHAREDIR/info]"
250 echo ""
251 echo "Advanced options (experts only):"
252 echo " --source-path=PATH path of source code [$source_path]"
253 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
254 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
255 echo " --cc=CC use C compiler CC [$cc]"
256 echo " --disable-static make libtcc.so instead of libtcc.a"
257 echo " --disable-rpath disable use of -rpath with the above"
258 echo " --strip-binaries strip symbol tables from resulting binaries"
259 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
260 echo " --enable-mingw32 build windows version on linux with mingw32"
261 echo " --enable-cygwin build windows version on windows with cygwin"
262 echo " [requires cygwin and mingw32-make]"
263 echo " --enable-cross build cross compilers"
264 echo " --extra-cflags= extra compiler flags"
265 echo " --extra-ldflags= extra linker options"
266 echo " --with-selinux use mmap instead of exec mem"
267 echo " [requires write access to /tmp]"
268 echo ""
269 #echo "NOTE: The object files are build at the place where configure is launched"
270 exit 1
273 if test "$mingw32" = "yes" ; then
274 if test x"$tccdir" = x""; then
275 tccdir="tcc"
277 if test -z "$prefix" ; then
278 prefix="C:/Program Files/${tccdir}"
280 if test -z "$sharedir" ; then
281 sharedir="${prefix}"
283 execprefix="$prefix"
284 bindir="${prefix}"
285 tccdir="${prefix}"
286 libdir="${prefix}/lib"
287 docdir="${sharedir}/doc"
288 mandir="${sharedir}/man"
289 infodir="${sharedir}/info"
290 else
291 if test -z "$prefix" ; then
292 prefix="/usr/local"
294 if test -z "$sharedir" ; then
295 sharedir="${prefix}/share"
297 if test x"$execprefix" = x""; then
298 execprefix="${prefix}"
300 if test x"$libdir" = x""; then
301 libdir="${execprefix}/lib"
303 if test x"$bindir" = x""; then
304 bindir="${execprefix}/bin"
306 if test x"$tccdir" = x""; then
307 tccdir="tcc"
309 if test x"$docdir" = x""; then
310 docdir="${sharedir}/doc/${tccdir}"
312 if test x"$mandir" = x""; then
313 mandir="${sharedir}/man"
315 if test x"$infodir" = x""; then
316 infodir="${sharedir}/info"
318 tccdir="${libdir}/${tccdir}"
319 fi # mingw32
321 if test x"$includedir" = x""; then
322 includedir="${prefix}/include"
325 echo "Binary directory $bindir"
326 echo "TinyCC directory $tccdir"
327 echo "Library directory $libdir"
328 echo "Include directory $includedir"
329 echo "Manual directory $mandir"
330 echo "Info directory $infodir"
331 echo "Doc directory $docdir"
332 echo "Target root prefix $sysroot"
333 echo "Source path $source_path"
334 echo "C compiler $cc"
335 echo "CPU $cpu"
336 echo "Big Endian $bigendian"
337 echo "gprof enabled $gprof"
338 echo "cross compilers $build_cross"
339 echo "use libgcc $use_libgcc"
341 echo "Creating config.mak and config.h"
343 echo "# Automatically generated by configure - do not modify" > config.mak
344 echo "/* Automatically generated by configure - do not modify */" > $TMPH
346 echo "prefix=$prefix" >> config.mak
347 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
348 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
349 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
350 echo "ln_libdir=$libdir" >> config.mak
351 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
352 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
353 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
354 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
356 echo "#ifndef CONFIG_SYSROOT" >> $TMPH
357 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
358 echo "#endif" >> $TMPH
359 echo "#ifndef CONFIG_TCCDIR" >> $TMPH
360 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
361 echo "#endif" >> $TMPH
362 echo "CC=$cc" >> config.mak
363 echo "GCC_MAJOR=$gcc_major" >> config.mak
364 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
365 echo "HOST_CC=$host_cc" >> config.mak
366 echo "AR=$ar" >> config.mak
367 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
368 echo "CFLAGS=$CFLAGS" >> config.mak
369 echo "LDFLAGS=$LDFLAGS" >> config.mak
370 echo "LIBSUF=$LIBSUF" >> config.mak
371 echo "EXESUF=$EXESUF" >> config.mak
372 if test "$cpu" = "x86" ; then
373 echo "ARCH=i386" >> config.mak
374 echo "#define HOST_I386 1" >> $TMPH
375 elif test "$cpu" = "x86-64" ; then
376 echo "ARCH=x86-64" >> config.mak
377 echo "#define HOST_X86_64 1" >> $TMPH
378 elif test "$cpu" = "armv4l" ; then
379 echo "ARCH=arm" >> config.mak
380 echo "#define HOST_ARM 1" >> $TMPH
381 elif test "$cpu" = "powerpc" ; then
382 echo "ARCH=ppc" >> config.mak
383 echo "#define HOST_PPC 1" >> $TMPH
384 elif test "$cpu" = "mips" ; then
385 echo "ARCH=mips" >> config.mak
386 echo "#define HOST_MIPS 1" >> $TMPH
387 elif test "$cpu" = "s390" ; then
388 echo "ARCH=s390" >> config.mak
389 echo "#define HOST_S390 1" >> $TMPH
390 elif test "$cpu" = "alpha" ; then
391 echo "ARCH=alpha" >> config.mak
392 echo "#define HOST_ALPHA 1" >> $TMPH
393 else
394 echo "Unsupported CPU"
395 exit 1
397 if test "$noldl" = "yes" ; then
398 echo "CONFIG_NOLDL=yes" >> config.mak
400 if test "$mingw32" = "yes" ; then
401 echo "CONFIG_WIN32=yes" >> config.mak
402 echo "#define CONFIG_WIN32 1" >> $TMPH
404 if test "$cygwin" = "yes" ; then
405 echo "#ifndef _WIN32" >> $TMPH
406 echo "#define _WIN32" >> $TMPH
407 echo "#endif" >> $TMPH
408 echo "AR=ar" >> config.mak
410 if test "$bigendian" = "yes" ; then
411 echo "WORDS_BIGENDIAN=yes" >> config.mak
412 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
414 if test "$gprof" = "yes" ; then
415 echo "TARGET_GPROF=yes" >> config.mak
416 echo "#define HAVE_GPROF 1" >> $TMPH
418 if test "$build_cross" = "yes" ; then
419 echo "CONFIG_CROSS=yes" >> config.mak
421 if test "$disable_static" = "yes" ; then
422 echo "DISABLE_STATIC=yes" >> config.mak
424 if test "$disable_rpath" = "yes" ; then
425 echo "DISABLE_RPATH=yes" >> config.mak
427 if test "$strip_binaries" = "yes" ; then
428 echo "STRIP_BINARIES=yes" >> config.mak
430 if test "$use_libgcc" = "yes" ; then
431 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
432 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
434 if test "$have_selinux" = "yes" ; then
435 echo "#define HAVE_SELINUX" >> $TMPH
436 echo "HAVE_SELINUX=yes" >> config.mak
438 version=`head $source_path/VERSION`
439 echo "VERSION=$version" >>config.mak
440 echo "#define TCC_VERSION \"$version\"" >> $TMPH
441 echo "@set VERSION $version" > config.texi
443 # build tree in object directory if source path is different from current one
444 if test "$source_path_used" = "yes" ; then
445 DIRS="tests"
446 FILES="Makefile tests/Makefile"
447 for dir in $DIRS ; do
448 mkdir -p $dir
449 done
450 for f in $FILES ; do
451 ln -sf $source_path/$f $f
452 done
454 echo "SRC_PATH=$source_path" >> config.mak
456 diff $TMPH config.h >/dev/null 2>&1
457 if test $? -ne 0 ; then
458 mv -f $TMPH config.h
459 else
460 echo "config.h is unchanged"
463 rm -f $TMPN*