darkcrusade 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #! /bin/sh -
  2. #
  3. # Deploy static cross-compilers for easy distribution
  4. #
  5. # Copyright (c) 2016-2020 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. # Exit immediately on any error
  20. set -e
  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 in the \"targets/\" directory."
  28. echo "If no target names are 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. ### Default values
  36. # Get physical working directory (absolute path)
  37. CWD="$(CDPATH='' cd -P -- "$(dirname -- "$0")" && pwd -P)"
  38. # Output directory for tarballs
  39. output="${CWD}/OUTPUT.darkcrusade"
  40. # Set temporary directory for compilation, exporting it
  41. TMPDIR=${output}/sources
  42. export TMPDIR
  43. # Compose tag for tarball names using year+month+day
  44. tarname=darkcrusade_"$(date +%Y%b)"
  45. # Prepare to start the cross compiler process in the phase 1
  46. phase_one=${output}/phase1-native-"$(uname -m)".$$
  47. echo "${PROGRAM}: Creating native cross compiler on $phase_one ..."
  48. "${CWD}"/bootstrap -s0 -o "$phase_one"
  49. # Now will start the preparatives to use the recent native cross compiler
  50. echo "${PROGRAM}: Using (existing) compiler from $phase_one ..."
  51. # Set flags according to the generated compiler
  52. for BTCC in "${phase_one}"/cross/*/bin/*-gcc
  53. do
  54. if test -x "$BTCC"
  55. then
  56. BTCC="$BTCC"
  57. break
  58. fi
  59. done
  60. for BTCXX in "${phase_one}"/cross/*/bin/*-g++
  61. do
  62. if test -x "$BTCXX"
  63. then
  64. BTCXX="$BTCXX"
  65. break
  66. fi
  67. done
  68. # Set and compose flags to be used as CC/CXX
  69. BTCC="$BTCC -static -Wl,-Bstatic -static-libgcc"
  70. BTCXX="$BTCXX -static -Wl,-Bstatic -static-libgcc"
  71. IS_DARKCRUSADE=IS_DARKCRUSADE
  72. export BTCC BTCXX IS_DARKCRUSADE
  73. # Loop for create the targets, phase 2
  74. for target in ${CWD}/targets/${@:-*}
  75. do
  76. target="${target##*/}"
  77. phase_two=${output}/phase2-${target}.$$
  78. echo "darkcrusade: Making target $target ..."
  79. "${CWD}"/bootstrap -s0 -a "$target" -o "$phase_two" 2>&1 | \
  80. tee "${output}/${tarname}-${target}.log"
  81. # Provide log file, tarball plus checkum
  82. lzip -9 "${output}/${tarname}-${target}.log" &
  83. rm -f "${output}/${tarname}-${target}.tar" \
  84. "${output}/${tarname}-${target}.tar.lz"
  85. cd "$phase_two"
  86. ( umask 022 ; tarlz --solid -9 -cvf - -- cross/ ) \
  87. > "${output}/${tarname}-${target}.tar.lz"
  88. (
  89. cd -- "$output" && \
  90. sha256sum "${tarname}-${target}.tar.lz" \
  91. > "${tarname}-${target}.tar.lz.sha256"
  92. )
  93. # Back to the current working directory
  94. cd -- "$CWD"
  95. done