build.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 RISC-V 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 RISC-V Embedded GCC distribution build script."
  41. host_functions_script_path="${script_folder_path}/helper/host-functions-source.sh"
  42. source "${host_functions_script_path}"
  43. common_functions_script_path="${script_folder_path}/common-functions-source.sh"
  44. source "${common_functions_script_path}"
  45. defines_script_path="${script_folder_path}/defs-source.sh"
  46. source "${defines_script_path}"
  47. host_detect
  48. # For clarity, explicitly define the docker images here.
  49. docker_linux64_image=${docker_linux64_image:-"ilegeul/ubuntu:amd64-12.04-xbb-v3.2"}
  50. docker_linux32_image=${docker_linux32_image:-"ilegeul/ubuntu:i386-12.04-xbb-v3.2"}
  51. docker_linux_arm64_image=${docker_linux_arm64_image:-"ilegeul/ubuntu:arm64v8-16.04-xbb-v3.2"}
  52. docker_linux_arm32_image=${docker_linux_arm32_image:-"ilegeul/ubuntu:arm32v7-16.04-xbb-v3.2"}
  53. # -----------------------------------------------------------------------------
  54. # Array where the remaining args will be stored.
  55. declare -a rest
  56. help_message=" bash $0 [--win32] [--win64] [--linux32] [--linux64] [--arm32] [--arm64] [--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]"
  57. host_options "${help_message}" "$@"
  58. # Intentionally moved after option parsing.
  59. echo
  60. echo "Host helper functions source script: \"${host_functions_script_path}\"."
  61. echo "Common functions source script: \"${common_functions_script_path}\"."
  62. echo "Definitions source script: \"${defines_script_path}\"."
  63. host_common
  64. # -----------------------------------------------------------------------------
  65. if [ -n "${DO_BUILD_WIN32}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX64}" ]
  66. then
  67. host_prepare_docker
  68. fi
  69. # ----- Build the native distribution. ----------------------------------------
  70. if [ -z "${DO_BUILD_OSX}${DO_BUILD_LINUX64}${DO_BUILD_LINUX_ARM64}${DO_BUILD_WIN64}${DO_BUILD_LINUX32}${DO_BUILD_LINUX_ARM32}${DO_BUILD_WIN32}" ]
  71. then
  72. host_build_target "Creating the native distribution..." \
  73. --script "${HOST_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  74. --env-file "${ENV_FILE}" \
  75. -- \
  76. ${rest[@]-}
  77. else
  78. # ----- Build the OS X distribution. ----------------------------------------
  79. if [ "${DO_BUILD_OSX}" == "y" ]
  80. then
  81. if [ "${HOST_UNAME}" == "Darwin" ]
  82. then
  83. host_build_target "Creating the OS X distribution..." \
  84. --script "${HOST_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  85. --env-file "${ENV_FILE}" \
  86. --target-platform "darwin" \
  87. -- \
  88. ${rest[@]-}
  89. else
  90. echo "Building the macOS image is not possible on this platform."
  91. exit 1
  92. fi
  93. fi
  94. # ----- Build the GNU/Linux 64-bit distribution. ---------------------------
  95. if [ "${DO_BUILD_LINUX64}" == "y" ]
  96. then
  97. host_build_target "Creating the GNU/Linux 64-bit distribution..." \
  98. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  99. --env-file "${ENV_FILE}" \
  100. --target-platform "linux" \
  101. --target-arch "x64" \
  102. --target-bits 64 \
  103. --docker-image "${docker_linux64_image}" \
  104. -- \
  105. ${rest[@]-}
  106. fi
  107. # ----- Build the Windows 64-bit distribution. -----------------------------
  108. if [ "${DO_BUILD_WIN64}" == "y" ]
  109. then
  110. linux_install_relative_path="linux-x64/install/${APP_LC_NAME}"
  111. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  112. then
  113. host_build_target "Creating the GNU/Linux 64-bit distribution..." \
  114. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  115. --env-file "${ENV_FILE}" \
  116. --target-platform "linux" \
  117. --target-arch "x64" \
  118. --target-bits 64 \
  119. --docker-image "${docker_linux64_image}" \
  120. -- \
  121. ${rest[@]-}
  122. fi
  123. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  124. then
  125. echo "Mandatory GNU/Linux binaries missing."
  126. exit 1
  127. fi
  128. host_build_target "Creating the Windows 64-bit distribution..." \
  129. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  130. --env-file "${ENV_FILE}" \
  131. --target-platform "win32" \
  132. --target-arch "x64" \
  133. --target-bits 64 \
  134. --docker-image "${docker_linux64_image}" \
  135. -- \
  136. --linux-install-path "${linux_install_relative_path}" \
  137. ${rest[@]-}
  138. fi
  139. # ----- Build the GNU/Linux 32-bit distribution. ---------------------------
  140. if [ "${DO_BUILD_LINUX32}" == "y" ]
  141. then
  142. host_build_target "Creating the GNU/Linux 32-bit distribution..." \
  143. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  144. --env-file "${ENV_FILE}" \
  145. --target-platform "linux" \
  146. --target-arch "x32" \
  147. --target-bits 32 \
  148. --docker-image "${docker_linux32_image}" \
  149. -- \
  150. ${rest[@]-}
  151. fi
  152. # ----- Build the Windows 32-bit distribution. -----------------------------
  153. # Since the actual container is a 32-bit, use the debian32 binaries.
  154. if [ "${DO_BUILD_WIN32}" == "y" ]
  155. then
  156. linux_install_relative_path="linux-x32/install/${APP_LC_NAME}"
  157. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  158. then
  159. host_build_target "Creating the GNU/Linux 32-bit distribution..." \
  160. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  161. --env-file "${ENV_FILE}" \
  162. --target-platform "linux" \
  163. --target-arch "x32" \
  164. --target-bits 32 \
  165. --docker-image "${docker_linux32_image}" \
  166. -- \
  167. ${rest[@]-}
  168. fi
  169. if [ ! -f "${HOST_WORK_FOLDER_PATH}/${linux_install_relative_path}/bin/${GCC_TARGET}-gcc" ]
  170. then
  171. echo "Mandatory GNU/Linux binaries missing."
  172. exit 1
  173. fi
  174. host_build_target "Creating the Windows 32-bit distribution..." \
  175. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  176. --env-file "${ENV_FILE}" \
  177. --target-platform "win32" \
  178. --target-arch "x32" \
  179. --target-bits 32 \
  180. --docker-image "${docker_linux32_image}" \
  181. -- \
  182. --linux-install-path "${linux_install_relative_path}" \
  183. ${rest[@]-}
  184. fi
  185. # ----- Build the GNU/Linux Arm 64-bit distribution. ---------------------------
  186. if [ "${DO_BUILD_LINUX_ARM64}" == "y" ]
  187. then
  188. host_build_target "Creating the GNU/Linux Arm 64-bit distribution..." \
  189. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  190. --env-file "${ENV_FILE}" \
  191. --target-platform "linux" \
  192. --target-arch "arm64" \
  193. --target-bits 64 \
  194. --docker-image "${docker_linux_arm64_image}" \
  195. -- \
  196. ${rest[@]-}
  197. fi
  198. # ----- Build the GNU/Linux Arm 32-bit distribution. ---------------------------
  199. if [ "${DO_BUILD_LINUX_ARM32}" == "y" ]
  200. then
  201. host_build_target "Creating the GNU/Linux Arm 32-bit distribution..." \
  202. --script "${CONTAINER_WORK_FOLDER_PATH}/${CONTAINER_BUILD_SCRIPT_REL_PATH}" \
  203. --env-file "${ENV_FILE}" \
  204. --target-platform "linux" \
  205. --target-arch "arm" \
  206. --target-bits 32 \
  207. --docker-image "${docker_linux_arm32_image}" \
  208. -- \
  209. ${rest[@]-}
  210. fi
  211. fi
  212. host_show_sha
  213. # -----------------------------------------------------------------------------
  214. host_stop_timer
  215. host_notify_completed
  216. # Completed successfully.
  217. exit 0
  218. # -----------------------------------------------------------------------------