%bcond_with systemd

Summary: Hardware monitoring tools
Summary(ja): ハードウェア監視ツール集
Name: lm-sensors
Version: 3.6.0
Release: 1%{?_dist_release}%{?with_systemd:.systemd}
Group: system
Vendor: Project Vine
Distribution: Vine Linux
Packager: shaolin, owa

%global ver_str %(echo -n "%{version}" | sed -e 's/\\./-/g')

License: LGPLv2+ and GPLv3+ and GPLv2+ and Verbatim and Public Domain
URL: https://github.com/lm-sensors/lm-sensors
Source0: https://github.com/lm-sensors/lm-sensors/archive/V%{ver_str}/lm-sensors-%{ver_str}.tar.gz
Source1: lm_sensors.sysconfig
# This one was taken from PLD-linux, Thanks!
Source2: sensord.sysconfig
Source3: lm_sensors-modprobe-wrapper
Source4: lm_sensors-modprobe-r-wrapper
Source5: sensord.service
Source6: sensord-service-wrapper
Source7: lm_sensors.service
Source8: lm_sensors-wrapper

# Upstream patch:
Patch1: 0001-Change-PIDFile-path-from-var-run-to-run.patch
Patch2: lm_sensors-3.6.0-allow_no_sensors.patch
# Upstream commit 5deee7d0c301df779:
Patch3: lm_sensors-3.6.0-sensors-detect-Add-support-for-AMD-CPU-Family-19h.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: bison
BuildRequires: flex
BuildRequires: gawk
BuildRequires: kernel-headers >= 2.2.16
%if "%{_dist_release}" >= "vl7"
BuildRequires: libsysfs-devel
%else
BuildRequires: sysfsutils-devel
%endif
BuildRequires: rrdtool-devel

Requires: perl
%if %{with systemd}
%else
Requires: initscripts
Requires(post): /sbin/chkconfig
Requires(preun): /sbin/chkconfig
%endif

%description
The lm-sensors package includes a collection of modules for general SMBus
access and hardware monitoring.


%package libs
Summary: Lm_sensors core libraries
Summary(ja): Lm_sensors コアライブラリ
Group: system

%description libs
Core libraries for lm_sensors applications


%package devel
Summary: Development files for programs which will use lm_sensors
Summary(ja): lm_sensors を使用するプログラムのための開発用ファイル
Group: programming
Requires: %{name}-libs = %{version}-%{release}

%description devel
The %{name}-devel package includes a header files and libraries for use
when building applications that make use of sensor data.


%package sensord
Summary: Daemon that periodically logs sensor readings
Summary(ja): センサーの読み取り値を定期的に記録するデーモン
Group: system
Requires: %{name} = %{version}-%{release}

%description sensord
Daemon that periodically logs sensor readings to syslog or a round-robin
database, and warns of sensor alarms.


%debug_package


%prep
%setup -q -n lm-sensors-%{ver_str}
%patch1 -p1
%patch2 -p1
%patch3 -p1

# Remove currently unused files to make sure we've got the license right
rm -f prog/init/sysconfig-lm_sensors-convert prog/hotplug/unhide_ICH_SMBus

mv prog/init/README prog/init/README.initscripts
chmod -x prog/init/fancontrol.init

# fixing the sensord-service-wrapper path
cp -p %{SOURCE5} sensord.service
cp -p %{SOURCE7} lm_sensors.service
sed -i "s|\@WRAPPER_DIR\@|%{_libexecdir}/%{name}|" sensord.service
sed -i "s|\@WRAPPER_DIR\@|%{_libexecdir}/%{name}|" lm_sensors.service



%build
%set_build_flags
make PREFIX=%{_prefix} LIBDIR=%{_libdir} MANDIR=%{_mandir} \
	EXLDFLAGS="$LDFLAGS" PROG_EXTRA=sensord BUILD_STATIC_LIB=0 user


%install
rm -rf %{buildroot}
make user_install \
     DESTDIR=%{buildroot} \
     PREFIX=%{_prefix} \
     LIBDIR=%{_libdir} \
     ETCDIR=%{_sysconfdir} \
     MANDIR=%{_mandir} \
     PROG_EXTRA=sensord \
     BUILD_STATIC_LIB=0 \
     user_install

ln -s sensors.conf.5.gz %{buildroot}%{_mandir}/man5/sensors3.conf.5.gz

# add initscript from proc/init
mkdir -p %{buildroot}%{_sysconfdir}/sensors.d
mkdir -p %{buildroot}%{_sysconfdir}/sysconfig
install -pm 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/sysconfig/lm_sensors

%if %{with systemd}
install -pm 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/sensord

# service files
mkdir -p %{buildroot}%{_unitdir}
install -pm 644 prog/init/fancontrol.service %{buildroot}%{_unitdir}
install -pm 644 lm_sensors.service           %{buildroot}%{_unitdir}
install -pm 644 sensord.service              %{buildroot}%{_unitdir}

