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