| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- #!/bin/bash
- # build_config.sh - Build and install configuration for USM and dependencies
- # Build order - dependencies must be built in this order
- BUILD_ORDER=("invercargill" "invercargill-json" "usm")
- # Component definitions
- declare -A COMPONENTS=(
- ["invercargill"]="Invercargill|invercargill-1|https://fabrica.unitatem.net/Tilo15/Invercargill.git"
- ["invercargill-json"]="Invercargill-Json|invercargill-json|https://git.sr.ht/~tilo15/Invercargill-Json"
- ["usm"]="USM|usm|BUNDLED"
- )
- # Component properties accessor functions
- get_component_name() {
- local key="$1"
- echo "${COMPONENTS[$key]}" | cut -d'|' -f1
- }
- get_component_vapi() {
- local key="$1"
- echo "${COMPONENTS[$key]}" | cut -d'|' -f2
- }
- get_component_source() {
- local key="$1"
- echo "${COMPONENTS[$key]}" | cut -d'|' -f3
- }
- # Get output redirection based on VERBOSE flag
- get_output_redirect() {
- if [[ "$VERBOSE" == "true" ]]; then
- echo "/dev/stdout"
- else
- echo "/dev/null"
- fi
- }
- # Build function for Invercargill
- build_invercargill() {
- local src_dir="$1"
- local prefix="$2"
- local output_redirect=$(get_output_redirect)
-
- pushd "$src_dir" >/dev/null || return 1
-
- # Configure with meson (force libdir=lib for consistency across platforms)
- if ! meson setup src builddir --prefix="$prefix" --libdir=lib -Ddefault_library=static >"$output_redirect" 2>&1; then
- log_error "Failed to configure Invercargill"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- # Build with ninja
- if ! ninja -C builddir >"$output_redirect" 2>&1; then
- log_error "Failed to build Invercargill"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- # Install
- if ! ninja -C builddir install >"$output_redirect" 2>&1; then
- log_error "Failed to install Invercargill"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- popd >/dev/null
- log_info "Invercargill built and installed successfully"
- return 0
- }
- # Build function for Invercargill-Json
- build_invercargill_json() {
- local src_dir="$1"
- local prefix="$2"
- local output_redirect=$(get_output_redirect)
-
- pushd "$src_dir" >/dev/null || return 1
-
- # Set PKG_CONFIG_PATH to find bundled Invercargill library
- export PKG_CONFIG_PATH="$prefix/lib/pkgconfig:$prefix/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
-
- # Set XDG_DATA_DIRS for GObject Introspection and Vala to find .gir and .vapi files
- # Include default system paths to ensure system vapi files are found
- export XDG_DATA_DIRS="$prefix/share${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}:/usr/local/share:/usr/share"
-
- # Configure with meson (force libdir=lib for consistency across platforms)
- if ! meson setup src builddir --prefix="$prefix" --libdir=lib -Ddefault_library=static >"$output_redirect" 2>&1; then
- log_error "Failed to configure Invercargill-Json"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- # Build with ninja
- if ! ninja -C builddir >"$output_redirect" 2>&1; then
- log_error "Failed to build Invercargill-Json"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- # Install
- if ! ninja -C builddir install >"$output_redirect" 2>&1; then
- log_error "Failed to install Invercargill-Json"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- popd >/dev/null
- log_info "Invercargill-Json built and installed successfully"
- return 0
- }
- # Build function for USM
- build_usm() {
- local src_dir="$1"
- local prefix="$2"
- local output_redirect=$(get_output_redirect)
-
- pushd "$src_dir" >/dev/null || return 1
-
- # Set PKG_CONFIG_PATH to find bundled Invercargill libraries
- export PKG_CONFIG_PATH="$prefix/lib/pkgconfig:$prefix/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
-
- # Set XDG_DATA_DIRS for GObject Introspection and Vala to find .gir and .vapi files
- # Include default system paths to ensure system vapi files are found
- export XDG_DATA_DIRS="$prefix/share${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}:/usr/local/share:/usr/share"
-
- # Configure with meson (USM's meson.build is at root, force libdir=lib for consistency)
- if ! meson setup builddir --prefix="$prefix" --libdir=lib >"$output_redirect" 2>&1; then
- log_error "Failed to configure USM"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- # Build with ninja
- if ! ninja -C builddir >"$output_redirect" 2>&1; then
- log_error "Failed to build USM"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- # Install
- if ! ninja -C builddir install >"$output_redirect" 2>&1; then
- log_error "Failed to install USM"
- [[ "$VERBOSE" != "true" ]] && log_info "Run with --verbose for details"
- popd >/dev/null
- return 1
- fi
-
- popd >/dev/null
- log_info "USM built and installed successfully"
- return 0
- }
- # Generic build dispatcher
- build_component() {
- local component="$1"
- local src_dir="$2"
- local prefix="$3"
-
- case "$component" in
- "invercargill")
- build_invercargill "$src_dir" "$prefix"
- ;;
- "invercargill-json")
- build_invercargill_json "$src_dir" "$prefix"
- ;;
- "usm")
- build_usm "$src_dir" "$prefix"
- ;;
- *)
- log_error "Unknown component: $component"
- return 1
- ;;
- esac
- }
- # Install shim to /usr/bin
- install_shim() {
- local target_dir="$1"
- local shim_path="/usr/bin/usm"
- local sudo=""
-
- if ! is_root; then
- sudo=$(get_sudo)
- fi
-
- log_step "Installing shim to $shim_path..."
-
- local shim_content="#!/bin/bash
- export LD_LIBRARY_PATH=\"${target_dir}/lib\${LD_LIBRARY_PATH:+:\$LD_LIBRARY_PATH}\"
- exec \"${target_dir}/bin/usm\" \"\$@\"
- "
-
- if [[ -n "$sudo" ]]; then
- echo "$shim_content" | $sudo tee "$shim_path" >/dev/null
- $sudo chmod +x "$shim_path"
- else
- echo "$shim_content" > "$shim_path"
- chmod +x "$shim_path"
- fi
-
- log_info "Shim installed to $shim_path"
- }
- # Build all components in order
- build_all() {
- local src_base="$1"
- local prefix="$2"
- local total=${#BUILD_ORDER[@]}
- local current=0
-
- for component in "${BUILD_ORDER[@]}"; do
- ((current++))
- log_step "[$current/$total] Building $(get_component_name "$component")..."
-
- local src_dir
-
- if [[ "$(get_component_source "$component")" == "BUNDLED" ]]; then
- src_dir="$src_base/usm"
- else
- src_dir="$src_base/$(get_component_name "$component")"
- fi
-
- if ! build_component "$component" "$src_dir" "$prefix"; then
- log_error "Failed to build $(get_component_name "$component"). Installation halted."
- return 1
- fi
- done
-
- return 0
- }
|