# customized modprobe calls
mkdir -p %{buildroot}%{_libexecdir}/%{name}
install -pm 755 %{SOURCE3} %{buildroot}%{_libexecdir}/%{name}/lm_sensors-modprobe-wrapper
install -pm 755 %{SOURCE4} %{buildroot}%{_libexecdir}/%{name}/lm_sensors-modprobe-r-wrapper
install -pm 755 %{SOURCE8} %{buildroot}%{_libexecdir}/%{name}/lm_sensors-wrapper

# sensord service wrapper
install -pm 755 %{SOURCE6} %{buildroot}%{_libexecdir}/%{name}/sensord-service-wrapper
%else
mkdir -p %{buildroot}%{_initdir}
install -m755 prog/init/lm_sensors.init %{buildroot}%{_initdir}/lm_sensors
%endif

# remove unuse files
rm -f %{buildroot}/%{_libdir}/*.a


%clean
rm -rf %{buildroot}


%post
%if %{with systemd}
%systemd_post lm_sensors.service
%else
if [ "$1" = 1 ] ; then
	/sbin/chkconfig --add lm_sensors
fi
%{_initdir}/lm_sensors condrestart
%endif

%preun
%if %{with systemd}
%systemd_preun lm_sensors.service
%else
if [ "$1" = 0 ] ; then
	%{_initdir}/lm_sensors stop > /dev/null 2>&1
    /sbin/chkconfig --del lm_sensors
fi
%endif

%if %{with systemd}
%postun
%systemd_postun_with_restart lm_sensors.service

%post sensord
%systemd_post sensord.service

%preun sensord
%systemd_preun sensord.service

%postun sensord
%systemd_postun_with_restart sensord.service
%endif


%files
%defattr(-,root,root,-)
%license COPYING
%doc CHANGES CONTRIBUTORS INSTALL README doc
%dir %{_sysconfdir}/sensors.d
%config(noreplace) %{_sysconfdir}/sensors3.conf
%config(noreplace) %{_sysconfdir}/sysconfig/lm_sensors
%{_bindir}/*
%{_sbindir}/*
%if %{with systemd}
%dir %{_libexecdir}/%{name}
%{_libexecdir}/%{name}/lm_sensors-modprobe*wrapper
%{_libexecdir}/%{name}/lm_sensors-wrapper
%{_unitdir}/lm_sensors.service
%{_unitdir}/fancontrol.service
%else
%config %{_initdir}/lm_sensors
%endif
%{_mandir}/man1/*
%{_mandir}/man5/*
%{_mandir}/man8/*
%exclude %{_sbindir}/sensord
%exclude %{_mandir}/man8/sensord.8.gz

%files libs
%{_libdir}/lib*.so.*

%files devel
%{_includedir}/sensors
%{_libdir}/lib*.so
%{_mandir}/man3/*

%if %{with systemd}
%files sensord
	
%doc prog/sensord/README
%{_sbindir}/sensord
%{_mandir}/man8/sensord.8.gz
%config(noreplace) %{_sysconfdir}/sysconfig/sensord
%{_unitdir}/sensord.service
%{_libexecdir}/%{name}/sensord-service-wrapper
%endif


%changelog
* Mon May 29 2023 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.6.0-1
- updated to 3.6.0.

* Fri May 10 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.5.0-1
- updated to 3.5.0.

* Sat Nov  7 2015 Daisuke SUZUKI <daisuke@vinelinux.org> 3.4.0-1
- update to 3.4.0

* Mon Jan  5 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 3.3.5-1
- updated to 3.3.5
- built on current VineSeed
- split libraries to libs subpackage

* Tue Apr 12 2011 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 3.3.0-1
- new upstrem release 3.3.0

* Tue Dec 14 2010 Shu KONNO <owa@bg.wakwak.com> 3.2.0-1
- updated lm-sensors to 3.2.0
- added RQ: initscripts

* Tue Mar 16 2010 Shu KONNO <owa@bg.wakwak.com> 3.1.2-1
- updated lm-sensors to 3.1.2

* Tue Oct 20 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 3.1.1-2
- isadump/isaset only available on ix86/x86_64 archs

* Mon Aug 31 2009 Shu KONNO <owa@bg.wakwak.com> 3.1.1-1
- updated lm-sensors to 3.1.1
- added japanese summary, spec in utf-8
- added %{_initdir}/lm_sensors to %%files
- added %%post, %%preun, %%postun scripts

* Fri Oct 03 2008 Shu KONNO <owa@bg.wakwak.com> 2.10.7-1vl5
- new upstream release
- applied new versioning policy

* Sun Nov 25 2007 Shu KONNO <owa@bg.wakwak.com> - 2.10.3-0vl2
- fixed libdir in Makefile (for support lib64)

* Tue May 29 2007 USAMI Kosuke <usami-k@yc5.so-net.ne.jp> - 2.10.3-0vl1
- Initial build.

