# Maintainer: fbt <fbt@fleshless.org>
# Contributor: artoo <artoo@manjaro.org>
# Contributor: Alexey D. <lq07829icatm@rambler.ru>
# Contributor: Ivailo Monev <xakepa10@gmail.com>

_udev_ver=220
_src_uri='http://dev.gentoo.org/~blueness/eudev'

pkgname=( 'eudev' 'libeudev' )
pkgver=3.1.2
pkgrel=3
pkgdesc="The userspace dev tools (udev) forked by Gentoo"
arch=('i686' 'x86_64')
url="http://www.gentoo.org/proj/en/eudev/"
license=('GPL')
makedepends=('gobject-introspection' 'gperf' 'gtk-doc' 'intltool')
backup=('etc/udev/udev.conf')
options=(!makeflags !libtool)
source=("${_src_uri}/${pkgname}-${pkgver}.tar.gz"
	'initcpio_hooks'
	'initcpio_install')

build() {
	cd "${srcdir}/${pkgname}-${pkgver}"
	./configure \
		--prefix=/usr \
		--with-rootprefix=/usr \
		--sysconfdir=/etc \
		--libdir=/usr/lib \
		--sbindir=/usr/bin \
		--with-html-dir=/usr/share/doc/${pkgname}-${pkgver}/html \
		--disable-gudev \
		--enable-introspection \
		--enable-kmod \
		--enable-split-usr

	make
}

package_eudev() {
	pkgdesc="The userspace dev tools (udev) forked by Gentoo"
	provides=( "udev=${_udevver}" )
	backup=( 'etc/udev/udev.conf' )
	depends=(
		'glib2'
		'kbd'
		'kmod'
		'hwids'
		'util-linux'
	)
	optdepends=(
		'eudev-systemdcompat: makes packages compiled with systemd features run'
		'libsystemd-standalone: same as the above, but built from upstream sources'
		'upower-pm-utils: pm-utils support'
	)

	cd "${srcdir}/${pkgname}-${pkgver}"
	make DESTDIR="${pkgdir}" install

	for i in "${pkgdir}/usr/lib/udev/rules.d/"*.rules; do
		sed -i -e 's#GROUP="dialout"#GROUP="uucp"#g;
                            s#GROUP="tape"#GROUP="storage"#g;
                            s#GROUP="cdrom"#GROUP="optical"#g' "${i}"
	done

	install -Dm644 "${srcdir}/initcpio_hooks" "${pkgdir}/usr/lib/initcpio/hooks/udev"
	install -Dm644 "${srcdir}/initcpio_install" "${pkgdir}/usr/lib/initcpio/install/udev"

	# split out...
	mkdir -pm755 "${srcdir}/_libeudev"
	cd "${srcdir}/_libeudev"

	# ...libs
	mkdir -pm755 usr/lib usr/lib/pkgconfig
	mv "$pkgdir"/usr/lib/libudev*.{so,a}* usr/lib/
	mv "$pkgdir"/usr/lib/pkgconfig/libudev.pc usr/lib/pkgconfig/libudev.pc

	# ...headers
	mkdir -pm755 usr/include
	mv "$pkgdir"/usr/include/libudev.h usr/include
}

package_libeudev() {
	pkgdesc="eudev client libraries"
	depends=( 'glibc' 'glib2' )
	provides=(
		"libudev=${_udevver}"
		'libudev.so'
	)
	conflicts=(
		'libeudev>=1.8'
		'libudev.so'
	)

	mv "$srcdir/_libeudev"/* "$pkgdir"
}

sha1sums=('bb50125dbf5aaa31cac926890dfbc8c68c72aac9'
          'defa489254f38e57723a8ff70654f29e47bd448a'
          'a6a6ee5c751fb92e2c79e0a297e4c318c8f6bb75')