configure: prefer here-documents
[tinycc.git] / configure
blob6467aaab1af740920a1293636c5608eef553800a
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*) mingw32=yes;;
105 DragonFly) noldl=yes;;
106 OpenBSD) noldl=yes;;
107 *) ;;
108 esac
110 # find source path
111 # XXX: we assume an absolute path is given when launching configure,
112 # except in './configure' case.
113 source_path=${0%configure}
114 source_path=${source_path%/}
115 source_path_used="yes"
116 if test -z "$source_path" -o "$source_path" = "." ; then
117 source_path=`pwd`
118 source_path_used="no"
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 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
152 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
154 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
156 --extra-libs=*) extralibs=${opt#--extra-libs=}
158 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
160 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
162 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
164 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
166 --cpu=*) 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 --disable-static) disable_static="yes"
178 --disable-rpath) disable_rpath="yes"
180 --strip-binaries) strip_binaries="yes"
182 --with-libgcc) use_libgcc="yes"
184 --with-selinux) have_selinux="yes"
186 --help|-h) show_help="yes"
188 *) echo "configure: WARNING: unrecognized option $opt"
190 esac
191 done
193 # Checking for CFLAGS
194 if test -z "$CFLAGS"; then
195 CFLAGS="-Wall -g -O2"
198 cc="${cross_prefix}${cc}"
199 ar="${cross_prefix}${ar}"
200 strip="${cross_prefix}${strip}"
202 if test "$mingw32" = "yes" ; then
203 LIBSUF=".lib"
204 EXESUF=".exe"
207 if test -z "$cross_prefix" ; then
209 # ---
210 # big/little endian test
211 cat > $TMPC << EOF
212 #include <inttypes.h>
213 int main(int argc, char ** argv){
214 volatile uint32_t i=0x01234567;
215 return (*((uint8_t*)(&i))) == 0x67;
219 if $cc -o $TMPE $TMPC 2>/dev/null ; then
220 $TMPE && bigendian="yes"
221 else
222 echo big/little test failed
225 else
227 # if cross compiling, cannot launch a program, so make a static guess
228 case $cpu in
229 powerpc|mips|s390) bigendian=yes;;
230 esac
234 # check gcc version
235 cat > $TMPC <<EOF
236 int main(void) {
237 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
238 return 0;
239 #else
240 #error gcc < 3.2
241 #endif
245 gcc_major="2"
246 if $cc -o $TMPO $TMPC 2> /dev/null ; then
247 gcc_major="3"
249 cat > $TMPC <<EOF
250 int main(void) {
251 #if __GNUC__ >= 4
252 return 0;
253 #else
254 #error gcc < 4
255 #endif
259 if $cc -o $TMPO $TMPC 2> /dev/null ; then
260 gcc_major="4"
263 if test x"$show_help" = "xyes" ; then
264 cat << EOF
265 Usage: configure [options]
266 Options: [defaults in brackets after descriptions]
268 Standard options:
269 --help print this message
270 --prefix=PREFIX install in PREFIX [$prefix]
271 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
272 [same as prefix]
273 --bindir=DIR user executables in DIR [EPREFIX/bin]
274 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
275 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
276 --includedir=DIR C header files in DIR [PREFIX/include]
277 --sharedir=DIR documentation root DIR [PREFIX]/share
278 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
279 --mandir=DIR man documentation in DIR [SHAREDIR/man]
280 --infodir=DIR info documentation in DIR [SHAREDIR/info]
282 Advanced options (experts only):
283 --source-path=PATH path of source code [$source_path]
284 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
285 --sysroot=PREFIX prepend PREFIX to library/include paths []
286 --cc=CC use C compiler CC [$cc]
287 --disable-static make libtcc.so instead of libtcc.a
288 --disable-rpath disable use of -rpath with the above
289 --strip-binaries strip symbol tables from resulting binaries
290 --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a
291 --enable-mingw32 build windows version on linux with mingw32
292 --enable-cygwin build windows version on windows with cygwin
293 [requires cygwin and mingw32-make]
294 --enable-cross build cross compilers
295 --extra-cflags= extra compiler flags
296 --extra-ldflags= extra linker options
297 --with-selinux use mmap instead of exec mem
298 [requires write access to /tmp]
299 --sysincludepaths=... specify system include paths, colon separated
300 --libpaths=... specify system library paths, colon separated
301 --crtprefix=... specify locations of crt?.o, colon separated
302 --elfinterp=... specify elf interpreter
304 #echo "NOTE: The object files are build at the place where configure is launched"
305 exit 1
308 if test "$mingw32" = "yes" ; then
309 if test x"$tccdir" = x""; then
310 tccdir="tcc"
312 if test -z "$prefix" ; then
313 prefix="C:/Program Files/${tccdir}"
315 if test -z "$sharedir" ; then
316 sharedir="${prefix}"
318 execprefix="$prefix"
319 bindir="${prefix}"
320 tccdir="${prefix}"
321 libdir="${prefix}/lib"
322 docdir="${sharedir}/doc"
323 mandir="${sharedir}/man"
324 infodir="${sharedir}/info"
325 else
326 if test -z "$prefix" ; then
327 prefix="/usr/local"
329 if test -z "$sharedir" ; then
330 sharedir="${prefix}/share"
332 if test x"$execprefix" = x""; then
333 execprefix="${prefix}"
335 if test x"$libdir" = x""; then
336 libdir="${execprefix}/lib"
338 if test x"$bindir" = x""; then
339 bindir="${execprefix}/bin"
341 if test x"$tccdir" = x""; then
342 tccdir="tcc"
344 if test x"$docdir" = x""; then
345 docdir="${sharedir}/doc/${tccdir}"
347 if test x"$mandir" = x""; then
348 mandir="${sharedir}/man"
350 if test x"$infodir" = x""; then
351 infodir="${sharedir}/info"
353 tccdir="${libdir}/${tccdir}"
354 fi # mingw32
356 if test x"$includedir" = x""; then
357 includedir="${prefix}/include"
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 Target OS $targetos
372 CPU $cpu
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 echo "# Automatically generated by configure - do not modify" > config.mak
382 echo "/* Automatically generated by configure - do not modify */" > $TMPH
384 echo "prefix=$prefix" >> config.mak
385 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
386 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
387 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
388 echo "ln_libdir=$libdir" >> config.mak
389 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
390 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
391 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
392 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
393 print_var1()
395 echo "#ifndef $1" >> $TMPH
396 echo "# define $1 \"$2\"" >> $TMPH
397 echo "#endif" >> $TMPH
399 print_var2()
401 if test -n "$2"; then print_var1 $1 "$2"; fi
403 print_var2 CONFIG_SYSROOT "$sysroot"
404 print_var1 CONFIG_TCCDIR "$tccdir"
405 print_var2 CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
406 print_var2 CONFIG_TCC_LIBPATHS "$tcc_libpaths"
407 print_var2 CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
408 print_var2 CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
410 echo "CC=$cc" >> config.mak
411 echo "GCC_MAJOR=$gcc_major" >> config.mak
412 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
413 echo "HOST_CC=$host_cc" >> config.mak
414 echo "AR=$ar" >> config.mak
415 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
416 cat >> config.mak <<EOF
417 CPPFLAGS = -I. -I\$(top_srcdir)
418 CFLAGS=$CFLAGS
419 LDFLAGS=$LDFLAGS
420 LIBSUF=$LIBSUF
421 EXESUF=$EXESUF
424 if test "$cpu" = "x86" ; then
425 echo "ARCH=i386" >> config.mak
426 echo "#define HOST_I386 1" >> $TMPH
427 elif test "$cpu" = "x86-64" ; then
428 echo "ARCH=x86-64" >> config.mak
429 echo "#define HOST_X86_64 1" >> $TMPH
430 elif test "$cpu" = "armv4l" ; then
431 echo "ARCH=arm" >> config.mak
432 echo "#define HOST_ARM 1" >> $TMPH
433 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
434 elif test "$cpu" = "powerpc" ; then
435 echo "ARCH=ppc" >> config.mak
436 echo "#define HOST_PPC 1" >> $TMPH
437 elif test "$cpu" = "mips" ; then
438 echo "ARCH=mips" >> config.mak
439 echo "#define HOST_MIPS 1" >> $TMPH
440 elif test "$cpu" = "s390" ; then
441 echo "ARCH=s390" >> config.mak
442 echo "#define HOST_S390 1" >> $TMPH
443 elif test "$cpu" = "alpha" ; then
444 echo "ARCH=alpha" >> config.mak
445 echo "#define HOST_ALPHA 1" >> $TMPH
446 else
447 echo "Unsupported CPU"
448 exit 1
450 echo "TARGETOS=$targetos" >> config.mak
451 if test "$noldl" = "yes" ; then
452 echo "CONFIG_NOLDL=yes" >> config.mak
454 if test "$mingw32" = "yes" ; then
455 echo "CONFIG_WIN32=yes" >> config.mak
456 echo "#define CONFIG_WIN32 1" >> $TMPH
458 if test "$cygwin" = "yes" ; then
459 echo "#ifndef _WIN32" >> $TMPH
460 echo "#define _WIN32" >> $TMPH
461 echo "#endif" >> $TMPH
462 echo "AR=ar" >> config.mak
464 if test "$bigendian" = "yes" ; then
465 echo "WORDS_BIGENDIAN=yes" >> config.mak
466 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
468 if test "$gprof" = "yes" ; then
469 echo "TARGET_GPROF=yes" >> config.mak
470 echo "#define HAVE_GPROF 1" >> $TMPH
472 if test "$build_cross" = "yes" ; then
473 echo "CONFIG_CROSS=yes" >> config.mak
475 if test "$disable_static" = "yes" ; then
476 echo "DISABLE_STATIC=yes" >> config.mak
478 if test "$disable_rpath" = "yes" ; then
479 echo "DISABLE_RPATH=yes" >> config.mak
481 if test "$strip_binaries" = "yes" ; then
482 echo "STRIP_BINARIES=yes" >> config.mak
484 if test "$use_libgcc" = "yes" ; then
485 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
486 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
488 if test "$have_selinux" = "yes" ; then
489 echo "#define HAVE_SELINUX" >> $TMPH
490 echo "HAVE_SELINUX=yes" >> config.mak
492 version=`head $source_path/VERSION`
493 echo "VERSION=$version" >>config.mak
494 echo "#define TCC_VERSION \"$version\"" >> $TMPH
495 echo "@set VERSION $version" > config.texi
497 # build tree in object directory if source path is different from current one
498 if test "$source_path_used" = "yes" ; then
499 FILES="Makefile lib/Makefile tests/Makefile tests2/Makefile"
500 for f in $FILES ; do
501 dir=`fn_dirname "$f"`
502 test -d "$dir" || mkdir -p "$dir"
503 back=`echo "$source_path/$dir/" | sed 's,/\./,/,g;s,[^/]*/,../,g'`
504 back=$back$f
505 ln -sf $back $f
506 done
508 cat >>config.mak <<EOF
509 SRC_PATH = $source_path
510 top_builddir = \$(TOP)
512 case $source_path in
513 /*) echo 'top_srcdir = $(SRC_PATH)';;
514 *) echo 'top_srcdir = $(TOP)/$(SRC_PATH)';;
515 esac >>config.mak
517 diff $TMPH config.h >/dev/null 2>&1
518 if test $? -ne 0 ; then
519 mv -f $TMPH config.h
520 else
521 echo "config.h is unchanged"
524 rm -f $TMPN*