# Copyright     : Obarun
#------------------------
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
#----------------
# Obarun PkgSrc : https://git.obarun.org/pkg/obcore/eudev
#--------------------------------------------------------------
# DESCRIPTION ]

pkgbase=eudev
pkgver=3.2.11
pkgrel=3
udevver=243
url="https://github.com/eudev-project/eudev"

pkgname=(
    'eudev'
    'libeudev'
)

track="eudev/releases/download/v$pkgver"
target="eudev-$pkgver"
source=(
    "https://github.com/eudev-project/${track}/${target}.tar.gz"
    initcpio_hooks
    initcpio_install
    udev-hwdb.hook
)

#----------------------
# BUILD CONFIGURATION ]

makedepends=(
    'gobject-introspection'
    'gperf'
    'gtk-doc'
    'intltool'
    'kmod'
)

options=(
    '!makeflags'
    '!libtool'
)

#----------------
# BUILD PREPARE ]

prepare(){
    cd $pkgbase-$pkgver

    sed -e 's/GROUP="dialout"/GROUP="uucp"/' \
        -e 's/GROUP="tape"/GROUP="storage"/' \
        -e 's/GROUP="cdrom"/GROUP="optical"/' \
        -i rules/*.rules
}

#----------------
# BUILD CONTROL ]

_flags=(
    --prefix=/usr
    --with-rootprefix=/usr
    --sysconfdir=/etc
    --libdir=/usr/lib
    --bindir=/usr/bin
    --sbindir=/usr/bin
    --enable-introspection
    --enable-kmod
    --enable-manpages
    --enable-split-usr
)

#--------
# BUILD ]

build() {
    cd $pkgbase-$pkgver

    if [ -f "Makefile" ];then
     msg2 "Cleaning up..."
     make clean
    fi

    ./configure "${_flags[@]}"
    make
}

#----------
# PACKAGE ]

package_eudev() {
    pkgdesc="The userspace dev tools (udev) forked by Gentoo"
    backup=(
        'etc/udev/udev.conf'
        'usr/lib/udev/rules.d/80-net-name-slot.rules'
    )
    depends=(
        'kbd'
        'kmod'
        'hwdata'
        'util-linux'
        'libeudev'
    )
    optdepends=(
        'upower-pm-utils: pm-utils support'
        'libgudev: GObject bindings for libudev'
    )
    conflicts=(
        'eudev-git'
        'udev'
        'eudev-libgudev'
    )
    replaces=(
        'udev'
    )
    provides=(
        "udev=$udevver"
    )

    cd $pkgbase-$pkgver

    make DESTDIR="$pkgdir" install

    ## we split this libudev
    rm -rv "$pkgdir"/usr/lib/pkgconfig
    rm -v "$pkgdir"/usr/include/libudev.h
    rm -v "$pkgdir"/usr/lib/libudev*.{so*,a}

    install -Dm644 "$srcdir"/initcpio_hooks "$pkgdir"/usr/lib/initcpio/hooks/udev
    install -Dm644 "$srcdir"/initcpio_install "$pkgdir"/usr/lib/initcpio/install/udev
    install -Dm644 "$srcdir"/udev-hwdb.hook "$pkgdir"/usr/share/libalpm/hooks/udev-hwdb.hook
}

package_libeudev() {
    pkgdesc="Eudev client libraries"
    depends=(
        'glib2'
        'glibc'
    )
    provides=(
        "libudev=$udevver"
        'libudev.so'
    )

    cd $pkgbase-$pkgver

    make -C src/libudev DESTDIR="$pkgdir" install
}

#--------------------
# ARCH LICENSE AUTH ]

arch=(x86_64)
license=(GPL)

sha512sums=('')
