sql-de-lite hackery added by Bunny351 on Sun Jan 12 21:40:01 2020

#!/bin/sh

set -e

# terrible workaround for passing the correct options to the manual
# compile of sqlite3/sqlite3.c:
static=
opts=
ignore=
for x in "$@"; do
    if [ -n "$ignore" ]; then
        ignore=
    else
        case $x in
            -static)
                static=.static
                opts="$opts $x";;
            -o)
                ignore=1;;
            sql-de-lite.scm)
                ;;
            *) opts="$opts $x";;
        esac
    fi
done

# If threadsafe=1, pthreads is required, so let's not.
sqlite3_options="-C -DSQLITE_ENABLE_FTS3 -C -DSQLITE_ENABLE_FTS3_PARENTHESIS -C -DSQLITE_THREADSAFE=0"

if /bin/sh ./use-system-sqlite3; then
    echo "SQlite3 version `./version-check` found"
    "$CHICKEN_CSC" -C "$CFLAGS" -L "$LDFLAGS -lsqlite3" "$@"
else
    echo "Using built-in SQLite3"
    if ! test -f sqlite3/sqlite3$static.o; then
        "$CHICKEN_CSC" $opts -C "$CFLAGS" -L "$LDFLAGS" \
    		   -c -Isqlite3 sqlite3/sqlite3.c $sqlite3_options \
                                      -o sqlite3/sqlite3$static.o
    fi
    "$CHICKEN_CSC" -C "$CFLAGS" -L "$LDFLAGS" "$@" \
		   -Isqlite3 sqlite3/sqlite3$static.o $sqlite3_options
fi