# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Mika Havela <mika.havela@gmail.com>
# Maintainer: Mika Havela <mika.havela@gmail.com>
pkgname=motion
pkgver=4.0.1
pkgrel=0
pkgdesc="Detect if a significant part of the picture has changed (e.g. from a webcam)."
url="https://motion-project.github.io"
arch="all"
options="!check"
license="GPL-2.0"
pkgusers="motion"
pkggroups="motion"
depends="jpeg v4l-utils ffmpeg"
depends_dev=""
makedepends="$depends_dev autoconf automake bash jpeg-dev v4l-utils-dev linux-headers ffmpeg-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/Motion-Project/$pkgname/archive/release-$pkgver.tar.gz
	motion.confd
	motion.initd
	motion-dist.conf.in.patch
	pthread.patch
	strerror_r.patch
	"

builddir="$srcdir"/$pkgname-release-$pkgver

prepare() {
	default_prepare
	autoreconf -fiv
}

build() {
	cd "$builddir"
	./configure \
		--without-pgsql \
		--without-mysql \
		--without-sqlite3 \
		--prefix=/usr \
		--sysconfdir=/etc \
		--without-optimizecpu
	make
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install
	install -d -o "$pkgusers" -g "$pkggroups" "$pkgdir"/var/run/motion
	install -d -o "$pkgusers" -g "$pkggroups" "$pkgdir"/var/lib/motion    # Default config is configured to store captures here
	install -Dm644 "$srcdir"/"$pkgname".confd "$pkgdir"/etc/conf.d/"$pkgname"
	install -Dm755 "$srcdir"/"$pkgname".initd "$pkgdir"/etc/init.d/"$pkgname"
	install -Dm644 COPYING "$pkgdir"/usr/share/licenses/$pkgname/COPYING
}

sha512sums="6ccde3890e6af56f28208321987dd1b9d62a55bbe7cbc3ab5600263602e6e8f47589392c2f3a3a6cb54f927ee76aea94d0e83f26ce8e4047890c891b6c2f8976  motion-4.0.1.tar.gz
8a67b5b0360924e58ba3136a737ce73bb43201a49b2b6e2c632426561b830f6ab55cbbeaa89be7f1683aa8fd322b4f31b9f560e67a93eaceb964c9f56ceef363  motion.confd
be30f19595dba27f2d0ca8133c93e134161781935a152bd1701e581410039e37742acd11987c38e6e64f495b1fd2b0a74a8c61ae0e6e211a475fca7994172501  motion.initd
2ac312c7bdd6a487b875a0b39c69a9e61a8d0767f6834be3598242d2f607e823920ad379c5bf10afe2d90de25a1ab03b6d745f18ba952181dad5a154b761388f  motion-dist.conf.in.patch
aab20c38dc57f5ad5f4a4a96220a69589208138401b42c181ab0cb8aa8238d5441b50af40c7bc481729cc74247aa3d2923633b06957817bbaa9282c9d6a24b8d  pthread.patch
a94ea4512c1b53fce38791a7773d01021092009afdac68552aad72749f7b9a18804a78adcf00f2810753f37b40617c5f4111711338369b28d2ddd63b268a0782  strerror_r.patch"
