build_config.sh 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #!/bin/bash
  2. # build_config.sh - Build and install configuration for USM and dependencies
  3. # Build order - dependencies must be built in this order
  4. BUILD_ORDER=("invercargill" "invercargill-json" "usm")
  5. # Component definitions
  6. declare -A COMPONENTS=(
  7. ["invercargill"]="Invercargill|invercargill-1|https://fabrica.unitatem.net/Tilo15/Invercargill.git"
  8. ["invercargill-json"]="Invercargill-Json|invercargill-json|https://git.sr.ht/~tilo15/Invercargill-Json"
  9. ["usm"]="USM|usm|BUNDLED"
  10. )
  11. # Component properties accessor functions
  12. get_component_name() {
  13. local key="$1"
  14. echo "${COMPONENTS[$key]}" | cut -d'|' -f1
  15. }
  16. get_component_vapi() {
  17. local key="$1"
  18. echo "${COMPONENTS[$key]}" | cut -d'|' -f2
  19. }
  20. get_component_source() {
  21. local key="$1"
  22. echo "${COMPONENTS[$key]}" | cut -d'|' -f3
  23. }
  24. # Get output redirection based on VERBOSE flag
  25. get_output_redirect() {
  26. if [[ "$VERBOSE" == "true" ]]; then
  27. echo "/dev/stdout"
  28. else
  29. echo "/dev/null"
  30. fi
  31. }
  32. # Build function for Invercargill
  33. build_invercargill() {
  34. local src_dir="$1"
  35. local prefix="$2"
  36. local output_redirect=$(get_output_redirect)
  37. log_step "Building Invercargill..."
  38. pushd "$src_dir" >/dev/null || return 1
  39. # Configure with meson
  40. if ! meson setup src builddir --prefix="$prefix" -Ddefault_library=static >"$output_redirect" 2>&1; then
  41. log_error "Failed to configure Invercargill"
  42. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  43. popd >/dev/null
  44. return 1
  45. fi
  46. # Build with ninja
  47. if ! ninja -C builddir >"$output_redirect" 2>&1; then
  48. log_error "Failed to build Invercargill"
  49. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  50. popd >/dev/null
  51. return 1
  52. fi
  53. # Install
  54. if ! ninja -C builddir install >"$output_redirect" 2>&1; then
  55. log_error "Failed to install Invercargill"
  56. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  57. popd >/dev/null
  58. return 1
  59. fi
  60. popd >/dev/null
  61. log_info "Invercargill built and installed successfully"
  62. return 0
  63. }
  64. # Build function for Invercargill-Json
  65. build_invercargill_json() {
  66. local src_dir="$1"
  67. local prefix="$2"
  68. local output_redirect=$(get_output_redirect)
  69. log_step "Building Invercargill-Json..."
  70. pushd "$src_dir" >/dev/null || return 1
  71. # Configure with meson
  72. if ! meson setup src builddir --prefix="$prefix" -Ddefault_library=static >"$output_redirect" 2>&1; then
  73. log_error "Failed to configure Invercargill-Json"
  74. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  75. popd >/dev/null
  76. return 1
  77. fi
  78. # Build with ninja
  79. if ! ninja -C builddir >"$output_redirect" 2>&1; then
  80. log_error "Failed to build Invercargill-Json"
  81. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  82. popd >/dev/null
  83. return 1
  84. fi
  85. # Install
  86. if ! ninja -C builddir install >"$output_redirect" 2>&1; then
  87. log_error "Failed to install Invercargill-Json"
  88. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  89. popd >/dev/null
  90. return 1
  91. fi
  92. popd >/dev/null
  93. log_info "Invercargill-Json built and installed successfully"
  94. return 0
  95. }
  96. # Build function for USM
  97. build_usm() {
  98. local src_dir="$1"
  99. local prefix="$2"
  100. local output_redirect=$(get_output_redirect)
  101. log_step "Building USM..."
  102. pushd "$src_dir" >/dev/null || return 1
  103. # Configure with meson
  104. if ! meson setup builddir --prefix="$prefix" >"$output_redirect" 2>&1; then
  105. log_error "Failed to configure USM"
  106. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  107. popd >/dev/null
  108. return 1
  109. fi
  110. # Build with ninja
  111. if ! ninja -C builddir >"$output_redirect" 2>&1; then
  112. log_error "Failed to build USM"
  113. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  114. popd >/dev/null
  115. return 1
  116. fi
  117. # Install
  118. if ! ninja -C builddir install >"$output_redirect" 2>&1; then
  119. log_error "Failed to install USM"
  120. [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
  121. popd >/dev/null
  122. return 1
  123. fi
  124. popd >/dev/null
  125. log_info "USM built and installed successfully"
  126. return 0
  127. }
  128. # Generic build dispatcher
  129. build_component() {
  130. local component="$1"
  131. local src_dir="$2"
  132. local prefix="$3"
  133. case "$component" in
  134. "invercargill")
  135. build_invercargill "$src_dir" "$prefix"
  136. ;;
  137. "invercargill-json")
  138. build_invercargill_json "$src_dir" "$prefix"
  139. ;;
  140. "usm")
  141. build_usm "$src_dir" "$prefix"
  142. ;;
  143. *)
  144. log_error "Unknown component: $component"
  145. return 1
  146. ;;
  147. esac
  148. }
  149. # Install shim to /usr/bin
  150. install_shim() {
  151. local target_dir="$1"
  152. local shim_path="/usr/bin/usm"
  153. local sudo=""
  154. if ! is_root; then
  155. sudo=$(get_sudo)
  156. fi
  157. log_step "Installing shim to $shim_path..."
  158. local shim_content="#!/bin/bash
  159. exec ${target_dir}/bin/usm \"\$@\"
  160. "
  161. if [[ -n "$sudo" ]]; then
  162. echo "$shim_content" | $sudo tee "$shim_path" >/dev/null
  163. $sudo chmod +x "$shim_path"
  164. else
  165. echo "$shim_content" > "$shim_path"
  166. chmod +x "$shim_path"
  167. fi
  168. log_info "Shim installed to $shim_path"
  169. }
  170. # Build all components in order
  171. build_all() {
  172. local src_base="$1"
  173. local prefix="$2"
  174. local total=${#BUILD_ORDER[@]}
  175. local current=0
  176. for component in "${BUILD_ORDER[@]}"; do
  177. ((current++))
  178. print_progress "$current" "$total" "Building $(get_component_name "$component")..."
  179. local src_dir
  180. if [[ "$(get_component_source "$component")" == "BUNDLED" ]]; then
  181. src_dir="$src_base/usm"
  182. else
  183. src_dir="$src_base/$(get_component_name "$component")"
  184. fi
  185. if ! build_component "$component" "$src_dir" "$prefix"; then
  186. log_error "Failed to build $(get_component_name "$component"). Installation halted."
  187. return 1
  188. fi
  189. done
  190. return 0
  191. }