%global convert_xkb 0

# {_exec_prefix}/lib/kbd is correct even on x86_64.
# It is traditionally used for kdb data (console fonts, keymaps, ...).
# It is not used for any shared objects/executables.
%global kbd_datadir /lib/kbd

Summary: Tools for configuring the console (keyboard, virtual terminals, etc.)
Summary(ja): コンソール(キーボードや仮想ターミナル等)を設定するツール群
Name: kbd
Version: 2.2.0
Release: 1%{?_dist_release}
Group: System Environment/Base
Vendor: Project Vine
Distribution: Vine Linux

License: GPL
Source0: https://www.kernel.org/pub/linux/utils/kbd/kbd-%{version}.tar.xz
Source1: kbd-latsun-fonts.tar.bz2
Source2: kbd-latarcyrheb-32.tar.bz2
Source3: xml2lst.pl
Source4: vlock.pamd
Source5: kbdinfo.1
Source6: cz-map.patch
Requires: pam >= 0.66-4, /etc/pam.d/system-auth, usermode
BuildRequires: bison, flex, gettext, pam-devel
%if 0%{convert_xkb}
BuildRequires: console-setup
%endif
BuildRoot: %{_tmppath}/%{name}-root
# Patch0: puts additional information into man pages
Patch0: kbd-1.15-keycodes-man.patch
# Patch1: sparc modifications
Patch1: kbd-1.15-sparc.patch
# Patch2: adds default unicode font to unicode_start script
Patch2: kbd-1.15-unicode_start.patch
# Patch3: add missing dumpkeys option to man page
Patch3: kbd-1.15.3-dumpkeys-man.patch
# Patch4: fixes decimal separator in Swiss German keyboard layout, bz 882529
Patch4: kbd-1.15.5-sg-decimal-separator.patch
# Patch5: adds xkb and legacy keymaps subdirs to loadkyes search path, bz 1028207
Patch5: kbd-1.15.5-loadkeys-search-path.patch
# Patch6: don't hardcode font used in unicode_start, take it from vconsole.conf,
#   bz 1101007
Patch6: kbd-2.0.2-unicode-start-font.patch
# Patch7: fixes issues found by static analysis
Patch7:         kbd-2.0.4-covscan-fixes.patch
# Patch8: fix flags
Patch8:         kbd-2.2.0-fix-flags.patch
# Patch9: workaround -Werror=format-security build error
Patch9:         kbd-2.2.0-format-security.patch

Obsoletes: console-tools open
Provides: console-tools open
Conflicts: util-linux < 2.11r-9
Requires(pre): initscripts >= 5.86-1
ExcludeArch: s390 s390x

%description
The %{name} package contains tools for managing a Linux
system's console's behavior, including the keyboard, the screen
fonts, the virtual terminals and font files.

%prep

%setup -q -a 1 -a 2
cp -fp %{SOURCE3} .
cp -fp %{SOURCE6} .
%patch0 -p1 -b .keycodes-man
%patch1 -p1 -b .sparc
%patch2 -p1 -b .unicode_start
%patch3 -p1 -b .dumpkeys-man
%patch4 -p1 -b .sg-decimal-separator
%if 0%{convert_xkb}
%patch5 -p1 -b .loadkeys-search-path
%endif
%patch6 -p1 -b .unicode-start-font
%patch7 -p1 -b .covscan-fixes
%patch8 -p1 -b .fix-flags
%patch9 -p1 -b .format-security

# 7-bit maps are obsolete; so are non-euro maps
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 # legacy alias

# Rename conflicting keymaps
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

# remove obsolete "gr" translation
pushd po
rm -f gr.po gr.gmo
popd

# Convert to utf-8
iconv -f iso-8859-1 -t utf-8 < "ChangeLog" > "ChangeLog_"
mv "ChangeLog_" "ChangeLog"

%build
export OLD_PO_FILE_INPUT=yes

# We don't use % {configure} because the ./configure included here does not
# understand most of the options.
CFLAGS="$RPM_OPT_FLAGS"; export CFLAGS
#./configure --prefix=%{_prefix} --datadir=/lib/kbd --mandir=%{_mandir} 
%configure --prefix=%{_prefix} --datadir=%{kbd_datadir} --mandir=%{_mandir} --localedir=%{_datadir}/locale --enable-nls
make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT

# Basic install.
make install DESTDIR=$RPM_BUILD_ROOT

# ro_win.map.gz is useless
rm -f $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/i386/qwerty/ro_win.map.gz

# Create additional name for Serbian latin keyboard
ln -s sr-cy.map.gz $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/i386/qwerty/sr-latin.map.gz

# The rhpl keyboard layout table is indexed by kbd layout names, so we need a
# Korean keyboard
ln -s us.map.gz $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/i386/qwerty/ko.map.gz

