build.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #!/usr/bin/env bash
  2. # -----------------------------------------------------------------------------
  3. # This file is part of the xPacks distribution.
  4. # (https://xpack.github.io)
  5. # Copyright (c) 2019 Liviu Ionescu.
  6. #
  7. # Permission to use, copy, modify, and/or distribute this software
  8. # for any purpose is hereby granted, under the terms of the MIT license.
  9. # -----------------------------------------------------------------------------
  10. # -----------------------------------------------------------------------------
  11. # Safety settings (see https://gist.github.com/ilg-ul/383869cbb01f61a51c4d).
  12. if [[ ! -z ${DEBUG} ]]
  13. then
  14. set ${DEBUG} # Activate the expand mode if DEBUG is anything but empty.
  15. else
  16. DEBUG=""
  17. fi
  18. set -o errexit # Exit if command failed.
  19. set -o pipefail # Exit if pipe failed.
  20. set -o nounset # Exit if variable not set.
  21. # Remove the initial space and instead use '\n'.
  22. IFS=$'\n\t'
  23. # -----------------------------------------------------------------------------
  24. # Identify the script location, to reach, for example, the helper scripts.
  25. build_script_path="$0"
  26. if [[ "${build_script_path}" != /* ]]
  27. then
  28. # Make relative path absolute.
  29. build_script_path="$(pwd)/$0"
  30. fi
  31. script_folder_path="$(dirname "${build_script_path}")"
  32. script_folder_name="$(basename "${script_folder_path}")"
  33. # =============================================================================
  34. # Script to build the xPack GNU Arm Embeded GCC distribution packages.
  35. #
  36. # Developed on macOS 10.13 High Sierra, but intended to run on
  37. # macOS 10.10 Yosemite and CentOS 6 XBB.
  38. # -----------------------------------------------------------------------------
  39. echo
  40. echo "xPack GNU Arm Embedded GCC distribution build script."
  41. host_functions_script_path="${script_folder_path}/helper/host-functions-source.sh"
  42. echo
  43. echo "Host helper functions source script: \"${host_functions_script_path}\"."
  44. source "${host_functions_script_path}"
  45. host_detect
  46. # docker_linux64_image="ilegeul/centos:6-xbb-v2"
  47. # docker_linux32_image="ilegeul/centos32:6-xbb-v2"
  48. # -----------------------------------------------------------------------------
  49. # Array where the remaining args will be stored.
  50. declare -a rest
  51. help_message=" bash $0 [--win32] [--win64] [--linux32] [--linux64] [--osx] [--all] [clean|cleanlibs|cleanall|preload-images] [--env-file file] [--disable-strip] [--without-pdf] [--with-html] [--disable-multilib] [--develop] [--debug] [--use-gits] [--jobs N] [--help]"
  52. host_options "${help_message}" $@
  53. host_common
  54. # -----------------------------------------------------------------------------
  55. if [ -n "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}" ]
  56. then
  57. host_prepare_docker
  58. fi
  59. # ----- Build the native distribution. ----------------------------------------
  60. if [ -z "${DO_BUILD_OSX}${DO_BUILD_LINUX64}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_WIN32}" ]
  61. then
  62. host_build_target "Creating the native distribution..." \
  63. --script "${HOST_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  64. --env-file "${ENV_FILE}" \
  65. -- \
  66. ${rest[@]-}
  67. else
  68. # ----- Build the OS X distribution. ----------------------------------------
  69. if [ "${DO_BUILD_OSX}" == "y" ]
  70. then
  71. if [ "${HOST_UNAME}" == "Darwin" ]
  72. then
  73. host_build_target "Creating the OS X distribution..." \
  74. --script "${HOST_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  75. --env-file "${ENV_FILE}" \
  76. --target-platform "darwin" \
  77. -- \
  78. ${rest[@]-}
  79. else
  80. echo "Building the macOS image is not possible on this platform."
  81. exit 1
  82. fi
  83. fi
  84. # ----- Build the GNU/Linux 64-bit distribution. ---------------------------
  85. if [ "${DO_BUILD_LINUX64}" == "y" ]
  86. then
  87. host_build_target "Creating the GNU/Linux 64-bit distribution..." \
  88. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  89. --env-file "${ENV_FILE}" \
  90. --target-platform "linux" \
  91. --target-arch "x64" \
  92. --target-bits 64 \
  93. --docker-image "${docker_linux64_image}" \
  94. -- \
  95. ${rest[@]-}
  96. fi
  97. # ----- Build the Windows 64-bit distribution. -----------------------------
  98. if [ "${DO_BUILD_WIN64}" == "y" ]
  99. then
  100. linux_install_relative_path="linux-x64/install/${APP_LC_NAME}"
  101. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  102. then
  103. host_build_target "Creating the GNU/Linux 64-bit distribution..." \
  104. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  105. --env-file "${ENV_FILE}" \
  106. --target-platform "linux" \
  107. --target-arch "x64" \
  108. --target-bits 64 \
  109. --docker-image "${docker_linux64_image}" \
  110. -- \
  111. ${rest[@]-}
  112. fi
  113. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  114. then
  115. echo "Mandatory GNU/Linux binaries missing."
  116. exit 1
  117. fi
  118. host_build_target "Creating the Windows 64-bit distribution..." \
  119. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  120. --env-file "${ENV_FILE}" \
  121. --target-platform "win32" \
  122. --target-arch "x64" \
  123. --target-bits 64 \
  124. --docker-image "${docker_linux64_image}" \
  125. -- \
  126. --linux-install-path "${linux_install_relative_path}" \
  127. ${rest[@]-}
  128. fi
  129. # ----- Build the GNU/Linux 32-bit distribution. ---------------------------
  130. if [ "${DO_BUILD_LINUX32}" == "y" ]
  131. then
  132. host_build_target "Creating the GNU/Linux 32-bit distribution..." \
  133. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  134. --env-file "${ENV_FILE}" \
  135. --target-platform "linux" \
  136. --target-arch "x32" \
  137. --target-bits 32 \
  138. --docker-image "${docker_linux32_image}" \
  139. -- \
  140. ${rest[@]-}
  141. fi
  142. # ----- Build the Windows 32-bit distribution. -----------------------------
  143. # Since the actual container is a 32-bit, use the debian32 binaries.
  144. if [ "${DO_BUILD_WIN32}" == "y" ]
  145. then
  146. linux_install_relative_path="linux-x32/install/${APP_LC_NAME}"
  147. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  148. then
  149. host_build_target "Creating the GNU/Linux 32-bit distribution..." \
  150. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  151. --env-file "${ENV_FILE}" \
  152. --target-platform "linux" \
  153. --target-arch "x32" \
  154. --target-bits 32 \
  155. --docker-image "${docker_linux32_image}" \
  156. -- \
  157. ${rest[@]-}
  158. fi
  159. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  160. then
  161. echo "Mandatory GNU/Linux binaries missing."
  162. exit 1
  163. fi
  164. host_build_target "Creating the Windows 32-bit distribution..." \
  165. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  166. --env-file "${ENV_FILE}" \
  167. --target-platform "win32" \
  168. --target-arch "x32" \
  169. --target-bits 32 \
  170. --docker-image "${docker_linux32_image}" \
  171. -- \
  172. --linux-install-path "${linux_install_relative_path}" \
  173. ${rest[@]-}
  174. fi
  175. fi
  176. host_show_sha
  177. # -----------------------------------------------------------------------------
  178. host_stop_timer
  179. host_notify_completed
  180. # Completed successfully.
  181. exit 0
  182. # -----------------------------------------------------------------------------