icebuild 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. set -e
  3. version=60.3.0
  4. archive=./icecat-${version}-gnu1.tar.bz2
  5. folder=./icecat-${version}
  6. function usage {
  7. echo "Usage: icebuild [command1 [command2 [...]]]"
  8. echo
  9. echo "Downloads, patches and builds GNU IceCat for macOS. Available"
  10. echo "commands:"
  11. echo
  12. echo " build Compile the sources"
  13. echo " help Display this message and exit"
  14. echo " prepare Download the sources and prepare them for"
  15. echo " compilation"
  16. echo " update_dmg Copy the final DMG into the dmgs folder"
  17. echo
  18. echo "Multiple commands can be specified at once. If no commands"
  19. echo "are given, the script defaults to 'prepare build'."
  20. exit 0
  21. }
  22. function announce {
  23. echo -e "\033[93m|> $1\033[0m"
  24. }
  25. function die {
  26. echo -e "\e[31mError: $1\e[0m"
  27. exit 1
  28. }
  29. function fetch_archive {
  30. announce "Fetching source archive for ${version}"
  31. if [[ ! -f "${archive}" ]]; then
  32. wget "https://ftpmirror.gnu.org/gnuzilla/${version}/${archive}"
  33. else
  34. echo "Found previously downloaded archive ${archive}"
  35. fi
  36. }
  37. function extract_archive {
  38. announce "Extracting source archive"
  39. if [[ ! -d "${folder}" ]]; then
  40. tar xjfv "${archive}"
  41. else
  42. echo "Found previously extracted archive contents ${folder}"
  43. fi
  44. }
  45. function apply_patches {
  46. announce "Patching files"
  47. pushd "${folder}"
  48. while read -r file; do
  49. if ! patch -Rsf --dry-run -p0 -i "${file}" > /dev/null; then
  50. patch -p0 -i "${file}"
  51. else
  52. echo "$(basename "${file}") was already applied"
  53. fi
  54. done < <(find ../ -maxdepth 1 -name "*.patch")
  55. popd
  56. }
  57. function prepare_folders {
  58. announce "Preparing build folders"
  59. pushd "${folder}"
  60. mkdir -vp objdir
  61. mkdir -vp browser/branding/unofficial/moz.build
  62. popd
  63. }
  64. function build {
  65. announce "Building"
  66. pushd "${folder}/objdir"
  67. export CXX='/usr/bin/clang++ -stdlib=libc++'
  68. ../configure \
  69. --with-l10n-base=../l10n \
  70. --enable-official-branding \
  71. --with-macos-sdk=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk
  72. make
  73. make package
  74. popd
  75. }
  76. function update_dmg {
  77. local dmg=${folder}/objdir/dist/icecat-${version}.en-US.mac.dmg
  78. if [[ ! -f "${dmg}" ]]; then
  79. die "Could not find ${dmg}"
  80. fi
  81. local txt=${dmg%%.dmg}.txt
  82. if [[ ! -f "${txt}" ]]; then
  83. die "Could not find ${txt}"
  84. fi
  85. local name=$(basename "${dmg}")
  86. local ts=$(cat "${txt}")
  87. cp -v "${dmg}" "dmgs/${name%%.dmg}.${ts}.dmg"
  88. }
  89. # Handle help command
  90. for arg in $@; do
  91. if [[ ${arg} == help ]]; then
  92. usage
  93. fi
  94. done
  95. # Default commands (if needed) and validate them
  96. commands=${@-prepare build}
  97. for command in ${commands}; do
  98. case "${command}" in
  99. prepare)
  100. ;;
  101. build)
  102. ;;
  103. update_dmg)
  104. ;;
  105. *)
  106. die "Invalid command ${command}"
  107. ;;
  108. esac
  109. done
  110. # Handle commands
  111. for command in ${commands}; do
  112. case "${command}" in
  113. prepare)
  114. fetch_archive
  115. extract_archive
  116. apply_patches
  117. prepare_folders
  118. ;;
  119. build)
  120. build
  121. ;;
  122. update_dmg)
  123. update_dmg
  124. ;;
  125. esac
  126. done