# Move binaries which we use before /usr is mounted from %{_bindir} to /bin.
mkdir -p $RPM_BUILD_ROOT/bin
for binary in setfont dumpkeys kbd_mode unicode_start unicode_stop loadkeys ; do

  mv $RPM_BUILD_ROOT%{_bindir}/$binary $RPM_BUILD_ROOT/bin/
done

# Some microoptimization
sed -i -e 's,\<kbd_mode\>,/bin/kbd_mode,g;s,\<setfont\>,/bin/setfont,g' \
        $RPM_BUILD_ROOT/bin/unicode_start

# Link open to openvt
ln -s openvt $RPM_BUILD_ROOT%{_bindir}/open
ln -s openvt.1.gz $RPM_BUILD_ROOT%{_mandir}/man1/open.1.gz

# install kbdinfo manpage
gzip -c %SOURCE5 > $RPM_BUILD_ROOT/%{_mandir}/man1/kbdinfo.1.gz

# Move locale files to correct place
cp -r $RPM_BUILD_ROOT%{kbd_datadir}/locale/ $RPM_BUILD_ROOT%{_datadir}/locale
rm -rf $RPM_BUILD_ROOT%{kbd_datadir}/locale

# Install PAM configuration for vlock
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/pam.d
install -m 644 %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/pam.d/vlock

%if 0%{convert_xkb}
# Move original keymaps to legacy directory
mkdir -p $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/legacy
mv $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/{amiga,atari,i386,include,mac,ppc,sun} $RPM_B
UILD_ROOT%{kbd_datadir}/keymaps/legacy

# Convert X keyboard layouts to console keymaps
mkdir -p $RPM_BUILD_ROOT%{kbd_datadir}/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 > $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xk
b/"$XKBLAYOUT"-"$XKBVARIANT".map.gz
done < layouts-variants.lst

# Convert X keyboard layouts (plain, no variant)
cat layouts-list.lst | sort -u >> layouts-list-uniq.lst
while read line; do
  ckbcomp "$line" | gzip > $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/"$line".map.gz
done < layouts-list-uniq.lst

# wipe converted layouts which cannot input ASCII (#1031848)
zgrep -L "U+0041" $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/* | xargs rm -f

# Rename the converted default fi (kotoistus) layout (#1117891)
gunzip $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/fi.map.gz
mv $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/fi.map $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xk
b/fi-kotoistus.map
gzip $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/fi-kotoistus.map

# Fix converted cz layout - add compose rules
gunzip $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/cz.map.gz
patch $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/cz.map < %{SOURCE6}
gzip $RPM_BUILD_ROOT%{kbd_datadir}/keymaps/xkb/cz.map
%endif

%find_lang %{name}

%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}

%triggerun -- kbd < 1.08-10.2
/sbin/chkconfig --del keytable || :

%files -f %{name}.lang
%defattr(-,root,root)
%license COPYING
%doc ChangeLog AUTHORS README docs/doc/kbd.FAQ*.html docs/doc/font-formats/*.html docs/doc/utf/utf* docs/doc/dvorak/*
/bin/*
%{_bindir}/*
%{_mandir}/*/*
%{kbd_datadir}
%config(noreplace) %{_sysconfdir}/pam.d/vlock


%changelog
* Sat Apr 11 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.2.0-1
- new upstream release.
- imported Patch7-9 from rawhide.

* Sun Sep 24 2017 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.0.4-1
- new upstream release.

* Mon Dec 30 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.12-22
- rebuild with VineSeed environment

* Fri Aug 15 2008 Shu KONNO <owa@bg.wakwak.com> 1.12-21vl5
- applied new versioning policy, spec in utf-8

* Sun May 20 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 1.12-21vl1
- initial build for Vine Linux based on Fedora package.

* Tue Jan  9 2007 Miloslav Trmac <mitr@redhat.com> - 1.12-21
- Add a "ko" (Korean) keyboard layout, equivalent to the "us" layout
  Resolves: #220151

* Thu Dec  7 2006 Miloslav Trmac <mitr@redhat.com> - 1.12-20
- Document that setkeycodes doesn't affect USB keyboards and that the kernel
  doesn't provide the raw scan codes by default
  Resolves: #211803

* Tue Oct 31 2006 Miloslav Trmac <mitr@redhat.com> - 1.12-19
- Ship "el" translation instead of the obsolete "gr" translation
  Resolves: #210749
- Fix %% quoting in %%changelog

