pkgname=pgweb
pkgver=0.16.2
pkgrel=11
pkgdesc='Simple web-based and cross platform PostgreSQL database explorer'
arch=('x86_64')
license=('MIT')
makedepends=('go')
url="https://gitea.balki.me/balki/$pkgname"
source=("$pkgname::git+$url#branch=anyhttp"
	bookmarks-example.toml
	pgweb.service
	pgweb.socket
	pgweb.sysusers
	pgweb.tmpfiles
)
sha256sums=('SKIP'
	'd19da3e2a7a1f4d35abf0992563792a51bf1a22074345d7a7c7de9f2209b21da'
	'38fe5b4af46ea97f00780b36a73976b325574352e6005ac524921ff3acd784bd'
	'8f2bd788a7f64ebe3d0f1b87d8da2eaee884dba96593c2f85883a5eb91a8b9e4'
	'1d5a0bf82a1c1a9f260252a3a1d09333150c78a5c830fb04ca24f331062a9767'
	'c11001ac35239b2a8be38d831ce62c67624df0ce5ed894850d129627b1eaa408')

prepare() {
	cd "$pkgname"
	mkdir -p build/
}

build() {
	cd "$pkgname"
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
	go build -o build
}

check() {
	cd "$pkgname"
	# tests depend on createdb command to be present
	# go test ./...
	true
}

package() {
	cd "$pkgname"
	install -Dm 755 build/$pkgname "${pkgdir}/usr/bin/$pkgname"
	install -Dm 644 LICENSE "${pkgdir}/usr/share/doc/pgweb/LICENSE"
	install -Dm 644 README.md "${pkgdir}/usr/share/doc/pgweb/README.md"
	install -Dm 644 "${srcdir}/pgweb.service" "${pkgdir}/usr/lib/systemd/system/pgweb.service"
	install -Dm 644 "${srcdir}/pgweb.socket" "${pkgdir}/usr/lib/systemd/system/pgweb.socket"
	install -Dm 644 "${srcdir}/bookmarks-example.toml" "${pkgdir}/usr/share/doc/pgweb/bookmarks-example.toml"
	install -Dm 644 "${srcdir}/pgweb.tmpfiles" "${pkgdir}/usr/lib/tmpfiles.d/pgweb.conf"
	install -Dm 644 "${srcdir}/pgweb.sysusers" "${pkgdir}/usr/lib/sysusers.d/pgweb.conf"
}