#!/usr/bin/env bash # Builds SQLite from its amalgamation into a prefix: /lib/libsqlite3.a, # /include/sqlite3.h and a pkg-config file, which the sqlite3 opam # package then finds. The source tarball is downloaded once into .cache/src, # checked against sqlite.org's SHA3-256, and kept by make clean-deps. # tools/sqlite.sh fetch (on the host) # tools/sqlite.sh build (with the target's C compiler) set -euo pipefail app=$(cd "$(dirname "$0")/.." && pwd) version=3540100 sha3=b6ced585c750916b1052667239a12c25a7ff34e7f06e1e6e01ecb0427657d9c4 tarball=$app/.cache/src/sqlite-autoconf-$version.tar.gz case $1 in fetch) [ -f "$tarball" ] && exit 0 mkdir -p "$(dirname "$tarball")" curl -sSfo "$tarball.part" "https://sqlite.org/2026/sqlite-autoconf-$version.tar.gz" got=$(python3 -c 'import hashlib,sys; print(hashlib.sha3_256(open(sys.argv[1],"rb").read()).hexdigest())' "$tarball.part") [ "$got" = "$sha3" ] || { echo "sqlite: SHA3-256 mismatch: $got" >&2; rm -f "$tarball.part"; exit 1; } mv "$tarball.part" "$tarball" ;; build) prefix=$2 [ -f "$prefix/lib/libsqlite3.a" ] && exit 0 rm -rf "$prefix" && mkdir -p "$prefix/build" "$prefix/lib/pkgconfig" "$prefix/include" tar xzf "$tarball" -C "$prefix/build" --strip-components=1 \ "sqlite-autoconf-$version/sqlite3.c" "sqlite-autoconf-$version/sqlite3.h" "sqlite-autoconf-$version/sqlite3ext.h" # -fPIC: the x86 build also links it into the OCaml stubs' shared library. cc -c -O2 -fPIC -DSQLITE_THREADSAFE=1 -DSQLITE_DQS=0 -DSQLITE_DEFAULT_MEMSTATUS=0 \ -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_SHARED_CACHE \ -o "$prefix/build/sqlite3.o" "$prefix/build/sqlite3.c" ar rcs "$prefix/lib/libsqlite3.a" "$prefix/build/sqlite3.o" cp "$prefix/build/sqlite3.h" "$prefix/build/sqlite3ext.h" "$prefix/include/" rm -rf "$prefix/build" cat > "$prefix/lib/pkgconfig/sqlite3.pc" <