darkcrusade 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #! /bin/sh -
  2. #
  3. # Deploy static cross-compilers for easy distribution
  4. #
  5. # Copyright (c) 2016-2019 Matias Fonzo, <selk@dragora.org>.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. PROGRAM="${0##*/}"
  19. # Show help via option
  20. if test "$1" = -h -o "$1" = --help
  21. then
  22. echo "Deploy static cross-compilers for easy distribution."
  23. echo ""
  24. echo "Usage: $PROGRAM [TARGET]..."
  25. echo ""
  26. echo "Where TARGET is any target found in the directory \"targets\"."
  27. echo "If no target names are passed, all available targets will be built."
  28. echo ""
  29. exit 0
  30. fi
  31. # Exit immediately on any error
  32. set -e
  33. # Override locale settings
  34. LC_ALL=C
  35. export LC_ALL
  36. #### Default values
  37. # Get physical working directory, absolute path name
  38. CWD=$(CDPATH= cd -P -- $(dirname -- "$0") && printf "$PWD")
  39. # Output directory for tarballs
  40. output="${CWD}/OUTPUT.darkcrusade"
  41. # Set temporary directory for compilation, exporting it
  42. TMPDIR=${output}/sources
  43. export TMPDIR
  44. # Compose tag for tarball names using year+month+day
  45. tarname=darkcrusade_"$(date +%Y%b)"
  46. # Prepare to start the cross compiler process in the phase 1
  47. phase_one=${output}/phase1-native-"$(uname -m)".$$
  48. echo "${PROGRAM}: Creating native cross compiler on $phase_one ..."
  49. "${CWD}"/bootstrap -s0 -o $phase_one
  50. # Now will start the preparatives to use the recent native cross compiler
  51. echo "${PROGRAM}: Using (existing) compiler from $phase_one ..."
  52. # Set flags according to the generated compiler
  53. for BTCC in ${phase_one}/cross/*/bin/*-gcc
  54. do
  55. if test -x "$BTCC"
  56. then
  57. BTCC="$BTCC"
  58. break
  59. fi
  60. done
  61. for BTCXX in ${phase_one}/cross/*/bin/*-g++
  62. do
  63. if test -x "$BTCXX"
  64. then
  65. BTCXX="$BTCXX"
  66. break
  67. fi
  68. done
  69. # Set and compose flags to be used as CC/CXX
  70. BTCC="$BTCC -static -Wl,-Bstatic -static-libgcc"
  71. BTCXX="$BTCXX -static -Wl,-Bstatic -static-libgcc"
  72. IS_DARKCRUSADE=IS_DARKCRUSADE
  73. export BTCC BTCXX IS_DARKCRUSADE
  74. # Loop for create the targets, phase 2
  75. for target in "${CWD}"/targets/${@:-*}
  76. do
  77. target="${target##*/}"
  78. phase_two=${output}/phase2-${target}.$$
  79. echo "darkcrusade: Making target $target ..."
  80. "${CWD}"/bootstrap -s0 -a $target -o $phase_two 2>&1 | \
  81. tee ${output}/${tarname}-${target}.log
  82. # Provide log file, tarball plus checkum
  83. lzip -9 ${output}/${tarname}-${target}.log
  84. # Produce tarball and .sha256
  85. cd $output && rm -f ${tarname}-${target}.tar ${tarname}-${target}.tar.lz
  86. cd $phase_two && tarlz -c cross/ > ${output}/${tarname}-${target}.tar.lz
  87. cd $output && sha256sum ${tarname}-${target}.tar.lz \
  88. > ${tarname}-${target}.tar.lz.sha256
  89. # Back to the current working directory
  90. cd -- "$CWD"
  91. done