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