pkgname="sqlite"
pkgver=3.50.4
_srcver=$(echo "$pkgver" | awk -F. '{ printf "%d%02d%02d00", $1, $2, $3 }')
_docver=${_srcver}
#_docver=3440000
pkgdesc="A C library that implements an SQL database engine"
arch=('x86_64')
license=('LicenseRef-Sqlite')
homepage="https://www.sqlite.org/"
sources=("sqlite-autoconf-${_srcver}.tar.gz"
  "sqlite-doc-${_docver}.zip"
)
urls=("https://sqlite.org/2025/${sources[0]}"
  "https://sqlite.org/2025/${sources[1]}"
)
md5sums=("d74bbdca4ab1b2bd46d3b3f8dbb0f3db"
  "faa12e794bcc37ba275fd6268317eb87"
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  unzip -q ${distdir}/${sources[1]}
}

src_build() {
  export CFLAGS="${CFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  export CXXFLAGS="${CXXFLAGS/_FORTIFY_SOURCE=3/_FORTIFY_SOURCE=2}"
  export CPPFLAGS="${CPPFLAGS} \
                   -D SQLITE_ENABLE_COLUMN_METADATA=1 \
                   -D SQLITE_ENABLE_UNLOCK_NOTIFY=1   \
                   -D SQLITE_ENABLE_DBSTAT_VTAB=1     \
                   -D SQLITE_SECURE_DELETE=1" 
  ./configure --prefix=/usr     \
              --disable-static  \
              --enable-fts{4,5} \
              CPPFLAGS="-D SQLITE_ENABLE_COLUMN_METADATA=1 \
                        -D SQLITE_ENABLE_UNLOCK_NOTIFY=1   \
                        -D SQLITE_ENABLE_DBSTAT_VTAB=1     \
                        -D SQLITE_SECURE_DELETE=1"         &&
  make
}

src_check() {
  :
}

src_install() {
  make DESTDIR="${pkgdir}" install
  install -v -m755 -d ${pkgdir}/usr/share/doc/sqlite-${pkgver} &&
  cp -v -R sqlite-doc-${_docver}/* ${pkgdir}/usr/share/doc/sqlite-${pkgver}
}
