container-build.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. # Inner script to run inside Docker containers to build the
  35. # xPack GNU RISC-V Embedded GCC distribution packages.
  36. # For native builds, it runs on the host (macOS build cases,
  37. # and development builds for GNU/Linux).
  38. # -----------------------------------------------------------------------------
  39. defines_script_path="${script_folder_path}/defs-source.sh"
  40. echo "Definitions source script: \"${defines_script_path}\"."
  41. source "${defines_script_path}"
  42. # This file is generated by the host build script.
  43. host_defines_script_path="${script_folder_path}/host-defs-source.sh"
  44. echo "Host definitions source script: \"${host_defines_script_path}\"."
  45. source "${host_defines_script_path}"
  46. common_helper_functions_script_path="${script_folder_path}/helper/common-functions-source.sh"
  47. echo "Common helper functions source script: \"${common_helper_functions_script_path}\"."
  48. source "${common_helper_functions_script_path}"
  49. common_helper_libs_functions_script_path="${script_folder_path}/helper/common-libs-functions-source.sh"
  50. echo "Common helper libs functions source script: \"${common_helper_libs_functions_script_path}\"."
  51. source "${common_helper_libs_functions_script_path}"
  52. common_functions_script_path="${script_folder_path}/common-functions-source.sh"
  53. echo "Common functions source script: \"${common_functions_script_path}\"."
  54. source "${common_functions_script_path}"
  55. container_functions_script_path="${script_folder_path}/helper/container-functions-source.sh"
  56. echo "Container helper functions source script: \"${container_functions_script_path}\"."
  57. source "${container_functions_script_path}"
  58. common_versions_script_path="${script_folder_path}/common-versions-source.sh"
  59. echo "Common versions source script: \"${common_versions_script_path}\"."
  60. source "${common_versions_script_path}"
  61. container_libs_functions_script_path="${script_folder_path}/${CONTAINER_LIBS_FUNCTIONS_SCRIPT_NAME}"
  62. echo "Container libs functions source script: \"${container_libs_functions_script_path}\"."
  63. source "${container_libs_functions_script_path}"
  64. container_app_functions_script_path="${script_folder_path}/${CONTAINER_APP_FUNCTIONS_SCRIPT_NAME}"
  65. echo "Container app functions source script: \"${container_app_functions_script_path}\"."
  66. source "${container_app_functions_script_path}"
  67. # -----------------------------------------------------------------------------
  68. if [ ! -z "#{DEBUG}" ]
  69. then
  70. echo $@
  71. fi
  72. WITH_STRIP="y"
  73. WITHOUT_MULTILIB=""
  74. WITH_PDF="y"
  75. WITH_HTML="n"
  76. WITH_TESTS="y"
  77. IS_DEVELOP=""
  78. IS_DEBUG=""
  79. LINUX_INSTALL_PATH=""
  80. USE_GITS=""
  81. if [ "$(uname)" == "Linux" ]
  82. then
  83. JOBS="$(nproc)"
  84. elif [ "$(uname)" == "Darwin" ]
  85. then
  86. JOBS="$(sysctl hw.ncpu | sed 's/hw.ncpu: //')"
  87. else
  88. JOBS="1"
  89. fi
  90. while [ $# -gt 0 ]
  91. do
  92. case "$1" in
  93. --disable-strip)
  94. WITH_STRIP="n"
  95. shift
  96. ;;
  97. --disable-tests)
  98. WITH_TESTS="n"
  99. shift
  100. ;;
  101. --without-pdf)
  102. WITH_PDF="n"
  103. shift
  104. ;;
  105. --with-pdf)
  106. WITH_PDF="y"
  107. shift
  108. ;;
  109. --without-html)
  110. WITH_HTML="n"
  111. shift
  112. ;;
  113. --with-html)
  114. WITH_HTML="y"
  115. shift
  116. ;;
  117. --jobs)
  118. JOBS=$2
  119. shift 2
  120. ;;
  121. --develop)
  122. IS_DEVELOP="y"
  123. shift
  124. ;;
  125. --debug)
  126. IS_DEBUG="y"
  127. WITH_STRIP="n"
  128. shift
  129. ;;
  130. # --- specific
  131. --linux-install-path)
  132. LINUX_INSTALL_PATH="$2"
  133. shift 2
  134. ;;
  135. --disable-multilib)
  136. WITHOUT_MULTILIB="y"
  137. shift
  138. ;;
  139. --use-gits)
  140. USE_GITS="y"
  141. shift
  142. ;;
  143. *)
  144. echo "Unknown action/option $1"
  145. exit 1
  146. ;;
  147. esac
  148. done
  149. if [ "${IS_DEBUG}" == "y" ]
  150. then
  151. WITH_STRIP="n"
  152. fi
  153. if [ "${TARGET_PLATFORM}" == "win32" ]
  154. then
  155. export WITH_TESTS="n"
  156. fi
  157. env | sort
  158. # -----------------------------------------------------------------------------
  159. start_timer
  160. detect_container
  161. prepare_xbb_env
  162. prepare_xbb_extras
  163. tests_initialize
  164. # -----------------------------------------------------------------------------
  165. echo
  166. echo "Here we go..."
  167. echo
  168. build_versions
  169. # -----------------------------------------------------------------------------
  170. copy_distro_files
  171. create_archive
  172. # Change ownership to non-root Linux user.
  173. fix_ownership
  174. # -----------------------------------------------------------------------------
  175. # Final checks.
  176. # To keep everything as pristine as possible, run tests
  177. # only after the archive is packed.
  178. prime_wine
  179. tests_run
  180. # -----------------------------------------------------------------------------
  181. stop_timer
  182. exit 0
  183. # -----------------------------------------------------------------------------