%define _sysconfdir /etc

%define pmudver 0.10
%define pmudrel 1

Name:          pmud 
Version:       %{pmudver}
Release:       %{pmudrel}vl15
Summary:       Power Manager daemon for Apple PowerBooks
Summary(ja):   PowerBook 用パワーマネージメントデーモン
Source:        http://prdownloads.sourceforge.net/apmud/pmud-%{pmudver}.%{pmudrel}.tar.gz
Patch1:        pmud_0.10-4.diff.gz
Patch2:        Batmon-comet.patch

## Vine Source(s)/Patch(es)
Patch10:       pmud-0.10-trackpad.patch
Patch11:       pmud-0.10-backlight.patch
Patch12:       pmud-0.10-comet.patch
Patch13:       pmud-0.10-pwrctl.patch
Patch14:       pmud-0.10-power.conf.patch
Patch30:       pmud-0.10-misc.patch

License:       GPL
Group:         Utilities/System
BuildRoot:     %{_tmppath}/%{name}-%{version}-root
Provides:      apmd
Prereq:        chkconfig, coreutils
ExclusiveArch: ppc
Requires:      hdparm
Obsoletes:     trackpad


%description 
pmud is a daemon which periodically polls the PMU (power manager) and performs 
functions such as enabling or disabling devices appropriately when the power 
source changes. It can also be instructed to signal init(8) that a power-
failure has occured.

%description -l ja
PMUD は Apple Powerbook のパワーマネージメントシステムを
制御するデーモンです。pmud は、PowerBook の蓋を閉じたり、
バッテリの残り容量が 5分を切った時などに自動的にスリープします。
マシンの負荷が高い時にはスリープは行われません。

Batmon という Tcl ベースのユーティリティも付属しており、
現在のバッテリ状況をモニタしたり、ボタンを押すことで
スリープさせたりすることが可能です。


%package tools
Summary:     Several front end tools for PowerBooks
Summary(ja): PowerBook 用各種フロントエンドツール
Group:       Utilities/System
Obsoletes:   gfblevel
Provides:    gfblevel


%description tools
Batmon   - TK-based battery status monitor
gfblevel - graphical front-end to set LCD backlight level
xmouse   - X mouse setting tool

%description tools -l ja
Batmon   - tk ベースのバッテリ残量モニタ
gfblevel - LCD バックライト調節を行うグラフィカルフロントエンド
xmouse   - X マウス設定ツール

 
%prep
%setup 

%patch1 -p1 -b .deb
%patch2 -p1 -b .comet-bat

%patch10 -p1
%patch11 -p1
%patch12 -p1 -b .comet
%patch13 -p1
%patch14 -p1

%patch30 -p1


%build
make clean
make

make -C contrib clean
make -C contrib

# compile even contrib/fblevel_misc/gfblevel.c
( cd contrib/fblevel_misc;
  make clean;
  make && mv gfblevel ../../.
)


%install
rm -rf ${RPM_BUILD_ROOT}

# pmud binaries and conffiles
mkdir -p ${RPM_BUILD_ROOT}%{_syssbindir}
mkdir -p ${RPM_BUILD_ROOT}%{_sbindir}

install -c pmud ${RPM_BUILD_ROOT}%{_syssbindir}
install -c snooze ${RPM_BUILD_ROOT}%{_syssbindir}
install -c wakebay ${RPM_BUILD_ROOT}%{_syssbindir}

mkdir -p ${RPM_BUILD_ROOT}/etc/sysconfig
install -m 0644 power.conf ${RPM_BUILD_ROOT}/etc/sysconfig/power
mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/power
install -c pwrctl ${RPM_BUILD_ROOT}%{_sysconfdir}/power
mkfifo -m 644 ${RPM_BUILD_ROOT}%{_sysconfdir}/power/apm

# We need our own default /etc/power/levels
# The first value is the battery policy, the second value is
# the AC policy. Valid values are 1 (minimum power consumption),
# 2 (medium power consumption) and 3 (maximum power consumption).
cat > ${RPM_BUILD_ROOT}%{_sysconfdir}/power/levels <<EOF
2 3
EOF

mkdir -p ${RPM_BUILD_ROOT}%{_initdir}
#install -c pmud.rc.debian ${RPM_BUILD_ROOT}%{_initdir}/pmud
install -c pmud.rc ${RPM_BUILD_ROOT}%{_initdir}/pmud

mkdir -p $RPM_BUILD_ROOT%{_bindir}
install -c on_ac_power ${RPM_BUILD_ROOT}%{_bindir}
(cd $RPM_BUILD_ROOT%{_bindir} ; ln -sf ../../sbin/snooze apm)

# pmud-utils binaries
install -c Batmon    ${RPM_BUILD_ROOT}%{_bindir}
#install -c trackpad  ${RPM_BUILD_ROOT}%{_bindir}
install -c gfblevel  ${RPM_BUILD_ROOT}%{_bindir}

install -c fblevel   ${RPM_BUILD_ROOT}%{_syssbindir}
#install -c backlight ${RPM_BUILD_ROOT}%{_syssbindir}

mkdir -p ${RPM_BUILD_ROOT}/usr/X11R6/bin
install -c xmouse ${RPM_BUILD_ROOT}/usr/X11R6/bin