* Fri Sep 29 2006 Miloslav Trmac <mitr@redhat.com> - 1.12-18
- Add a missing tilde to U+00E3 in latarcyrheb-sun16.psfu (#204470)

* Fri Jul 14 2006 Jesse Keating <jkeating@redhat.com> - 1.12-17
- Obsoletes/Provides open
- Create a symlink from open to openvt

* Wed Jul 12 2006 Jesse Keating <jkeating@redhat.com> - 1.12-16.1
- rebuild

* Sun Jul  9 2006 Miloslav Trmac <mitr@redhat.com> - 1.12-16
- Don't include <asm/kbdio.h> on SPARC (#198040, patch by Dennis Gilmore
  <dennis@ausil.us>)

* Mon May 29 2006 Miloslav Trmac <mitr@redhat.com> - 1.12-15
- Fix missing BuildRequires (#193406)

* Mon Mar 27 2006 Miloslav Trmac <mitr@redhat.com> - 1.12-14
- Don't install resizecons.8 on non-x86 (#186877, patch by Keiichi Mori
  <kmori@redhat.com>)

* Fri Feb 10 2006 Jesse Keating <jkeating@redhat.com> - 1.12-13.2
- bump again for double-long bug on ppc(64)

* Tue Feb 07 2006 Jesse Keating <jkeating@redhat.com> - 1.12-13.1
- rebuilt for new gcc4.1 snapshot and glibc changes

* Fri Jan 20 2006 Miloslav Trmac <mitr@redhat.com> - 1.12-13
- Fix build with new coreutils
- Hardcode paths in unicode_start to avoid a few file lookups (#178329)
- Drop unnecessary Prereq: sed mktemp

* Fri Dec 09 2005 Jesse Keating <jkeating@redhat.com>
- rebuilt

* Thu Dec  1 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-12
- Don't reload the keymap in unicode_start (#172425)

* Fri Nov 11 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-11
- Don't ship character set lists (they are already in glibc-common) and an
  obsolete copy of kbd.FAQ

* Fri May 20 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-10
- Don't attempt to open directories as source files (#141634, original patch by
  Paul Nasrat)

