build.sh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. list="x86_64-linux-gnu-gcc x86-linux-gnu-gcc arm-linux-gnueabi-gcc aarch64-linux-gnu-gcc \
  3. sparc64-linux-gnu-gcc mips-linux-gnu-gcc powerpc-linux-gnu-gcc x86_64-macos-darwin-gcc \
  4. arm64-macos-darwin-cc x86_64-freebsd-gnu-gcc x86_64-solaris-gnu-gcc armv6-linux-gnueabi-gcc \
  5. armv5-linux-gnueabi-gcc"
  6. declare -A alias=( [x86-linux-gnu-gcc]=i686-stretch-linux-gnu-gcc \
  7. [x86_64-linux-gnu-gcc]=x86_64-stretch-linux-gnu-gcc \
  8. [arm-linux-gnueabi-gcc]=armv7-stretch-linux-gnueabi-gcc \
  9. [armv5-linux-gnueabi-gcc]=armv6-stretch-linux-gnueabi-gcc \
  10. [armv6-linux-gnueabi-gcc]=armv6-stretch-linux-gnueabi-gcc \
  11. [aarch64-linux-gnu-gcc]=aarch64-stretch-linux-gnu-gcc \
  12. [sparc64-linux-gnu-gcc]=sparc64-stretch-linux-gnu-gcc \
  13. [mips-linux-gnu-gcc]=mips64-stretch-linux-gnu-gcc \
  14. [powerpc-linux-gnu-gcc]=powerpc64-stretch-linux-gnu-gcc \
  15. [x86_64-macos-darwin-gcc]=x86_64-apple-darwin19-gcc \
  16. [arm64-macos-darwin-cc]=arm64-apple-darwin20.4-cc \
  17. [x86_64-freebsd-gnu-gcc]=x86_64-cross-freebsd12.3-gcc \
  18. [x86_64-solaris-gnu-gcc]=x86_64-cross-solaris2.x-gcc )
  19. declare -A cflags=( [sparc64-linux-gnu-gcc]="-mcpu=v7" \
  20. [mips-linux-gnu-gcc]="-march=mips32" \
  21. [armv5-linux-gnueabi-gcc]="-march=armv5t -mfloat-abi=soft" \
  22. [powerpc-linux-gnu-gcc]="-m32" )
  23. declare -a compilers
  24. IFS= read -ra candidates <<< "$list"
  25. # do we have "clean" somewhere in parameters (assuming no compiler has "clean" in it...
  26. if [[ $@[*]} =~ clean ]]; then
  27. clean="clean"
  28. fi
  29. # first select platforms/compilers
  30. for cc in ${candidates[@]}; do
  31. # check compiler first
  32. if ! command -v ${alias[$cc]:-$cc} &> /dev/null; then
  33. if command -v $cc &> /dev/null; then
  34. unset alias[$cc]
  35. else
  36. continue
  37. fi
  38. fi
  39. if [[ $# == 0 || ($# == 1 && -n $clean) ]]; then
  40. compilers+=($cc)
  41. continue
  42. fi
  43. for arg in $@
  44. do
  45. if [[ $cc =~ $arg ]]; then
  46. compilers+=($cc)
  47. fi
  48. done
  49. done
  50. # then do the work
  51. for cc in ${compilers[@]}
  52. do
  53. IFS=- read -r platform host package dummy <<< $cc
  54. export CFLAGS=${cflags[$cc]}
  55. CC=${alias[$cc]:-$cc}
  56. make AR=${CC%-*}-ar CC=$CC PLATFORM=$platform HOST=$host $clean -j8
  57. if [[ -n $clean ]]; then
  58. continue
  59. fi
  60. done