configure 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/usr/bin/env bash
  2. srcdir=$(cd "$(dirname "$0")"; pwd)
  3. prefix=/usr/local
  4. cc=gcc
  5. cxx=g++
  6. ld=ld
  7. objcopy=objcopy
  8. objdump=objdump
  9. ar=ar
  10. addr2line=addr2line
  11. arch=`uname -m | sed -e 's/i.86/i386/;s/arm.*/arm/;s/ppc64.*/ppc64/'`
  12. host=$arch
  13. cross_prefix=
  14. endian=""
  15. pretty_print_stacks=yes
  16. environ_default=yes
  17. u32_long=
  18. usage() {
  19. cat <<-EOF
  20. Usage: $0 [options]
  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. --cxx=CXX c++ compiler to use ($cxx)
  27. --ld=LD ld linker to use ($ld)
  28. --prefix=PREFIX where to install things ($prefix)
  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)
  32. --[enable|disable]-default-environ
  33. enable or disable the generation of a default environ when
  34. no environ is provided by the user (enabled by default)
  35. EOF
  36. exit 1
  37. }
  38. while [[ "$1" = -* ]]; do
  39. opt="$1"; shift
  40. arg=
  41. if [[ "$opt" = *=* ]]; then
  42. arg="${opt#*=}"
  43. opt="${opt%%=*}"
  44. fi
  45. case "$opt" in
  46. --prefix)
  47. prefix="$arg"
  48. ;;
  49. --arch)
  50. arch="$arg"
  51. ;;
  52. --processor)
  53. processor="$arg"
  54. ;;
  55. --cross-prefix)
  56. cross_prefix="$arg"
  57. ;;
  58. --endian)
  59. endian="$arg"
  60. ;;
  61. --cc)
  62. cc="$arg"
  63. ;;
  64. --cxx)
  65. cxx="$arg"
  66. ;;
  67. --ld)
  68. ld="$arg"
  69. ;;
  70. --enable-pretty-print-stacks)
  71. pretty_print_stacks=yes
  72. ;;
  73. --disable-pretty-print-stacks)
  74. pretty_print_stacks=no
  75. ;;
  76. --enable-default-environ)
  77. environ_default=yes
  78. ;;
  79. --disable-default-environ)
  80. environ_default=no
  81. ;;
  82. --help)
  83. usage
  84. ;;
  85. *)
  86. usage
  87. ;;
  88. esac
  89. done
  90. arch_name=$arch
  91. [ "$arch" = "aarch64" ] && arch="arm64"
  92. [ "$arch_name" = "arm64" ] && arch_name="aarch64"
  93. [ -z "$processor" ] && processor="$arch"
  94. if [ "$processor" = "arm64" ]; then
  95. processor="cortex-a57"
  96. elif [ "$processor" = "arm" ]; then
  97. processor="cortex-a15"
  98. fi
  99. if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then
  100. testdir=x86
  101. elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then
  102. testdir=arm
  103. elif [ "$arch" = "ppc64" ]; then
  104. testdir=powerpc
  105. firmware="$testdir/boot_rom.bin"
  106. if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then
  107. echo "You must provide endianness (big or little)!"
  108. usage
  109. fi
  110. else
  111. testdir=$arch
  112. fi
  113. if [ ! -d "$srcdir/$testdir" ]; then
  114. echo "$testdir does not exist!"
  115. exit 1
  116. fi
  117. if [ -f "$srcdir/$testdir/run" ]; then
  118. ln -fs "$srcdir/$testdir/run" $testdir-run
  119. fi
  120. # check if uint32_t needs a long format modifier
  121. cat << EOF > lib-test.c
  122. __UINT32_TYPE__
  123. EOF
  124. u32_long=$($cross_prefix$cc -E lib-test.c | grep -v '^#' | grep -q long && echo yes)
  125. rm -f lib-test.c
  126. # api/: check for dependent 32 bit libraries and gnu++11 support
  127. if [ "$testdir" = "x86" ]; then
  128. echo 'int main () {}' > lib-test.c
  129. $cc -m32 -o /dev/null -lstdc++ -lpthread -lrt lib-test.c &> /dev/null
  130. exit=$?
  131. $cxx -m32 -o /dev/null -std=gnu++11 lib-test.c &> /dev/null
  132. if [ $? -eq 0 -a $exit -eq 0 ]; then
  133. api=true
  134. fi
  135. rm -f lib-test.c
  136. fi
  137. # Are we in a separate build tree? If so, link the Makefile
  138. # and shared stuff so that 'make' and run_tests.sh work.
  139. if test ! -e Makefile; then
  140. echo "linking Makefile..."
  141. ln -s "$srcdir/Makefile" .
  142. echo "linking tests..."
  143. mkdir -p $testdir
  144. ln -sf "$srcdir/$testdir/run" $testdir/
  145. ln -sf "$srcdir/$testdir/unittests.cfg" $testdir/
  146. ln -sf "$srcdir/run_tests.sh"
  147. echo "linking scripts..."
  148. ln -sf "$srcdir/scripts"
  149. fi
  150. # link lib/asm for the architecture
  151. rm -f lib/asm
  152. asm=asm-generic
  153. if [ -d "$srcdir/lib/$arch/asm" ]; then
  154. asm="$srcdir/lib/$arch/asm"
  155. elif [ -d "$srcdir/lib/$testdir/asm" ]; then
  156. asm="$srcdir/lib/$testdir/asm"
  157. fi
  158. mkdir -p lib
  159. ln -sf "$asm" lib/asm
  160. # create the config
  161. cat <<EOF > config.mak
  162. SRCDIR=$srcdir
  163. PREFIX=$prefix
  164. HOST=$host
  165. ARCH=$arch
  166. ARCH_NAME=$arch_name
  167. PROCESSOR=$processor
  168. CC=$cross_prefix$cc
  169. CXX=$cross_prefix$cxx
  170. LD=$cross_prefix$ld
  171. OBJCOPY=$cross_prefix$objcopy
  172. OBJDUMP=$cross_prefix$objdump
  173. AR=$cross_prefix$ar
  174. ADDR2LINE=$cross_prefix$addr2line
  175. API=$api
  176. TEST_DIR=$testdir
  177. FIRMWARE=$firmware
  178. ENDIAN=$endian
  179. PRETTY_PRINT_STACKS=$pretty_print_stacks
  180. ENVIRON_DEFAULT=$environ_default
  181. ERRATATXT=errata.txt
  182. U32_LONG_FMT=$u32_long
  183. EOF