# Building the libdivecomputer component used by Scubbl

Scubbl currently distributes upstream `libdivecomputer` commit:

`fe26d46ee0e695d3ba1753b84944d6b6e0d407f2`

The upstream project is available at:

`https://github.com/libdivecomputer/libdivecomputer`

Scubbl does not currently carry source modifications inside the pinned upstream submodule. The Scubbl-owned bridge, application code, synchronization logic and UI are separate proprietary works.

## Corresponding source

The exact source archive distributed for this Scubbl integration is published in this directory as:

`libdivecomputer-source.tar.gz`

The full LGPL-2.1 license text is published beside it as `COPYING`.

Extract the source archive and use the extracted directory as `LIBDC_ROOT` in the Android instructions below, or place it at `native/libdivecomputer` for the iOS layout shown below.

## Android

Scubbl builds libdivecomputer as a standalone shared library named `libdivecomputer.so`.

The library-only CMake definition is published in this directory as:

`android/CMakeLists.txt`

It contains the exact upstream C translation units, include paths and compile definitions used by the Scubbl Android build. Scubbl's proprietary JNI bridge is compiled separately and links against the `divecomputer` shared target.

A minimal wrapper CMake project can consume the published definition without any Scubbl proprietary source:

```cmake
cmake_minimum_required(VERSION 3.22.1)
project(libdivecomputer_scubbl_rebuild LANGUAGES C)
set(LIBDC_ROOT "/absolute/path/to/extracted/libdivecomputer-source")
add_subdirectory("/absolute/path/to/published/android" libdivecomputer-build)
```

With Android NDK and CMake installed, an `arm64-v8a` example is:

```sh
cmake -S /path/to/wrapper-project -B /path/to/build \
  -DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK/build/cmake/android.toolchain.cmake" \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-23
cmake --build /path/to/build --target divecomputer
```

Repeat with the ABI required by the package you are testing. The relevant output is the shared library `libdivecomputer.so`.

## iOS

Scubbl builds libdivecomputer as a dynamic framework named `LibDiveComputer.framework` and packages device/simulator slices into `LibDiveComputer.xcframework`.

The exact Scubbl build script is published in this directory as:

`ios/build-ios-libdivecomputer-xcframework.mjs`

The script is intentionally the same file used by Scubbl's mobile build. It therefore expects the same relative directory layout. To run the published copy independently, create this temporary layout:

```text
work/
├── native/
│   ├── libdivecomputer/                  # extracted exact source archive
│   └── libdivecomputer-build/
│       └── CMakeLists.txt                 # copy of published android/CMakeLists.txt
├── scripts/
│   └── build-ios-libdivecomputer-xcframework.mjs  # copy of published iOS script
└── ios/
    └── vendor/
```

Then, on macOS with Xcode command-line tools installed:

```sh
cd /path/to/work
node scripts/build-ios-libdivecomputer-xcframework.mjs
```

The script reads the same source inventory as Android, compiles with Apple clang, links with `-dynamiclib`, sets the install name to:

`@rpath/LibDiveComputer.framework/LibDiveComputer`

and writes the final output to:

`ios/vendor/LibDiveComputer.xcframework`

Requirements:

- macOS
- Xcode command-line tools
- the exact libdivecomputer source tree at the pinned commit
- Node.js

## Integrity

`archive-metadata.json` beside these files records the SHA-256 digest and byte length of the exact source archive served by Scubbl. It can be used to verify the downloaded source archive before rebuilding it.

## License boundary

These build instructions cover the LGPL libdivecomputer component only. They do not grant a license to Scubbl-owned proprietary source code. Rights concerning libdivecomputer remain governed by LGPL-2.1.
