summaryrefslogtreecommitdiff
path: root/configure
blob: 3bb10ce9f5b1cf7b7704e6ce17826833714ca0a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash

prefix=/usr/local
kerneldir=/lib/modules/$(uname -r)/build
cc=gcc
ld=ld
objcopy=objcopy
want_module=1
qemu_cflags=
qemu_ldflags=
qemu_opts=()
cross_prefix=
arch=`uname -m`
target_exec=

usage() {
    cat <<-EOF
	Usage: $0 [options]

	Options include:
	    --arch=ARCH            architecture to compile for ($arch)
	    --cross-prefix=PREFIX  prefix for cross compile
	    --prefix=PREFIX        where to install things ($prefix)
	    --with-patched-kernel  don't use external module
	    --kerneldir=DIR        kernel build directory ($kerneldir)
	    --qemu-cflags=CFLAGS   CFLAGS to add to qemu configuration
	    --qemu-ldflags=LDFLAGS LDFLAGS to add to qemu configuration

	Any additional option is given to qemu's configure verbatim; including:

EOF
    cd qemu
    ./configure --help | egrep "enable-|disable-" \
	| grep -v user | grep -v system | grep -v kqemu | grep -v kvm \
	| sed -e "s/^  /    /g" \
	| sed -e"s/  enable/enable/g" | sed -e "s/  disable/disable/g"
    exit 1
}

while [[ "$1" = -* ]]; do
    opt="$1"; shift
    arg=
    hasarg=
    if [[ "$opt" = *=* ]]; then
	arg="${opt#*=}"
	opt="${opt%%=*}"
	hasarg=1
    fi
    case "$opt" in
	--prefix)
	    prefix="$arg"
	    ;;
	--kerneldir)
	    kerneldir="$arg"
	    ;;
	--with-patched-kernel)
	    want_module=
	    ;;
	--qemu-cflags)
	    qemu_cflags="$arg"
	    ;;
	--qemu-ldflags)
	    qemu_ldflags="$arg"
	    ;;
	--arch)
	    arch="$arg"
	    ;;
	--cross-prefix)
	    cross_prefix="$arg"
            ;;
	--help)
	    usage
	    ;;
	*)
	    qemu_opts=("${qemu_opts[@]}" "$opt${hasarg:+=$arg}")
	    ;;
    esac
done


#set kenel directory
libkvm_kerneldir=$(readlink -f kernel)

#if arch is an x86 arch set to i386
if [[ $arch = i?86 ]]; then
  arch="i386"
fi

#set parameters compiling
if [ "$arch" = "i386" -o "$arch" = "x86_64" ]; then
    target_exec="x86_64-softmmu"
    qemu_cflags="$qemu_cflags -DCONFIG_X86"
fi

if [ "$arch" = "ia64" ]; then
    target_exec="ia64-softmmu"
fi

if [ "$arch" = "powerpc" ]; then
    target_exec="ppcemb-softmmu"
    qemu_cflags="$qemu_cflags -I $PWD/libfdt"
    qemu_ldflags="$qemu_ldflags -L $PWD/libfdt"
fi

#configure user dir
(cd user; ./configure --prefix="$prefix" --kerneldir="$libkvm_kerneldir" \
          --arch="$arch" \
          ${cross_prefix:+"--cross-prefix=$cross_prefix"})

#configure qemu
(cd qemu; ./configure --target-list=$target_exec \
    --disable-kqemu \
    --disable-gcc-check \
    --extra-cflags="-I $PWD/../libkvm $qemu_cflags" \
    --extra-ldflags="-L $PWD/../libkvm $qemu_ldflags" \
    --kernel-path="$libkvm_kerneldir" \
    --prefix="$prefix" \
    ${cross_prefix:+"--cross-prefix=$cross_prefix"} \
    ${cross_prefix:+"--cpu=$arch"} "${qemu_opts[@]}"
) || usage


cat <<EOF > config.mak
ARCH=$arch
PREFIX=$prefix
KERNELDIR=$kerneldir
LIBKVM_KERNELDIR=$libkvm_kerneldir
WANT_MODULE=$want_module
CROSS_COMPILE=$cross_prefix
CC=$cross_prefix$cc
LD=$cross_prefix$ld
OBJCOPY=$cross_prefix$objcopy
EOF