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/'` 10host=$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 --processor=PROCESSOR processor to compile for ($arch) 20 --cross-prefix=PREFIX cross compiler prefix 21 --cc=CC c compiler to use ($cc) 22 --ld=LD ld linker to use ($ld) 23 --prefix=PREFIX where to install things ($prefix) 24 --kerneldir=DIR kernel build directory for kvm.h ($kerneldir) 25EOF 26 exit 1 27} 28 29while [[ "$1" = -* ]]; do 30 opt="$1"; shift 31 arg= 32 if [[ "$opt" = *=* ]]; then 33 arg="${opt#*=}" 34 opt="${opt%%=*}" 35 fi 36 case "$opt" in 37 --prefix) 38 prefix="$arg" 39 ;; 40 --kerneldir) 41 kerneldir="$arg" 42 ;; 43 --arch) 44 arch="$arg" 45 ;; 46 --processor) 47 processor="$arg" 48 ;; 49 --cross-prefix) 50 cross_prefix="$arg" 51 ;; 52 --cc) 53 cc="$arg" 54 ;; 55 --ld) 56 ld="$arg" 57 ;; 58 --help) 59 usage 60 ;; 61 *) 62 usage 63 ;; 64 esac 65done 66 67arch_name=$arch 68[ "$arch" = "aarch64" ] && arch="arm64" 69[ "$arch_name" = "arm64" ] && arch_name="aarch64" 70 71[ -z "$processor" ] && processor="$arch" 72 73if [ "$processor" = "arm64" ]; then 74 processor="cortex-a57" 75elif [ "$processor" = "arm" ]; then 76 processor="cortex-a15" 77fi 78 79if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then 80 testdir=x86 81elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then 82 testdir=arm 83else 84 testdir=$arch 85fi 86if [ ! -d $testdir ]; then 87 echo "$testdir does not exist!" 88 exit 1 89fi 90if [ -f $testdir/run ]; then 91 ln -fs $testdir/run $testdir-run 92fi 93 94# check for dependent 32 bit libraries 95if [ "$arch" != "arm" ]; then 96cat << EOF > lib_test.c 97#include <stdc++.h> 98#include <boost_thread-mt.h> 99#include <pthread.h> 100 101int main () 102{} 103EOF 104$cc -m32 -o /dev/null lib_test.c &> /dev/null 105exit=$? 106if [ $exit -eq 0 ]; then 107 api=true 108fi 109rm -f lib_test.c 110fi 111 112# link lib/asm for the architecture 113rm -f lib/asm 114asm=asm-generic 115if [ -d lib/$arch/asm ]; then 116 asm=$arch/asm 117elif [ -d lib/$testdir/asm ]; then 118 asm=$testdir/asm 119fi 120ln -s $asm lib/asm 121 122# create the config 123cat <<EOF > config.mak 124PREFIX=$prefix 125KERNELDIR=$(readlink -f $kerneldir) 126HOST=$host 127ARCH=$arch 128ARCH_NAME=$arch_name 129PROCESSOR=$processor 130CC=$cross_prefix$cc 131LD=$cross_prefix$ld 132OBJCOPY=$cross_prefix$objcopy 133AR=$cross_prefix$ar 134API=$api 135TEST_DIR=$testdir 136EOF 137