summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 85577f3c3e8516aebd4cf28fe5348da17a1849d3 (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
# Maintainer: Gegrely Imreh <imrehg@gmail.com>

pkgname=edgetpu_api
pkgver=2.11.1
pkgrel=1
pkgdesc='Google Coral Edge TPU runtime and Python library'
arch=('x86_64' 'aarch64' 'armv7h')
url='https://coral.withgoogle.com/'
license=('Apache')
options=(!strip)
depends=('python' 'python-pip' 'python-pillow' 'python-numpy' 'libunwind' 'libc++')
source=("https://dl.google.com/coral/${pkgname}/${pkgname}_${pkgver}.tar.gz")
md5sums=('b9f38b4322da647e2ec460126750bf80')
sha256sums=('6067fcc921423c3dc23e1bc12186e42ff954eada50b44826b2167700b50dc69e')

package() {

  install -Dm644 "${srcdir}/${pkgname}/99-edgetpu-accelerator.rules" \
    "${pkgdir}/usr/lib/udev/rules.d/99-edgetpu-accelerator.rules"

  case $CARCH in
    x86_64)
      LIBEDGETPU_SUFFIX=x86_64
      libfile="libedgetpu_x86_64.so"
      SWIG_ARCH=x86_64
      ;;
    aarch64)
      LIBEDGETPU_SUFFIX=arm64
      libfile="libedgetpu_arm64.so"
      SWIG_ARCH=aarch64
      ;;
    armv7h)
      LIBEDGETPU_SUFFIX=arm32
      libfile="libedgetpu_arm32.so"
      SWIG_ARCH=arm
      ;;
  esac
  LIBEDGETPU_SRC="${srcdir}/${pkgname}/libedgetpu/libedgetpu_${LIBEDGETPU_SUFFIX}.so"
  LIBEDGETPU_DST="${pkgdir}/usr/lib/libedgetpu.so.1.0"
  install -Dm755 "${LIBEDGETPU_SRC}" "${LIBEDGETPU_DST}"

  python -m pip install --no-cache-dir --no-compile --no-deps --ignore-installed --root="${pkgdir}" "${srcdir}/${pkgname}/edgetpu-${pkgver}-py3-none-any.whl"

  # Architecture cleanup and symlinking for relevant Python versions
  python_versions=( "36m" "37m" )
  find "${pkgdir}/usr/lib/" -name "_edgetpu_cpp_wrapper.*.so"|while read wrapperfile; do
    wrapperfilename=$(basename "$wrapperfile")
    wrapperdirname=$(dirname "$wrapperfile")
    if [ -n "${wrapperfilename##*$SWIG_ARCH*}" ]; then
      rm $wrapperfile
    else
      for version in "${python_versions[@]}" ; do
        testfile="${wrapperfilename/3[5-7]m/$version}"
        if [ "$wrapperfilename" = "$testfile" ]; then
          continue
        elif [ -f "$wrapperdirname/$testfile" ]; then
          break
        else
          msg "Creating link: $wrapperfilename -> $testfile"
          ln -s "$wrapperfilename" "$wrapperdirname/$testfile"
        fi
      done
    fi
  done

}