#!/bin/sh

set -e

cmake -Wno-dev \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCONC_WITH_UNIT_TESTS=OFF \
    -DCONNECT_WITH_BSON=OFF \
    -DCONNECT_WITH_MONGO=OFF \
    -DCONNECT_WITH_MYSQL=ON \
    -DCONNECT_WITH_LIBXML2=system \
    -DCONNECT_WITH_ODBC=NO \
    -DCONNECT_WITH_JDBC=NO \
    -DENABLED_PROFILING=OFF \
    -DPLUGIN_ARCHIVE=NO \
    -DPLUGIN_ARIA=NO \
    -DPLUGIN_BLACKHOLE=NO \
    -DPLUGIN_CASSANDRA=NO \
    -DPLUGIN_CSV=NO \
    -DPLUGIN_MYISAM=NO \
    -DPLUGIN_MROONGA=NO \
    -DPLUGIN_OQGRAPH=NO \
    -DPLUGIN_PARTITION=STATIC \
    -DPLUGIN_ROCKSDB=NO \
    -DPLUGIN_SPHINX=NO \
    -DPLUGIN_TOKUDB=NO \
    -DPLUGIN_AUTH_GSSAPI=NO \
    -DPLUGIN_AUTH_GSSAPI_CLIENT=OFF \
    -DPLUGIN_CRACKLIB_PASSWORD_CHECK=NO \
    -DWITH_ASAN=OFF \
    -DWITH_EMBEDDED_SERVER=ON \
    -DWITH_EXTRA_CHARSETS=complex \
    -DWITH_INNODB_BZIP2=OFF \
    -DWITH_INNODB_LZ4=OFF \
    -DWITH_INNODB_LZMA=OFF \
    -DWITH_INNODB_LZO=OFF \
    -DWITH_INNODB_SNAPPY=OFF \
    -DWITH_JEMALLOC=NO \
    -DWITH_LIBARCHIVE=system \
    -DWITH_LIBFMT=NO \
    -DWITH_LIBNUMA=NO \
    -DWITH_LIBWRAP=OFF \
    -DWITH_LIBWSEP=OFF \
    -DWITH_MARIABACKUP=ON \
    -DWITH_READLINE=OFF \
    -DWITH_SYSTEMD=no \
    -DWITH_UNIT_TESTS=OFF \
    -DWITH_SSL=system \
    -DWITH_VALGRIND=OFF \
    -DWITH_ZLIB=system \
    -DSKIP_TESTS=ON
patch -p1 <../lfs64.patch || true
cmake --build . --parallel "$(nproc)"
./scripts/mariadb-install-db --srcdir=.

./sql/mariadbd -u root --datadir ./data &
sleep 0.5
r=0
./extra/mariabackup/mariadb-backup --backup --target-dir /tmp/backup || r=$?
[ "${r}" -eq 139 ] && exit 1
