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