Add multiarch dirs to linker search path
[tinycc.git] / configure
blob57317be0887ba13e518d8ac878747b398818a8d1
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 lddir=""
30 extralddir=""
31 tccdir=""
32 includedir=""
33 mandir=""
34 infodir=""
35 sysroot=""
36 cross_prefix=""
37 cc="gcc"
38 host_cc="gcc"
39 ar="ar"
40 strip="strip"
41 cygwin="no"
42 cpu=`uname -m`
43 case "$cpu" in
44 i386|i486|i586|i686|i86pc|BePC|i686-AT386)
45 cpu="x86"
47 x86_64)
48 cpu="x86-64"
50 arm|armv4l|armv5tel|armv5tejl|armv6j|armv7a|armv7l)
51 cpu="armv4l"
53 alpha)
54 cpu="alpha"
56 "Power Macintosh"|ppc|ppc64)
57 cpu="powerpc"
59 mips)
60 cpu="mips"
62 s390)
63 cpu="s390"
66 cpu="unknown"
68 esac
69 gprof="no"
70 bigendian="no"
71 mingw32="no"
72 LIBSUF=".a"
73 EXESUF=""
75 # OS specific
76 targetos=`uname -s`
77 case $targetos in
78 MINGW32*)
79 mingw32="yes"
81 DragonFly)
82 noldl="yes"
84 OpenBSD)
85 noldl="yes"
87 *) ;;
88 esac
90 # find source path
91 # XXX: we assume an absolute path is given when launching configure,
92 # except in './configure' case.
93 source_path=${0%configure}
94 source_path=${source_path%/}
95 source_path_used="yes"
96 if test -z "$source_path" -o "$source_path" = "." ; then
97 source_path=`pwd`
98 source_path_used="no"
101 for opt do
102 case "$opt" in
103 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
105 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
107 --tccdir=*) tccdir=`echo $opt | cut -d '=' -f 2`
109 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
111 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
113 --lddir=*) lddir=`echo $opt | cut -d '=' -f 2`
115 --extralddir=*) extralddir="$extralddir:`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 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
143 --enable-gprof) gprof="yes"
145 --enable-mingw32) mingw32="yes" ; cross_prefix="i686-pc-mingw32-" ; cpu=x86
147 --enable-cygwin) mingw32="yes" ; cygwin="yes" ; cross_prefix="mingw32-" ; cpu=x86
149 --enable-cross) build_cross="yes"
151 --disable-static) disable_static="yes"
153 --disable-rpath) disable_rpath="yes"
155 --strip-binaries) strip_binaries="yes"
157 --with-libgcc) use_libgcc="yes"
159 --with-selinux) have_selinux="yes"
161 --help|-h) show_help="yes"
163 esac
164 done
166 # Checking for CFLAGS
167 if test -z "$CFLAGS"; then
168 CFLAGS="-Wall -g -O2"
171 cc="${cross_prefix}${cc}"
172 ar="${cross_prefix}${ar}"
173 strip="${cross_prefix}${strip}"
175 if test "$mingw32" = "yes" ; then
176 LIBSUF=".lib"
177 EXESUF=".exe"
180 if test -z "$cross_prefix" ; then
182 # ---
183 # big/little endian test
184 cat > $TMPC << EOF
185 #include <inttypes.h>
186 int main(int argc, char ** argv){
187 volatile uint32_t i=0x01234567;
188 return (*((uint8_t*)(&i))) == 0x67;
192 if $cc -o $TMPE $TMPC 2>/dev/null ; then
193 $TMPE && bigendian="yes"
194 else
195 echo big/little test failed
198 else
200 # if cross compiling, cannot launch a program, so make a static guess
201 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
202 bigendian="yes"
207 # check gcc version
208 cat > $TMPC <<EOF
209 int main(void) {
210 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
211 return 0;
212 #else
213 #error gcc < 3.2
214 #endif
218 gcc_major="2"
219 if $cc -o $TMPO $TMPC 2> /dev/null ; then
220 gcc_major="3"
222 cat > $TMPC <<EOF
223 int main(void) {
224 #if __GNUC__ >= 4
225 return 0;
226 #else
227 #error gcc < 4
228 #endif
232 if $cc -o $TMPO $TMPC 2> /dev/null ; then
233 gcc_major="4"
236 if test x"$show_help" = "xyes" ; then
237 cat << EOF
239 Usage: configure [options]
240 Options: [defaults in brackets after descriptions]
243 echo "Standard options:"
244 echo " --help print this message"
245 echo " --prefix=PREFIX install in PREFIX [$prefix]"
246 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
247 echo " [same as prefix]"
248 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
249 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
250 echo " --lddir=DIR loader library search path in DIR [/lib]"
251 echo " --extralddir=DIR extra loader library search path in DIR []"
252 echo " --tccdir=DIR installation directory [EPREFIX/lib/tcc]"
253 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
254 echo " --sharedir=DIR documentation root DIR [PREFIX]/share"
255 echo " --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]"
256 echo " --mandir=DIR man documentation in DIR [SHAREDIR/man]"
257 echo " --infodir=DIR info documentation in DIR [SHAREDIR/info]"
258 echo ""
259 echo "Advanced options (experts only):"
260 echo " --source-path=PATH path of source code [$source_path]"
261 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
262 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
263 echo " --cc=CC use C compiler CC [$cc]"
264 echo " --disable-static make libtcc.so instead of libtcc.a"
265 echo " --disable-rpath disable use of -rpath with the above"
266 echo " --strip-binaries strip symbol tables from resulting binaries"
267 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc.a"
268 echo " --enable-mingw32 build windows version on linux with mingw32"
269 echo " --enable-cygwin build windows version on windows with cygwin"
270 echo " [requires cygwin and mingw32-make]"
271 echo " --enable-cross build cross compilers"
272 echo " --extra-cflags= extra compiler flags"
273 echo " --extra-ldflags= extra linker options"
274 echo " --with-selinux use mmap instead of exec mem"
275 echo " [requires write access to /tmp]"
276 echo ""
277 #echo "NOTE: The object files are build at the place where configure is launched"
278 exit 1
281 if test "$mingw32" = "yes" ; then
282 if test x"$tccdir" = x""; then
283 tccdir="tcc"
285 if test -z "$prefix" ; then
286 prefix="C:/Program Files/${tccdir}"
288 if test -z "$sharedir" ; then
289 sharedir="${prefix}"
291 execprefix="$prefix"
292 bindir="${prefix}"
293 tccdir="${prefix}"
294 libdir="${prefix}/lib"
295 docdir="${sharedir}/doc"
296 mandir="${sharedir}/man"
297 infodir="${sharedir}/info"
298 else
299 if test -z "$prefix" ; then
300 prefix="/usr/local"
302 if test -z "$sharedir" ; then
303 sharedir="${prefix}/share"
305 if test x"$execprefix" = x""; then
306 execprefix="${prefix}"
308 if test x"$libdir" = x""; then
309 libdir="${execprefix}/lib"
311 if test x"$bindir" = x""; then
312 bindir="${execprefix}/bin"
314 if test x"$tccdir" = x""; then
315 tccdir="tcc"
317 if test x"$docdir" = x""; then
318 docdir="${sharedir}/doc/${tccdir}"
320 if test x"$mandir" = x""; then
321 mandir="${sharedir}/man"
323 if test x"$infodir" = x""; then
324 infodir="${sharedir}/info"
326 tccdir="${libdir}/${tccdir}"
327 fi # mingw32
329 if test x"$includedir" = x""; then
330 includedir="${prefix}/include"
333 echo "Binary directory $bindir"
334 echo "TinyCC directory $tccdir"
335 echo "Library directory $libdir"
336 echo "Loader library search directory ${lddir:-default value (see tcc.h)}"
337 echo "Extra loader library search directory ${extralddir:-(none)}"
338 echo "Include directory $includedir"
339 echo "Manual directory $mandir"
340 echo "Info directory $infodir"
341 echo "Doc directory $docdir"
342 echo "Target root prefix $sysroot"
343 echo "Source path $source_path"
344 echo "C compiler $cc"
345 echo "CPU $cpu"
346 echo "Big Endian $bigendian"
347 echo "gprof enabled $gprof"
348 echo "cross compilers $build_cross"
349 echo "use libgcc $use_libgcc"
351 echo "Creating config.mak and config.h"
353 echo "# Automatically generated by configure - do not modify" > config.mak
354 echo "/* Automatically generated by configure - do not modify */" > $TMPH
356 echo "prefix=$prefix" >> config.mak
357 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
358 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
359 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
360 echo "ln_libdir=$libdir" >> config.mak
361 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
362 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
363 echo "infodir=\$(DESTDIR)$infodir" >> config.mak
364 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
366 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
367 echo "#ifndef CONFIG_TCCDIR" >> $TMPH
368 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
369 echo "#define CONFIG_TCC_LDDIR \"$lddir\"" >> $TMPH
370 echo "#define CONFIG_TCC_EXTRA_LDDIR \"$extralddir\"" >> $TMPH
371 echo "#endif" >> $TMPH
372 echo "CC=$cc" >> config.mak
373 echo "GCC_MAJOR=$gcc_major" >> config.mak
374 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
375 echo "HOST_CC=$host_cc" >> config.mak
376 echo "AR=$ar" >> config.mak
377 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
378 echo "CFLAGS=$CFLAGS" >> config.mak
379 echo "LDFLAGS=$LDFLAGS" >> config.mak
380 echo "LIBSUF=$LIBSUF" >> config.mak
381 echo "EXESUF=$EXESUF" >> config.mak
382 if test "$cpu" = "x86" ; then
383 echo "ARCH=i386" >> config.mak
384 echo "#define HOST_I386 1" >> $TMPH
385 elif test "$cpu" = "x86-64" ; then
386 echo "ARCH=x86-64" >> config.mak
387 echo "#define HOST_X86_64 1" >> $TMPH
388 elif test "$cpu" = "armv4l" ; then
389 echo "ARCH=arm" >> config.mak
390 echo "#define HOST_ARM 1" >> $TMPH
391 elif test "$cpu" = "powerpc" ; then
392 echo "ARCH=ppc" >> config.mak
393 echo "#define HOST_PPC 1" >> $TMPH
394 elif test "$cpu" = "mips" ; then
395 echo "ARCH=mips" >> config.mak
396 echo "#define HOST_MIPS 1" >> $TMPH
397 elif test "$cpu" = "s390" ; then
398 echo "ARCH=s390" >> config.mak
399 echo "#define HOST_S390 1" >> $TMPH
400 elif test "$cpu" = "alpha" ; then
401 echo "ARCH=alpha" >> config.mak
402 echo "#define HOST_ALPHA 1" >> $TMPH
403 else
404 echo "Unsupported CPU"
405 exit 1
407 if test "$noldl" = "yes" ; then
408 echo "CONFIG_NOLDL=yes" >> config.mak
410 if test "$mingw32" = "yes" ; then
411 echo "CONFIG_WIN32=yes" >> config.mak
412 echo "#define CONFIG_WIN32 1" >> $TMPH
414 if test "$cygwin" = "yes" ; then
415 echo "#ifndef _WIN32" >> $TMPH
416 echo "#define _WIN32" >> $TMPH
417 echo "#endif" >> $TMPH
418 echo "AR=ar" >> config.mak
420 if test "$bigendian" = "yes" ; then
421 echo "WORDS_BIGENDIAN=yes" >> config.mak
422 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
424 if test "$gprof" = "yes" ; then
425 echo "TARGET_GPROF=yes" >> config.mak
426 echo "#define HAVE_GPROF 1" >> $TMPH
428 if test "$build_cross" = "yes" ; then
429 echo "CONFIG_CROSS=yes" >> config.mak
431 if test "$disable_static" = "yes" ; then
432 echo "DISABLE_STATIC=yes" >> config.mak
434 if test "$disable_rpath" = "yes" ; then
435 echo "DISABLE_RPATH=yes" >> config.mak
437 if test "$strip_binaries" = "yes" ; then
438 echo "STRIP_BINARIES=yes" >> config.mak
440 if test "$use_libgcc" = "yes" ; then
441 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
442 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
444 if test "$have_selinux" = "yes" ; then
445 echo "#define HAVE_SELINUX" >> $TMPH
446 echo "HAVE_SELINUX=yes" >> config.mak
448 version=`head $source_path/VERSION`
449 echo "VERSION=$version" >>config.mak
450 echo "#define TCC_VERSION \"$version\"" >> $TMPH
451 echo "@set VERSION $version" > config.texi
453 # build tree in object directory if source path is different from current one
454 if test "$source_path_used" = "yes" ; then
455 DIRS="tests"
456 FILES="Makefile tests/Makefile"
457 for dir in $DIRS ; do
458 mkdir -p $dir
459 done
460 for f in $FILES ; do
461 ln -sf $source_path/$f $f
462 done
464 echo "SRC_PATH=$source_path" >> config.mak
466 diff $TMPH config.h >/dev/null 2>&1
467 if test $? -ne 0 ; then
468 mv -f $TMPH config.h
469 else
470 echo "config.h is unchanged"
473 rm -f $TMPN*