Add a --multiarch-triplet switch to configure
[tinycc/miki.git] / configure
blob0ab2a3dd21d13f09d79d2d83aaf528c02bb41d05
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 multiarch_triplet=""
35 cross_prefix=""
36 cc="gcc"
37 host_cc="gcc"
38 ar="ar"
39 strip="strip"
40 cygwin="no"
41 cpu=`uname -m`
42 case "$cpu" in
43 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
44 cpu="x86"
46 x86_64)
47 cpu="x86-64"
49 arm|armv4l|armv5tel|armv5tejl|armv6j|armv7a|armv7l)
50 cpu="armv4l"
52 alpha)
53 cpu="alpha"
55 "Power Macintosh"|ppc|ppc64)
56 cpu="powerpc"
58 mips)
59 cpu="mips"
61 s390)
62 cpu="s390"
65 cpu="unknown"
67 esac
68 gprof="no"
69 bigendian="no"
70 mingw32="no"
71 LIBSUF=".a"
72 EXESUF=""
74 # OS specific
75 targetos=`uname -s`
76 case $targetos in
77 MINGW32*)
78 mingw32="yes"
80 DragonFly)
81 noldl="yes"
83 OpenBSD)
84 noldl="yes"
86 *) ;;
87 esac
89 # find source path
90 # XXX: we assume an absolute path is given when launching configure,
91 # except in './configure' case.
92 source_path=${0%configure}
93 source_path=${source_path%/}
94 source_path_used="yes"
95 if test -z "$source_path" -o "$source_path" = "." ; then
96 source_path=`pwd`
97 source_path_used="no"
100 for opt do
101 case "$opt" in
102 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
104 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
106 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
108 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
110 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
112 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
114 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
116 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
118 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
120 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
122 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
124 --multiarch-triplet=*) multiarch_triplet=`echo $opt | cut -d '=' -f 2`
126 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
128 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
130 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
132 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
134 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
136 --extra-libs=*) extralibs=${opt#--extra-libs=}
138 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
140 --enable-gprof) gprof="yes"
142 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
144 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
146 --enable-cross) build_cross="yes"
148 --disable-static) disable_static="yes"
150 --disable-rpath) disable_rpath="yes"
152 --strip-binaries) strip_binaries="yes"
154 --with-libgcc) use_libgcc="yes"
156 --with-selinux) have_selinux="yes"
158 --help|-h) show_help="yes"
160 esac
161 done
163 # Checking for CFLAGS
164 if test -z "$CFLAGS"; then
165 CFLAGS="-Wall -g -O2"
168 cc="${cross_prefix}${cc}"
169 ar="${cross_prefix}${ar}"
170 strip="${cross_prefix}${strip}"
172 if test "$mingw32" = "yes" ; then
173 LIBSUF=".lib"
174 EXESUF=".exe"
177 if test -z "$cross_prefix" ; then
179 # ---
180 # big/little endian test
181 cat > $TMPC << EOF
182 #include <inttypes.h>
183 int main(int argc, char ** argv){
184 volatile uint32_t i=0x01234567;
185 return (*((uint8_t*)(&i))) == 0x67;
189 if $cc -o $TMPE $TMPC 2>/dev/null ; then
190 $TMPE && bigendian="yes"
191 else
192 echo big/little test failed
195 else
197 # if cross compiling, cannot launch a program, so make a static guess
198 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
199 bigendian="yes"
204 # check gcc version
205 cat > $TMPC <<EOF
206 int main(void) {
207 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
208 return 0;
209 #else
210 #error gcc < 3.2
211 #endif
215 gcc_major="2"
216 if $cc -o $TMPO $TMPC 2> /dev/null ; then
217 gcc_major="3"
219 cat > $TMPC <<EOF
220 int main(void) {
221 #if __GNUC__ >= 4
222 return 0;
223 #else
224 #error gcc < 4
225 #endif
229 if $cc -o $TMPO $TMPC 2> /dev/null ; then
230 gcc_major="4"
233 if test x"$show_help" = "xyes" ; then
234 cat << EOF
236 Usage: configure [options]
237 Options: [defaults in brackets after descriptions]
240 echo "Standard options:"
241 echo " --help print this message"
242 echo " --prefix=PREFIX install in PREFIX [$prefix]"
243 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
244 echo " [same as prefix]"
245 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
246 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
247 echo " --tccdir=DIR installation directory [EPREFIX/lib/tcc]"
248 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
249 echo " --sharedir=DIR documentation root DIR [PREFIX]/share"
250 echo " --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]"
251 echo " --mandir=DIR man documentation in DIR [SHAREDIR/man]"
252 echo " --infodir=DIR info documentation in DIR [SHAREDIR/info]"
253 echo ""
254 echo "Advanced options (experts only):"
255 echo " --source-path=PATH path of source code [$source_path]"
256 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
257 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
258 echo " --multiarch-triplet=SUFFIX append SUFFIX to library/include paths []"
259 echo " --cc=CC use C compiler CC [$cc]"
260 echo " --disable-static make libtcc.so instead of libtcc.a"
261 echo " --disable-rpath disable use of -rpath with the above"
262 echo " --strip-binaries strip symbol tables from resulting binaries"
263 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
264 echo " --enable-mingw32 build windows version on linux with mingw32"
265 echo " --enable-cygwin build windows version on windows with cygwin"
266 echo " [requires cygwin and mingw32-make]"
267 echo " --enable-cross build cross compilers"
268 echo " --extra-cflags= extra compiler flags"
269 echo " --extra-ldflags= extra linker options"
270 echo " --with-selinux use mmap instead of exec mem"
271 echo " [requires write access to /tmp]"
272 echo ""
273 #echo "NOTE: The object files are build at the place where configure is launched"
274 exit 1
277 if test "$mingw32" = "yes" ; then
278 if test x"$tccdir" = x""; then
279 tccdir="tcc"
281 if test -z "$prefix" ; then
282 prefix="C:/Program Files/${tccdir}"
284 if test -z "$sharedir" ; then
285 sharedir="${prefix}"
287 execprefix="$prefix"
288 bindir="${prefix}"
289 tccdir="${prefix}"
290 libdir="${prefix}/lib"
291 docdir="${sharedir}/doc"
292 mandir="${sharedir}/man"
293 infodir="${sharedir}/info"
294 else
295 if test -z "$prefix" ; then
296 prefix="/usr/local"
298 if test -z "$sharedir" ; then
299 sharedir="${prefix}/share"
301 if test x"$execprefix" = x""; then
302 execprefix="${prefix}"
304 if test x"$libdir" = x""; then
305 libdir="${execprefix}/lib"
307 if test x"$bindir" = x""; then
308 bindir="${execprefix}/bin"
310 if test x"$tccdir" = x""; then
311 tccdir="tcc"
313 if test x"$docdir" = x""; then
314 docdir="${sharedir}/doc/${tccdir}"
316 if test x"$mandir" = x""; then
317 mandir="${sharedir}/man"
319 if test x"$infodir" = x""; then
320 infodir="${sharedir}/info"
322 tccdir="${libdir}/${tccdir}"
323 fi # mingw32
325 if test x"$includedir" = x""; then
326 includedir="${prefix}/include"
329 echo "Binary directory $bindir"
330 echo "TinyCC directory $tccdir"
331 echo "Library directory $libdir"
332 echo "Include directory $includedir"
333 echo "Manual directory $mandir"
334 echo "Info directory $infodir"
335 echo "Doc directory $docdir"
336 echo "Target root prefix $sysroot"
337 echo "Multiarch triplet $multiarch_triplet"
338 echo "Source path $source_path"
339 echo "C compiler $cc"
340 echo "CPU $cpu"
341 echo "Big Endian $bigendian"
342 echo "gprof enabled $gprof"
343 echo "cross compilers $build_cross"
344 echo "use libgcc $use_libgcc"
346 echo "Creating config.mak and config.h"
348 echo "# Automatically generated by configure - do not modify" > config.mak
349 echo "/* Automatically generated by configure - do not modify */" > $TMPH
351 echo "prefix=$prefix" >> config.mak
352 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
353 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
354 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
355 echo "ln_libdir=$libdir" >> config.mak
356 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
357 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
358 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
359 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
361 echo "#ifndef CONFIG_SYSROOT" >> $TMPH
362 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
363 echo "#endif" >> $TMPH
364 echo "" >> $TMPH
366 # Set default include and library paths
367 win_incpaths="\\\b/include;\\\b/include/winapi"
368 unix_incpaths="/usr/local/include:/usr/include:\\\b/include"
369 win_libpaths="\\\b/lib"
370 unix_libpaths="CONFIG_SYSROOT CONFIG_TCC_CRT_PREFIX"
371 unix_libpaths="$unix_libpaths\":\"CONFIG_SYSROOT CONFIG_TCC_LDDIR"
372 unix_libpaths="$unix_libpaths\":\"CONFIG_SYSROOT \"/usr/local\" CONFIG_TCC_LDDIR"
374 # sep: path separator in paths
375 # tmp: paths multiarchified (one path per line)
376 # q: quote (if sep contains ")
377 # r: carriage return pattern (if sep contains ")
378 # s: space (if sep contains ")
379 multiarchify()
381 local sep tmp
383 paths="$1"
384 sep="$2"
385 tmp=""
386 q=""
387 r=""
388 s=""
389 if [ -z "${sep%%\"*}" ] ; then
390 q="\""
391 r=" \\\\\n "
392 s=" "
394 paths="$paths$sep"
395 while test -n "$paths" ; do
396 tmp="$tmp${tmp:+$r$sep$s}${paths%%$sep*}$s$q/$multiarch_triplet$q"
397 tmp="$tmp$r$sep$s${paths%%$sep*}"
398 paths="${paths#*$sep}"
399 done
400 paths="$tmp"
403 if test -n "$multiarch_triplet" ; then
404 multiarchify "$win_incpaths" ";"
405 win_incpaths="\"$paths\""
406 multiarchify "$unix_incpaths" ":"
407 unix_incpaths="\"$paths\""
408 multiarchify "$win_libpaths" ";"
409 win_libpaths="\"$paths\""
410 multiarchify "$unix_libpaths" "\":\""
411 unix_libpaths="$paths"
412 echo "#define CONFIG_TCC_MULTIARCH_TRIPLET \"$multiarch_triplet\"" >> $TMPH
415 echo "#ifndef CONFIG_TCC_LDDIR" >> $TMPH
416 echo " #if defined(TCC_TARGET_X86_64_CENTOS)" >> $TMPH
417 echo " #define CONFIG_TCC_LDDIR \"/lib64\"" >> $TMPH
418 echo " #else" >> $TMPH
419 echo " #define CONFIG_TCC_LDDIR \"/lib\"" >> $TMPH
420 echo " #endif" >> $TMPH
421 echo "#endif" >> $TMPH
422 echo "" >> $TMPH
424 echo "/* path to find crt1.o, crti.o and crtn.o */" >> $TMPH
425 echo "#ifndef CONFIG_TCC_CRT_PREFIX" >> $TMPH
426 echo "# define CONFIG_TCC_CRT_PREFIX \"/usr\" CONFIG_TCC_LDDIR" >> $TMPH
427 echo "#endif" >> $TMPH
428 echo "" >> $TMPH
430 echo "#ifndef CONFIG_TCC_SYSINCLUDE_PATHS" >> $TMPH
431 echo "# ifdef TCC_TARGET_PE" >> $TMPH
432 echo "# define CONFIG_TCC_SYSINCLUDE_PATHS $win_incpaths" >> $TMPH
433 echo "# else" >> $TMPH
434 echo "# define CONFIG_TCC_SYSINCLUDE_PATHS $unix_incpaths" >> $TMPH
435 echo "# endif" >> $TMPH
436 echo "#endif" >> $TMPH
437 echo "" >> $TMPH
438 echo "#ifndef CONFIG_TCC_LIBPATH" >> $TMPH
439 echo "# ifdef TCC_TARGET_PE" >> $TMPH
440 echo "# define CONFIG_TCC_LIBPATH $win_libpaths" >> $TMPH
441 echo "# else" >> $TMPH
442 echo "# define CONFIG_TCC_LIBPATH $unix_libpaths" >> $TMPH
443 echo "# endif" >> $TMPH
444 echo "#endif" >> $TMPH
445 echo "" >> $TMPH
447 echo "#ifndef CONFIG_TCCDIR" >> $TMPH
448 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
449 echo "#endif" >> $TMPH
450 echo "" >> $TMPH
451 echo "CC=$cc" >> config.mak
452 echo "GCC_MAJOR=$gcc_major" >> config.mak
453 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
454 echo "HOST_CC=$host_cc" >> config.mak
455 echo "AR=$ar" >> config.mak
456 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
457 echo "CFLAGS=$CFLAGS" >> config.mak
458 echo "LDFLAGS=$LDFLAGS" >> config.mak
459 echo "LIBSUF=$LIBSUF" >> config.mak
460 echo "EXESUF=$EXESUF" >> config.mak
461 if test "$cpu" = "x86" ; then
462 echo "ARCH=i386" >> config.mak
463 echo "#define HOST_I386 1" >> $TMPH
464 elif test "$cpu" = "x86-64" ; then
465 echo "ARCH=x86-64" >> config.mak
466 echo "#define HOST_X86_64 1" >> $TMPH
467 elif test "$cpu" = "armv4l" ; then
468 echo "ARCH=arm" >> config.mak
469 echo "#define HOST_ARM 1" >> $TMPH
470 elif test "$cpu" = "powerpc" ; then
471 echo "ARCH=ppc" >> config.mak
472 echo "#define HOST_PPC 1" >> $TMPH
473 elif test "$cpu" = "mips" ; then
474 echo "ARCH=mips" >> config.mak
475 echo "#define HOST_MIPS 1" >> $TMPH
476 elif test "$cpu" = "s390" ; then
477 echo "ARCH=s390" >> config.mak
478 echo "#define HOST_S390 1" >> $TMPH
479 elif test "$cpu" = "alpha" ; then
480 echo "ARCH=alpha" >> config.mak
481 echo "#define HOST_ALPHA 1" >> $TMPH
482 else
483 echo "Unsupported CPU"
484 exit 1
486 if test "$noldl" = "yes" ; then
487 echo "CONFIG_NOLDL=yes" >> config.mak
489 if test "$mingw32" = "yes" ; then
490 echo "CONFIG_WIN32=yes" >> config.mak
491 echo "#define CONFIG_WIN32 1" >> $TMPH
493 if test "$cygwin" = "yes" ; then
494 echo "#ifndef _WIN32" >> $TMPH
495 echo "#define _WIN32" >> $TMPH
496 echo "#endif" >> $TMPH
497 echo "AR=ar" >> config.mak
499 if test "$bigendian" = "yes" ; then
500 echo "WORDS_BIGENDIAN=yes" >> config.mak
501 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
503 if test "$gprof" = "yes" ; then
504 echo "TARGET_GPROF=yes" >> config.mak
505 echo "#define HAVE_GPROF 1" >> $TMPH
507 if test "$build_cross" = "yes" ; then
508 echo "CONFIG_CROSS=yes" >> config.mak
510 if test "$disable_static" = "yes" ; then
511 echo "DISABLE_STATIC=yes" >> config.mak
513 if test "$disable_rpath" = "yes" ; then
514 echo "DISABLE_RPATH=yes" >> config.mak
516 if test "$strip_binaries" = "yes" ; then
517 echo "STRIP_BINARIES=yes" >> config.mak
519 if test "$use_libgcc" = "yes" ; then
520 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
521 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
523 if test "$have_selinux" = "yes" ; then
524 echo "#define HAVE_SELINUX" >> $TMPH
525 echo "HAVE_SELINUX=yes" >> config.mak
527 version=`head $source_path/VERSION`
528 echo "VERSION=$version" >>config.mak
529 echo "#define TCC_VERSION \"$version\"" >> $TMPH
530 echo "@set VERSION $version" > config.texi
532 # build tree in object directory if source path is different from current one
533 if test "$source_path_used" = "yes" ; then
534 DIRS="tests"
535 FILES="Makefile tests/Makefile"
536 for dir in $DIRS ; do
537 mkdir -p $dir
538 done
539 for f in $FILES ; do
540 ln -sf $source_path/$f $f
541 done
543 echo "SRC_PATH=$source_path" >> config.mak
545 diff $TMPH config.h >/dev/null 2>&1
546 if test $? -ne 0 ; then
547 mv -f $TMPH config.h
548 else
549 echo "config.h is unchanged"
552 rm -f $TMPN*