Fix parsing function macro invocations
[tinycc.git] / configure
blob188c36093f43912224f491c400920cbd3264bfbc
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`
42 tcc_sysincludepaths=""
43 tcc_libpaths=""
44 tcc_crtprefix=""
45 tcc_elfinterp=""
47 case "$cpu" in
48 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
49 cpu="x86"
51 x86_64)
52 cpu="x86-64"
54 arm|armv4l|armv5tel|armv5tejl|armv6j|armv7a|armv7l)
55 cpu="armv4l"
57 alpha)
58 cpu="alpha"
60 "Power Macintosh"|ppc|ppc64)
61 cpu="powerpc"
63 mips)
64 cpu="mips"
66 s390)
67 cpu="s390"
70 cpu="unknown"
72 esac
73 gprof="no"
74 bigendian="no"
75 mingw32="no"
76 LIBSUF=".a"
77 EXESUF=""
79 # OS specific
80 targetos=`uname -s`
81 case $targetos in
82 MINGW32*)
83 mingw32="yes"
85 DragonFly)
86 noldl="yes"
88 OpenBSD)
89 noldl="yes"
91 *) ;;
92 esac
94 # find source path
95 # XXX: we assume an absolute path is given when launching configure,
96 # except in './configure' case.
97 source_path=${0%configure}
98 source_path=${source_path%/}
99 source_path_used="yes"
100 if test -z "$source_path" -o "$source_path" = "." ; then
101 source_path=`pwd`
102 source_path_used="no"
105 for opt do
106 case "$opt" in
107 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
109 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
111 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
113 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
115 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
117 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
119 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
121 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
123 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
125 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
127 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
129 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
131 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
133 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
135 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
137 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
139 --extra-libs=*) extralibs=${opt#--extra-libs=}
141 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
143 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
145 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
147 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
149 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
151 --enable-gprof) gprof="yes"
153 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
155 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
157 --enable-cross) build_cross="yes"
159 --disable-static) disable_static="yes"
161 --disable-rpath) disable_rpath="yes"
163 --strip-binaries) strip_binaries="yes"
165 --with-libgcc) use_libgcc="yes"
167 --with-selinux) have_selinux="yes"
169 --help|-h) show_help="yes"
171 *) echo "configure: unrecognized option $opt"; exit 1
173 esac
174 done
176 # Checking for CFLAGS
177 if test -z "$CFLAGS"; then
178 CFLAGS="-Wall -g -O2"
181 cc="${cross_prefix}${cc}"
182 ar="${cross_prefix}${ar}"
183 strip="${cross_prefix}${strip}"
185 if test "$mingw32" = "yes" ; then
186 LIBSUF=".lib"
187 EXESUF=".exe"
190 if test -z "$cross_prefix" ; then
192 # ---
193 # big/little endian test
194 cat > $TMPC << EOF
195 #include <inttypes.h>
196 int main(int argc, char ** argv){
197 volatile uint32_t i=0x01234567;
198 return (*((uint8_t*)(&i))) == 0x67;
202 if $cc -o $TMPE $TMPC 2>/dev/null ; then
203 $TMPE && bigendian="yes"
204 else
205 echo big/little test failed
208 else
210 # if cross compiling, cannot launch a program, so make a static guess
211 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
212 bigendian="yes"
217 # check gcc version
218 cat > $TMPC <<EOF
219 int main(void) {
220 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
221 return 0;
222 #else
223 #error gcc < 3.2
224 #endif
228 gcc_major="2"
229 if $cc -o $TMPO $TMPC 2> /dev/null ; then
230 gcc_major="3"
232 cat > $TMPC <<EOF
233 int main(void) {
234 #if __GNUC__ >= 4
235 return 0;
236 #else
237 #error gcc < 4
238 #endif
242 if $cc -o $TMPO $TMPC 2> /dev/null ; then
243 gcc_major="4"
246 if test x"$show_help" = "xyes" ; then
247 cat << EOF
249 Usage: configure [options]
250 Options: [defaults in brackets after descriptions]
253 echo "Standard options:"
254 echo " --help print this message"
255 echo " --prefix=PREFIX install in PREFIX [$prefix]"
256 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
257 echo " [same as prefix]"
258 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
259 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
260 echo " --tccdir=DIR installation directory [EPREFIX/lib/tcc]"
261 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
262 echo " --sharedir=DIR documentation root DIR [PREFIX]/share"
263 echo " --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]"
264 echo " --mandir=DIR man documentation in DIR [SHAREDIR/man]"
265 echo " --infodir=DIR info documentation in DIR [SHAREDIR/info]"
266 echo ""
267 echo "Advanced options (experts only):"
268 echo " --source-path=PATH path of source code [$source_path]"
269 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
270 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
271 echo " --cc=CC use C compiler CC [$cc]"
272 echo " --disable-static make libtcc.so instead of libtcc.a"
273 echo " --disable-rpath disable use of -rpath with the above"
274 echo " --strip-binaries strip symbol tables from resulting binaries"
275 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
276 echo " --enable-mingw32 build windows version on linux with mingw32"
277 echo " --enable-cygwin build windows version on windows with cygwin"
278 echo " [requires cygwin and mingw32-make]"
279 echo " --enable-cross build cross compilers"
280 echo " --extra-cflags= extra compiler flags"
281 echo " --extra-ldflags= extra linker options"
282 echo " --with-selinux use mmap instead of exec mem"
283 echo " [requires write access to /tmp]"
284 echo " --sysincludepaths=... specify system include paths, colon separated"
285 echo " --libpaths=... specify system library paths, colon separated"
286 echo " --crtprefix=... specify locations of crt?.o, colon separated"
287 echo " --elfinterp=... specify elf interpreter"
288 echo ""
289 #echo "NOTE: The object files are build at the place where configure is launched"
290 exit 1
293 if test "$mingw32" = "yes" ; then
294 if test x"$tccdir" = x""; then
295 tccdir="tcc"
297 if test -z "$prefix" ; then
298 prefix="C:/Program Files/${tccdir}"
300 if test -z "$sharedir" ; then
301 sharedir="${prefix}"
303 execprefix="$prefix"
304 bindir="${prefix}"
305 tccdir="${prefix}"
306 libdir="${prefix}/lib"
307 docdir="${sharedir}/doc"
308 mandir="${sharedir}/man"
309 infodir="${sharedir}/info"
310 else
311 if test -z "$prefix" ; then
312 prefix="/usr/local"
314 if test -z "$sharedir" ; then
315 sharedir="${prefix}/share"
317 if test x"$execprefix" = x""; then
318 execprefix="${prefix}"
320 if test x"$libdir" = x""; then
321 libdir="${execprefix}/lib"
323 if test x"$bindir" = x""; then
324 bindir="${execprefix}/bin"
326 if test x"$tccdir" = x""; then
327 tccdir="tcc"
329 if test x"$docdir" = x""; then
330 docdir="${sharedir}/doc/${tccdir}"
332 if test x"$mandir" = x""; then
333 mandir="${sharedir}/man"
335 if test x"$infodir" = x""; then
336 infodir="${sharedir}/info"
338 tccdir="${libdir}/${tccdir}"
339 fi # mingw32
341 if test x"$includedir" = x""; then
342 includedir="${prefix}/include"
345 echo "Binary directory $bindir"
346 echo "TinyCC directory $tccdir"
347 echo "Library directory $libdir"
348 echo "Include directory $includedir"
349 echo "Manual directory $mandir"
350 echo "Info directory $infodir"
351 echo "Doc directory $docdir"
352 echo "Target root prefix $sysroot"
353 echo "Source path $source_path"
354 echo "C compiler $cc"
355 echo "Target OS $targetos"
356 echo "CPU $cpu"
357 echo "Big Endian $bigendian"
358 echo "gprof enabled $gprof"
359 echo "cross compilers $build_cross"
360 echo "use libgcc $use_libgcc"
362 echo "Creating config.mak and config.h"
364 echo "# Automatically generated by configure - do not modify" > config.mak
365 echo "/* Automatically generated by configure - do not modify */" > $TMPH
367 echo "prefix=$prefix" >> config.mak
368 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
369 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
370 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
371 echo "ln_libdir=$libdir" >> config.mak
372 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
373 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
374 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
375 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
376 print_var1()
378 echo "#ifndef $1" >> $TMPH
379 echo "# define $1 \"$2\"" >> $TMPH
380 echo "#endif" >> $TMPH
382 print_var2()
384 if test -n "$2"; then print_var1 $1 "$2"; fi
386 print_var2 CONFIG_SYSROOT "$sysroot"
387 print_var1 CONFIG_TCCDIR "$tccdir"
388 print_var2 CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
389 print_var2 CONFIG_TCC_LIBPATHS "$tcc_libpaths"
390 print_var2 CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
391 print_var2 CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
393 echo "CC=$cc" >> config.mak
394 echo "GCC_MAJOR=$gcc_major" >> config.mak
395 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
396 echo "HOST_CC=$host_cc" >> config.mak
397 echo "AR=$ar" >> config.mak
398 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
399 echo "CFLAGS=$CFLAGS" >> config.mak
400 echo "LDFLAGS=$LDFLAGS" >> config.mak
401 echo "LIBSUF=$LIBSUF" >> config.mak
402 echo "EXESUF=$EXESUF" >> config.mak
404 if test "$cpu" = "x86" ; then
405 echo "ARCH=i386" >> config.mak
406 echo "#define HOST_I386 1" >> $TMPH
407 elif test "$cpu" = "x86-64" ; then
408 echo "ARCH=x86-64" >> config.mak
409 echo "#define HOST_X86_64 1" >> $TMPH
410 elif test "$cpu" = "armv4l" ; then
411 echo "ARCH=arm" >> config.mak
412 echo "#define HOST_ARM 1" >> $TMPH
413 elif test "$cpu" = "powerpc" ; then
414 echo "ARCH=ppc" >> config.mak
415 echo "#define HOST_PPC 1" >> $TMPH
416 elif test "$cpu" = "mips" ; then
417 echo "ARCH=mips" >> config.mak
418 echo "#define HOST_MIPS 1" >> $TMPH
419 elif test "$cpu" = "s390" ; then
420 echo "ARCH=s390" >> config.mak
421 echo "#define HOST_S390 1" >> $TMPH
422 elif test "$cpu" = "alpha" ; then
423 echo "ARCH=alpha" >> config.mak
424 echo "#define HOST_ALPHA 1" >> $TMPH
425 else
426 echo "Unsupported CPU"
427 exit 1
429 echo "TARGETOS=$targetos" >> config.mak
430 if test "$noldl" = "yes" ; then
431 echo "CONFIG_NOLDL=yes" >> config.mak
433 if test "$mingw32" = "yes" ; then
434 echo "CONFIG_WIN32=yes" >> config.mak
435 echo "#define CONFIG_WIN32 1" >> $TMPH
437 if test "$cygwin" = "yes" ; then
438 echo "#ifndef _WIN32" >> $TMPH
439 echo "#define _WIN32" >> $TMPH
440 echo "#endif" >> $TMPH
441 echo "AR=ar" >> config.mak
443 if test "$bigendian" = "yes" ; then
444 echo "WORDS_BIGENDIAN=yes" >> config.mak
445 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
447 if test "$gprof" = "yes" ; then
448 echo "TARGET_GPROF=yes" >> config.mak
449 echo "#define HAVE_GPROF 1" >> $TMPH
451 if test "$build_cross" = "yes" ; then
452 echo "CONFIG_CROSS=yes" >> config.mak
454 if test "$disable_static" = "yes" ; then
455 echo "DISABLE_STATIC=yes" >> config.mak
457 if test "$disable_rpath" = "yes" ; then
458 echo "DISABLE_RPATH=yes" >> config.mak
460 if test "$strip_binaries" = "yes" ; then
461 echo "STRIP_BINARIES=yes" >> config.mak
463 if test "$use_libgcc" = "yes" ; then
464 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
465 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
467 if test "$have_selinux" = "yes" ; then
468 echo "#define HAVE_SELINUX" >> $TMPH
469 echo "HAVE_SELINUX=yes" >> config.mak
471 version=`head $source_path/VERSION`
472 echo "VERSION=$version" >>config.mak
473 echo "#define TCC_VERSION \"$version\"" >> $TMPH
474 echo "@set VERSION $version" > config.texi
476 # build tree in object directory if source path is different from current one
477 if test "$source_path_used" = "yes" ; then
478 DIRS="tests"
479 FILES="Makefile tests/Makefile"
480 for dir in $DIRS ; do
481 mkdir -p $dir
482 done
483 for f in $FILES ; do
484 ln -sf $source_path/$f $f
485 done
487 echo "SRC_PATH=$source_path" >> config.mak
489 diff $TMPH config.h >/dev/null 2>&1
490 if test $? -ne 0 ; then
491 mv -f $TMPH config.h
492 else
493 echo "config.h is unchanged"
496 rm -f $TMPN*