%define build_compat32  %{?_with_compat32:1}%{!?_with_compat32:0}

%define debug false
%define udev_scriptdir /lib/udev
%define firmwaredir /lib/firmware

Summary: A userspace implementation of devfs
Summary(ja): ユーザスペース実装のデバイスファイルシステム
Name: eudev
Version: 3.2.10
Release: 1%{?_dist_release}
License: GPL
Group: system
Vendor: Project Vine
Distribution: Vine Linux
Packager: daisuke

URL: https://github.com/gentoo/eudev
Source: https://dev.gentoo.org/~blueness/%{name}/%{name}-%{version}.tar.gz
Source1: start_udev
Source3: udev-post.init
Source4: fw_unit_symlinks.sh
Source5: udev.sysconfig

# vine patch
Patch1002: eudev-3.0-blkid.patch
Patch1003: eudev-3.1.1-rules-vine.patch

ExclusiveOS: Linux

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildRequires: sed, flex
BuildRequires: pam-devel, glib2-devel, bison
BuildRequires: findutils
BuildRequires: hwdata
BuildRequires: gobject-introspection-devel >= 1.31.1
BuildRequires: gtk-doc
BuildRequires: usbutils >= 0.82
BuildRequires: gperf
BuildRequires: libacl-devel
BuildRequires: libusb-devel
BuildRequires: kmod-devel
BuildRequires: libblkid-devel >= 2.20

Requires(pre): /bin/sh fileutils
Requires(pre): MAKEDEV >= 3.21
Requires: %{name}-libudev = %{version}-%{release}
Requires: MAKEDEV >= 3.21
Requires: util-linux-ng >= 2.16

Obsoletes: udev < 220
Provides: udev = 220

Obsoletes: dev < 3.22
Conflicts: dev < 3.22
Provides: dev = 3.22

Obsoletes: murasaki, usbmgr, hotplug, hal, hal-info

Requires: pam

%description
The udev package contains an implementation of devfs in 
userspace using sysfs and netlink.


%package libudev
Summary: Dynamic library to access udev device information
Summary(ja): Udev デバイス情報にアクセスするための動的ライブラリ
Group: system

%description libudev
This package contains the dynamic library libudev, which provides access
to udev device information, and an interface to search devices in sysfs.


%package libudev-devel
Summary: Development files for libudev
Summary(ja): Libudev の開発用ファイル
Group: programming
Requires: %{name} = %{version}-%{release}
Requires: %{name}-libudev = %{version}-%{release}
Obsoletes: libudev-devel < 213
Provides: libudev-devel = 213

%description libudev-devel
This package contains the development files for the library libudev, a
dynamic library, which provides access to udev device information.


%package libudev-static
Summary: Static libraries for libudev
Summary(ja): Libudev の静的ライブラリ
Group: programming
Requires: %{name}-libudev-devel = %{version}-%{release}
Obsoletes: libudev-static < 213
Provides: libudev-static = 213

%description libudev-static
This package contains the static library libudev, which provides 
access to udev device information.


# compat32
%package -n compat32-%{name}-libudev
Summary: Dynamic library to access udev device information
Summary(ja): Udev デバイス情報にアクセスするための動的ライブラリ
Group: system
Requires: %{name}-libudev = %{version}-%{release}

%description -n compat32-%{name}-libudev
This package contains the dynamic library libudev, which provides access
to udev device information, and an interface to search devices in sysfs.


%package -n compat32-%{name}-libudev-devel
Summary: Development files for libudev
Summary(ja): Libudev の開発用ファイル
Group: programming
Requires: compat32-%{name}-libudev = %{version}-%{release}
Obsoletes: compat32-libudev-devel < 213
Provides: compat32-libudev-devel = 213

%description -n compat32-%{name}-libudev-devel
This package contains the development files for the library libudev, a
dynamic library, which provides access to udev device information.


%debug_package


%prep
%setup -q  
%patch1002 -p1 -b .vine
%patch1003 -p1 -b .vine


