Merge branch 'qemu-cvs'
[kvm-userspace.git] / configure
blobc3910cd99b367ae70d264793456437036e9a1e3e
1 #!/bin/bash
3 prefix=/usr/local
4 kernelsourcedir=
5 kerneldir=/lib/modules/$(uname -r)/build
6 cc=gcc
7 ld=ld
8 objcopy=objcopy
9 ar=ar
10 want_module=1
11 qemu_cflags=
12 qemu_ldflags=
13 kvm_trace=
14 qemu_opts=()
15 cross_prefix=
16 arch=`uname -m`
17 target_exec=
18 # don't use uname if kerneldir is set
19 no_uname=
20 depmod_version=
21 if [ -z "TMPDIR" ] ; then
22 TMPDIR=.
25 usage() {
26 cat <<-EOF
27 Usage: $0 [options]
29 Options include:
30 --arch=ARCH architecture to compile for ($arch)
31 --cross-prefix=PREFIX prefix for cross compile
32 --prefix=PREFIX where to install things ($prefix)
33 --with-patched-kernel don't use external module
34 --with-kvm-trace Enable kvm_trace
35 --kerneldir=DIR kernel build directory ($kerneldir)
36 --qemu-cflags=CFLAGS CFLAGS to add to qemu configuration
37 --qemu-ldflags=LDFLAGS LDFLAGS to add to qemu configuration
39 Any additional option is given to qemu's configure verbatim; including:
41 EOF
42 cd qemu
43 ./configure --help | egrep "enable-|disable-" \
44 | grep -v user | grep -v system | grep -v kqemu | grep -v kvm \
45 | sed -e "s/^ / /g" \
46 | sed -e"s/ enable/enable/g" | sed -e "s/ disable/disable/g"
47 exit 1
50 while [[ "$1" = -* ]]; do
51 opt="$1"; shift
52 arg=
53 hasarg=
54 if [[ "$opt" = *=* ]]; then
55 arg="${opt#*=}"
56 opt="${opt%%=*}"
57 hasarg=1
59 case "$opt" in
60 --prefix)
61 prefix="$arg"
63 --kerneldir)
64 kerneldir="$arg"
65 no_uname=1
67 --with-patched-kernel)
68 want_module=
70 --with-kvm-trace)
71 kvm_trace=y
73 --qemu-cflags)
74 qemu_cflags="$arg"
76 --qemu-ldflags)
77 qemu_ldflags="$arg"
79 --arch)
80 arch="$arg"
82 --cross-prefix)
83 cross_prefix="$arg"
85 --help)
86 usage
89 qemu_opts=("${qemu_opts[@]}" "$opt${hasarg:+=$arg}")
91 esac
92 done
95 #set kenel directory
96 libkvm_kerneldir=$(readlink -f kernel)
98 case $arch in
99 i?86*|x86_64*)
100 arch=${arch/#i?86/i386}
101 target_exec="x86_64-softmmu"
102 qemu_cflags="$qemu_cflags -DCONFIG_X86"
104 ia64*)
105 target_exec="ia64-softmmu"
107 powerpc*)
108 target_exec="ppcemb-softmmu"
109 qemu_cflags="$qemu_cflags -I $PWD/libfdt"
110 qemu_ldflags="$qemu_ldflags -L $PWD/libfdt"
112 esac
114 processor=${arch#*-}
115 arch=${arch%%-*}
117 # see if we have split build and source directories
118 if [ -d "$kerneldir/include2" ]; then
119 kernelsourcedir=${kerneldir%/*}/source
122 if [ -n "$no_uname" -a "$want_module" ]; then
123 if [ -e "$kerneldir/.kernelrelease" ]; then
124 depmod_version=`cat "$kerneldir/.kernelrelease"`
126 elif [ -e "$kerneldir/include/config/kernel.release" ]; then
127 depmod_version=`cat "$kerneldir/include/config/kernel.release"`
128 elif [ -e "$kerneldir/.config" ]; then
129 depmod_version=$(awk '/Linux kernel version:/ { print $NF }' \
130 "$kerneldir/.config")
131 else
132 echo
133 echo "Error: kernelversion not found"
134 echo "Please make sure your kernel is configured"
135 echo
136 exit 1
140 #configure user dir
141 (cd user; ./configure --prefix="$prefix" --kerneldir="$libkvm_kerneldir" \
142 --arch="$arch" --processor="$processor" \
143 ${cross_prefix:+"--cross-prefix=$cross_prefix"})
145 #configure qemu
146 (cd qemu; ./configure --target-list=$target_exec \
147 --disable-kqemu \
148 --extra-cflags="-I $PWD/../libkvm $qemu_cflags" \
149 --extra-ldflags="-L $PWD/../libkvm $qemu_ldflags" \
150 --kerneldir="$libkvm_kerneldir" \
151 --prefix="$prefix" \
152 ${cross_prefix:+"--cross-prefix=$cross_prefix"} \
153 ${cross_prefix:+"--cpu=$arch"} "${qemu_opts[@]}"
154 ) || usage
157 cat <<EOF > config.mak
158 ARCH=$arch
159 PROCESSOR=$processor
160 PREFIX=$prefix
161 KERNELDIR=$kerneldir
162 KERNELSOURCEDIR=$kernelsourcedir
163 LIBKVM_KERNELDIR=$libkvm_kerneldir
164 WANT_MODULE=$want_module
165 CROSS_COMPILE=$cross_prefix
166 CC=$cross_prefix$cc
167 LD=$cross_prefix$ld
168 OBJCOPY=$cross_prefix$objcopy
169 AR=$cross_prefix$ar
170 DEPMOD_VERSION=$depmod_version
173 cat <<EOF > kernel/config.kbuild
174 EXT_CONFIG_KVM_TRACE=$kvm_trace