Fix bashims in configure and gcctestsuite.sh.
[tinycc.git] / configure
blobb3de471dd8cc570f3e07735966d9590325e02d91
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 RDM1="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
15 RDM2="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
16 TMPC="${TMPDIR1}/tcc-conf-${RDM1}-$$-${RDM2}.c"
17 RDM1="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
18 RDM2="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
19 TMPO="${TMPDIR1}/tcc-conf-${RDM1}-$$-${RDM2}.o"
20 RDM1="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
21 RDM2="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
22 TMPE="${TMPDIR1}/tcc-conf-${RDM1}-$$-${RDM2}"
23 RDM1="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
24 RDM2="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
25 TMPS="${TMPDIR1}/tcc-conf-${RDM1}-$$-${RDM2}.S"
26 RDM1="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
27 RDM2="$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " )"
28 TMPH="${TMPDIR1}/tcc-conf-${RDM1}-$$-${RDM2}.h"
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 sysroot=""
41 cross_prefix=""
42 cc="gcc"
43 host_cc="gcc"
44 ar="ar"
45 strip="strip"
46 cpu=`uname -m`
47 case "$cpu" in
48 i386|i486|i586|i686|i86pc|BePC)
49 cpu="x86"
51 x86_64)
52 cpu="x86-64"
54 armv4l|armv5tel|armv6j|armv7a)
55 cpu="armv4l"
57 alpha)
58 cpu="alpha"
60 "Power Macintosh"|ppc|ppc64)
61 cpu="powerpc"
63 mips)
64 cpu="mips"
66 s390)
67 cpu="s390"
70 cpu="unknown"
72 esac
73 gprof="no"
74 bigendian="no"
75 mingw32="no"
76 LIBSUF=".a"
77 EXESUF=""
79 # OS specific
80 targetos=`uname -s`
81 case $targetos in
82 MINGW32*)
83 mingw32="yes"
85 DragonFly)
86 noldl="yes"
88 OpenBSD)
89 noldl="yes"
91 *) ;;
92 esac
94 # find source path
95 # XXX: we assume an absolute path is given when launching configure,
96 # except in './configure' case.
97 source_path=${0%configure}
98 source_path=${source_path%/}
99 source_path_used="yes"
100 if test -z "$source_path" -o "$source_path" = "." ; then
101 source_path=`pwd`
102 source_path_used="no"
105 for opt do
106 case "$opt" in
107 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
109 --exec-prefix=*) execprefix=`echo $opt | cut -d '=' -f 2`
111 --bindir=*) bindir=`echo $opt | cut -d '=' -f 2`
113 --libdir=*) libdir=`echo $opt | cut -d '=' -f 2`
115 --includedir=*) includedir=`echo $opt | cut -d '=' -f 2`
117 --mandir=*) mandir=`echo $opt | cut -d '=' -f 2`
119 --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
121 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
123 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
125 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
127 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
129 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
131 --extra-libs=*) extralibs=${opt#--extra-libs=}
133 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
135 --enable-gprof) gprof="yes"
137 --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-"
139 --enable-cross) build_cross="yes"
141 --disable-static) disable_static="yes"
143 --with-libgcc) use_libgcc="yes"
145 --with-selinux) have_selinux="yes"
147 --help|-h) show_help="yes"
149 esac
150 done
152 # Checking for CFLAGS
153 if test -z "$CFLAGS"; then
154 CFLAGS="-O2"
157 cc="${cross_prefix}${cc}"
158 ar="${cross_prefix}${ar}"
159 strip="${cross_prefix}${strip}"
161 if test "$mingw32" = "yes" ; then
162 LIBSUF=".lib"
163 EXESUF=".exe"
166 if test -z "$cross_prefix" ; then
168 # ---
169 # big/little endian test
170 cat > $TMPC << EOF
171 #include <inttypes.h>
172 int main(int argc, char ** argv){
173 volatile uint32_t i=0x01234567;
174 return (*((uint8_t*)(&i))) == 0x67;
178 if $cc -o $TMPE $TMPC 2>/dev/null ; then
179 $TMPE && bigendian="yes"
180 else
181 echo big/little test failed
184 else
186 # if cross compiling, cannot launch a program, so make a static guess
187 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" ; then
188 bigendian="yes"
193 # check gcc version
194 cat > $TMPC <<EOF
195 int main(void) {
196 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2)
197 return 0;
198 #else
199 #error gcc < 3.2
200 #endif
204 gcc_major="2"
205 if $cc -o $TMPO $TMPC 2> /dev/null ; then
206 gcc_major="3"
208 cat > $TMPC <<EOF
209 int main(void) {
210 #if __GNUC__ >= 4
211 return 0;
212 #else
213 #error gcc < 4
214 #endif
218 if $cc -o $TMPO $TMPC 2> /dev/null ; then
219 gcc_major="4"
222 if test x"$show_help" = "xyes" ; then
223 cat << EOF
225 Usage: configure [options]
226 Options: [defaults in brackets after descriptions]
229 echo "Standard options:"
230 echo " --help print this message"
231 echo " --prefix=PREFIX install in PREFIX [$prefix]"
232 echo " --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX"
233 echo " [same as prefix]"
234 echo " --bindir=DIR user executables in DIR [EPREFIX/bin]"
235 echo " --libdir=DIR object code libraries in DIR [EPREFIX/lib]"
236 echo " --includedir=DIR C header files in DIR [PREFIX/include]"
237 echo " --mandir=DIR man documentation in DIR [PREFIX/man]"
238 echo " --enable-cross build cross compilers"
239 echo ""
240 echo "Advanced options (experts only):"
241 echo " --source-path=PATH path of source code [$source_path]"
242 echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
243 echo " --sysroot=PREFIX prepend PREFIX to library/include paths []"
244 echo " --cc=CC use C compiler CC [$cc]"
245 echo " --disable-static make libtcc.so instead of libtcc.a"
246 echo " --with-libgcc use /lib/libgcc_s.so.1 instead of libtcc1.a"
247 echo " --with-selinux use mmap instead of exec mem"
248 echo " [requires write access to /tmp]"
249 echo ""
250 #echo "NOTE: The object files are build at the place where configure is launched"
251 exit 1
254 if test "$mingw32" = "yes" ; then
255 if test -z "$prefix" ; then
256 prefix="C:/Program Files/tcc"
258 execprefix="$prefix"
259 bindir="$prefix"
260 tccdir="$prefix"
261 docdir="$prefix/doc"
262 else
263 if test -z "$prefix" ; then
264 prefix="/usr/local"
266 if test x"$execprefix" = x""; then
267 execprefix="${prefix}"
269 if test x"$bindir" = x""; then
270 bindir="${execprefix}/bin"
272 if test x"$docdir" = x""; then
273 docdir="$prefix/share/doc/tcc"
275 fi # mingw32
277 if test x"$libdir" = x""; then
278 libdir="${execprefix}/lib"
280 if test x"$tccdir" = x""; then
281 tccdir="${libdir}/tcc"
283 if test x"$mandir" = x""; then
284 mandir="${prefix}/man"
286 if test x"$includedir" = x""; then
287 includedir="${prefix}/include"
290 echo "Binary directory $bindir"
291 echo "TinyCC directory $tccdir"
292 echo "Library directory $libdir"
293 echo "Include directory $includedir"
294 echo "Manual directory $mandir"
295 echo "Doc directory $docdir"
296 echo "Target root prefix $sysroot"
297 echo "Source path $source_path"
298 echo "C compiler $cc"
299 echo "CPU $cpu"
300 echo "Big Endian $bigendian"
301 echo "gprof enabled $gprof"
302 echo "cross compilers $build_cross"
303 echo "use libgcc $use_libgcc"
305 echo "Creating config.mak and config.h"
307 echo "# Automatically generated by configure - do not modify" > config.mak
308 echo "/* Automatically generated by configure - do not modify */" > $TMPH
310 echo "prefix=$prefix" >> config.mak
311 echo "bindir=\$(DESTDIR)$bindir" >> config.mak
312 echo "tccdir=\$(DESTDIR)$tccdir" >> config.mak
313 echo "libdir=\$(DESTDIR)$libdir" >> config.mak
314 echo "ln_libdir=$libdir" >> config.mak
315 echo "includedir=\$(DESTDIR)$includedir" >> config.mak
316 echo "mandir=\$(DESTDIR)$mandir" >> config.mak
317 echo "docdir=\$(DESTDIR)$docdir" >> config.mak
319 echo "#define CONFIG_SYSROOT \"$sysroot\"" >> $TMPH
320 echo "#define CONFIG_TCCDIR \"$tccdir\"" >> $TMPH
321 echo "CC=$cc" >> config.mak
322 echo "GCC_MAJOR=$gcc_major" >> config.mak
323 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
324 echo "HOST_CC=$host_cc" >> config.mak
325 echo "AR=$ar" >> config.mak
326 echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
327 echo "CFLAGS=$CFLAGS" >> config.mak
328 echo "LDFLAGS=$LDFLAGS" >> config.mak
329 echo "LIBSUF=$LIBSUF" >> config.mak
330 echo "EXESUF=$EXESUF" >> config.mak
331 if test "$cpu" = "x86" ; then
332 echo "ARCH=i386" >> config.mak
333 echo "#define HOST_I386 1" >> $TMPH
334 elif test "$cpu" = "x86-64" ; then
335 echo "ARCH=x86-64" >> config.mak
336 echo "#define HOST_X86_64 1" >> $TMPH
337 elif test "$cpu" = "armv4l" ; then
338 echo "ARCH=arm" >> config.mak
339 echo "#define HOST_ARM 1" >> $TMPH
340 elif test "$cpu" = "powerpc" ; then
341 echo "ARCH=ppc" >> config.mak
342 echo "#define HOST_PPC 1" >> $TMPH
343 elif test "$cpu" = "mips" ; then
344 echo "ARCH=mips" >> config.mak
345 echo "#define HOST_MIPS 1" >> $TMPH
346 elif test "$cpu" = "s390" ; then
347 echo "ARCH=s390" >> config.mak
348 echo "#define HOST_S390 1" >> $TMPH
349 elif test "$cpu" = "alpha" ; then
350 echo "ARCH=alpha" >> config.mak
351 echo "#define HOST_ALPHA 1" >> $TMPH
352 else
353 echo "Unsupported CPU"
354 exit 1
356 if test "$noldl" = "yes" ; then
357 echo "CONFIG_NOLDL=yes" >> config.mak
359 if test "$mingw32" = "yes" ; then
360 echo "CONFIG_WIN32=yes" >> config.mak
361 echo "#define CONFIG_WIN32 1" >> $TMPH
363 if test "$bigendian" = "yes" ; then
364 echo "WORDS_BIGENDIAN=yes" >> config.mak
365 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
367 if test "$gprof" = "yes" ; then
368 echo "TARGET_GPROF=yes" >> config.mak
369 echo "#define HAVE_GPROF 1" >> $TMPH
371 if test "$build_cross" = "yes" ; then
372 echo "CONFIG_CROSS=yes" >> config.mak
374 if test "$disable_static" = "yes" ; then
375 echo "DISABLE_STATIC=yes" >> config.mak
377 if test "$use_libgcc" = "yes" ; then
378 echo "#define CONFIG_USE_LIBGCC" >> $TMPH
379 echo "CONFIG_USE_LIBGCC=yes" >> config.mak
381 if test "$have_selinux" = "yes" ; then
382 echo "#define HAVE_SELINUX" >> $TMPH
383 echo "HAVE_SELINUX=yes" >> config.mak
385 version=`head $source_path/VERSION`
386 echo "VERSION=$version" >>config.mak
387 echo "#define TCC_VERSION \"$version\"" >> $TMPH
388 echo "@set VERSION $version" > config.texi
390 # build tree in object directory if source path is different from current one
391 if test "$source_path_used" = "yes" ; then
392 DIRS="tests"
393 FILES="Makefile tests/Makefile"
394 for dir in $DIRS ; do
395 mkdir -p $dir
396 done
397 for f in $FILES ; do
398 ln -sf $source_path/$f $f
399 done
401 echo "SRC_PATH=$source_path" >> config.mak
403 diff $TMPH config.h >/dev/null 2>&1
404 if test $? -ne 0 ; then
405 mv -f $TMPH config.h
406 else
407 echo "config.h is unchanged"
410 rm -f $TMPO $TMPC $TMPE $TMPS $TMPH