#!/usr/bin/env bash # Makes sure an OrbbecSDK v2 build exists for THIS platform — INCLUDING the custom # MKV recorder example — and prints where it all is: # # OB_SDK_ROOT / OB_SDK_BUILD / OB_SDK_GENERATED the SDK # RECORDER_BIN the recorder binary, or empty # # Never ships a prebuilt binary between Jetsons: CUDA and glibc differ by # generation, so everything is built from source on the machine that runs it. The # heavy artifacts stay out of git. # # The recorder is FTF's own source (recorder/ in this repo), not a stock SDK # example, so it is injected into the SDK's examples tree before the build and # compiled there — it depends on the SDK's own cmake targets (ob::examples::utils). # It needs the Orbbec K4A wrapper's headers; build_k4a_wrapper.sh provides them. # # Order of preference for the SDK itself: # 1. $OB_SDK_ROOT if it already holds a build — reused, which keeps a working # node (the Nano) untouched. # 2. A build at a known location, likewise reused. # 3. A fresh clone + build. set -euo pipefail here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) repo=$(cd "$here/.." && pwd) eval "$("$here/detect_platform.sh")" SDK_REPO="${OB_SDK_REPO:-https://github.com/orbbec/OrbbecSDK_v2.git}" # Pinned to the version the recorder source is written against: v2.4.3 (which came # pre-placed on the Orin) lacks ob::Error::getStatus() that the recorder uses. A # caller can override for a platform that needs a different tag. SDK_REF="${OB_SDK_REF:-v2.8.6}" find_build() { local root="$1" b [[ -f "$root/include/libobsensor/ObSensor.hpp" ]] || return 1 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" } recorder_bin_in() { # echoes the recorder path under a build dir if present local b="$1" [[ -x "$b/bin/ob_stream_depth_color_k4arec_pipeline" ]] \ && echo "$b/bin/ob_stream_depth_color_k4arec_pipeline" } emit() { local root="$1" build="$2" echo "OB_SDK_ROOT=$root" echo "OB_SDK_BUILD=$build" echo "OB_SDK_GENERATED=$root/build/src/generated" echo "RECORDER_BIN=$(recorder_bin_in "$build")" } # Drops the FTF recorder into the SDK examples tree and registers it, so a plain # example build picks it up. Idempotent. inject_recorder() { local root="$1" local dst="$root/examples/1.stream.depth_color.k4arec.pipeline" mkdir -p "$dst" cp "$repo/recorder/depth_color_k4arec_pipeline.cpp" "$dst/" cp "$repo/recorder/CMakeLists.txt" "$dst/" local ex_cmake="$root/examples/CMakeLists.txt" if [[ -f "$ex_cmake" ]] \ && ! grep -q "1.stream.depth_color.k4arec.pipeline" "$ex_cmake"; then echo "add_subdirectory(1.stream.depth_color.k4arec.pipeline)" >> "$ex_cmake" fi } # 1 & 2: reuse an existing SDK build. Only inject/rebuild the recorder if it is # missing there — never disturb the library build. for candidate in "${OB_SDK_ROOT:-}" \ "$HOME/OrbbecSDK_v2" \ "$HOME/OrbbecSDK_v2_jetson" \ "$HOME/Downloads/OrbbecSDK_v2" \ "$HOME/Downloads/OrbbecSDK_v2_jetson"; do [[ -z "$candidate" ]] && continue if b=$(find_build "$candidate" 2>/dev/null); then echo ">> SDK deja bati, reutilise: $candidate" >&2 if [[ -z "$(recorder_bin_in "$b")" && -n "${K4A_WRAPPER_DIR:-}" ]]; then echo ">> Recorder absent de ce build — injection et compilation…" >&2 inject_recorder "$candidate" ( cd "$b" && cmake .. -DOB_BUILD_EXAMPLES=ON \ -DK4A_WRAPPER_DIR="$K4A_WRAPPER_DIR" >&2 \ && make -j"$(nproc)" ob_stream_depth_color_k4arec_pipeline >&2 ) || true fi emit "$candidate" "$b" exit 0 fi done # 3: clone + build from source, with examples and the recorder. root="${OB_SDK_ROOT:-$HOME/OrbbecSDK_v2}" echo ">> Aucun SDK bati — clone et compilation (JetPack ${JETPACK}, ${SOC})" >&2 [[ -d "$root/.git" ]] || git clone --depth 1 --branch "$SDK_REF" "$SDK_REPO" "$root" >&2 inject_recorder "$root" # The recorder needs the wrapper; without it the SDK still builds (its CMakeLists # skips the recorder with a warning), giving preview-only. cmake_k4a=() [[ -n "${K4A_WRAPPER_DIR:-}" ]] && cmake_k4a=(-DK4A_WRAPPER_DIR="$K4A_WRAPPER_DIR") # Build in $root/build and configure from there (cmake ..): the SDK's own # linux_config.cmake places its outputs in a build/linux_ subdir itself. # Creating that subdir and configuring from inside it double-nests the outputs # (build/linux_aarch64/linux_arm64/lib), where find_build cannot see them. mkdir -p "$root/build" ( cd "$root/build" cmake .. -DCMAKE_BUILD_TYPE=Release -DOB_BUILD_EXAMPLES=ON "${cmake_k4a[@]}" >&2 make -j"$(nproc)" >&2 ) if ! b=$(find_build "$root" 2>/dev/null); then cat >&2 <> SDK bati: $b" >&2 [[ -z "$(recorder_bin_in "$b")" ]] && \ echo ">> NOTE: recorder non produit (wrapper K4A absent) — preview seule." >&2 emit "$root" "$b"