| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #!/bin/sh
- # SQLite binding tests and showcase.
- set -e
- trap 'rm -f /tmp/m2-sqlite-utils.db' EXIT
- cd "$(dirname "$0")"
- ROOT="$(cd ../.. && pwd)"
- M2MAKE="$ROOT/tools/m2make/b_v3/M2make"
- if [ ! -x "$M2MAKE" ]; then
- echo "missing $M2MAKE; run tools/m2make/build_m2.sh" >&2
- exit 1
- fi
- # Allow an explicit override, then use pkg-config, ldconfig or a
- # platform-specific runtime library. The .so.0 fallback matters on
- # systems with the SQLite runtime but without the development package.
- if [ -n "${SQLITE_LIBS:-}" ]; then
- :
- elif command -v pkg-config >/dev/null 2>&1 && pkg-config --exists sqlite3; then
- SQLITE_LIBS="$(pkg-config --libs sqlite3)"
- else
- SQLITE_LIBS=""
- if command -v ldconfig >/dev/null 2>&1; then
- SQLITE_LIBS="$(ldconfig -p 2>/dev/null |
- awk '/libsqlite3\.so\.0/ { print $NF; exit }')"
- fi
- if [ -z "$SQLITE_LIBS" ] && command -v cc >/dev/null 2>&1; then
- cand="$(cc -print-file-name=libsqlite3.so 2>/dev/null || true)"
- if [ -n "$cand" ] && [ "$cand" != "libsqlite3.so" ] && [ -f "$cand" ]; then
- SQLITE_LIBS="$cand"
- fi
- if [ -z "$SQLITE_LIBS" ]; then
- cand="$(cc -print-file-name=libsqlite3.dylib 2>/dev/null || true)"
- if [ -n "$cand" ] && [ "$cand" != "libsqlite3.dylib" ] && [ -f "$cand" ]; then
- SQLITE_LIBS="$cand"
- fi
- fi
- fi
- if [ -z "$SQLITE_LIBS" ]; then
- for cand in \
- /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 \
- /usr/lib/aarch64-linux-gnu/libsqlite3.so.0 \
- /usr/lib64/libsqlite3.so.0 \
- /usr/lib/libsqlite3.so.0 \
- /usr/local/lib/libsqlite3.so.0 \
- /opt/homebrew/opt/sqlite/lib/libsqlite3.dylib \
- /usr/local/opt/sqlite/lib/libsqlite3.dylib; do
- if [ -f "$cand" ]; then SQLITE_LIBS="$cand"; break; fi
- done
- fi
- if [ -z "$SQLITE_LIBS" ]; then
- SQLITE_LIBS="-lsqlite3"
- fi
- fi
- echo "SQLite library: $SQLITE_LIBS"
- build_and_run() {
- name="$1"
- src="${2:-tests/$name.mod}"
- out="${TMPDIR:-/tmp}/m2-sqlite-$name"
- "$M2MAKE" -c m2 \
- --m2bin "$ROOT/compiler/M2" \
- --shim "$ROOT/runtime/syslib/shim.c" \
- --lib "$SQLITE_LIBS" \
- -I "$ROOT/bindings/sqlite3" \
- -I "$ROOT/runtime/syslib" \
- -I "$ROOT/lib/common" \
- -o "$out" \
- "$src"
- set +e
- "$out"
- rc=$?
- set -e
- if [ "$rc" = 42 ]; then return 0; fi
- return 1
- }
- build_and_run SQLiteSmoke
- build_and_run SQLitePrepared
- build_and_run SQLiteParams
- build_and_run SQLitePrepareTail
- build_and_run SQLiteHelpers
- build_and_run SQLiteIntrospection
- build_and_run SQLiteScalar
- build_and_run SQLiteErrors
- build_and_run SQLiteBlob
- build_and_run SQLiteBlobErrors
- build_and_run SQLiteConstraints
- build_and_run SQLiteBackup
- build_and_run SQLiteCapi3c
- build_and_run SQLiteConnection
- build_and_run SQLiteCallback
- build_and_run SQLiteHooks
- build_and_run SQLiteAggregate
- build_and_run SQLiteShowcase showcase/SQLiteShowcase.mod
- build_and_run SQLiteFeatureShowcase showcase/SQLiteFeatureShowcase.mod
|