blob: e56c603d04094ddde9e0624420180babd25ea380 [file] [log] [blame]
bellard7d132992003-03-06 23:23:54 +00001#!/bin/sh
2#
bellard3ef693a2003-03-23 20:17:16 +00003# qemu configure script (c) 2003 Fabrice Bellard
bellard7d132992003-03-06 23:23:54 +00004#
5# set temporary file name
6if test ! -z "$TMPDIR" ; then
7 TMPDIR1="${TMPDIR}"
8elif test ! -z "$TEMPDIR" ; then
9 TMPDIR1="${TEMPDIR}"
10else
11 TMPDIR1="/tmp"
12fi
13
bellard3ef693a2003-03-23 20:17:16 +000014TMPC="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c"
15TMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o"
16TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}"
17TMPS="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.S"
18TMPH="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.h"
bellard7d132992003-03-06 23:23:54 +000019
20# default parameters
21prefix="/usr/local"
bellard32ce6332003-04-11 00:16:16 +000022interp_prefix="/usr/gnemul/qemu-i386"
bellard43ce4df2003-06-09 19:53:12 +000023static="no"
bellard7d132992003-03-06 23:23:54 +000024cross_prefix=""
25cc="gcc"
26host_cc="gcc"
27ar="ar"
28make="make"
29strip="strip"
bellarda98fd892003-04-29 21:24:12 +000030target_cpu="x86"
bellardde83cd02003-06-15 20:25:43 +000031target_bigendian="default"
bellard7d132992003-03-06 23:23:54 +000032cpu=`uname -m`
33case "$cpu" in
34 i386|i486|i586|i686|i86pc|BePC)
35 cpu="x86"
36 ;;
37 armv4l)
38 cpu="armv4l"
39 ;;
40 alpha)
41 cpu="alpha"
42 ;;
bellard295defa2003-04-07 21:31:29 +000043 "Power Macintosh"|ppc|ppc64)
bellard7d132992003-03-06 23:23:54 +000044 cpu="powerpc"
45 ;;
46 mips)
47 cpu="mips"
48 ;;
bellardfb3e5842003-03-29 17:32:36 +000049 s390)
50 cpu="s390"
51 ;;
bellardae228532003-05-13 18:59:59 +000052 sparc)
53 cpu="sparc"
54 ;;
55 sparc64)
56 cpu="sparc64"
57 ;;
bellarda8baa8c2003-04-29 20:53:31 +000058 ia64)
59 cpu="ia64"
60 ;;
bellard7d132992003-03-06 23:23:54 +000061 *)
62 cpu="unknown"
63 ;;
64esac
65gprof="no"
66bigendian="no"
67
68# OS specific
69targetos=`uname -s`
70case $targetos in
bellard7d132992003-03-06 23:23:54 +000071*) ;;
72esac
73
74# find source path
75# XXX: we assume an absolute path is given when launching configure,
76# except in './configure' case.
77source_path=${0%configure}
78source_path=${source_path%/}
79source_path_used="yes"
80if test -z "$source_path" -o "$source_path" = "." ; then
81 source_path=`pwd`
82 source_path_used="no"
83fi
84
85for opt do
86 case "$opt" in
87 --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
88 ;;
bellard32ce6332003-04-11 00:16:16 +000089 --interp-prefix=*) interp_prefix=`echo $opt | cut -d '=' -f 2`
90 ;;
bellard7d132992003-03-06 23:23:54 +000091 --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
92 ;;
93 --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
94 ;;
95 --cc=*) cc=`echo $opt | cut -d '=' -f 2`
96 ;;
97 --make=*) make=`echo $opt | cut -d '=' -f 2`
98 ;;
99 --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
100 ;;
101 --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
102 ;;
103 --extra-libs=*) extralibs=${opt#--extra-libs=}
104 ;;
105 --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
106 ;;
bellardde83cd02003-06-15 20:25:43 +0000107 --target-cpu=*) target_cpu=`echo $opt | cut -d '=' -f 2`
108 ;;
109 --target-big-endian) target_bigendian="yes"
110 ;;
111 --target-little-endian) target_bigendian="no"
112 ;;
bellard7d132992003-03-06 23:23:54 +0000113 --enable-gprof) gprof="yes"
114 ;;
bellard43ce4df2003-06-09 19:53:12 +0000115 --static) static="yes"
116 ;;
bellard7d132992003-03-06 23:23:54 +0000117 esac
118done
119
120# Checking for CFLAGS
121if test -z "$CFLAGS"; then
122 CFLAGS="-O2"
123fi
124
125cc="${cross_prefix}${cc}"
126ar="${cross_prefix}${ar}"
127strip="${cross_prefix}${strip}"
128
129if test -z "$cross_prefix" ; then
130
131# ---
132# big/little endian test
133cat > $TMPC << EOF
134#include <inttypes.h>
135int main(int argc, char ** argv){
136 volatile uint32_t i=0x01234567;
137 return (*((uint8_t*)(&i))) == 0x67;
138}
139EOF
140
141if $cc -o $TMPE $TMPC 2>/dev/null ; then
142$TMPE && bigendian="yes"
143else
144echo big/little test failed
145fi
146
147else
148
149# if cross compiling, cannot launch a program, so make a static guess
bellardae228532003-05-13 18:59:59 +0000150if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" -o "$cpu" = "sparc" -o "$cpu" = "sparc64"; then
bellard7d132992003-03-06 23:23:54 +0000151 bigendian="yes"
152fi
153
154fi
155
bellarde8cd23d2003-06-25 16:08:13 +0000156# check gcc options support
bellard04369ff2003-03-20 22:33:23 +0000157cat > $TMPC <<EOF
158int main(void) {
bellard04369ff2003-03-20 22:33:23 +0000159}
160EOF
161
bellarde8cd23d2003-06-25 16:08:13 +0000162have_gcc3_options="no"
163if $cc -fno-reorder-blocks -fno-optimize-sibling-calls -o $TMPO $TMPC 2> /dev/null ; then
164 have_gcc3_options="yes"
bellard04369ff2003-03-20 22:33:23 +0000165fi
bellardca735202003-03-18 20:41:34 +0000166
bellardde83cd02003-06-15 20:25:43 +0000167if test "$target_bigendian" = "default" ; then
168 if test "$target_cpu" = "x86" ; then
169 target_bigendian="no"
170 elif test "$target_cpu" = "arm" ; then
171 target_bigendian="no"
172 else
173 target_bigendian="no"
174 fi
175fi
176
bellard7d132992003-03-06 23:23:54 +0000177if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
178cat << EOF
179
180Usage: configure [options]
181Options: [defaults in brackets after descriptions]
182
183EOF
184echo "Standard options:"
185echo " --help print this message"
186echo " --prefix=PREFIX install in PREFIX [$prefix]"
bellard32ce6332003-04-11 00:16:16 +0000187echo " --interp-prefix=PREFIX where to find shared libraries, etc. [$interp_prefix]"
bellardde83cd02003-06-15 20:25:43 +0000188echo " --target_cpu=CPU set target cpu (x86 or arm) [$target_cpu]"
bellard7d132992003-03-06 23:23:54 +0000189echo ""
190echo "Advanced options (experts only):"
191echo " --source-path=PATH path of source code [$source_path]"
192echo " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]"
193echo " --cc=CC use C compiler CC [$cc]"
194echo " --make=MAKE use specified make [$make]"
bellard43ce4df2003-06-09 19:53:12 +0000195echo " --static enable static build [$static]"
bellard7d132992003-03-06 23:23:54 +0000196echo ""
197echo "NOTE: The object files are build at the place where configure is launched"
198exit 1
199fi
200
bellard43ce4df2003-06-09 19:53:12 +0000201echo "Install prefix $prefix"
202echo "Source path $source_path"
203echo "ELF interp prefix $interp_prefix"
204echo "C compiler $cc"
205echo "make $make"
206echo "host CPU $cpu"
bellardde83cd02003-06-15 20:25:43 +0000207echo "host big endian $bigendian"
bellard43ce4df2003-06-09 19:53:12 +0000208echo "target CPU $target_cpu"
bellardde83cd02003-06-15 20:25:43 +0000209echo "target big endian $target_bigendian"
bellard43ce4df2003-06-09 19:53:12 +0000210echo "gprof enabled $gprof"
211echo "static build $static"
bellard7d132992003-03-06 23:23:54 +0000212
213echo "Creating config.mak and config.h"
214
215echo "# Automatically generated by configure - do not modify" > config.mak
216echo "/* Automatically generated by configure - do not modify */" > $TMPH
217
218echo "prefix=$prefix" >> config.mak
bellard32ce6332003-04-11 00:16:16 +0000219echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix\"" >> $TMPH
bellard7d132992003-03-06 23:23:54 +0000220echo "MAKE=$make" >> config.mak
221echo "CC=$cc" >> config.mak
bellarde8cd23d2003-06-25 16:08:13 +0000222if test "$have_gcc3_options" = "yes" ; then
223 echo "HAVE_GCC3_OPTIONS=yes" >> config.mak
224fi
bellard7d132992003-03-06 23:23:54 +0000225echo "HOST_CC=$host_cc" >> config.mak
226echo "AR=$ar" >> config.mak
227echo "STRIP=$strip -s -R .comment -R .note" >> config.mak
228echo "CFLAGS=$CFLAGS" >> config.mak
229echo "LDFLAGS=$LDFLAGS" >> config.mak
230if test "$cpu" = "x86" ; then
231 echo "ARCH=i386" >> config.mak
bellard295defa2003-04-07 21:31:29 +0000232 echo "#define HOST_I386 1" >> $TMPH
bellard7d132992003-03-06 23:23:54 +0000233elif test "$cpu" = "armv4l" ; then
234 echo "ARCH=arm" >> config.mak
bellard295defa2003-04-07 21:31:29 +0000235 echo "#define HOST_ARM 1" >> $TMPH
bellard7d132992003-03-06 23:23:54 +0000236elif test "$cpu" = "powerpc" ; then
bellard04369ff2003-03-20 22:33:23 +0000237 echo "ARCH=ppc" >> config.mak
bellard295defa2003-04-07 21:31:29 +0000238 echo "#define HOST_PPC 1" >> $TMPH
bellard7d132992003-03-06 23:23:54 +0000239elif test "$cpu" = "mips" ; then
bellard04369ff2003-03-20 22:33:23 +0000240 echo "ARCH=mips" >> config.mak
bellard295defa2003-04-07 21:31:29 +0000241 echo "#define HOST_MIPS 1" >> $TMPH
bellardfb3e5842003-03-29 17:32:36 +0000242elif test "$cpu" = "s390" ; then
243 echo "ARCH=s390" >> config.mak
bellard295defa2003-04-07 21:31:29 +0000244 echo "#define HOST_S390 1" >> $TMPH
245elif test "$cpu" = "alpha" ; then
246 echo "ARCH=alpha" >> config.mak
247 echo "#define HOST_ALPHA 1" >> $TMPH
bellardae228532003-05-13 18:59:59 +0000248elif test "$cpu" = "sparc" ; then
249 echo "ARCH=sparc" >> config.mak
250 echo "#define HOST_SPARC 1" >> $TMPH
251elif test "$cpu" = "sparc64" ; then
252 echo "ARCH=sparc64" >> config.mak
253 echo "#define HOST_SPARC64 1" >> $TMPH
bellarda8baa8c2003-04-29 20:53:31 +0000254elif test "$cpu" = "ia64" ; then
255 echo "ARCH=ia64" >> config.mak
256 echo "#define HOST_IA64 1" >> $TMPH
bellard7d132992003-03-06 23:23:54 +0000257else
258 echo "Unsupported CPU"
259 exit 1
260fi
261if test "$bigendian" = "yes" ; then
262 echo "WORDS_BIGENDIAN=yes" >> config.mak
263 echo "#define WORDS_BIGENDIAN 1" >> $TMPH
264fi
bellardde83cd02003-06-15 20:25:43 +0000265
266if test "$target_cpu" = "x86" ; then
267 echo "TARGET_ARCH=i386" >> config.mak
268 echo "#define TARGET_ARCH \"i386\"" >> $TMPH
269 echo "#define TARGET_I386 1" >> $TMPH
270elif test "$target_cpu" = "arm" ; then
271 echo "TARGET_ARCH=arm" >> config.mak
272 echo "#define TARGET_ARCH \"arm\"" >> $TMPH
273 echo "#define TARGET_ARM 1" >> $TMPH
274else
275 echo "Unsupported target CPU"
276 exit 1
277fi
278if test "$target_bigendian" = "yes" ; then
279 echo "TARGET_WORDS_BIGENDIAN=yes" >> config.mak
280 echo "#define TARGET_WORDS_BIGENDIAN 1" >> $TMPH
281fi
282
bellard7d132992003-03-06 23:23:54 +0000283if test "$gprof" = "yes" ; then
284 echo "TARGET_GPROF=yes" >> config.mak
285 echo "#define HAVE_GPROF 1" >> $TMPH
286fi
bellard43ce4df2003-06-09 19:53:12 +0000287if test "$static" = "yes" ; then
288 echo "CONFIG_STATIC=yes" >> config.mak
289fi
bellard7d132992003-03-06 23:23:54 +0000290echo -n "VERSION=" >>config.mak
291head $source_path/VERSION >>config.mak
292echo "" >>config.mak
bellard3ef693a2003-03-23 20:17:16 +0000293echo -n "#define QEMU_VERSION \"" >> $TMPH
bellard7d132992003-03-06 23:23:54 +0000294head $source_path/VERSION >> $TMPH
295echo "\"" >> $TMPH
bellard7d132992003-03-06 23:23:54 +0000296
297# build tree in object directory if source path is different from current one
298if test "$source_path_used" = "yes" ; then
299 DIRS="tests"
300 FILES="Makefile tests/Makefile"
301 for dir in $DIRS ; do
302 mkdir -p $dir
303 done
304 for f in $FILES ; do
305 ln -sf $source_path/$f $f
306 done
307fi
308echo "SRC_PATH=$source_path" >> config.mak
309
310diff $TMPH config.h >/dev/null 2>&1
311if test $? -ne 0 ; then
312 mv -f $TMPH config.h
313else
314 echo "config.h is unchanged"
315fi
316
bellard1eb87252003-04-11 01:12:28 +0000317rm -f $TMPO $TMPC $TMPE $TMPS $TMPH