%build
autoreconf -if
%configure \
  --disable-selinux \
  --prefix=%{_prefix} \
  --with-rootprefix= \
  --sysconfdir=%{_sysconfdir} \
  --exec-prefix="" \
  --bindir="/sbin" \
  --sbindir="/sbin" \
  --libexecdir=/lib \
  --with-rootlibdir=/%{_lib} \
  --with-rootlibexecdir=/lib/udev \
  --enable-introspection \
  --enable-manpages \
  --enable-static

make %{?_smp_mflags}


%install
rm -rf $RPM_BUILD_ROOT

mkdir -p $RPM_BUILD_ROOT%{_sbindir}

make DESTDIR=$RPM_BUILD_ROOT install

rm -fr $RPM_BUILD_ROOT%{_docdir}/udev
rm -f $RPM_BUILD_ROOT/%{_libdir}/*.la

rm -f $RPM_BUILD_ROOT%{_sysconfdir}/udev/udev.rules
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/init.d/udev
rm -f $RPM_BUILD_ROOT%{_sysconfdir}/hotplug.d/default/10-udev.hotplug

mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/udev/{rules.d,makedev.d,scripts,devices}
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/dev.d
mkdir -p $RPM_BUILD_ROOT%{_bindir}
touch $RPM_BUILD_ROOT%{_sysconfdir}/scsi_id.config

# force relative symlinks
ln -sf ..%{udev_scriptdir}/scsi_id $RPM_BUILD_ROOT/sbin/scsi_id

ln -sf ../../sbin/udevadm $RPM_BUILD_ROOT%{_bindir}/udevinfo
ln -sf ../../sbin/udevadm $RPM_BUILD_ROOT%{_bindir}/udevtest
ln -sf ../../sbin/udevadm $RPM_BUILD_ROOT%{_sbindir}/udevmonitor

ln -sf udevadm $RPM_BUILD_ROOT/sbin/udevtrigger
ln -sf udevadm $RPM_BUILD_ROOT/sbin/udevsettle
ln -sf udevadm $RPM_BUILD_ROOT/sbin/udevcontrol

mkdir -p $RPM_BUILD_ROOT%{udev_scriptdir}/{,devices}

for i in \
%ifarch ppc ppc64
        rules/arch/40-ppc.rules \
%endif
	; do
	install -m 0644 "$i"  "$RPM_BUILD_ROOT%{udev_scriptdir}/rules.d/${i##*/}"
done

mkdir -p $RPM_BUILD_ROOT%{udev_scriptdir}/{,devices}

install -m 0755 %{SOURCE4} $RPM_BUILD_ROOT%{udev_scriptdir}/fw_unit_symlinks.sh

mkdir -p $RPM_BUILD_ROOT%{_datadir}/udev
install -m 0755 %{SOURCE1} $RPM_BUILD_ROOT/sbin/start_udev

mkdir -p -m 0755 $RPM_BUILD_ROOT%{firmwaredir}

mkdir -p -m 0755 $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d
cat > $RPM_BUILD_ROOT%{_sysconfdir}/modprobe.d/floppy-pnp.conf <<EOF
alias pnp:dPNP0700 floppy
alias acpi:PNP0700: floppy
EOF

mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d
install -m 0755 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/udev-post

mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
install -m 0755 %{SOURCE5} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/udev

mkdir -p $RPM_BUILD_ROOT/var/lib/udev/makedev.d


%clean
rm -rf $RPM_BUILD_ROOT


%pre
getent group video >/dev/null || /usr/sbin/groupadd -g 39 video || :
getent group audio >/dev/null || /usr/sbin/groupadd -g 63 audio || :
getent group cdrom >/dev/null || /usr/sbin/groupadd -g 11 cdrom || :
getent group tape >/dev/null || /usr/sbin/groupadd -g 33 tape || :
getent group dialout >/dev/null || /usr/sbin/groupadd -g 18 dialout || :

