win32: build-tcc.bat: get rid of hardcoded VERSION string
[tinycc.git] / configure
blobb4ac32812042a2d7d8f78fc86c217ecf4e6f8bae
1 #!/bin/sh
3 # tcc configure script (c) 2003 Fabrice Bellard
5 fn_dirname()
7 case $1 in
8 */*) echo "$1" | sed -e 's,/[^/]*,,';;
9 *) echo '.'
10 esac
13 # set temporary file name
14 if test ! -z "$TMPDIR" ; then
15 TMPDIR1="${TMPDIR}"
16 elif test ! -z "$TEMPDIR" ; then
17 TMPDIR1="${TEMPDIR}"
18 else
19 TMPDIR1="/tmp"
22 # bashism: TMPN="${TMPDIR1}/tcc-conf-${RANDOM}-$$-${RANDOM}.c"
23 TMPN="./conftest-$$"
25 TMPC=$TMPN.c
26 TMPH=$TMPN.h
27 TMPO=$TMPN.o
28 TMPE=$TMPN
30 # default parameters
31 build_cross="no"
32 use_libgcc="no"
33 prefix=""
34 execprefix=""
35 bindir=""
36 libdir=""
37 tccdir=""
38 includedir=""
39 mandir=""
40 infodir=""
41 sysroot=""
42 cross_prefix=""
43 cc="gcc"
44 host_cc="gcc"
45 ar="ar"
46 strip="strip"
47 cygwin="no"
48 cpu=`uname -m`
50 tcc_sysincludepaths=""
51 tcc_libpaths=""
52 tcc_crtprefix=""
53 tcc_elfinterp=""
55 case "$cpu" in
56 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
57 cpu="x86"
59 x86_64)
60 cpu="x86-64"
62 arm*)
63 case "$cpu" in
64 arm|armv4l)
65 cpuver=4
67 armv5tel|armv5tejl)
68 cpuver=5
70 armv6j|armv6l)
71 cpuver=6
73 armv7a|armv7l)
74 cpuver=7
76 esac
77 cpu="armv4l"
79 alpha)
80 cpu="alpha"
82 "Power Macintosh"|ppc|ppc64)
83 cpu="powerpc"
85 mips)
86 cpu="mips"
88 s390)
89 cpu="s390"
92 cpu="unknown"
94 esac
95 gprof="no"
96 bigendian="no"
97 mingw32="no"
98 LIBSUF=".a"
99 EXESUF=""
101 # OS specific
102 targetos=`uname -s`
103 case $targetos in
104 MINGW32*)
105 mingw32="yes"
107 DragonFly)
108 noldl="yes"
110 OpenBSD)
111 noldl="yes"
113 *) ;;
114 esac
116 # find source path
117 # XXX: we assume an absolute path is given when launching configure,
118 # except in './configure' case.
119 source_path=${0%configure}
120 source_path=${source_path%/}
121 source_path_used="yes"
122 if test -z "$source_path" -o "$source_path" = "." ; then
123 source_path=`pwd`
124 source_path_used="no"
127 for opt do
128 eval opt=$opt
129 case "$opt" in
130 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
132 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
134 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
136 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
138 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
140 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
142 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
144 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
146 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
148 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
150 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
152 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
154 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
156 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
158 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
160 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
162 --extra-libs=*) extralibs=${opt#--extra-libs=}
164 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
166 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
168 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
170 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
172 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
174 --enable-gprof) gprof="yes"
176 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
178 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
180 --enable-cross) build_cross="yes"
182 --disable-static) disable_static="yes"
184 --disable-rpath) disable_rpath="yes"
186 --strip-binaries) strip_binaries="yes"
188 --with-libgcc) use_libgcc="yes"
190 --with-selinux) have_selinux="yes"
192 --help|-h) show_help="yes"
194 *) echo "configure: WARNING: unrecognized option $opt"
196 esac
197 done
199 # Checking for CFLAGS
200 if test -z "$CFLAGS"; then
201 CFLAGS="-Wall -g -O2"
204 cc="${cross_prefix}${cc}"
205 ar="${cross_prefix}${ar}"
206 strip="${cross_prefix}${strip}"
208 if test "$mingw32" = "yes" ; then
209 LIBSUF=".lib"
210 EXESUF=".exe"
213 if test -z "$cross_prefix" ; then
215 # ---
216 # big/little endian test
217 cat > $TMPC << EOF
218 #include <inttypes.h>
219 int main(int argc, char ** argv){
220 volatile uint32_t i=0x01234567;
221 return (*((uint8_t*)(&i))) == 0x67;
225 if $cc -o $TMPE $TMPC 2>/dev/null ; then
226 $TMPE && bigendian="yes"
227 else
228 echo big/little test failed
231 else
233 # if cross compiling, cannot launch a program, so make a static guess
234 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
235 bigendian="yes"
240 # check gcc version
241 cat > $TMPC <<EOF
242 int main(void) {
243 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
244 return 0;
245 #else
246 #error gcc < 3.2
247 #endif
251 gcc_major="2"
252 if $cc -o $TMPO $TMPC 2> /dev/null ; then
253 gcc_major="3"
255 cat > $TMPC <<EOF
256 int main(void) {
257 #if __GNUC__ >= 4
258 return 0;
259 #else
260 #error gcc < 4
261 #endif
265 if $cc -o $TMPO $TMPC 2> /dev/null ; then
266 gcc_major="4"
269 if test x"$show_help" = "xyes" ; then
270 cat << EOF
272 Usage: configure [options]
273 Options: [defaults in brackets after descriptions]
276 echo "Standard options:"
277 echo " --help print this message"
278 echo " --prefix=PREFIX install in PREFIX [$prefix]"
279 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
280 echo " [same as prefix]"
281 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
282 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
283 echo " --tccdir=DIR installation directory [EPREFIX/lib/tcc]"
284 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
285 echo " --sharedir=DIR documentation root DIR [PREFIX]/share"
286 echo " --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]"
287 echo " --mandir=DIR man documentation in DIR [SHAREDIR/man]"
288 echo " --infodir=DIR info documentation in DIR [SHAREDIR/info]"
289 echo ""
290 echo "Advanced options (experts only):"
291 echo " --source-path=PATH path of source code [$source_path]"
292 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
293 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
294 echo " --cc=CC use C compiler CC [$cc]"
295 echo " --disable-static make libtcc.so instead of libtcc.a"
296 echo " --disable-rpath disable use of -rpath with the above"
297 echo " --strip-binaries strip symbol tables from resulting binaries"
298 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
299 echo " --enable-mingw32 build windows version on linux with mingw32"
300 echo " --enable-cygwin build windows version on windows with cygwin"
301 echo " [requires cygwin and mingw32-make]"
302 echo " --enable-cross build cross compilers"
303 echo " --extra-cflags= extra compiler flags"
304 echo " --extra-ldflags= extra linker options"
305 echo " --with-selinux use mmap instead of exec mem"
306 echo " [requires write access to /tmp]"
307 echo " --sysincludepaths=... specify system include paths, colon separated"
308 echo " --libpaths=... specify system library paths, colon separated"
309 echo " --crtprefix=... specify locations of crt?.o, colon separated"
310 echo " --elfinterp=... specify elf interpreter"
311 echo ""
312 #echo "NOTE: The object files are build at the place where configure is launched"
313 exit 1
316 if test "$mingw32" = "yes" ; then
317 if test x"$tccdir" = x""; then
318 tccdir="tcc"
320 if test -z "$prefix" ; then
321 prefix="C:/Program Files/${tccdir}"
323 if test -z "$sharedir" ; then
324 sharedir="${prefix}"
326 execprefix="$prefix"
327 bindir="${prefix}"
328 tccdir="${prefix}"
329 libdir="${prefix}/lib"
330 docdir="${sharedir}/doc"
331 mandir="${sharedir}/man"
332 infodir="${sharedir}/info"
333 else
334 if test -z "$prefix" ; then
335 prefix="/usr/local"
337 if test -z "$sharedir" ; then
338 sharedir="${prefix}/share"
340 if test x"$execprefix" = x""; then
341 execprefix="${prefix}"
343 if test x"$libdir" = x""; then
344 libdir="${execprefix}/lib"
346 if test x"$bindir" = x""; then
347 bindir="${execprefix}/bin"
349 if test x"$tccdir" = x""; then
350 tccdir="tcc"
352 if test x"$docdir" = x""; then
353 docdir="${sharedir}/doc/${tccdir}"
355 if test x"$mandir" = x""; then
356 mandir="${sharedir}/man"
358 if test x"$infodir" = x""; then
359 infodir="${sharedir}/info"
361 tccdir="${libdir}/${tccdir}"
362 fi # mingw32
364 if test x"$includedir" = x""; then
365 includedir="${prefix}/include"
368 echo "Binary directory $bindir"
369 echo "TinyCC directory $tccdir"
370 echo "Library directory $libdir"
371 echo "Include directory $includedir"
372 echo "Manual directory $mandir"
373 echo "Info directory $infodir"
374 echo "Doc directory $docdir"
375 echo "Target root prefix $sysroot"
376 echo "Source path $source_path"
377 echo "C compiler $cc"
378 echo "Target OS $targetos"
379 echo "CPU $cpu"
380 echo "Big Endian $bigendian"
381 echo "gprof enabled $gprof"
382 echo "cross compilers $build_cross"
383 echo "use libgcc $use_libgcc"
385 echo "Creating config.mak and config.h"
387 echo "# Automatically generated by configure - do not modify" > config.mak
388 echo "/* Automatically generated by configure - do not modify */" > $TMPH
390 echo "prefix=$prefix" >> config.mak
391 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
392 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
393 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
394 echo "ln_libdir=$libdir" >> config.mak
395 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
396 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
397 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
398 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
399 print_var1()
401 echo "#ifndef $1" >> $TMPH
402 echo "# define $1 \"$2\"" >> $TMPH
403 echo "#endif" >> $TMPH
405 print_var2()
407 if test -n "$2"; then print_var1 $1 "$2"; fi
409 print_var2 CONFIG_SYSROOT "$sysroot"
410 print_var1 CONFIG_TCCDIR "$tccdir"
411 print_var2 CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
412 print_var2 CONFIG_TCC_LIBPATHS "$tcc_libpaths"
413 print_var2 CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
414 print_var2 CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
416 echo "CC=$cc" >> config.mak
417 echo "GCC_MAJOR=$gcc_major" >> config.mak
418 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
419 echo "HOST_CC=$host_cc" >> config.mak
420 echo "AR=$ar" >> config.mak
421 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
422 cat >> config.mak <<EOF
423 CPPFLAGS = -I. -I\$(top_srcdir)
424 CFLAGS=$CFLAGS
425 LDFLAGS=$LDFLAGS
426 LIBSUF=$LIBSUF
427 EXESUF=$EXESUF
430 if test "$cpu" = "x86" ; then
431 echo "ARCH=i386" >> config.mak
432 echo "#define HOST_I386 1" >> $TMPH
433 elif test "$cpu" = "x86-64" ; then
434 echo "ARCH=x86-64" >> config.mak
435 echo "#define HOST_X86_64 1" >> $TMPH
436 elif test "$cpu" = "armv4l" ; then
437 echo "ARCH=arm" >> config.mak
438 echo "#define HOST_ARM 1" >> $TMPH
439 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
440 elif test "$cpu" = "powerpc" ; then
441 echo "ARCH=ppc" >> config.mak
442 echo "#define HOST_PPC 1" >> $TMPH
443 elif test "$cpu" = "mips" ; then
444 echo "ARCH=mips" >> config.mak
445 echo "#define HOST_MIPS 1" >> $TMPH
446 elif test "$cpu" = "s390" ; then
447 echo "ARCH=s390" >> config.mak
448 echo "#define HOST_S390 1" >> $TMPH
449 elif test "$cpu" = "alpha" ; then
450 echo "ARCH=alpha" >> config.mak
451 echo "#define HOST_ALPHA 1" >> $TMPH
452 else
453 echo "Unsupported CPU"
454 exit 1
456 echo "TARGETOS=$targetos" >> config.mak
457 if test "$noldl" = "yes" ; then
458 echo "CONFIG_NOLDL=yes" >> config.mak
460 if test "$mingw32" = "yes" ; then
461 echo "CONFIG_WIN32=yes" >> config.mak
462 echo "#define CONFIG_WIN32 1" >> $TMPH
464 if test "$cygwin" = "yes" ; then
465 echo "#ifndef _WIN32" >> $TMPH
466 echo "#define _WIN32" >> $TMPH
467 echo "#endif" >> $TMPH
468 echo "AR=ar" >> config.mak
470 if test "$bigendian" = "yes" ; then
471 echo "WORDS_BIGENDIAN=yes" >> config.mak
472 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
474 if test "$gprof" = "yes" ; then
475 echo "TARGET_GPROF=yes" >> config.mak
476 echo "#define HAVE_GPROF 1" >> $TMPH
478 if test "$build_cross" = "yes" ; then
479 echo "CONFIG_CROSS=yes" >> config.mak
481 if test "$disable_static" = "yes" ; then
482 echo "DISABLE_STATIC=yes" >> config.mak
484 if test "$disable_rpath" = "yes" ; then
485 echo "DISABLE_RPATH=yes" >> config.mak
487 if test "$strip_binaries" = "yes" ; then
488 echo "STRIP_BINARIES=yes" >> config.mak
490 if test "$use_libgcc" = "yes" ; then
491 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
492 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
494 if test "$have_selinux" = "yes" ; then
495 echo "#define HAVE_SELINUX" >> $TMPH
496 echo "HAVE_SELINUX=yes" >> config.mak
498 version=`head $source_path/VERSION`
499 echo "VERSION=$version" >>config.mak
500 echo "#define TCC_VERSION \"$version\"" >> $TMPH
501 echo "@set VERSION $version" > config.texi
503 # build tree in object directory if source path is different from current one
504 if test "$source_path_used" = "yes" ; then
505 FILES="Makefile lib/Makefile tests/Makefile tests2/Makefile"
506 for f in $FILES ; do
507 dir=`fn_dirname "$f"`
508 test -d "$dir" || mkdir -p "$dir"
509 back=`echo "$source_path/$dir/" | sed 's,/\./,/,g;s,[^/]*/,../,g'`
510 back=$back$f
511 ln -sf $back $f
512 done
514 cat >>config.mak <<EOF
515 SRC_PATH = $source_path
516 top_builddir = \$(TOP)
518 case $source_path in
519 /*) echo 'top_srcdir = $(SRC_PATH)';;
520 *) echo 'top_srcdir = $(TOP)/$(SRC_PATH)';;
521 esac >>config.mak
523 diff $TMPH config.h >/dev/null 2>&1
524 if test $? -ne 0 ; then
525 mv -f $TMPH config.h
526 else
527 echo "config.h is unchanged"
530 rm -f $TMPN*