xref: /kvm-unit-tests/configure (revision a322d4c597bb7a4de7985e7b51b80504f7e4fdda)
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/`
10processor="$arch"
11cross_prefix=
12
13usage() {
14    cat <<-EOF
15	Usage: $0 [options]
16
17	Options include:
18	    --arch=ARCH            architecture 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
65if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
66    testdir=x86
67else
68    testdir=$arch
69fi
70if [ ! -d $testdir ]; then
71    echo "$testdir does not exist!"
72    exit 1
73fi
74if [ -f $testdir/run ]; then
75    ln -fs $testdir/run $testdir-run
76fi
77
78# check for dependent 32 bit libraries
79cat << EOF > lib_test.c
80#include <stdc++.h>
81#include <boost_thread-mt.h>
82#include <pthread.h>
83
84int main ()
85{}
86EOF
87$cc -m32 -o /dev/null lib_test.c &> /dev/null
88exit=$?
89if [ $exit -eq 0 ]; then
90    api=true
91fi
92rm -f lib_test.c
93
94cat <<EOF > config.mak
95PREFIX=$prefix
96KERNELDIR=$(readlink -f $kerneldir)
97ARCH=$arch
98PROCESSOR=$processor
99CC=$cross_prefix$cc
100LD=$cross_prefix$ld
101OBJCOPY=$cross_prefix$objcopy
102AR=$cross_prefix$ar
103API=$api
104TEST_DIR=$testdir
105EOF
106