2b830710a7ca495f93735c04baf7e10be2281962
[qemu] / configure
1 #!/bin/sh
2 #
3 # qemu configure script (c) 2003 Fabrice Bellard
4 #
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"
12 fi
13
14 TMPC="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c"
15 TMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o"
16 TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}"
17 TMPS="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.S"
18
19 # default parameters
20 prefix="/usr/local"
21 interp_prefix="/usr/gnemul/qemu-i386"
22 static="no"
23 cross_prefix=""
24 cc="gcc"
25 host_cc="gcc"
26 ar="ar"
27 make="make"
28 strip="strip"
29 cpu=`uname -m`
30 target_list="i386 i386-softmmu arm"
31 case "$cpu" in
32   i386|i486|i586|i686|i86pc|BePC)
33     cpu="i386"
34   ;;
35   armv4l)
36     cpu="armv4l"
37   ;;
38   alpha)
39     cpu="alpha"
40   ;;
41   "Power Macintosh"|ppc|ppc64)
42     cpu="powerpc"
43   ;;
44   mips)
45     cpu="mips"
46   ;;
47   s390)
48     cpu="s390"
49   ;;
50   sparc)
51     cpu="sparc"
52   ;;
53   sparc64)
54     cpu="sparc64"
55   ;;
56   ia64)
57     cpu="ia64"
58   ;;
59   *)
60     cpu="unknown"
61   ;;
62 esac
63 gprof="no"
64 bigendian="no"
65
66 # OS specific
67 targetos=`uname -s`
68 case $targetos in
69 *) ;;
70 esac
71
72 ##########################################
73 # SDL probe
74
75 cat > $TMPC << EOF
76 #include <SDL.h>
77 #undef main /* We don't want SDL to override our main() */
78 int main( void ) { return SDL_Init (SDL_INIT_VIDEO); }
79 EOF
80
81 sdl_too_old=no
82 sdl=no
83 if $cc -o $TMPE `sdl-config --cflags` $TMPC `sdl-config --libs`  2> /dev/null  ; then
84 _sdlversion=`sdl-config --version | sed 's/[^0-9]//g'`
85 if test "$_sdlversion" -lt 121 ; then
86 sdl_too_old=yes
87 else
88 sdl=yes
89 fi
90 fi
91
92 # find source path
93 # XXX: we assume an absolute path is given when launching configure, 
94 # except in './configure' case.
95 source_path=${0%configure}
96 source_path=${source_path%/}
97 source_path_used="yes"
98 if test -z "$source_path" -o "$source_path" = "." ; then
99     source_path=`pwd`
100     source_path_used="no"
101 fi
102
103 for opt do
104   case "$opt" in
105   --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
106   ;;
107   --interp-prefix=*) interp_prefix=`echo $opt | cut -d '=' -f 2`
108   ;;
109   --source-path=*) source_path=`echo $opt | cut -d '=' -f 2`
110   ;;
111   --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2`
112   ;;
113   --cc=*) cc=`echo $opt | cut -d '=' -f 2`
114   ;;
115   --make=*) make=`echo $opt | cut -d '=' -f 2`
116   ;;
117   --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}"
118   ;;
119   --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}"
120   ;;
121   --extra-libs=*) extralibs=${opt#--extra-libs=}
122   ;;
123   --cpu=*) cpu=`echo $opt | cut -d '=' -f 2`
124   ;;
125   --target-list=*) target_list=${opt#--target-list=}
126   ;;
127   --enable-gprof) gprof="yes"
128   ;;
129   --static) static="yes"
130   ;;
131   --disable-sdl) sdl="no"
132   ;;
133   esac
134 done
135
136 # Checking for CFLAGS
137 if test -z "$CFLAGS"; then
138     CFLAGS="-O2"
139 fi
140
141 cc="${cross_prefix}${cc}"
142 ar="${cross_prefix}${ar}"
143 strip="${cross_prefix}${strip}"
144
145 if test -z "$cross_prefix" ; then
146
147 # ---
148 # big/little endian test
149 cat > $TMPC << EOF
150 #include <inttypes.h>
151 int main(int argc, char ** argv){
152         volatile uint32_t i=0x01234567;
153         return (*((uint8_t*)(&i))) == 0x67;
154 }
155 EOF
156
157 if $cc -o $TMPE $TMPC 2>/dev/null ; then
158 $TMPE && bigendian="yes"
159 else
160 echo big/little test failed
161 fi
162
163 else
164
165 # if cross compiling, cannot launch a program, so make a static guess
166 if test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" -o "$cpu" = "sparc" -o "$cpu" = "sparc64"; then
167     bigendian="yes"
168 fi
169
170 fi
171
172 # check gcc options support
173 cat > $TMPC <<EOF
174 int main(void) {
175 }
176 EOF
177
178 have_gcc3_options="no"
179 if $cc -fno-reorder-blocks -fno-optimize-sibling-calls -o $TMPO $TMPC 2> /dev/null ; then
180    have_gcc3_options="yes"
181 fi
182
183 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
184 cat << EOF
185
186 Usage: configure [options]
187 Options: [defaults in brackets after descriptions]
188
189 EOF
190 echo "Standard options:"
191 echo "  --help                   print this message"
192 echo "  --prefix=PREFIX          install in PREFIX [$prefix]"
193 echo "  --interp-prefix=PREFIX   where to find shared libraries, etc. [$interp_prefix]"
194 echo "  --target-list=LIST       set target list [$target_list]"
195 echo ""
196 echo "Advanced options (experts only):"
197 echo "  --source-path=PATH       path of source code [$source_path]"
198 echo "  --cross-prefix=PREFIX    use PREFIX for compile tools [$cross_prefix]"
199 echo "  --cc=CC                  use C compiler CC [$cc]"
200 echo "  --make=MAKE              use specified make [$make]"
201 echo "  --static                 enable static build [$static]"
202 echo ""
203 echo "NOTE: The object files are build at the place where configure is launched"
204 exit 1
205 fi
206
207 echo "Install prefix    $prefix"
208 echo "Source path       $source_path"
209 echo "ELF interp prefix $interp_prefix"
210 echo "C compiler        $cc"
211 echo "make              $make"
212 echo "host CPU          $cpu"
213 echo "host big endian   $bigendian"
214 echo "target list       $target_list"
215 echo "gprof enabled     $gprof"
216 echo "static build      $static"
217 echo "SDL support       $sdl"
218 if test $sdl_too_old = "yes"; then
219 echo "-> Your SDL version is too old - please upgrade to have FFplay/SDL support"
220 fi
221
222 config_mak="config-host.mak"
223 config_h="config-host.h"
224
225 echo "Creating $config_mak and $config_h"
226
227 echo "# Automatically generated by configure - do not modify" > $config_mak
228 echo "/* Automatically generated by configure - do not modify */" > $config_h
229
230 echo "prefix=$prefix" >> $config_mak
231 echo "MAKE=$make" >> $config_mak
232 echo "CC=$cc" >> $config_mak
233 if test "$have_gcc3_options" = "yes" ; then
234   echo "HAVE_GCC3_OPTIONS=yes" >> $config_mak
235 fi
236 echo "HOST_CC=$host_cc" >> $config_mak
237 echo "AR=$ar" >> $config_mak
238 echo "STRIP=$strip -s -R .comment -R .note" >> $config_mak
239 echo "CFLAGS=$CFLAGS" >> $config_mak
240 echo "LDFLAGS=$LDFLAGS" >> $config_mak
241 if test "$cpu" = "i386" ; then
242   echo "ARCH=i386" >> $config_mak
243   echo "#define HOST_I386 1" >> $config_h
244 elif test "$cpu" = "armv4l" ; then
245   echo "ARCH=arm" >> $config_mak
246   echo "#define HOST_ARM 1" >> $config_h
247 elif test "$cpu" = "powerpc" ; then
248   echo "ARCH=ppc" >> $config_mak
249   echo "#define HOST_PPC 1" >> $config_h
250 elif test "$cpu" = "mips" ; then
251   echo "ARCH=mips" >> $config_mak
252   echo "#define HOST_MIPS 1" >> $config_h
253 elif test "$cpu" = "s390" ; then
254   echo "ARCH=s390" >> $config_mak
255   echo "#define HOST_S390 1" >> $config_h
256 elif test "$cpu" = "alpha" ; then
257   echo "ARCH=alpha" >> $config_mak
258   echo "#define HOST_ALPHA 1" >> $config_h
259 elif test "$cpu" = "sparc" ; then
260   echo "ARCH=sparc" >> $config_mak
261   echo "#define HOST_SPARC 1" >> $config_h
262 elif test "$cpu" = "sparc64" ; then
263   echo "ARCH=sparc64" >> $config_mak
264   echo "#define HOST_SPARC64 1" >> $config_h
265 elif test "$cpu" = "ia64" ; then
266   echo "ARCH=ia64" >> $config_mak
267   echo "#define HOST_IA64 1" >> $config_h
268 else
269   echo "Unsupported CPU"
270   exit 1
271 fi
272 if test "$bigendian" = "yes" ; then
273   echo "WORDS_BIGENDIAN=yes" >> $config_mak
274   echo "#define WORDS_BIGENDIAN 1" >> $config_h
275 fi
276 echo "#define HAVE_BYTESWAP_H 1" >> $config_h
277 if test "$gprof" = "yes" ; then
278   echo "TARGET_GPROF=yes" >> $config_mak
279   echo "#define HAVE_GPROF 1" >> $config_h
280 fi
281 if test "$static" = "yes" ; then
282   echo "CONFIG_STATIC=yes" >> $config_mak
283 fi
284 if test "$sdl" = "yes" ; then
285   echo "CONFIG_SDL=yes" >> $config_mak
286   echo "#define CONFIG_SDL 1" >> $config_h
287   echo "SDL_LIBS=`sdl-config --libs`" >> $config_mak
288   echo "SDL_CFLAGS=`sdl-config --cflags`" >> $config_mak
289 fi
290 echo -n "VERSION=" >>$config_mak
291 head $source_path/VERSION >>$config_mak
292 echo "" >>$config_mak
293 echo -n "#define QEMU_VERSION \"" >> $config_h
294 head $source_path/VERSION >> $config_h
295 echo "\"" >> $config_h
296
297 echo "SRC_PATH=$source_path" >> $config_mak
298 echo "TARGET_DIRS=$target_list" >> $config_mak
299
300 for target in $target_list; do 
301
302 target_dir="$target"
303 config_mak=$target_dir/config.mak
304 config_h=$target_dir/config.h
305 target_cpu=`echo $target | cut -d '-' -f 1`
306 target_bigendian="no"
307 target_softmmu="no"
308 if expr $target : '.*-softmmu' > /dev/null ; then
309   target_softmmu="yes"
310 fi
311
312 echo "Creating $config_mak, $config_h and $target_dir/Makefile"
313
314 mkdir -p $target_dir
315 ln -sf $source_path/Makefile.target $target_dir/Makefile
316
317 echo "# Automatically generated by configure - do not modify" > $config_mak
318 echo "/* Automatically generated by configure - do not modify */" > $config_h
319
320
321 echo "include ../config-host.mak" >> $config_mak
322 echo "#include \"../config-host.h\"" >> $config_h
323 echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix\"" >> $config_h
324
325 if test "$target_cpu" = "i386" ; then
326   echo "TARGET_ARCH=i386" >> $config_mak
327   echo "#define TARGET_ARCH \"i386\"" >> $config_h
328   echo "#define TARGET_I386 1" >> $config_h
329 elif test "$target_cpu" = "arm" ; then
330   echo "TARGET_ARCH=arm" >> $config_mak
331   echo "#define TARGET_ARCH \"arm\"" >> $config_h
332   echo "#define TARGET_ARM 1" >> $config_h
333 else
334   echo "Unsupported target CPU"
335   exit 1
336 fi
337 if test "$target_bigendian" = "yes" ; then
338   echo "TARGET_WORDS_BIGENDIAN=yes" >> $config_mak
339   echo "#define TARGET_WORDS_BIGENDIAN 1" >> $config_h
340 fi
341 if test "$target_softmmu" = "yes" ; then
342   echo "CONFIG_SOFTMMU=yes" >> $config_mak
343   echo "#define CONFIG_SOFTMMU 1" >> $config_h
344 fi
345
346 done # for target in $targets
347
348 # build tree in object directory if source path is different from current one
349 if test "$source_path_used" = "yes" ; then
350     DIRS="tests"
351     FILES="Makefile tests/Makefile"
352     for dir in $DIRS ; do
353             mkdir -p $dir
354     done
355     for f in $FILES ; do
356         ln -sf $source_path/$f $f
357     done
358 fi
359
360 rm -f $TMPO $TMPC $TMPE $TMPS