Skip to content

Instantly share code, notes, and snippets.

@ayghri
Last active April 30, 2019 18:12
Show Gist options
  • Save ayghri/f0e4745b2195dbfeb1639ae4cc952611 to your computer and use it in GitHub Desktop.
Save ayghri/f0e4745b2195dbfeb1639ae4cc952611 to your computer and use it in GitHub Desktop.
AUR - Openfst for python3.7 on Arch Linux
# Maintainer: Ayoub Ghriss <[email protected]>
# Save file in folder as PKGBUILD and run "makepkg -si" in the same folder
# Works for Python3.7 on Arch, for other versions, change the Vim replacement line to corresponding folders
pkgname=openfst
pkgver=1.7.2
pkgrel=1
pkgdesc='Library for constructing, combining, optimizing, and searching weighted finite-state transducers (FSTs)'
arch=(i686 x86_64)
url='http://www.openfst.org'
license=(Apache)
depends=(gcc-libs glibc python2 graphviz vim)
options=(!libtool)
source=(http://www.openfst.org/twiki/pub/FST/FstDownload/$pkgname-$pkgver.tar.gz)
sha1sums=(61dc891dd528a4d2a4e1a9ec9e504b5ecac0d509)
sha256sums=(21c3758ff8574dedaf22b0a6b88c2829bbf3b2e59fbf04740ce2cf92029a0f3b)
build() {
cd $srcdir/$pkgname-$pkgver
# Options according to http://openfst.cs.nyu.edu/twiki/bin/view/FST/ReadMe
OPTIONS='--prefix=/usr --disable-dependency-tracking'
OPTIONS+=' --enable-bin' # Enable fst::script and command-line binaries; Default: yes
OPTIONS+=' --enable-compact-fsts' # Enable all CompactFst classes; Default: no
OPTIONS+=' --enable-compress' # Enable compression extension; Default: no
OPTIONS+=' --enable-const-fsts' # Enable all ConstFst classes; Default: no
OPTIONS+=' --enable-far' # Enable FAR (FST Archive) extension; Default: no
OPTIONS+=' --enable-linear-fsts' # Enable Linear{Tagger,Classifier}Fst extensions; Default: no
OPTIONS+=' --enable-lookahead-fsts' # Enable LookAheadFst classes; Default: no
OPTIONS+=' --enable-mpdt' # Enable MPDT extensions; Default: no
OPTIONS+=' --enable-ngram-fsts' # Enable NGramFst extensions; Default: no
OPTIONS+=' --enable-pdt' # Enable PDT extensions; Default: no
OPTIONS+=' --enable-python PYTHON=python2' # Enable Python extensions; Default: no
pip install cython --user
pushd ./src/extensions/python/
mv pywrapfst.cc pywrapfst.cc.py2bkup
vim -c ":1755" -c ':s/"write/b"write' -c ":wq" pywrapfst.pyx
cython -f --cplus -3 pywrapfst.pyx -o pywrapfst.cc
popd
LIBS=-ldl ./configure $OPTIONS
vim -c ":%s/PYTHON_CPPFLAGS = -I\/usr\/include\/python2.7/PYTHON_CPPFLAGS = -I\/usr\/include\/python3.7m/" -c ":%s/PYTHON_LDFLAGS = -L\/usr\/lib\/python2.7 -lpython2.7/PYTHON_LDFLAGS = -L\/usr\/include\/python3.7/" -c ":%s/PYTHON_SITE_PKG = \/usr\/lib\/python2.7/PYTHON_SITE_PKG = \/usr\/lib\/python3.7\/site-packages/" -c ":%s/PYTHON_VERSION = 2.7/PYTHON_VERSION = 3.7/" -c ":%s/lib\/python2.7\/dist-packages/lib\/python3.7\/dist-packages/" -c ":wq" ./src/extensions/python/Makefile
make
}
package() {
cd $srcdir/$pkgname-$pkgver
make DESTDIR=$pkgdir install
install -d $pkgdir/etc/ld.so.conf.d/
echo /usr/lib/fst > $pkgdir/etc/ld.so.conf.d/openfst.conf
}
@ayghri
Copy link
Author

ayghri commented Apr 30, 2019

Works for Python3.7 on Arch, for other versions, change the Vim replacement line to corresponding folders.
For Ubuntu for example, Python libraries folder has slightly different location, for python 3.5:
vim -c ":%s/PYTHON_CPPFLAGS = -I\/usr\/include\/python2.7/PYTHON_CPPFLAGS = -I\/usr\/include\/python3.5m/" -c ":%s/PYTHON_LDFLAGS = -L\/usr\/lib\/python2.7 -lpython2.7/PYTHON_LDFLAGS = -L\/usr\/include\/python3.5/" -c ":%s/PYTHON_SITE_PKG = \/usr\/lib\/python2.7/PYTHON_SITE_PKG = \/usr\/local\/lib\/python3.5\/site-packages/" -c ":%s/PYTHON_VERSION = 2.7/PYTHON_VERSION = 3.5/" -c ":%s/lib\/python2.7\/dist-packages/lib\/python3.5\/dist-packages/" -c ":wq" ./src/extensions/python/Makefile

See this gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment