summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 01c0caa671ed6898046f8a0cb1b1a2cdc005313c (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# Maintainer:  dreieck (https://aur.archlinux.org/account/dreieck)

_gitname="meshcore-open"
_pkgname="${_gitname}"
pkgname="${_pkgname}-git"
pkgver=alpha9+217.r962.20260903.dbd7f2aa
pkgrel=2
pkgdesc="Open-source Flutter client for MeshCore LoRa mesh networking devices."
groups=('meshcore')
arch=(
  'i686'
  'x86_64'
  'aarch64'
)
_githost='github.com'
_gituser='zjs81'
url="https://${_githost}/${_gituser}/${_gitname}"
license=("MIT")
depends=(

  # glib2
  libglib-2.0.so
  libgio-2.0.so
  libgobject-2.0.so

  # gtk3
  libgdk-3.so
  libgtk-3.so

  glibc
  libgcc_s.so
  libatk-1.0.so  # at-spi2-core
  libfontconfig.so
  libstdc++.so
  libcairo.so
  libepoxy.so
  libpango-1.0.so
  libpangocairo-1.0.so
)
makedepends=(
  # To retrieve the source:
  'git'

  # Used for packaging
  'cmake'
  'ninja'

  ## Flutter and dart recommendations:
  # 
  #  Recommended in 2026-09:
  #  Use aur/flutter-bin (https://aur.archlinux.org/packages/flutter-bin) or chaotic-aur/flutter-bin (https://aur.chaotic.cx/ | https://aur.chaotic.cx/stats/search?search=flutter-bin | https://builds.garudalinux.org/repos/chaotic-aur/x86_64/#:~:text=flutter-bin).
  # 
  #  Recommended in beginning of 2026:
  #  Use 'arch4edu' repository (https://wiki.archlinux.org/title/Unofficial_user_repositories#arch4edu).
  #  This later errored out with "Wrong full snapshot version, expected '0451907c2eaa8467e848c0067bfe8ed4' found '78da37fed6bf1489361a312568249f3f'" or so.
  'flutter-tool'         # >=3.41. # Should be a versioned dependency, but not specifying now since `flutter-bin` does not has a versioned provides entry as of 2026-09-05, see https://aur.archlinux.org/packages/flutter-bin#comment-1084386.
  'dart'                 # >=3.11. # Should be a versioned dependency, but not specifying now since `flutter-bin` does not has a versioned provides entry as of 2026-09-05, see https://aur.archlinux.org/packages/flutter-bin#comment-1084386.
  # the Flutter linux files
  'flutter-target-linux' # >=3.41. # Should be a versioned dependency, but not specifying now since `flutter-bin` does not has a versioned provides entry as of 2026-09-05, see https://aur.archlinux.org/packages/flutter-bin#comment-1084386.

  # dependency libraries
  'glib2'
  'gtk3'
  'libgcc'
  'at-spi2-core'
  'fontconfig'
  'libstdc++'
  'cairo'
  'libepoxy'
  'pango'

  ## To reduce the size of PNG images
  #'parallel'
  #'zopfli'
)
optdepends=(
  'hicolor-icon-theme: For hicolor theme hierarchy.'
)
provides=(
  "${_pkgname}=${pkgver}"
)
conflicts=(
  "${_pkgname}"
)

source=(
  "${_pkgname}::git+https://${_githost}/${_gituser}/${_gitname}.git"
  "flserial_once_flag_fix.patch::https://github.com/MeshEnvy/flserial/pull/1.patch"
  "${_pkgname}.desktop"
)
sha256sums=(
  'SKIP'                                                              # Main 'meshcore-open' source.
  '0a870e4ca333c53457948cdc6cf31597f090a8291209314c9ac74660d8d8dc08' # 'flserial_once_flag_fix.patch'
  '693903df45168de884191be566334fad4c5bd829b36f7e6c33440cf2efa79c5a'  # '.desktop' file.
)

case "${CARCH}" in
  "i686")
    export _dartarch="x86"
  ;;
  "x86_64")
    export _dartarch="x64"
  ;;
  "aarch64")
    export _dartarch="arm64"
  ;;
  *)
    error "Architecture '$CARCH' not supported."
    false
  ;;
esac


_patch_only_if_not_applied() {
  # Tries to apply a patch and if it already has been applied also return zero exit code.
  # Arguments:
  #   $1: Patch file to apply.
  #   $2...: Other options to patch.
  local _patch="$1"
  shift
  if ! patch --dry-run -R -i "${_patch}" "$@"; then
    printf '%s\n' '   `-> Patch not yet applied, applying ...'
    patch -i "${_patch}" "$@"
  else
    printf '%s\n' '   `-> Patch already applied.'
  fi
}

