# Maintainer: Integral <integral@member.fsf.org>
# Contributor: George Rawlinson <grawlinson@archlinux.org>

pkgname=lemmy
pkgver=0.19.18
pkgrel=1
pkgdesc="A link aggregator for the fediverse"
arch=('x86_64' 'aarch64' 'riscv64')
url="https://join-${pkgname}.org"
license=('AGPL-3.0-or-later')
depends=(
	'gcc-libs'
	'openssl'
	'postgresql-libs'
	'imagemagick'
	'ffmpeg'
	'perl-image-exiftool'
)
makedepends=('git' 'cargo' 'protobuf')
optdepends=(
	'lemmy-ui: for the web app'
	'pict-rs: for image hosting backend'
)
backup=("etc/${pkgname}/${pkgname}.hjson")
source=(
	"git+https://github.com/LemmyNet/${pkgname}.git#tag=${pkgver}"
	"git+https://github.com/LemmyNet/${pkgname}-translations.git"
	"${pkgname}.service"
	'sysusers.conf'
	'tmpfiles.conf'
)
sha256sums=('60fdc5de19db9f37ddefc58b6df95a99ce1409d58177388e7d2c1a18e6aa4749'
            'SKIP'
            'dd0a63a4149a456dc53d613d30f0a25bbbaf7e634b0cd74c3a3a3e4d25140c21'
            '0728494d597534462d9d685b0f9c9efb1d30b0af48f884a8bca7ad9a299b3c67'
            'fd87872099956ec495b7d0e598dc66f0e7e051b7d26a22e8ac59f910ed4ebc29')

prepare() {
	cd "${pkgname}/"

	# setup submodules
	git submodule init
	git config submodule.crates/utils/translations.url "${srcdir}/${pkgname}-translations"
	git -c protocol.file.allow=always submodule update

	# download dependencies
	cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
	cd "${pkgname}/"

	# Version 0.19.12 fails to build with `--all-features`.
	CFLAGS+=" -ffat-lto-objects" cargo build --frozen --release # --all-features
}

package() {
	install -vDm644 "${pkgname}.service" -t "${pkgdir}/usr/lib/systemd/system/"
	install -vDm644 sysusers.conf "${pkgdir}/usr/lib/sysusers.d/${pkgname}.conf"
	install -vDm644 tmpfiles.conf "${pkgdir}/usr/lib/tmpfiles.d/${pkgname}.conf"

	cd "${pkgname}/"
	install -vDm644 "config/config.hjson" "${pkgdir}/etc/${pkgname}/${pkgname}.hjson"
	install -vDm755 "target/release/${pkgname}_server" -t "${pkgdir}/usr/bin/"
}
