summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 50b2d79f46aaf64bebbf401cd48e8d8599bf100a (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
# Maintainer: William Gathoye <william + aur at gathoye dot be>
# Contributor: Jameson Pugh <imntreal at gmail dot com>

pkgname=python-pocketsphinx-git
pkgbase=python-pocketsphinx-git
pkgname=('python-pocketsphinx-git' 'python2-pocketsphinx-git' 'sphinxbase-git' 'pocketsphinx-git')
pkgver=r185.769492d
pkgrel=2
pkgdesc='Python interface to CMU SphinxBase and PocketSphinx libraries'
arch=('i686' 'x86_64')
url='https://github.com/bambocher/pocketsphinx-python'
license=('BSD')
depends=('python' 'swig')
makedepends=('git' 'python' 'python2')
# The Python bindings to pocketsphinx are made by bambocher. Dependencies are
# stored as git submodules and are maintained by the CMU Sphinx project.
source=(
    'python-pocketsphinx::git+https://github.com/bambocher/pocketsphinx-python.git'
    'pocketsphinx::git+https://github.com/cmusphinx/pocketsphinx.git'
    'sphinxbase::git+https://github.com/cmusphinx/sphinxbase.git'
)
sha512sums=('SKIP' 'SKIP' 'SKIP')
_gitname='python-pocketsphinx'

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

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

    git submodule init
    git config submodule.deps/pocketsphinx.url ${srcdir}/pocketsphinx
    git config submodule.deps/sphinxbase.url ${srcdir}/sphinxbase
    git submodule update

    # We want a python2 package as well. Let's copy the sources.
    cd "${srcdir}"
    cp -rf "${_gitname}" python2-pocketsphinx-git
}

build() {
    cd "${srcdir}/${_gitname}/deps/sphinxbase"
    ./autogen.sh --prefix=/usr
    make

    cd "${srcdir}/${_gitname}/deps/pocketsphinx"
    ./autogen.sh --prefix=/usr
    make

    cd "${srcdir}/${_gitname}"
    python setup.py build

    export PYTHON=/usr/bin/python2

    cd "${srcdir}/python2-pocketsphinx-git/deps/sphinxbase"
    ./autogen.sh --prefix=/usr --libdir=/garbage --bindir=/garbage --includedir=/garbage --datarootdir=/garbage
    make

    cd "${srcdir}/python2-pocketsphinx-git/deps/pocketsphinx"
    ./autogen.sh --prefix=/usr --libdir=/garbage --bindir=/garbage --includedir=/garbage --datarootdir=/garbage
    make

    cd "${srcdir}/python2-pocketsphinx-git"
    python2 setup.py build
}

package_sphinxbase-git() {
    provides=('sphinxbase')
    conflicts=('sphinxbase')

    cd "${srcdir}/${_gitname}/deps/sphinxbase"
    export PYTHON=/usr/bin/python
    make DESTDIR="${pkgdir}/" install

    pythonVersion="$(python -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')"
    rm -f "${pkgdir}/usr/lib/python${pythonVersion}/site-packages/sphinxbase/__init__.py"
    rm -f "${pkgdir}/usr/lib/python${pythonVersion}/site-packages/sphinxbase/sphinxbase.py"
    rm -rf "${pkgdir}/usr/lib/python${pythonVersion}/site-packages/sphinxbase/__pycache__"
}

package_pocketsphinx-git() {
    provides=('pocketsphinx')
    conflicts=('procketsphinx')
    depends=('sphinxbase')

    # Pocketsphinx needs libpocketsphinx which is located in the other package
    # (sphinxbase). Copy the libs temporarily just to allow linking. Then
    # remove them.
    mkdir -p "${pkgdir}/usr/lib"
    cd "${pkgdir}/../sphinxbase-git"
    files=""
    for i in usr/lib/*.so*; do
        files+="$i "
        cp "$i" "${pkgdir}/usr/lib"
    done

    cd "${srcdir}/${_gitname}/deps/pocketsphinx"
    export PYTHON=/usr/bin/python
    make DESTDIR="${pkgdir}/" install

    for i in $files; do
        rm "${pkgdir}/$i"
    done
    pythonVersion="$(python -c 'import sys; print(str(sys.version_info.major) + "." + str(sys.version_info.minor))')"
    rm -rf "${pkgdir}/usr/lib/python${pythonVersion}/site-packages/sphinxbase"
    rm -f "${pkgdir}/usr/lib/python${pythonVersion}/site-packages/pocketsphinx/__init__.py"
    rm -f "${pkgdir}/usr/lib/python${pythonVersion}/site-packages/pocketsphinx/pocketsphinx.py"
    rm -rf "${pkgdir}/usr/lib/python${pythonVersion}/site-packages/pocketsphinx/__pycache__"
}

package_python-pocketsphinx-git() {
    cd "${srcdir}/${_gitname}"

    export PYTHON=/usr/bin/python
    python setup.py install --root="${pkgdir}/" --optimize=1
}

package_python2-pocketsphinx-git() {
    export PYTHON=/usr/bin/python2

    cd "${srcdir}/python2-pocketsphinx-git/deps/sphinxbase"
    make DESTDIR="${pkgdir}/" install

    cd "${srcdir}/python2-pocketsphinx-git/deps/pocketsphinx"
    make DESTDIR="${pkgdir}/" install

    cd "${srcdir}/python2-pocketsphinx-git"
    python2 setup.py install --root="${pkgdir}/" --optimize=1

    rm -rf "${pkgdir}/garbage"
}