# install man pages
mkdir -p ${RPM_BUILD_ROOT}%{_mandir}/man8
install -m 644 pmud.8 fblevel.8 snooze.8 xmouse.8 \
	${RPM_BUILD_ROOT}%{_mandir}/man8
install -m 644  batmon.8 \
	${RPM_BUILD_ROOT}%{_mandir}/man8/Batmon.8

make PREFIX=${RPM_BUILD_ROOT} -C contrib install

make -C contrib clean


%clean
rm -rf $RPM_BUILD_ROOT


%pre 
[ -c /dev/pmu ] || {
	echo "creating /dev/pmu"
	mknod /dev/pmu c 10 154
	chmod 666 /dev/pmu
}
[ -c /dev/adb ] || {
	echo "creating /dev/adb"
	mknod /dev/adb c 56 0
	chmod 666 /dev/adb
}
#[ -p /etc/power/apm ] || {
#	echo "creating /etc/power/apm"
#	mkfifo -m 644 /etc/power/apm
#}


%post 
/sbin/chkconfig --add pmud


%preun
if [ $1 = 0 ]; then
	/sbin/chkconfig --del pmud
fi


%triggerpostun -- pmud < 0.10-0vl7
/sbin/chkconfig --add pmud


%files
%defattr(-,root,root)
%doc TODO BUGS README INSTALL CHANGES pwrctl-local contrib
%doc powerfail debian
%{_syssbindir}/backlight
%{_syssbindir}/fblevel
%{_syssbindir}/pmud
%{_syssbindir}/snooze
%{_syssbindir}/wakebay
%{_sbindir}/m3mirror
%{_sbindir}/m6mirror
%{_bindir}/apm
%{_bindir}/trackpad
%{_bindir}/on_ac_power

%config /etc/sysconfig/power
%{_sysconfdir}/power/pwrctl
%{_sysconfdir}/power/apm
%{_sysconfdir}/power/levels
%{_initdir}/pmud 

%{_mandir}/man8/fblevel*
%{_mandir}/man8/pmud*
%{_mandir}/man8/snooze*


%files tools
%defattr(-,root,root)
%{_bindir}/Batmon
%{_bindir}/gfblevel
/usr/X11R6/bin/xmouse

%{_mandir}/man8/Batmon*
%{_mandir}/man8/xmouse*


%changelog
* Mon May 21 2007 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.10-1vl15
- rebuilt with new toolchain

* Sun Jan 21 2007 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.10-1vl14
- add PreReq: coreutils

* Wed Oct 11 2006 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.10-1vl13
- split graphical frontends to -tools subpackage
- make -C contrib clean before they are stored into docdir

* Wed Oct 11 2006 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.10-1vl12
- added Patch30 (include m3mirror and m6mirror, gfblevel with gtk2, misc fixes)

* Sun Dec 21 2003 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.10-1vl11
- rebuilt with kernel-2.3.23-0vl2

* Wed Dec 10 2003 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl10
- rebuild with kernel-2.4.23-0vl1

* Mon Nov 10 2003 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl9
- update Patch1
- rebuild with kernel-2.4.22-0vl11

* Fri Jul 25 2003 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl8
- rebuild with kernel-2.4.21-0vl19

* Sun Mar 10 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl7
- added %%triggerpostun

* Sun Mar 03 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl6
- modified %preun; not to delete rc? entries at package update

* Sun Feb 24 2002 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.10-1vl5
- added Patch14 to set "-a -K" as default
- /etc/sysconfig/power now set to %%config

* Thu Feb 22 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl4
- fixed Batmon for PB2400/3400/3500
- fixed pmud.c for PB2400/3400/3500

* Thu Jan 31 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl3
- fixed generating /etc/power/apm 
- fixed pmud.c for PB2400

* Thu Jan 10 2002 KOBAYASHI R. Taizo <tkoba@vinelinux.org> 0.10-1vl2
- fixed contrib/backlight.c

* Tue Dec 25 2001 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.8-1vl3
- added some contrib binaries
- gfblevel is now a seperated subpackage

* Wed Dec 12 2001 KONAYASHI R. Taizo <tkoba@vinelinux.org>
- pmud-0.8-1vl2
- update to Debian pmud-0.8-1

* Fri Aug 03 2001 KONAYASHI R. Taizo <tkoba@vinelinux.org>
- added pwrctl-notap.patch

* Fri Jul 06 2001 KONAYASHI R. Taizo <tkoba@ike-dyn.ritsumei.ac.jp>
- rebuild for 2.4.6

* Sun May 13 2001 KONAYASHI R. Taizo <tkoba@ike-dyn.ritsumei.ac.jp>
- rebuild for 2.4

* Sun Jan 21 2001 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 0.7-1vl4
- use better macros (%%{_syssbindir}, %%{_bindir}, %%{_sysconfdir}, 
  %%{_mandir}, %%{_initdir})

* Fri Oct 13 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 0.7-1vl3
- disabled %post section
  (pmud seems to be unstable under certain environments....)

* Fri Oct 13 2000 T.R. Kobayashi <tkoba@ike-dyn.ritsumei.ac.jp>
- 0.7-1vl2
- update to 0.7

* Mon May 15 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 0.6-2vl1
- added %preun section
- modified %version -> %pmudver, %release -> %pmudrel

* Fri May 12 2000 T.R. Kobayashi <tkoba@ike-dyn.ritsumei.ac.jp>
- 0.6.1-0.6.2
- Fixed Batmon on 2400
