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