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 66arch_name=$arch 67[ "$arch" = "aarch64" ] && arch="arm64" 68[ "$arch_name" = "arm64" ] && arch_name="aarch64" 69 70[ -z "$processor" ] && processor="$arch" 71 72if [ "$processor" = "arm64" ]; then 73 processor="cortex-a57" 74elif [ "$processor" = "arm" ]; then 75 processor="cortex-a15" 76fi 77 78if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then 79 testdir=x86 80elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then 81 testdir=arm 82else 83 testdir=$arch 84fi 85if [ ! -d $testdir ]; then 86 echo "$testdir does not exist!" 87 exit 1 88fi 89if [ -f $testdir/run ]; then 90 ln -fs $testdir/run $testdir-run 91fi 92 93# check for dependent 32 bit libraries 94if [ "$arch" != "arm" ]; then 95cat << EOF > lib_test.c 96#include <stdc++.h> 97#include <boost_thread-mt.h> 98#include <pthread.h> 99 100int main () 101{} 102EOF 103$cc -m32 -o /dev/null lib_test.c &> /dev/null 104exit=$? 105if [ $exit -eq 0 ]; then 106 api=true 107fi 108rm -f lib_test.c 109fi 110 111# link lib/asm for the architecture 112rm -f lib/asm 113asm=asm-generic 114if [ -d lib/$arch/asm ]; then 115 asm=$arch/asm 116elif [ -d lib/$testdir/asm ]; then 117 asm=$testdir/asm 118fi 119ln -s $asm lib/asm 120 121# create the config 122cat <<EOF > config.mak 123PREFIX=$prefix 124KERNELDIR=$(readlink -f $kerneldir) 125ARCH=$arch 126ARCH_NAME=$arch_name 127PROCESSOR=$processor 128CC=$cross_prefix$cc 129LD=$cross_prefix$ld 130OBJCOPY=$cross_prefix$objcopy 131AR=$cross_prefix$ar 132API=$api 133TEST_DIR=$testdir 134EOF 135