%preun
if [ $1 = 0 -a -f %{_initrddir}/udev ]; then
	if [ -x /sbin/pidof ]; then
		pid=$(/sbin/pidof udevd)
		if [ -n "$pid" ]; then
			kill $pid
		fi
	fi
	/sbin/chkconfig --del udev
fi
if [ "$1" = 0 ]; then
	/sbin/chkconfig --del udev-post
fi
exit 0

%post
if [ "$1" -ge "1" -a -x /sbin/pidof ]; then
	pid=$(/sbin/pidof udevd)
	if [ -n "$pid" ]; then
		kill $pid
		/sbin/udevd -d
	fi
fi
exit 0

%posttrans
udevadm hwdb --update > /dev/null 2>&1 || :
/sbin/chkconfig --add udev-post

%triggerpostun -- dev <= 0:3.21-1vl1
if [ $2 = 0 ]; then
    if [ -x /sbin/MAKEDEV ]; then 
	/sbin/MAKEDEV null
	/sbin/MAKEDEV console
    else
	/bin/mknod /dev/null c 1 3
	/bin/mknod /dev/console c 5 1
    fi
    if [ "$(/sbin/kernelversion)" == "2.6" ] &&
       [ $(($(uname -r |cut -f1 -d-|cut -f3 -d.))) -gt 15 ]
    then
	/sbin/start_udev >/dev/null 2>&1
	if [ -e /dev/mapper/control -a -x /sbin/lvm ]; then
		/sbin/lvm vgmknodes >/dev/null 2>&1
	fi
    fi
fi
exit 0

%ldconfig_scriptlets libudev

%if %{build_compat32}
%ldconfig_scriptlets  -n compat32-%{name}-libudev
%endif


%files
%defattr(-,root,root)
%license COPYING
%doc README
%attr(0755,root,root) /sbin/udevadm
%attr(0755,root,root) /sbin/udevd
%attr(0755,root,root) /sbin/start_udev
/sbin/udevcontrol
/sbin/udevtrigger
/sbin/udevsettle
/sbin/scsi_id
%attr(0755,root,root) %{udev_scriptdir}/ata_id
%attr(0755,root,root) %{udev_scriptdir}/cdrom_id
%attr(0755,root,root) %{udev_scriptdir}/fw_unit_symlinks.sh
%attr(0755,root,root) %{udev_scriptdir}/collect
%attr(0755,root,root) %{udev_scriptdir}/mtd_probe

%attr(0755,root,root) %{_sysconfdir}/rc.d/init.d/udev-post
%{_bindir}/udevtest
%{_bindir}/udevinfo
%{_sbindir}/udevmonitor
%attr(0755,root,root) %dir %{_sysconfdir}/udev/
%attr(0755,root,root) %dir %{_sysconfdir}/udev/rules.d/
%attr(0755,root,root) %dir %{udev_scriptdir}/
%attr(0755,root,root) %dir %{udev_scriptdir}/rules.d/
%attr(0755,root,root) %dir %{udev_scriptdir}/devices/
%attr(0755,root,root) %dir %{_sysconfdir}/udev/makedev.d/

%dir %{_sysconfdir}/udev/hwdb.d
%{_sysconfdir}/udev/hwdb.d/20-OUI.hwdb
%{_sysconfdir}/udev/hwdb.d/20-acpi-vendor.hwdb
%{_sysconfdir}/udev/hwdb.d/20-bluetooth-vendor-product.hwdb
%{_sysconfdir}/udev/hwdb.d/20-net-ifname.hwdb
%{_sysconfdir}/udev/hwdb.d/20-pci-classes.hwdb
%{_sysconfdir}/udev/hwdb.d/20-pci-vendor-model.hwdb
%{_sysconfdir}/udev/hwdb.d/20-sdio-classes.hwdb
%{_sysconfdir}/udev/hwdb.d/20-sdio-vendor-model.hwdb
%{_sysconfdir}/udev/hwdb.d/20-usb-classes.hwdb
%{_sysconfdir}/udev/hwdb.d/20-usb-vendor-model.hwdb
%{_sysconfdir}/udev/hwdb.d/20-vmbus-class.hwdb
%{_sysconfdir}/udev/hwdb.d/60-evdev.hwdb
%{_sysconfdir}/udev/hwdb.d/60-keyboard.hwdb
%{_sysconfdir}/udev/hwdb.d/60-sensor.hwdb
%{_sysconfdir}/udev/hwdb.d/70-mouse.hwdb
%{_sysconfdir}/udev/hwdb.d/70-pointingstick.hwdb
%{_sysconfdir}/udev/hwdb.d/70-touchpad.hwdb

