#!/usr/bin/env bash # Makes sure an OrbbecSDK v2 build exists for THIS platform, and prints where it # is as OB_SDK_ROOT=... / OB_SDK_BUILD=... / OB_SDK_GENERATED=... for build_server.sh. # # Never ships a prebuilt binary between Jetsons: CUDA and glibc differ by # generation, so the SDK is built from source on the machine that will run it. # The heavy artifact stays out of git. # # Order of preference: # 1. An existing build pointed to by $OB_SDK_ROOT — reused as-is. This is what # keeps a working node (the Nano already has one) untouched. # 2. A build at one of the known locations, likewise reused. # 3. A fresh clone + build. On a new JetPack this is the step to watch; if it # fails, build the SDK by hand once and re-run install.sh with OB_SDK_ROOT set. set -euo pipefail here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) eval "$("$here/detect_platform.sh")" # The official v2 source. Pinned loosely: a caller can override both to match a # tag known to build on their JetPack. SDK_REPO="${OB_SDK_REPO:-https://github.com/orbbec/OrbbecSDK_v2.git}" SDK_REF="${OB_SDK_REF:-main}" find_build() { local root="$1" [[ -f "$root/include/libobsensor/ObSensor.hpp" ]] || return 1 local b b=$(ls -d "$root"/build/linux_* 2>/dev/null | head -1) [[ -z "$b" ]] && b="$root/build" [[ -f "$b/lib/libOrbbecSDK.so" ]] || return 1 echo "$b" } emit() { local root="$1" build="$2" echo "OB_SDK_ROOT=$root" echo "OB_SDK_BUILD=$build" echo "OB_SDK_GENERATED=$root/build/src/generated" } # 1 & 2: reuse whatever is already built. for candidate in "${OB_SDK_ROOT:-}" \ "$HOME/OrbbecSDK_v2" \ "$HOME/OrbbecSDK_v2_jetson"; do [[ -z "$candidate" ]] && continue if b=$(find_build "$candidate" 2>/dev/null); then echo ">> SDK deja bati, reutilise: $candidate" >&2 emit "$candidate" "$b" exit 0 fi done # 3: clone + build from source. root="${OB_SDK_ROOT:-$HOME/OrbbecSDK_v2}" echo ">> Aucun SDK bati — clone et compilation (JetPack ${JETPACK}, ${SOC})" >&2 echo ">> ${SDK_REPO} @ ${SDK_REF} -> ${root}" >&2 if [[ ! -d "$root/.git" ]]; then git clone --depth 1 --branch "$SDK_REF" "$SDK_REPO" "$root" >&2 fi build="$root/build/linux_$(uname -m)" mkdir -p "$build" ( cd "$build" # -DOB_BUILD_EXAMPLES=ON gives the k4a recorder sample used as recorder_bin. cmake ../.. -DCMAKE_BUILD_TYPE=Release -DOB_BUILD_EXAMPLES=ON >&2 make -j"$(nproc)" >&2 ) if ! b=$(find_build "$root" 2>/dev/null); then cat >&2 < ./install.sh EOF exit 1 fi echo ">> SDK bati: $b" >&2 emit "$root" "$b"