17d13299dSbellard#!/bin/sh 27d13299dSbellard# 33ef693a0Sbellard# qemu configure script (c) 2003 Fabrice Bellard 47d13299dSbellard# 57d13299dSbellard# set temporary file name 67d13299dSbellardif test ! -z "$TMPDIR" ; then 77d13299dSbellard TMPDIR1="${TMPDIR}" 87d13299dSbellardelif test ! -z "$TEMPDIR" ; then 97d13299dSbellard TMPDIR1="${TEMPDIR}" 107d13299dSbellardelse 117d13299dSbellard TMPDIR1="/tmp" 127d13299dSbellardfi 137d13299dSbellard 143ef693a0SbellardTMPC="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c" 153ef693a0SbellardTMPO="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.o" 163ef693a0SbellardTMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}" 173ef693a0SbellardTMPS="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.S" 183ef693a0SbellardTMPH="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.h" 197d13299dSbellard 207d13299dSbellard# default parameters 217d13299dSbellardprefix="/usr/local" 2232ce6337Sbellardinterp_prefix="/usr/gnemul/qemu-i386" 2343ce4dfeSbellardstatic="no" 247d13299dSbellardcross_prefix="" 257d13299dSbellardcc="gcc" 267d13299dSbellardhost_cc="gcc" 277d13299dSbellardar="ar" 287d13299dSbellardmake="make" 297d13299dSbellardstrip="strip" 30a98fd896Sbellardtarget_cpu="x86" 31de83cd02Sbellardtarget_bigendian="default" 327d13299dSbellardcpu=`uname -m` 337d13299dSbellardcase "$cpu" in 347d13299dSbellard i386|i486|i586|i686|i86pc|BePC) 357d13299dSbellard cpu="x86" 367d13299dSbellard ;; 377d13299dSbellard armv4l) 387d13299dSbellard cpu="armv4l" 397d13299dSbellard ;; 407d13299dSbellard alpha) 417d13299dSbellard cpu="alpha" 427d13299dSbellard ;; 43295defa5Sbellard "Power Macintosh"|ppc|ppc64) 447d13299dSbellard cpu="powerpc" 457d13299dSbellard ;; 467d13299dSbellard mips) 477d13299dSbellard cpu="mips" 487d13299dSbellard ;; 49fb3e5849Sbellard s390) 50fb3e5849Sbellard cpu="s390" 51fb3e5849Sbellard ;; 52ae228531Sbellard sparc) 53ae228531Sbellard cpu="sparc" 54ae228531Sbellard ;; 55ae228531Sbellard sparc64) 56ae228531Sbellard cpu="sparc64" 57ae228531Sbellard ;; 58a8baa8c5Sbellard ia64) 59a8baa8c5Sbellard cpu="ia64" 60a8baa8c5Sbellard ;; 617d13299dSbellard *) 627d13299dSbellard cpu="unknown" 637d13299dSbellard ;; 647d13299dSbellardesac 657d13299dSbellardgprof="no" 667d13299dSbellardbigendian="no" 677d13299dSbellard 687d13299dSbellard# OS specific 697d13299dSbellardtargetos=`uname -s` 707d13299dSbellardcase $targetos in 717d13299dSbellard*) ;; 727d13299dSbellardesac 737d13299dSbellard 747d13299dSbellard# find source path 757d13299dSbellard# XXX: we assume an absolute path is given when launching configure, 767d13299dSbellard# except in './configure' case. 777d13299dSbellardsource_path=${0%configure} 787d13299dSbellardsource_path=${source_path%/} 797d13299dSbellardsource_path_used="yes" 807d13299dSbellardif test -z "$source_path" -o "$source_path" = "." ; then 817d13299dSbellard source_path=`pwd` 827d13299dSbellard source_path_used="no" 837d13299dSbellardfi 847d13299dSbellard 857d13299dSbellardfor opt do 867d13299dSbellard case "$opt" in 877d13299dSbellard --prefix=*) prefix=`echo $opt | cut -d '=' -f 2` 887d13299dSbellard ;; 8932ce6337Sbellard --interp-prefix=*) interp_prefix=`echo $opt | cut -d '=' -f 2` 9032ce6337Sbellard ;; 917d13299dSbellard --source-path=*) source_path=`echo $opt | cut -d '=' -f 2` 927d13299dSbellard ;; 937d13299dSbellard --cross-prefix=*) cross_prefix=`echo $opt | cut -d '=' -f 2` 947d13299dSbellard ;; 957d13299dSbellard --cc=*) cc=`echo $opt | cut -d '=' -f 2` 967d13299dSbellard ;; 977d13299dSbellard --make=*) make=`echo $opt | cut -d '=' -f 2` 987d13299dSbellard ;; 997d13299dSbellard --extra-cflags=*) CFLAGS="${opt#--extra-cflags=}" 1007d13299dSbellard ;; 1017d13299dSbellard --extra-ldflags=*) LDFLAGS="${opt#--extra-ldflags=}" 1027d13299dSbellard ;; 1037d13299dSbellard --extra-libs=*) extralibs=${opt#--extra-libs=} 1047d13299dSbellard ;; 1057d13299dSbellard --cpu=*) cpu=`echo $opt | cut -d '=' -f 2` 1067d13299dSbellard ;; 107de83cd02Sbellard --target-cpu=*) target_cpu=`echo $opt | cut -d '=' -f 2` 108de83cd02Sbellard ;; 109de83cd02Sbellard --target-big-endian) target_bigendian="yes" 110de83cd02Sbellard ;; 111de83cd02Sbellard --target-little-endian) target_bigendian="no" 112de83cd02Sbellard ;; 1137d13299dSbellard --enable-gprof) gprof="yes" 1147d13299dSbellard ;; 11543ce4dfeSbellard --static) static="yes" 11643ce4dfeSbellard ;; 1177d13299dSbellard esac 1187d13299dSbellarddone 1197d13299dSbellard 1207d13299dSbellard# Checking for CFLAGS 1217d13299dSbellardif test -z "$CFLAGS"; then 1227d13299dSbellard CFLAGS="-O2" 1237d13299dSbellardfi 1247d13299dSbellard 1257d13299dSbellardcc="${cross_prefix}${cc}" 1267d13299dSbellardar="${cross_prefix}${ar}" 1277d13299dSbellardstrip="${cross_prefix}${strip}" 1287d13299dSbellard 1297d13299dSbellardif test -z "$cross_prefix" ; then 1307d13299dSbellard 1317d13299dSbellard# --- 1327d13299dSbellard# big/little endian test 1337d13299dSbellardcat > $TMPC << EOF 1347d13299dSbellard#include <inttypes.h> 1357d13299dSbellardint main(int argc, char ** argv){ 1367d13299dSbellard volatile uint32_t i=0x01234567; 1377d13299dSbellard return (*((uint8_t*)(&i))) == 0x67; 1387d13299dSbellard} 1397d13299dSbellardEOF 1407d13299dSbellard 1417d13299dSbellardif $cc -o $TMPE $TMPC 2>/dev/null ; then 1427d13299dSbellard$TMPE && bigendian="yes" 1437d13299dSbellardelse 1447d13299dSbellardecho big/little test failed 1457d13299dSbellardfi 1467d13299dSbellard 1477d13299dSbellardelse 1487d13299dSbellard 1497d13299dSbellard# if cross compiling, cannot launch a program, so make a static guess 150ae228531Sbellardif test "$cpu" = "powerpc" -o "$cpu" = "mips" -o "$cpu" = "s390" -o "$cpu" = "sparc" -o "$cpu" = "sparc64"; then 1517d13299dSbellard bigendian="yes" 1527d13299dSbellardfi 1537d13299dSbellard 1547d13299dSbellardfi 1557d13299dSbellard 156*e8cd23deSbellard# check gcc options support 15704369ff2Sbellardcat > $TMPC <<EOF 15804369ff2Sbellardint main(void) { 15904369ff2Sbellard} 16004369ff2SbellardEOF 16104369ff2Sbellard 162*e8cd23deSbellardhave_gcc3_options="no" 163*e8cd23deSbellardif $cc -fno-reorder-blocks -fno-optimize-sibling-calls -o $TMPO $TMPC 2> /dev/null ; then 164*e8cd23deSbellard have_gcc3_options="yes" 16504369ff2Sbellardfi 166ca735206Sbellard 167de83cd02Sbellardif test "$target_bigendian" = "default" ; then 168de83cd02Sbellard if test "$target_cpu" = "x86" ; then 169de83cd02Sbellard target_bigendian="no" 170de83cd02Sbellard elif test "$target_cpu" = "arm" ; then 171de83cd02Sbellard target_bigendian="no" 172de83cd02Sbellard else 173de83cd02Sbellard target_bigendian="no" 174de83cd02Sbellard fi 175de83cd02Sbellardfi 176de83cd02Sbellard 1777d13299dSbellardif test x"$1" = x"-h" -o x"$1" = x"--help" ; then 1787d13299dSbellardcat << EOF 1797d13299dSbellard 1807d13299dSbellardUsage: configure [options] 1817d13299dSbellardOptions: [defaults in brackets after descriptions] 1827d13299dSbellard 1837d13299dSbellardEOF 1847d13299dSbellardecho "Standard options:" 1857d13299dSbellardecho " --help print this message" 1867d13299dSbellardecho " --prefix=PREFIX install in PREFIX [$prefix]" 18732ce6337Sbellardecho " --interp-prefix=PREFIX where to find shared libraries, etc. [$interp_prefix]" 188de83cd02Sbellardecho " --target_cpu=CPU set target cpu (x86 or arm) [$target_cpu]" 1897d13299dSbellardecho "" 1907d13299dSbellardecho "Advanced options (experts only):" 1917d13299dSbellardecho " --source-path=PATH path of source code [$source_path]" 1927d13299dSbellardecho " --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix]" 1937d13299dSbellardecho " --cc=CC use C compiler CC [$cc]" 1947d13299dSbellardecho " --make=MAKE use specified make [$make]" 19543ce4dfeSbellardecho " --static enable static build [$static]" 1967d13299dSbellardecho "" 1977d13299dSbellardecho "NOTE: The object files are build at the place where configure is launched" 1987d13299dSbellardexit 1 1997d13299dSbellardfi 2007d13299dSbellard 2017d13299dSbellardecho "Install prefix $prefix" 2027d13299dSbellardecho "Source path $source_path" 20343ce4dfeSbellardecho "ELF interp prefix $interp_prefix" 2047d13299dSbellardecho "C compiler $cc" 2057d13299dSbellardecho "make $make" 206a98fd896Sbellardecho "host CPU $cpu" 207de83cd02Sbellardecho "host big endian $bigendian" 208a98fd896Sbellardecho "target CPU $target_cpu" 209de83cd02Sbellardecho "target big endian $target_bigendian" 2107d13299dSbellardecho "gprof enabled $gprof" 21143ce4dfeSbellardecho "static build $static" 2127d13299dSbellard 2137d13299dSbellardecho "Creating config.mak and config.h" 2147d13299dSbellard 2157d13299dSbellardecho "# Automatically generated by configure - do not modify" > config.mak 2167d13299dSbellardecho "/* Automatically generated by configure - do not modify */" > $TMPH 2177d13299dSbellard 2187d13299dSbellardecho "prefix=$prefix" >> config.mak 21932ce6337Sbellardecho "#define CONFIG_QEMU_PREFIX \"$interp_prefix\"" >> $TMPH 2207d13299dSbellardecho "MAKE=$make" >> config.mak 2217d13299dSbellardecho "CC=$cc" >> config.mak 222*e8cd23deSbellardif test "$have_gcc3_options" = "yes" ; then 223*e8cd23deSbellard echo "HAVE_GCC3_OPTIONS=yes" >> config.mak 224*e8cd23deSbellardfi 2257d13299dSbellardecho "HOST_CC=$host_cc" >> config.mak 2267d13299dSbellardecho "AR=$ar" >> config.mak 2277d13299dSbellardecho "STRIP=$strip -s -R .comment -R .note" >> config.mak 2287d13299dSbellardecho "CFLAGS=$CFLAGS" >> config.mak 2297d13299dSbellardecho "LDFLAGS=$LDFLAGS" >> config.mak 2307d13299dSbellardif test "$cpu" = "x86" ; then 2317d13299dSbellard echo "ARCH=i386" >> config.mak 232295defa5Sbellard echo "#define HOST_I386 1" >> $TMPH 2337d13299dSbellardelif test "$cpu" = "armv4l" ; then 2347d13299dSbellard echo "ARCH=arm" >> config.mak 235295defa5Sbellard echo "#define HOST_ARM 1" >> $TMPH 2367d13299dSbellardelif test "$cpu" = "powerpc" ; then 23704369ff2Sbellard echo "ARCH=ppc" >> config.mak 238295defa5Sbellard echo "#define HOST_PPC 1" >> $TMPH 2397d13299dSbellardelif test "$cpu" = "mips" ; then 24004369ff2Sbellard echo "ARCH=mips" >> config.mak 241295defa5Sbellard echo "#define HOST_MIPS 1" >> $TMPH 242fb3e5849Sbellardelif test "$cpu" = "s390" ; then 243fb3e5849Sbellard echo "ARCH=s390" >> config.mak 244295defa5Sbellard echo "#define HOST_S390 1" >> $TMPH 245295defa5Sbellardelif test "$cpu" = "alpha" ; then 246295defa5Sbellard echo "ARCH=alpha" >> config.mak 247295defa5Sbellard echo "#define HOST_ALPHA 1" >> $TMPH 248ae228531Sbellardelif test "$cpu" = "sparc" ; then 249ae228531Sbellard echo "ARCH=sparc" >> config.mak 250ae228531Sbellard echo "#define HOST_SPARC 1" >> $TMPH 251ae228531Sbellardelif test "$cpu" = "sparc64" ; then 252ae228531Sbellard echo "ARCH=sparc64" >> config.mak 253ae228531Sbellard echo "#define HOST_SPARC64 1" >> $TMPH 254a8baa8c5Sbellardelif test "$cpu" = "ia64" ; then 255a8baa8c5Sbellard echo "ARCH=ia64" >> config.mak 256a8baa8c5Sbellard echo "#define HOST_IA64 1" >> $TMPH 2577d13299dSbellardelse 2587d13299dSbellard echo "Unsupported CPU" 2597d13299dSbellard exit 1 2607d13299dSbellardfi 2617d13299dSbellardif test "$bigendian" = "yes" ; then 2627d13299dSbellard echo "WORDS_BIGENDIAN=yes" >> config.mak 2637d13299dSbellard echo "#define WORDS_BIGENDIAN 1" >> $TMPH 2647d13299dSbellardfi 265de83cd02Sbellard 266de83cd02Sbellardif test "$target_cpu" = "x86" ; then 267de83cd02Sbellard echo "TARGET_ARCH=i386" >> config.mak 268de83cd02Sbellard echo "#define TARGET_ARCH \"i386\"" >> $TMPH 269de83cd02Sbellard echo "#define TARGET_I386 1" >> $TMPH 270de83cd02Sbellardelif test "$target_cpu" = "arm" ; then 271de83cd02Sbellard echo "TARGET_ARCH=arm" >> config.mak 272de83cd02Sbellard echo "#define TARGET_ARCH \"arm\"" >> $TMPH 273de83cd02Sbellard echo "#define TARGET_ARM 1" >> $TMPH 274de83cd02Sbellardelse 275de83cd02Sbellard echo "Unsupported target CPU" 276de83cd02Sbellard exit 1 277de83cd02Sbellardfi 278de83cd02Sbellardif test "$target_bigendian" = "yes" ; then 279de83cd02Sbellard echo "TARGET_WORDS_BIGENDIAN=yes" >> config.mak 280de83cd02Sbellard echo "#define TARGET_WORDS_BIGENDIAN 1" >> $TMPH 281de83cd02Sbellardfi 282de83cd02Sbellard 2837d13299dSbellardif test "$gprof" = "yes" ; then 2847d13299dSbellard echo "TARGET_GPROF=yes" >> config.mak 2857d13299dSbellard echo "#define HAVE_GPROF 1" >> $TMPH 2867d13299dSbellardfi 28743ce4dfeSbellardif test "$static" = "yes" ; then 28843ce4dfeSbellard echo "CONFIG_STATIC=yes" >> config.mak 28943ce4dfeSbellardfi 2907d13299dSbellardecho -n "VERSION=" >>config.mak 2917d13299dSbellardhead $source_path/VERSION >>config.mak 2927d13299dSbellardecho "" >>config.mak 2933ef693a0Sbellardecho -n "#define QEMU_VERSION \"" >> $TMPH 2947d13299dSbellardhead $source_path/VERSION >> $TMPH 2957d13299dSbellardecho "\"" >> $TMPH 2967d13299dSbellard 2977d13299dSbellard# build tree in object directory if source path is different from current one 2987d13299dSbellardif test "$source_path_used" = "yes" ; then 2997d13299dSbellard DIRS="tests" 3007d13299dSbellard FILES="Makefile tests/Makefile" 3017d13299dSbellard for dir in $DIRS ; do 3027d13299dSbellard mkdir -p $dir 3037d13299dSbellard done 3047d13299dSbellard for f in $FILES ; do 3057d13299dSbellard ln -sf $source_path/$f $f 3067d13299dSbellard done 3077d13299dSbellardfi 3087d13299dSbellardecho "SRC_PATH=$source_path" >> config.mak 3097d13299dSbellard 3107d13299dSbellarddiff $TMPH config.h >/dev/null 2>&1 3117d13299dSbellardif test $? -ne 0 ; then 3127d13299dSbellard mv -f $TMPH config.h 3137d13299dSbellardelse 3147d13299dSbellard echo "config.h is unchanged" 3157d13299dSbellardfi 3167d13299dSbellard 3171eb87257Sbellardrm -f $TMPO $TMPC $TMPE $TMPS $TMPH 318