prepare() {
  cd "${srcdir}/${_pkgname}"
  export PUB_CACHE="${srcdir}/.pub_cache"

  git log > "${srcdir}/git.log"

  printf '%s\n' " --> downloading flutter/ dart dependencies ..."
  flutter -v --disable-analytics
  flutter -v pub get # --enforce-lockfile

  # Patch this after downloading flutter dependencies -- since it patches a dependency:
  local _patch='flserial_once_flag_fix.patch'
  local _flserialdir
  for _flserialdir in "${PUB_CACHE}/git"/flserial-[0-9a-f]*; do
    printf '%s\n' " --> Applying patch '${_patch}' to '${_flserialdir}' ..."
    _patch_only_if_not_applied "${srcdir}/${_patch}" -Np1 --follow-symlinks -d "${_flserialdir}"
  done

  #printf '%s\n' " --> size-optimising PNG images ..."
  #find -name '*.png' -type f | parallel -j "${_nproc}" zopflipng -m -y {} {}
}

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

  #_ver="$(grep -E '^[[:space:]]*version[[:space:]]*=' pyproject.toml  | head -n1 | awk -F= '{print $2}' | tr -d \'\"[[:space:]])"
  _ver="$(git describe --tags | sed -E -e 's|^[vV]||' -e 's|\-g[0-9a-f]*$||' | tr '-' '+' | awk '{ print tolower($0) }')"
  _rev="$(git rev-list --count HEAD)"
  _date="$(git log -1 --date=format:"%Y%m%d" --format="%ad")"
  _hash="$(git rev-parse --short HEAD)"

  if [ -z "${_ver}" ]; then
    error "Version could not be determined."
    return 1
  else
    printf '%s' "${_ver}.r${_rev}.${_date}.${_hash}"
  fi
}

build() {
  cd "${srcdir}/${_pkgname}"
  export PUB_CACHE="${srcdir}/.pub_cache"

  printf '%s\n' " --> building ..."

  # build in release mode without running pub
  flutter -v build linux --no-pub --release
}

check() {
  cd "${srcdir}/${_pkgname}"
  export PUB_CACHE="${srcdir}/.pub_cache"

  printf '%s\n' " --> testing ..."

  flutter -v test
}

package() {
  cd "${srcdir}/${_pkgname}"
  export PUB_CACHE="${srcdir}/.pub_cache"

  printf '%s\n' " --> installing ..."

  # enter the output directory of the Flutter build
  cd "build/linux/${_dartarch}/release"
  cmake . \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${pkgdir}/usr/lib/${_pkgname}
  # install the Flutter project using cmake
  cmake -P cmake_install.cmake

  # link executable into PATH
  install -dvm755 "${pkgdir}/usr/bin"
  ln -sv "/usr/lib/${_pkgname}/meshcore_open" "${pkgdir}/usr/bin/meshcore_open"
  cd "${pkgdir}/usr/bin"
  ln -sv meshcore_open meshcore-open


  printf '%s\n' " --> installing icon and desktop file ..."

  cd "${srcdir}/${_pkgname}"
  install -Dvm644  assets/images/mesh-icon.png    "${pkgdir}/usr/share/icons/hicolor/1024x1024/apps/${_pkgname}.png"
  install -dvm755  "${pkgdir}/usr/share/pixmaps"
  ln -sv "/usr/share/icons/hicolor/1024x1024/apps/${_pkgname}.png"  "${pkgdir}/usr/share/pixmaps/${_pkgname}.png"
  install -Dvm644 "${srcdir}/${_pkgname}.desktop" "${pkgdir}/usr/share/applications/${_pkgname}.desktop"

  _docfiles=(
    "${srcdir}/git.log"
    AGENTS.md
    README.md
    CLAUDE.md
    TESTFLIGHT_GUIDE.md
  )
  _docdirs=(
    assets
    docs
  )
  _manfiles=()
  _infofiles=()
  _licensefiles=(
    LICENSE
  )
  printf '%s\n' " --> installing documentation ..."
  for _docfile in "${_docfiles[@]}"; do
    install -D -v -m644 "${_docfile}" "${pkgdir}/usr/share/doc/${_pkgname}/$(basename "${_docfile}")"
  done
  for _docdir in "${_docdirs[@]}"; do
    cp -rv "${_docdir}" "${pkgdir}/usr/share/doc/${_pkgname}/$(basename "${_docdir}")"
  done
  for _manfile in "${_manfiles[@]}"; do
    _section="$(basename "${_manfile}" .gz | sed -E -e 's|^.*\.([^.]*)$|\1|')"
    install -D -v -m644 "docs/build/man/${_manfile}" "${pkgdir}/usr/share/man/man${_section}/$(basename "${_manfile}")"
  done
  for _infofile in "${_infofiles[@]}"; do
    install -D -v -m644 "${_infofile}" "${pkgdir}/usr/share/info/$(basename "${_infofile}")"
  done
  printf '%s\n' " --> installing license ..."
  for _licensefile in "${_licensefiles[@]}"; do
    install -D -v -m644 "${_licensefile[@]}" "${pkgdir}/usr/share/licenses/${pkgname}/$(basename "${_licensefile}")"
    ln -svr "${pkgdir}/usr/share/licenses/${pkgname}/$(basename "${_licensefile}")" "${pkgdir}/usr/share/doc/${_pkgname}/$(basename "${_licensefile}")"
  done
}

# vim: set sw=2 ts=2 et: