darkcrusade 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #! /bin/sh -
  2. #
  3. # Deploy static cross-compilers for easy distribution
  4. #
  5. # Copyright (c) 2016-2021 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. # Exit immediately on any error
  19. set -e
  20. PROGRAM="${0##*/}"
  21. # Show help via option
  22. if test "$1" = -h || test "$1" = --help
  23. then
  24. echo "Usage: $PROGRAM [TARGET]..."
  25. echo "Deploy static cross-compilers for easy distribution."
  26. echo ""
  27. echo "Where TARGET is any target found at the targets/ directory."
  28. echo "If no target name is passed, all available targets will be built."
  29. echo ""
  30. exit 0;
  31. fi
  32. # Override locale settings
  33. LC_ALL=C
  34. export LC_ALL
  35. umask 022
  36. ### Default values
  37. # Get physical working directory (absolute path)
  38. CWD="$(CDPATH='' cd -P -- "$(dirname -- "$0")" && pwd -P)"
  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 yearNumber+monthName+dayNumber
  45. tarname="darkcrusade_$(date +%Y%b%d)"
  46. # Prepare to start the cross compiler process in the phase 1
  47. phase_one="${output}/phase1-native-$(uname -m)-$(date +%Y-%m-%d.%H%M%S)-$$"
  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}-$(date +%Y-%m-%d.%H%M%S)-$$"
  79. # Build target against native compiler, logging its output
  80. echo "darkcrusade: Making target $target ..."
  81. rm -f "${output}/bootstrapfailed"
  82. {
  83. "${CWD}"/bootstrap -s0 -a "$target" -o "$phase_two" || touch "${output}/bootstrapfailed"
  84. } 2>&1 | tee "${output}/${tarname}-${target}.log"
  85. if test -f "${output}/bootstrapfailed"
  86. then
  87. echo "${PROGRAM}: An error occurred while processing the target: $target" 1>&2
  88. echo " Please check the log file ${output}/${tarname}-${target}.log" 1>&2
  89. exit 99;
  90. fi
  91. # Provide log file, tarball and checkum
  92. lzip -9 "${output}/${tarname}-${target}.log" &
  93. (
  94. cd -- "$phase_two" && \
  95. tarlz --solid -9 -cvf - -- cross/ \
  96. > "${output}/${tarname}-${target}.tar.lz"
  97. )
  98. (
  99. cd -- "$output" && \
  100. sha256sum "${tarname}-${target}.tar.lz" \
  101. > "${tarname}-${target}.tar.lz.sha256"
  102. )
  103. done