Create config-print program to test $cc
[tinycc.git] / configure
blob649b67b4fb357b3b9f1a050620fc7b573bb3451a
1 #!/bin/sh
3 # tcc configure script (c) 2003 Fabrice Bellard
5 fn_dirname()
7 case $1 in
8 */*) echo ${1%/*};;
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 TMPH=$TMPN.h
27 # default parameters
28 build_cross="no"
29 use_libgcc="no"
30 prefix=""
31 execprefix=""
32 bindir=""
33 libdir=""
34 tccdir=""
35 includedir=""
36 mandir=""
37 infodir=""
38 sysroot=""
39 cross_prefix=""
40 cc="gcc"
41 host_cc="gcc"
42 ar="ar"
43 strip="strip"
44 cygwin="no"
45 cpu=`uname -m`
47 tcc_sysincludepaths=""
48 tcc_libpaths=""
49 tcc_crtprefix=""
50 tcc_elfinterp=""
52 case "$cpu" in
53 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
54 cpu="x86"
56 x86_64)
57 cpu="x86-64"
59 arm*)
60 case "$cpu" in
61 arm|armv4l)
62 cpuver=4
64 armv5tel|armv5tejl)
65 cpuver=5
67 armv6j|armv6l)
68 cpuver=6
70 armv7a|armv7l)
71 cpuver=7
73 esac
74 cpu="armv4l"
76 alpha)
77 cpu="alpha"
79 "Power Macintosh"|ppc|ppc64)
80 cpu="powerpc"
82 mips)
83 cpu="mips"
85 s390)
86 cpu="s390"
89 cpu="unknown"
91 esac
92 gprof="no"
93 bigendian="no"
94 mingw32="no"
95 LIBSUF=".a"
96 EXESUF=""
98 # OS specific
99 targetos=`uname -s`
100 case $targetos in
101 MINGW32*) mingw32=yes;;
102 DragonFly) noldl=yes;;
103 OpenBSD) noldl=yes;;
104 *) ;;
105 esac
107 # find source path
108 # XXX: we assume an absolute path is given when launching configure,
109 # except in './configure' case.
110 source_path=${0%configure}
111 source_path=${source_path%/}
112 source_path_used="yes"
113 if test -z "$source_path" -o "$source_path" = "." ; then
114 source_path=`pwd`
115 source_path_used="no"
118 for opt do
119 eval opt=$opt
120 case "$opt" in
121 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
123 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
125 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
127 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
129 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
131 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
133 --sharedir=*) sharedir=`echo $opt | cut -d '=' -f 2`
135 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
137 --infodir=*) infodir=`echo $opt | cut -d '=' -f 2`
139 --docdir=*) docdir=`echo $opt | cut -d '=' -f 2`
141 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
143 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
145 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
147 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
149 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
151 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
153 --extra-libs=*) extralibs=${opt#--extra-libs=}
155 --sysincludepaths=*) tcc_sysincludepaths=`echo $opt | cut -d '=' -f 2`
157 --libpaths=*) tcc_libpaths=`echo $opt | cut -d '=' -f 2`
159 --crtprefix=*) tcc_crtprefix=`echo $opt | cut -d '=' -f 2`
161 --elfinterp=*) tcc_elfinterp=`echo $opt | cut -d '=' -f 2`
163 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
165 --enable-gprof) gprof="yes"
167 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
169 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
171 --enable-cross) build_cross="yes"
173 --disable-static) disable_static="yes"
175 --disable-rpath) disable_rpath="yes"
177 --strip-binaries) strip_binaries="yes"
179 --with-libgcc) use_libgcc="yes"
181 --with-selinux) have_selinux="yes"
183 --help|-h) show_help="yes"
185 *) echo "configure: WARNING: unrecognized option $opt"
187 esac
188 done
190 # Checking for CFLAGS
191 if test -z "$CFLAGS"; then
192 CFLAGS="-Wall -g -O2"
195 cc="${cross_prefix}${cc}"
196 ar="${cross_prefix}${ar}"
197 strip="${cross_prefix}${strip}"
199 if test "$mingw32" = "yes" ; then
200 LIBSUF=".lib"
201 EXESUF=".exe"
204 if test -z "$cross_prefix" ; then
206 if ! $cc -o config-print config-print.c 2>/dev/null ; then
207 echo "$cc is not able to compile TCC"
208 else
209 bigendian="$(./config-print e)"
210 gcc_major="$(./config-print v)"
213 else
215 # if cross compiling, cannot launch a program, so make a static guess
216 case $cpu in
217 powerpc|mips|s390) bigendian=yes;;
218 esac
222 if test -z "$cross_prefix" ; then
223 libc_dir="$(ldd ./config-print | grep libc.so | sed 's|[^/]*/\(.*/\)[^/]*|\1|')"
224 multiarch_triplet=${libc_dir#*/}
225 multiarch_triplet=${multiarch_triplet%/}
226 lddir="${libc_dir%%/*}"
227 if test -n "$multiarch_triplet" ; then
228 lddir="$lddir/$multiarch_triplet"
231 rm config-print
233 if test x"$show_help" = "xyes" ; then
234 cat << EOF
235 Usage: configure [options]
236 Options: [defaults in brackets after descriptions]
238 Standard options:
239 --help print this message
240 --prefix=PREFIX install in PREFIX [$prefix]
241 --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
242 [same as prefix]
243 --bindir=DIR user executables in DIR [EPREFIX/bin]
244 --libdir=DIR object code libraries in DIR [EPREFIX/lib]
245 --tccdir=DIR installation directory [EPREFIX/lib/tcc]
246 --includedir=DIR C header files in DIR [PREFIX/include]
247 --sharedir=DIR documentation root DIR [PREFIX]/share
248 --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
249 --mandir=DIR man documentation in DIR [SHAREDIR/man]
250 --infodir=DIR info documentation in DIR [SHAREDIR/info]
252 Advanced options (experts only):
253 --source-path=PATH path of source code [$source_path]
254 --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]
255 --sysroot=PREFIX prepend PREFIX to library/include paths []
256 --cc=CC use C compiler CC [$cc]
257 --disable-static make libtcc.so instead of libtcc.a
258 --disable-rpath disable use of -rpath with the above
259 --strip-binaries strip symbol tables from resulting binaries
260 --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a
261 --enable-mingw32 build windows version on linux with mingw32
262 --enable-cygwin build windows version on windows with cygwin
263 [requires cygwin and mingw32-make]
264 --enable-cross build cross compilers
265 --extra-cflags= extra compiler flags
266 --extra-ldflags= extra linker options
267 --with-selinux use mmap instead of exec mem
268 [requires write access to /tmp]
269 --sysincludepaths=... specify system include paths, colon separated
270 --libpaths=... specify system library paths, colon separated
271 --crtprefix=... specify locations of crt?.o, colon separated
272 --elfinterp=... specify elf interpreter
274 #echo "NOTE: The object files are build at the place where configure is launched"
275 exit 1
278 if test "$mingw32" = "yes" ; then
279 if test x"$tccdir" = x""; then
280 tccdir="tcc"
282 if test -z "$prefix" ; then
283 prefix="C:/Program Files/${tccdir}"
285 if test -z "$sharedir" ; then
286 sharedir="${prefix}"
288 execprefix="$prefix"
289 bindir="${prefix}"
290 tccdir="${prefix}"
291 libdir="${prefix}/lib"
292 docdir="${sharedir}/doc"
293 mandir="${sharedir}/man"
294 infodir="${sharedir}/info"
295 else
296 if test -z "$prefix" ; then
297 prefix="/usr/local"
299 if test -z "$sharedir" ; then
300 sharedir="${prefix}/share"
302 if test x"$execprefix" = x""; then
303 execprefix="${prefix}"
305 if test x"$libdir" = x""; then
306 libdir="${execprefix}/lib"
308 if test x"$bindir" = x""; then
309 bindir="${execprefix}/bin"
311 if test x"$tccdir" = x""; then
312 tccdir="tcc"
314 if test x"$docdir" = x""; then
315 docdir="${sharedir}/doc/${tccdir}"
317 if test x"$mandir" = x""; then
318 mandir="${sharedir}/man"
320 if test x"$infodir" = x""; then
321 infodir="${sharedir}/info"
323 tccdir="${libdir}/${tccdir}"
324 fi # mingw32
326 if test x"$includedir" = x""; then
327 includedir="${prefix}/include"
330 cat <<EOF
331 Binary directory $bindir
332 TinyCC directory $tccdir
333 Library directory $libdir
334 Include directory $includedir
335 Manual directory $mandir
336 Info directory $infodir
337 Doc directory $docdir
338 Target root prefix $sysroot
339 Source path $source_path
340 C compiler $cc
341 Target OS $targetos
342 CPU $cpu
343 Big Endian $bigendian
344 gprof enabled $gprof
345 cross compilers $build_cross
346 use libgcc $use_libgcc
349 echo "Creating config.mak and config.h"
351 cat >config.mak <<EOF
352 # Automatically generated by configure - do not modify
353 prefix=$prefix
354 bindir=\$(DESTDIR)$bindir
355 tccdir=\$(DESTDIR)$tccdir
356 libdir=\$(DESTDIR)$libdir
357 ln_libdir=$libdir
358 includedir=\$(DESTDIR)$includedir
359 mandir=\$(DESTDIR)$mandir
360 infodir=\$(DESTDIR)$infodir
361 docdir=\$(DESTDIR)$docdir
364 echo "/* Automatically generated by configure - do not modify */" > $TMPH
365 print_var1()
367 echo "#ifndef $1" >> $TMPH
368 echo "# define $1 \"$2\"" >> $TMPH
369 echo "#endif" >> $TMPH
371 print_var2()
373 if test -n "$2"; then print_var1 $1 "$2"; fi
375 print_var2 CONFIG_SYSROOT "$sysroot"
376 print_var1 CONFIG_TCCDIR "$tccdir"
377 print_var2 CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
378 print_var2 CONFIG_TCC_LIBPATHS "$tcc_libpaths"
379 print_var2 CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
380 print_var2 CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
381 print_var2 CONFIG_MULTIARCHDIR "$multiarch_triplet"
382 print_var2 CONFIG_LDDIR "$lddir"
384 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
386 cat >> config.mak <<EOF
387 CC=$cc
388 GCC_MAJOR=$gcc_major
389 HOST_CC=$host_cc
390 AR=$ar
391 STRIP=$strip -s -R .comment -R .note
392 CFLAGS=$CFLAGS
393 LDFLAGS=$LDFLAGS
394 LIBSUF=$LIBSUF
395 EXESUF=$EXESUF
398 if test "$cpu" = "x86" ; then
399 echo "ARCH=i386" >> config.mak
400 echo "#define HOST_I386 1" >> $TMPH
401 elif test "$cpu" = "x86-64" ; then
402 echo "ARCH=x86-64" >> config.mak
403 echo "#define HOST_X86_64 1" >> $TMPH
404 elif test "$cpu" = "armv4l" ; then
405 echo "ARCH=arm" >> config.mak
406 echo "#define HOST_ARM 1" >> $TMPH
407 echo "#define TCC_ARM_VERSION $cpuver" >> $TMPH
408 elif test "$cpu" = "powerpc" ; then
409 echo "ARCH=ppc" >> config.mak
410 echo "#define HOST_PPC 1" >> $TMPH
411 elif test "$cpu" = "mips" ; then
412 echo "ARCH=mips" >> config.mak
413 echo "#define HOST_MIPS 1" >> $TMPH
414 elif test "$cpu" = "s390" ; then
415 echo "ARCH=s390" >> config.mak
416 echo "#define HOST_S390 1" >> $TMPH
417 elif test "$cpu" = "alpha" ; then
418 echo "ARCH=alpha" >> config.mak
419 echo "#define HOST_ALPHA 1" >> $TMPH
420 else
421 echo "Unsupported CPU"
422 exit 1
424 echo "TARGETOS=$targetos" >> config.mak
425 if test "$noldl" = "yes" ; then
426 echo "CONFIG_NOLDL=yes" >> config.mak
428 if test "$mingw32" = "yes" ; then
429 echo "CONFIG_WIN32=yes" >> config.mak
430 echo "#define CONFIG_WIN32 1" >> $TMPH
432 if test "$cygwin" = "yes" ; then
433 echo "#ifndef _WIN32" >> $TMPH
434 echo "#define _WIN32" >> $TMPH
435 echo "#endif" >> $TMPH
436 echo "AR=ar" >> config.mak
438 if test "$bigendian" = "yes" ; then
439 echo "WORDS_BIGENDIAN=yes" >> config.mak
440 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
442 if test "$gprof" = "yes" ; then
443 echo "TARGET_GPROF=yes" >> config.mak
444 echo "#define HAVE_GPROF 1" >> $TMPH
446 if test "$build_cross" = "yes" ; then
447 echo "CONFIG_CROSS=yes" >> config.mak
449 if test "$disable_static" = "yes" ; then
450 echo "DISABLE_STATIC=yes" >> config.mak
452 if test "$disable_rpath" = "yes" ; then
453 echo "DISABLE_RPATH=yes" >> config.mak
455 if test "$strip_binaries" = "yes" ; then
456 echo "STRIP_BINARIES=yes" >> config.mak
458 if test "$use_libgcc" = "yes" ; then
459 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
460 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
462 if test "$have_selinux" = "yes" ; then
463 echo "#define HAVE_SELINUX" >> $TMPH
464 echo "HAVE_SELINUX=yes" >> config.mak
467 version=`head $source_path/VERSION`
468 echo "VERSION=$version" >>config.mak
469 echo "#define TCC_VERSION \"$version\"" >> $TMPH
470 echo "@set VERSION $version" > config.texi
471 echo "SRC_PATH=$source_path" >>config.mak
473 # build tree in object directory if source path is different from current one
474 if test "$source_path_used" = "yes" ; then
475 FILES="Makefile lib/Makefile tests/Makefile tests/tests2/Makefile"
476 for f in $FILES ; do
477 dir=`fn_dirname "$f"`
478 test -d "$dir" || mkdir -p "$dir"
479 # Build a symlink $f that points to $dest, its $source_path
480 # counterpart.
481 case $source_path in
482 /*) dest=$source_path/$f;;
483 *) dest=`echo "$dir/" | sed 's,^\./,,;s,[^/]*/,../,g'`
484 dest=$dest$source_path/$f;;
485 esac
486 ln -sf $dest $f
487 done
488 case $source_path in
489 /*) echo "top_srcdir=$source_path";;
490 *) echo "top_srcdir=\$(TOP)/$source_path";;
491 esac >>config.mak
492 else
493 echo 'top_srcdir=$(TOP)' >>config.mak
495 echo 'top_builddir=$(TOP)' >>config.mak
497 diff $TMPH config.h >/dev/null 2>&1
498 if test $? -ne 0 ; then
499 mv -f $TMPH config.h
500 else
501 echo "config.h is unchanged"
504 rm -f $TMPN*