summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: b1b01432032c4da89e4bc12cf3ad1550649bae36 (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
# Maintainer: TimWcx <timwcx#qq.com>

_pkgbase=rime-frost
pkgname=${_pkgbase}-git
pkgver=r210.1daf5e1
pkgrel=1
pkgdesc="Rime 配置:白霜词库 | 蒹葭苍苍,白露为霜。基于雾凇拼音重制的,更纯净、词频准确、智能的词库。"
arch=("any")
url="https://github.com/gaboolic/rime-frost"
license=("GPL-3.0-or-later")
depends=("lua" "librime")
makedepends=("git" "rime-prelude" "sed")
conflicts=(
  rime-luna-pinyin
  rime-emoji
  rime-ice-git
  rime-ice-pinyin-git
  rime-ice-double-pinyin-git
  rime-ice-double-pinyin-abc-git
  rime-ice-double-pinyin-mspy-git
  rime-ice-double-pinyin-sogou-git
  rime-ice-double-pinyin-flypy-git
  rime-ice-double-pinyin-ziguang-git
)
provides=(rime-luna-pinyin)
source=("${_pkgbase}::git+${url}.git" "package.patch")
sha512sums=("SKIP" 
be94577ee610847ecb17aa1a22d4341bb124dd1b50a89a06b512e9b16370340e16284268985bebec7472482a9ee8e3b24a84a066829877d8e9e8307d69b6eb0e)

_schemas=(
  rime_frost
  double_pinyin
  double_pinyin_abc
  double_pinyin_mspy
  double_pinyin_sogou
  double_pinyin_flypy
  double_pinyin_ziguang
)

pkgver() {
  cd "${_pkgbase}" &&
    printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

_suggestion=${_pkgbase//-/_}_suggestion.yaml

prepare() {
  cd "${_pkgbase}" &&
    mv ./default.yaml "./${_suggestion}" &&
    # Link essentials.
    for _f in $(pacman -Qql rime-prelude | grep -v "/$"); do ln -sf "$_f" .; done &&
    patch --forward --strip=1 --input="../package.patch"
}

build() {
  cd "${_pkgbase}" || return

  _schemas_deps=()
  for _s in "${_schemas[@]}"; do
    _deps=()
    mapfile -t _deps <<< "$(sed -n '/dependencies:/,/^$/ {/dependencies:/d; /^$/d; s/.*- *//g; s/ *#.*//g; p }' "$_s.schema.yaml")"
    _schemas_deps=("${_schemas_deps[@]}" "${_deps[@]}")
  done

  mapfile -t _schemas_deps <<< "$(printf "%s\n" "${_schemas_deps[@]}" | sort -u)"
  # build current schema and it's depends only, sort by length
  _compile_schemas=("${_schemas_deps[@]}" "${_schemas[@]}")

  for _s in "${_compile_schemas[@]}"; do rime_deployer --compile "$_s.schema.yaml"; done

  # comment ignore schemas
  _suggestion_schemas=$(sed -n '/^schema_list:/,/^$/ {/^schema_list:/d; /^\s*#.*$/d; /^$/d; s/.*schema:\s*//g; s/\s*#.*//g; p }' "$_suggestion")

  for _s in $_suggestion_schemas; do
    if [[ ! ${_schemas[*]} =~ (^|[[:space:]])"$_s"($|[[:space:]]) ]]; then
      sed -i "s/^\s*- schema: $_s .*\$/#&/" "$_suggestion";
    fi
  done

  find . -type l -delete
}

package() {
  cd "${_pkgbase}" || return

  _install_base="$pkgdir/usr/share/rime-data"

  install -Dm644 "$_suggestion"       -t "$_install_base/"
  install -Dm644 ./build/*.{bin,yaml} -t "$_install_base/build"

  [ -f "./rime.lua" ] && install -Dm644 ./rime.lua -t "$_install_base/"
  find lua -type f -exec sh -c 'install -Dm644 "$1" -t '"$_install_base"'/$(dirname $1)' shell {} \;

  for _f in *.schema.yaml; do
    if [ -f "build/$_f" ]; then
      install -Dm644 "$_f" -t "$_install_base/"

      grep -q "opencc_config: emoji.json" "$_f" &&
        install -Dm644 ./opencc/* -t "$_install_base/opencc/"
    fi
  done

  for _f in *.dict.yaml; do
    if [ -f "build/${_f/.dict.yaml/}.table.bin" ]; then
      install -Dm644 "$_f" -t "$_install_base/"
    fi
  done

  for _f in */*.dict.yaml; do
    if grep -q "\- ${_f/.dict.yaml/}" "$_install_base/"*.dict.yaml; then
      install -Dm644 "$_f" -t "$_install_base/$(dirname "$_f")"
    fi
  done

  for _f in *.yaml; do
    if grep -q "${_f/.yaml/:}" build/*.schema.yaml; then
      install -Dm644 "$_f" -t "$_install_base/"
    fi
  done
}