%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/sysconfig/udev

%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/udev/udev.conf
%attr(0644,root,root) %{udev_scriptdir}/rules.d/*.rules

%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/scsi_id.config

%config %attr(0644,root,root) %{_sysconfdir}/modprobe.d/floppy-pnp.conf

%dir %attr(0755,root,root) %{firmwaredir}
%{_mandir}/man8/udev*.8*
%{_mandir}/man7/udev*.7*
%{_mandir}/man5/udev*.5*

%dir %attr(0755,root,root) /var/lib/udev
%dir %attr(0755,root,root) /var/lib/udev/makedev.d

# Deprecated, but keep the ownership
%ghost %dir %{_sysconfdir}/udev/scripts/
%ghost %dir %{_sysconfdir}/udev/devices/
%ghost %dir %{_sysconfdir}/dev.d/

%attr(0755,root,root) %{udev_scriptdir}/scsi_id
%attr(0755,root,root) %{udev_scriptdir}/v4l_id

%files libudev
%defattr(-,root,root,-)
/%{_lib}/libudev.so.*

%files libudev-devel
%defattr(-,root,root,-)
%license COPYING
%{_includedir}/libudev.h
%{_includedir}/udev.h
%{_libdir}/libudev.so
%{_libdir}/pkgconfig/libudev.pc
%{_datadir}/pkgconfig/udev.pc

%files libudev-static
%defattr(-,root,root,-)
%{_libdir}/libudev.a

%if %{build_compat32}
%files -n compat32-%{name}-libudev
%defattr(-,root,root,-)
/%{_lib}/libudev.so.*

%files -n compat32-%{name}-libudev-devel
%defattr(-,root,root,-)
%{_libdir}/libudev.so
%endif


%changelog
* Thu Feb 25 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.2.10-1
- new upstream release.

* Wed Sep 18 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.2.8-1
- new upstream release.

* Sun Jun 19 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.2-1
- new upstream release
- remove Patch0 (eudev-3.1.5-git20160322.patch)

* Sun Apr 24 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.5-1
- new upstream release
- add Patch0 (eudev-3.1.5-git20160322.patch)
- remove Patch1001 (eudev-1.7-gudev-vine.patch)
- remove libgudev1,libgudev1-devel subpackages

* Thu Nov 12 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.2-2
- fix spec file

* Sun Jun 28 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.2-1
- new upstream release

* Wed Jun 10 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.1-1
- new upstream release
- update Patch1003 (eudev-3.1.1-rules-vine.patch)

* Sun May 24 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0-2
- add Patch1003 (eudev-3.0-rules-vine.patch)

* Sun May 24 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0-1
- new upstream release
- add Patch1002 (eudev-3.0-blkid.patch)

* Sun Feb 01 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.1.1-2
- fix SOURCE1 (remove udevadm trigger --type=failed)

* Tue Nov 04 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.1.1-1
- new upstream release

* Tue Oct 14 2014 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 1.10-2
- added Japanese summary
- added %%post and %%postun section to library subpackages
- changed Group of libgudev1, compat32-eudev-libudev and compat32-eudev-libgudev1

* Sun Aug 31 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.10-1
- new upstream release

* Fri Jun 27 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.8-1
- new upstream release

* Wed Jun 25 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.7-1
- initial build for Vine Linux based on udev package

