xref: /kvm-unit-tests/configure (revision d3aacb4f57d05f74f2030dbe12e7dfd6aa1b273d)
1#!/bin/bash
2
3prefix=/usr/local
4kerneldir=/lib/modules/$(uname -r)/build
5cc=gcc
6ld=ld
7objcopy=objcopy
8ar=ar
9arch=`uname -m | sed -e s/i.86/i386/ | sed -e 's/arm.*/arm/'`
10cross_prefix=
11
12usage() {
13    cat <<-EOF
14	Usage: $0 [options]
15
16	Options include:
17	    --arch=ARCH            architecture to compile for ($arch)
18	    --processor=PROCESSOR  processor to compile for ($arch)
19	    --cross-prefix=PREFIX  cross compiler prefix
20	    --cc=CC		   c compiler to use ($cc)
21	    --ld=LD		   ld linker to use ($ld)
22	    --prefix=PREFIX        where to install things ($prefix)
23	    --kerneldir=DIR        kernel build directory for kvm.h ($kerneldir)
24EOF
25    exit 1
26}
27
28while [[ "$1" = -* ]]; do
29    opt="$1"; shift
30    arg=
31    if [[ "$opt" = *=* ]]; then
32	arg="${opt#*=}"
33	opt="${opt%%=*}"
34    fi
35    case "$opt" in
36	--prefix)
37	    prefix="$arg"
38	    ;;
39	--kerneldir)
40	    kerneldir="$arg"
41	    ;;
42        --arch)
43	    arch="$arg"
44	    ;;
45        --processor)
46	    processor="$arg"
47	    ;;
48	--cross-prefix)
49	    cross_prefix="$arg"
50	    ;;
51	--cc)
52	    cc="$arg"
53	    ;;
54	--ld)
55	    ld="$arg"
56	    ;;
57	--help)
58	    usage
59	    ;;
60	*)
61	    usage
62	    ;;
63    esac
64done
65[ -z "$processor" ] && processor="$arch"
66
67if [ "$processor" = "arm" ]; then
68    processor="cortex-a15"
69fi
70
71if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
72    testdir=x86
73else
74    testdir=$arch
75fi
76if [ ! -d $testdir ]; then
77    echo "$testdir does not exist!"
78    exit 1
79fi
80if [ -f $testdir/run ]; then
81    ln -fs $testdir/run $testdir-run
82fi
83
84# check for dependent 32 bit libraries
85if [ "$arch" != "arm" ]; then
86cat << EOF > lib_test.c
87#include <stdc++.h>
88#include <boost_thread-mt.h>
89#include <pthread.h>
90
91int main ()
92{}
93EOF
94$cc -m32 -o /dev/null lib_test.c &> /dev/null
95exit=$?
96if [ $exit -eq 0 ]; then
97    api=true
98fi
99rm -f lib_test.c
100fi
101
102# link lib/asm for the architecture
103rm -f lib/asm
104asm=asm-generic
105if [ -d lib/$arch/asm ]; then
106	asm=$arch/asm
107elif [ -d lib/$testdir/asm ]; then
108	asm=$testdir/asm
109fi
110ln -s $asm lib/asm
111
112# create the config
113cat <<EOF > config.mak
114PREFIX=$prefix
115KERNELDIR=$(readlink -f $kerneldir)
116ARCH=$arch
117PROCESSOR=$processor
118CC=$cross_prefix$cc
119LD=$cross_prefix$ld
120OBJCOPY=$cross_prefix$objcopy
121AR=$cross_prefix$ar
122API=$api
123TEST_DIR=$testdir
124EOF
125