app=kbd
version=2.0.4
build=1sml
homepage="http://ftp.iij.ad.jp/pub/linux/kernel/linux/utils/kbd/"
download="https://ftp.iij.ad.jp/pub/linux/kernel/linux/utils/kbd/kbd-$version.tar.xz"
desc="utility to change console fonts and keyborad mappings"
requires="busybox"

build() {
  mkandenterbuilddir
  rm -rf $app-$version

  tar xf $srcdir/$app-$version.tar.?z*
  cd $app-$version
  fixbuilddirpermissions

  cp $srcdir/config.h src/
  cp $srcdir/config.h src/libkeymap/
  sed -i 's/progname/prgname/g' src/loadkeys.c

  gcc -Isrc -Isrc/libkeymap src/libkeymap/common.c \
   src/libkeymap/findfile.c src/libkeymap/array.c \
   src/libkeymap/parser.c src/libkeymap/analyze.c \
   src/libkeymap/func.c src/libkeymap/kmap.c \
   src/libkeymap/diacr.c src/libkeymap/ksyms.c \
   src/libkeymap/dump.c src/libkeymap/loadkeys.c \
   src/libkeymap/modifiers.c \
   src/kbd_error.c src/getfd.c \
   src/loadkeys.c -o loadkeys

  # generate busybox loadkmap compatible keymaps from the gnu ones
  # taken from http://hg.slitaz.org/wok/file/3f989c266063/kbd-busybox/receipt

  mkdir -p "$pkg"/share/kmap
  for i in $(cat $srcdir/keymaps) ; do
	k=$(basename $i)
	k=${k%.map} # strips off .map from $k
	./loadkeys -b -q data/keymaps/i386/$i > "$pkg"/share/kmap/$k.kmap || echo "Error loadkeys...$i"
  done

  install -Dm 755 $srcdir/loadkeys $pkg/bin/loadkeys

  cp COPYING $pkgdocs/

  mkfinalpkg
}

sha512sums="
5e264b3695b0af0bc85e0a4fa2c43e13648d8ea82102f3b051c28da2abfc52977577c470bce48f30cec9b0d215297e48c9b05e00561c990e3770fb68f6544e0f  kbd-2.0.4.tar.xz
ef992b2e7b7ac30b19ed22a6e263d09a6711f7aba2e473a70586c7aa48df8eac9846cef1a490c49de330123e7070e77ffb8b469d4a78b930ca0f72b134b204d1  config.h
"
