#!/usr/bin/env bash # # Standalone, reproducible build script for "DB Browser for SQLite" (sqlitebrowser) # on macOS. Produces a fully self-contained "DB Browser for SQLite.app". # # Everything the build needs lives inside this script. On a fresh `git clone` # into which only build.sh (and launch.sh) are copied, `bash build.sh` produces # the .app. # # Project facts that shape this script: # * It is a Qt5 + CMake project (find_package(Qt5 REQUIRED ...)); the code uses # QDesktopWidget / QRegExp / QTextCodec, which are removed in Qt6, so we build # against Homebrew's keg-only `qt@5` (5.15.x) rather than the system Qt6. # * `find_package(SQLite3)` must resolve to a SQLite header that declares # sqlite3_load_extension(); the macOS SDK header omits it, so we point # SQLite3_INCLUDE_DIR/LIBRARY at Homebrew's `sqlite`. # * The bundled libs (qscintilla/qhexedit/qcustomplot) declare # cmake_minimum_required(<3.5), which CMake 4.x rejects; we pass # -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to configure them anyway. # * src/app.plist leaves @EXECUTABLE@/@ICON@ for CMake to fill, but no CMake # variables feed them, so the generated Info.plist has empty # CFBundleExecutable/CFBundleIconFile. We fix those post-build (build # artifact only -- no source edit). # * macdeployqt bundles the Qt frameworks + the required cocoa platform plugin # and rewrites linkage to @executable_path, yielding a portable .app. # set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$SCRIPT_DIR" APP_NAME="DB Browser for SQLite" BUILD_DIR="$SCRIPT_DIR/build" # --------------------------------------------------------------------------- # 0. Ensure Homebrew is on PATH (works on both Apple Silicon and Intel) # --------------------------------------------------------------------------- if ! command -v brew >/dev/null 2>&1; then for b in /opt/homebrew/bin/brew /usr/local/bin/brew; do if [ -x "$b" ]; then eval "$("$b" shellenv)"; break; fi done fi if ! command -v brew >/dev/null 2>&1; then echo "ERROR: Homebrew is required but was not found on PATH." >&2 exit 1 fi # --------------------------------------------------------------------------- # 1. Dependencies (idempotent -- brew install is a no-op if already present) # --------------------------------------------------------------------------- echo ">>> Installing/verifying build dependencies ..." for formula in cmake ninja sqlite; do brew list --versions "$formula" >/dev/null 2>&1 || brew install "$formula" done if ! brew list --versions qt@5 >/dev/null 2>&1; then # The VM image carries Homebrew's modular Qt 6 formulae. They link the same executable names # as the keg-only Qt 5 package and make `brew install qt@5` abort before the build starts. for formula in $(brew list --formula | grep -E '^qt(base|3d|charts|connectivity|datavis3d|declarative|multimedia|networkauth|positioning|quick3d|remoteobjects|scxml|sensors|serialport|speech|svg|tools|webchannel|websockets)$' || true); do brew unlink "$formula" >/dev/null 2>&1 || true done brew install qt@5 fi QT5_PREFIX="$(brew --prefix qt@5)" SQLITE_PREFIX="$(brew --prefix sqlite)" if [ ! -x "$QT5_PREFIX/bin/qmake" ]; then echo "ERROR: qt@5 not found at $QT5_PREFIX" >&2 exit 1 fi echo ">>> Using Qt5 at: $QT5_PREFIX" echo ">>> Using SQLite at: $SQLITE_PREFIX" # --------------------------------------------------------------------------- # 2. Configure (CMake / Ninja, Release, native arch) # --------------------------------------------------------------------------- echo ">>> Configuring ..." rm -rf "$BUILD_DIR" mkdir -p "$BUILD_DIR" cmake -S "$SCRIPT_DIR" -B "$BUILD_DIR" -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ -DCMAKE_PREFIX_PATH="$QT5_PREFIX" \ -DSQLite3_INCLUDE_DIR="$SQLITE_PREFIX/include" \ -DSQLite3_LIBRARY="$SQLITE_PREFIX/lib/libsqlite3.dylib" # --------------------------------------------------------------------------- # 3. Build # --------------------------------------------------------------------------- echo ">>> Building ..." cmake --build "$BUILD_DIR" -j "$(sysctl -n hw.ncpu)" APP="$BUILD_DIR/$APP_NAME.app" if [ ! -d "$APP" ]; then echo "ERROR: expected app bundle not produced: $APP" >&2 exit 1 fi # --------------------------------------------------------------------------- # 4. Fix bundle metadata that CMake left blank (build artifact, not source) # - CFBundleExecutable was configured from @EXECUTABLE@ -> empty # - CFBundleIconFile was configured from @ICON@ -> empty # --------------------------------------------------------------------------- echo ">>> Fixing Info.plist and bundling icon ..." PLIST="$APP/Contents/Info.plist" /usr/libexec/PlistBuddy -c "Set :CFBundleExecutable $APP_NAME" "$PLIST" 2>/dev/null \ || /usr/libexec/PlistBuddy -c "Add :CFBundleExecutable string $APP_NAME" "$PLIST" mkdir -p "$APP/Contents/Resources" if [ -f "$SCRIPT_DIR/src/macapp.icns" ]; then cp -f "$SCRIPT_DIR/src/macapp.icns" "$APP/Contents/Resources/macapp.icns" /usr/libexec/PlistBuddy -c "Set :CFBundleIconFile macapp.icns" "$PLIST" 2>/dev/null \ || /usr/libexec/PlistBuddy -c "Add :CFBundleIconFile string macapp.icns" "$PLIST" fi # --------------------------------------------------------------------------- # 5. Bundle Qt frameworks + plugins -> self-contained, relocatable .app # --------------------------------------------------------------------------- echo ">>> Running macdeployqt ..." "$QT5_PREFIX/bin/macdeployqt" "$APP" -verbose=1 # --------------------------------------------------------------------------- # 6. Deliver the .app to the output directory # --------------------------------------------------------------------------- OUT_DIR="${APP_OUTPUT_DIR:-$SCRIPT_DIR}" mkdir -p "$OUT_DIR" OUT_APP="$OUT_DIR/$APP_NAME.app" # Only copy when the output location differs from where it was built. if [ "$(cd "$OUT_DIR" && pwd)" != "$BUILD_DIR" ]; then rm -rf "$OUT_APP" ditto "$APP" "$OUT_APP" fi echo "" echo ">>> BUILD SUCCEEDED" echo ">>> App bundle: $OUT_APP"