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