* Tue May 17 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-9
- Fix another violation of C aliasing rules (#157720, patch by Jan Kratochvil)

* Sat Mar 12 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-8
- Fix violation of C aliasing rules (#150440)

* Sun Mar  6 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-7
- Don't run ldconfig
- Don't strip executables

* Fri Mar  4 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-6
- Rebuild with gcc4

* Sun Feb 20 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-5
- Put "Meta_acute" back in German keymaps, just ignore it in (loadkeys -u)
  (patch by Jochen Schmitt)
- Don't ship patch backup files, simpler way

* Sat Feb 19 2005 Miloslav Trmac <mitr@redhat.com> - 1.12-4
- Don't ship a patch backup file
- Mention in setfont.8 that 512-glyph fonts reduce the number of available 
  colors (#140935, patch by Dmitry Butskoj)
- Remove "Meta_acute" from German keymaps (#143124)
- Make the %%triggerun script condition more precise, ignore failure of the
  script

* Mon Feb 14 2005 Adrian Havill <havill@redhat.com>
- rebuilt

* Tue Jun 15 2004 Elliot Lee <sopwith@redhat.com>
- rebuilt

* Thu Feb 26 2004 Adrian Havill <havill@redhat.com>
- update to 1.12

* Fri Feb 13 2004 Elliot Lee <sopwith@redhat.com>
- rebuilt

* Wed Jan 14 2004 Bill Nottingham <notting@redhat.com> 1.08-12
- remove speakup patch at request of author

* Fri Oct 10 2003 Bill Nottingham <notting@redhat.com> 1.08-11
- remove keytable init script (#106783)

* Tue Aug 12 2003 Adrian Havill <havill@rtedhat.com> 1.08-10.1
- bump for RHEL

* Tue Aug 12 2003 Adrian Havill <havill@rtedhat.com> 1.08-10
- apply the rukbd patch (#78218)

* Thu Jul 31 2003 Adrian Havill <havill@redhat.com> 1.08-9
- don't print "plus before..." warnings about non-supported capslock
  in unimode <Andries.Brouwer@cwi.nl> (#81855)

* Wed Jul 30 2003 Adrian Havill <havill@redhat.com> 1.08-8
- replaced Russian keyboard map with working UTF-8 equivalent (#79338)

* Thu Jul 24 2003 Adrian Havill <havill@redhat.com> 1.08-7
- make euro/latin-9 the default instead of latin-1 and 7-bit (#97013)
- fix swedish keymap; se, not sv (#88791)
- add fr-latin0 legacy alias of fr-latin-9 (#88324)
- add ".map" ext to filename param of init script (#90562)

* Wed Jun 04 2003 Elliot Lee <sopwith@redhat.com>
- rebuilt

* Thu Mar 06 2003 Florian La Roche <Florian.LaRoche@redhat.de>
- build new rpm

* Fri Feb 21 2003 Florian La Roche <Florian.LaRoche@redhat.de>
- ExcludeArch mainframe

* Thu Jan 30 2003 Bill Nottingham <notting@redhat.com> 1.08-4
- remove condrestart from initscript

* Wed Jan 22 2003 Tim Powers <timp@redhat.com>
- rebuilt

* Fri Dec  6 2002 Nalin Dahyabhai <nalin@redhat.com> 1.08-2
- only output terminal unicode init sequence if both stdout and stderr are
  connected to terminals, so that it doesn't show up when script outputs
  get piped to files

* Fri Nov 22 2002 Nalin Dahyabhai <nalin@redhat.com> 1.08-1
- update to 1.08
- drop updates which went mainline

* Mon Nov 11 2002 Nalin Dahyabhai <nalin@redhat.com> 1.06-27
- add detached signature
- remove directory names from PAM configuration so that the same config file
  can be used for any arch on multilib systems

* Wed Sep  4 2002 Bill Nottingham <notting@redhat.com> 1.06-26
- don't munge /etc/sysconfig/i18n

* Tue Sep  3 2002 Bill Nottingham <notting@redhat.com> 1.06-25
- don't run setsysfont in upgrade trigger on console-tools

* Thu Aug 29 2002 Jakub Jelinek <jakub@redhat.com> 1.06-24
- use cyr-sun16 cyrillic chars in latarcyrheb-sun16 font
  instead of old LatArCyrHeb-16 chars
- add Euro character to latarcyrheb-sun16
- use latarcyrheb-sun16 by default in unicode_start script

* Tue Aug 27 2002 Jakub Jelinek <jakub@redhat.com> 1.06-23
- add back lat[02]-sun16 fonts plus latarcyrheb-sun16 font

* Thu Aug 22 2002 Karsten Hopp <karsten@redhat.de>
- needs to conflict with older util-linux packages 
  (kbdrate moved between packages)

* Tue Aug 13 2002 Bill Nottingham <notting@redhat.com> 1.06-21
- remove Evil Hack in favor of slightly-less-evil-hack in initscripts

* Tue Jul  9 2002 Bill Nottingham <notting@redhat.com> 1.06-20
- fix speakup keymap names

* Tue Jul 09 2002 Phil Knirsch <pknirsch@redhat.com> 1.06-19
- Evil hack to make setfont work correctly on all consoles (#68018)

* Thu Jun 27 2002 Bill Nottingham <notting@redhat.com> 1.06-18
- move unicode_stop to /bin too
- fix path to loadkeys in keytable.init
- add in speakup keymaps

* Fri Jun 21 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Tue Jun 11 2002 Nalin Dahyabhai <nalin@redhat.com> 1.06-16
- fix incorrect path in console.apps configuration file

* Thu May 30 2002 Bill Nottingham <notting@redhat.com> 1.06-14
- move some more stuff to /bin (unicode_start and dependencies)

* Thu May 23 2002 Tim Powers <timp@redhat.com>
- automated rebuild

* Mon Feb 25 2002 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-12
- Rebuild in new environment

* Wed Jan 30 2002 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-11
- Oops, actually list the pam files in %%files

* Tue Jan 29 2002 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-10
- Add and consolehelper'ify kbdrate

* Tue Jan 29 2002 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-9
- Re-remove kbdrate

* Thu Jan 24 2002 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-7
- Fix build in current environment
- Get rid of kbdrate, it's in util-linux these days

* Wed Jul 18 2001 Matt Wilson <msw@redhat.com>
- added a patch (Patch4) that allows --tty= in setfont
- modified patch not to break translations

* Tue Jul  3 2001 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-4
- Add cyrillic patches from leon@geon.donetsk.ua (#47144)

* Tue Jun 26 2001 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-3
- Fix "Alt+AltGr=Compose" in qwertz-keyboards

* Mon Jun 25 2001 Bernhard Rosenkraenzer <bero@redhat.com> 1.06-2
- Fix "make install" and init script (#45327)

* Sat Jun 16 2001 Than Ngo <than@redhat.com>
- update to 1.0.6
- use %%{_tmppath}
- use find_lang
- support new gettext
- remove some patch files, which are included in 1.0.6
- fix to use RPM_OPT_FLAGS

* Thu May  3 2001 Bernhard Rosenkraenzer <bero@redhat.com> 1.05-3
- Fix up resizecons

* Wed May  2 2001 Bernhard Rosenkraenzer <bero@redhat.com> 1.05-2
- Build everything, obsoletes console-tools
- s/Copyright:/License:/
- License is GPL, not just distributable
- Add our compose mappings from old console-tools
- Add triggerpostun -- console-tools magic to get sane fonts and mappings

* Tue Apr 17 2001 Erik Troan <ewt@redhat.com>
- initial packaging for kbdrate
