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

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

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

URL: https://github.com/eudev-project/eudev
Source: https://github.com/eudev-project/eudev/releases/download/v%{version}/%{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 .blkid
%patch1003 -p1 -b .vine


%build
autoreconf -if
%configure \
  --disable-selinux \
  --prefix=%{_prefix} \
  --sysconfdir=%{_sysconfdir} \
  --bindir="%{_sbindir}" \
  --sbindir="%{_sbindir}" \
  --libexecdir=%{_libexecdir} \
  --with-rootlibdir=%{_libdir} \
  --with-rootlibexecdir=/usr/lib/udev \
  --enable-introspection \
  --enable-manpages \
  --enable-static

make %{?_smp_mflags}


%install
rm -rf %{buildroot}

mkdir -p %{buildroot}%{_sbindir}

make DESTDIR=%{buildroot} install

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

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

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

# force relative symlinks
ln -sf ../lib/udev/scsi_id %{buildroot}%{_sbindir}/scsi_id

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

ln -sf udevadm %{buildroot}%{_sbindir}/udevtrigger
ln -sf udevadm %{buildroot}%{_sbindir}/udevsettle
ln -sf udevadm %{buildroot}%{_sbindir}/udevcontrol

mkdir -p %{buildroot}%{udev_scriptdir}/{,devices}

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

mkdir -p %{buildroot}%{udev_scriptdir}/{,devices}

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

mkdir -p %{buildroot}%{_datadir}/udev
install -m 0755 %{SOURCE1} %{buildroot}%{_sbindir}/start_udev

mkdir -p -m 0755 %{buildroot}%{firmwaredir}

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

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

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

mkdir -p %{buildroot}/var/lib/udev/makedev.d


%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 || :

if [ ! -L /lib -a -d /lib/udev -a ! -d /usr/lib/udev ]; then
  cp -af /lib/udev /usr/lib/udev && \
  mv -f /lib/udev /lib/udev.old && \
  ln -sf ../usr/lib/udev /lib/udev && \
  rm -rf /lib/udev.old
fi
if [ ! -e /lib/udev ]; then
  ln -sf ../usr/lib/udev /lib/udev
fi
if [ ! -L /lib -a -d /lib/firmware -a ! -d /usr/lib/firmware ]; then
  cp -af /lib/firmware /usr/lib/firmware && \
  mv -f /lib/firmware /lib/firmware.old && \
  ln -sf ../usr/lib/firmware /lib/firmware && \
  rm -rf /lib/firmware.old
fi
if [ ! -e /lib/firmware ]; then
  ln -sf ../usr/lib/firmware /lib/firmware
fi

%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

%postun
if [ "$1" = 0 ]; then
	rm -f /sbin/scsi_id
	rm -f /sbin/start_udev
	rm -f /sbin/udevd
	rm -f /sbin/udevadm
	rm -f /sbin/udevcontrol
	rm -f /sbin/udevtrigger
	rm -f /sbin/udevsettle
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

%triggerpostun -- %{name} < 3.2.14-1
if [ -d /bin -a ! -L /bin ]; then
	if [ ! -L /sbin/udevadm ]; then
		ln -sf ../../%{udev_scriptdir}/scsi_id /sbin/scsi_id
		ln -sf ../usr/sbin/start_udev /sbin/start_udev
		ln -sf ../usr/sbin/udevd /sbin/udevd
		ln -sf ../usr/sbin/udevadm /sbin/udevadm
		ln -sf ../usr/sbin/udevadm /sbin/udevcontrol
		ln -sf ../usr/sbin/udevadm /sbin/udevtrigger
		ln -sf ../usr/sbin/udevadm /sbin/udevsettle
	fi
fi
if [ ! -e /lib/udev ]; then
  ln -sf ../usr/lib/udev /lib/udev
fi
if [ ! -e /lib/firmware ]; then
  ln -sf ../usr/lib/firmware /lib/firmware
fi

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

if [ -d /bin -a ! -L /bin ]; then
	if [ ! -L /sbin/udevadm ]; then
		ln -sf ../../%{udev_scriptdir}/scsi_id /sbin/scsi_id
		ln -sf ../usr/sbin/start_udev /sbin/start_udev
		ln -sf ../usr/sbin/udevd /sbin/udevd
		ln -sf ../usr/sbin/udevadm /sbin/udevadm
		ln -sf ../usr/sbin/udevadm /sbin/udevcontrol
		ln -sf ../usr/sbin/udevadm /sbin/udevtrigger
		ln -sf ../usr/sbin/udevadm /sbin/udevsettle
	fi
fi
if [ ! -e /lib/udev ]; then
  ln -sf ../usr/lib/udev /lib/udev
fi
if [ ! -e /lib/firmware ]; then
  ln -sf ../usr/lib/firmware /lib/firmware
fi

%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


%files
%defattr(-,root,root)
%license COPYING
%doc README
%attr(0755,root,root) %{_sbindir}/udevadm
%attr(0755,root,root) %{_sbindir}/udevd
%attr(0755,root,root) %{_sbindir}/start_udev
%{_sbindir}/udevcontrol
%{_sbindir}/udevtrigger
%{_sbindir}/udevsettle
%{_sbindir}/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/*.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/hwdb.7*
%{_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}/dmi_memory_id
%attr(0755,root,root) %{udev_scriptdir}/fido_id
%attr(0755,root,root) %{udev_scriptdir}/scsi_id
%attr(0755,root,root) %{udev_scriptdir}/v4l_id

%files libudev
%defattr(-,root,root,-)
%{_libdir}/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,-)
%{_libdir}/libudev.so.*

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


%changelog
* Tue Jul 02 2024 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.2.14-1
- new upstream release.
- prepared usrmerge.

* 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

