Name:           kbd
Version:        2.2.0
Release:        2
Summary:        Tools for managing Linux console(keyboard, virtual terminals, etc.)
License:        GPLv2+
URL:            https://www.%{name}-project.org/
                                                                                    
Source0:        http://ftp.altlinux.org/pub/people/legion/%{name}/%{name}-%{version}.tar.gz
Source1:        %{name}-latsun-fonts.tar.bz2
Source2:        %{name}-latarcyrheb-32.tar.bz2
Source3:        xml2lst.pl
Source4:        vlock.pamd
Source6:        cz-map.patch

BuildRequires:  bison flex gettext pam-devel check-devel libtool
BuildRequires:  gcc console-setup xkeyboard-config gettext-devel
Requires:       %{name}-misc = %{version}-%{release}
Requires:       %{name}-legacy = %{version}-%{release}
Provides:       vlock = %{version}
Conflicts:      vlock <= 1.3
Obsoletes:      vlock

%description
The %{name} project contains tools for managing Linux console ,including 
Linux console,virtual terminals, keyboard, etc, mainly, what they do 
is loading console fonts and keyboard maps.

%package 	misc
Summary:        Data for %{name} package
BuildArch:      noarch
 
%description 	misc
The %{name}-misc package contains data for %{name} package,including console fonts,
keymaps and so on. But %{name}-misc can do nothing without %{name}.

%package 	legacy
Summary:        Legacy data for %{name} package
BuildArch:      noarch

%description 	legacy
The %{name}-legacy package contains original keymaps for %{name} package.
But %{name}-legacy can do nothing without %{name}.

%package_help

%prep
%setup -q -a 1 -a 2
cp -fp %{SOURCE3} .
cp -fp %{SOURCE6} .

pushd data/keymaps/i386
cp qwerty/pt-latin9.map qwerty/pt.map
cp qwerty/sv-latin1.map qwerty/se-latin1.map

mv azerty/fr.map azerty/fr-old.map
cp azerty/fr-latin9.map azerty/fr.map

cp azerty/fr-latin9.map azerty/fr-latin0.map 

mv dvorak/dvorak-no.map dvorak/no-dvorak.map
mv fgGIod/trf.map fgGIod/trf-fgGIod.map
mv olpc/es.map olpc/es-olpc.map
mv olpc/pt.map olpc/pt-olpc.map
mv qwerty/cz.map qwerty/cz-qwerty.map
popd

pushd po
rm -f gr.po gr.gmo
popd

iconv -f iso-8859-1 -t utf-8 < "ChangeLog" > "ChangeLog_"
mv "ChangeLog_" "ChangeLog"
./autogen.sh

%build


%configure --prefix=%{_prefix} --datadir=/lib/%{name} --mandir=%{_mandir} --localedir=%{_datadir}/locale --enable-nls
%make_build

%install
%make_install

rm -f %{buildroot}/lib/%{name}/keymaps/i386/qwerty/ro_win.map.gz

ln -s sr-cy.map.gz %{buildroot}/lib/%{name}/keymaps/i386/qwerty/sr-latin.map.gz

ln -s us.map.gz %{buildroot}/lib/%{name}/keymaps/i386/qwerty/ko.map.gz

mkdir -p %{buildroot}/bin
for binary in setfont dumpkeys %{name}_mode unicode_start unicode_stop loadkeys ; do
  mv %{buildroot}%{_bindir}/$binary %{buildroot}/bin/
done

sed -i -e 's,\<%{name}_mode\>,/bin/%{name}_mode,g;s,\<setfont\>,/bin/setfont,g' \
        %{buildroot}/bin/unicode_start

cp -r %{buildroot}/lib/%{name}/locale/ %{buildroot}%{_datadir}/locale
rm -rf %{buildroot}/lib/%{name}/locale

mkdir -p %{buildroot}%{_sysconfdir}/pam.d
install -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/pam.d/vlock

mkdir -p %{buildroot}/lib/%{name}/keymaps/legacy
mv %{buildroot}/lib/%{name}/keymaps/{amiga,atari,i386,include,mac,ppc,sun} %{buildroot}/lib/%{name}/keymaps/legacy

mkdir -p %{buildroot}/lib/%{name}/keymaps/xkb
perl xml2lst.pl < /usr/share/X11/xkb/rules/base.xml > layouts-variants.lst
while read line; do
  XKBLAYOUT=`echo "$line" | cut -d " " -f 1`
  echo "$XKBLAYOUT" >> layouts-list.lst
  XKBVARIANT=`echo "$line" | cut -d " " -f 2`
  ckbcomp "$XKBLAYOUT" "$XKBVARIANT" | gzip > %{buildroot}/lib/%{name}/keymaps/xkb/"$XKBLAYOUT"-"$XKBVARIANT".map.gz
done < layouts-variants.lst

cat layouts-list.lst | sort -u >> layouts-list-uniq.lst
while read line; do
  ckbcomp "$line" | gzip > %{buildroot}/lib/%{name}/keymaps/xkb/"$line".map.gz
done < layouts-list-uniq.lst

gunzip %{buildroot}/lib/%{name}/keymaps/xkb/fi.map.gz
mv %{buildroot}/lib/%{name}/keymaps/xkb/fi.map %{buildroot}/lib/%{name}/keymaps/xkb/fi-kotoistus.map
gzip %{buildroot}/lib/%{name}/keymaps/xkb/fi-kotoistus.map

gunzip %{buildroot}/lib/%{name}/keymaps/xkb/cz.map.gz
patch %{buildroot}/lib/%{name}/keymaps/xkb/cz.map < %{SOURCE6}
gzip %{buildroot}/lib/%{name}/keymaps/xkb/cz.map

%files 
%defattr(-,root,root)
%license COPYING
%doc AUTHORS 
/bin/*
%{_datadir}/locale/*
%{_bindir}/*
%{_mandir}/*/*
%config(noreplace) %{_sysconfdir}/pam.d/vlock

%files misc
%defattr(-,root,root)
/lib/%{name}/*
%exclude /lib/%{name}/keymaps/legacy

%files legacy
%defattr(-,root,root)
/lib/%{name}/keymaps/legacy/*

%files help
%defattr(-,root,root)
%doc ChangeLog README docs/doc/%{name}.FAQ*.html docs/doc/font-formats/*.html docs/doc/utf/utf* docs/doc/dvorak/*
%{_mandir}/man1/*.1.gz
%{_mandir}/man5/keymaps.5.gz
%{_mandir}/man8/*.8.gz

%changelog
* Mon Jan 20 2020 openEuler Buildteam <buildteam@openeuler.org> - 2.2.0-2
- Type:bugfix
- Id:NA
- SUG:NA
- DESC:add libtool in buildrequires

* Sat Jan 11 2020 openEuler Buildteam <buildteam@openeuler.org> - 2.2.0-1
- Type:bugfix
- Id:NA
- SUG:NA
- DESC:update to 2.2.0

* Wed Sep 18 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.0.4-10
- Package init
