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