summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: ffec8552fcd0d03531d7763fb90d58595d0a830f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Maintainer: dreieck

_pkgname=keyboardlayouteditor
pkgname="${_pkgname}"-git
pkgver=1.1+r100.20190121.56726a3
pkgrel=4
epoch=1
pkgdesc="PyGTK programme that helps create or edit XKB keyboard layouts."
arch=('any')
# url="http://github.com/simos/keyboardlayouteditor" # Original repo.
url="http://github.com/hupfdule/keyboardlayouteditor" # Fork with some fixes.
license=('GPL3')
# To run the application, you need the python UI binding packages. For Ubuntu 14.04, the packages below are already pre-installed.
# * Cairo
# * Pango
# * GObject
# * lxml
depends=(
  'pygtk'
  'python2'
  #'python2-antlr3=3.1.2'
  'python2-antlr3-3.1.2'
  'python2-cairo'
  'python2-gobject2'
  'python2-lxml'
)
makedepends=(
  #'antlr3=3.1.2'
  'antlr3-3.1.2'
  'git'
)
optdepends=(
  'gucharmap: To open a character map and drag and drop characters.'
)
provides=(
  "${_pkgname}=${pkgver}"
)
source=(
  # "${_pkgname}::git+https://github.com/simos/${_pkgname}.git" # Original repo.
  "${_pkgname}::git+https://github.com/hupfdule/${_pkgname}.git" # Fork with some fixes.
  "keyboardlayouteditor.sh"
)
sha256sums=(
  "SKIP"
  "349b12f237a19f76af16082d58bf443892190faa5f741aced92e10f6e79d8761"
)

_cmd() {
  # Prints out what to be run to stdout, and then executes it.
  # The command and it's arguments is passed as argument(s).

  printf '%s' '> '; cat <<< "$@"
  "$@"
}

pkgver() {
  cd "${srcdir}/${_pkgname}"

  _ver="$(grep '__version__' KeyboardLayoutEditor | tail -n 1 | awk -F '=' '{print $2}' | tr -d "[[:space:]]'\"")"
  _date="$(git log -n 1 --format=tformat:%ci | awk '{print $1}' | tr -d '-')"
  _rev="$(git rev-list --count HEAD)"
  _githash="$(git rev-parse --short HEAD)"

  if [ -z "${_ver}" ]; then
    msg2 "Error in 'pkgver()': Could not determine version."
    return 11
  fi
  if [ -z "${_date}" ]; then
    msg2 "Error in 'pkgver()': Could not determine latest commit date."
    return 11
  fi
  if [ -z "${_rev}" ]; then
    msg2 "Error in 'pkgver()': Could not determine commit count."
    return 12
  fi
  if [ -z "${_githash}" ]; then
    msg2 "Error in 'pkgver()': Could not determine git commit hash."
    return 13
  fi

  echo "${_ver}+r${_rev}.${_date}.${_githash}"
}

prepare() {
  cd "${srcdir}/${_pkgname}"

  msg2 "Creating 'website.url' documentation file ..."
  cat <<< "${url}" > website.url

  msg2 "Creating git commit changelog ..."
  git log --date=iso > ChangeLog-git.txt
}

build() {

  _patch_for_python2() {
    # Arguments: Tiles to check if the shabeng line needs patching.
    # It patches the shabeng-line from 'python' to 'python2', if not already done.

    ls -1 "$@" | while read _f; do
      if head -n1 "${_f}" | grep -Eq '^#!.*python[[:space:]]*$'; then
        _cmd sed -E '1s|python[[:space:]]*$|python2|' -i "${_f}"
      fi
    done
  }

  cd "${srcdir}/${_pkgname}"

  _cmd antlr3 *.g
  # _cmd java -classpath /usr/share/java/antlr-3.1.2.jar org.antlr.Tool *.g

  ### This takes too long, since each call of 'antlr3' starts a java environment. Use the 'antlr3 *.g'-call instead.
  # ls -1 *.g | while read _g; do
  #   _cmd antlr3 "${_g}"
  # done

  _patch_for_python2 *.py KeyboardLayoutEditor


  _cmd cd utils
  _cmd antlr3 *.g

  _patch_for_python2 *.py
}

package() {
  _instbase="/opt/${_pkgname}"
  _instdir="${pkgdir}/${_instbase}"

  cd "${srcdir}/${_pkgname}"

  _cmd install -d -m755 "${_instdir}"

  _cmd cp -a * "${_instdir}/"
  _cmd rm -Rf "${_instdir}"/{.[a-zA-Z0-9_]*,utils/*.g,*.g,COPYING,README.md,TODO}

  _cmd install -D -m755 "${srcdir}/keyboardlayouteditor.sh" "${pkgdir}/usr/bin/keyboardlayouteditor"

  for _docfile in 'ChangeLog-git.txt' 'README.md' 'TODO' 'screenshot.png' 'website.url'; do
    _cmd install -D -m644 "${_docfile}" "${pkgdir}/usr/share/doc/${_pkgname}/${_docfile}"
  done

  _cmd install -D -m644 'COPYING' "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}