Skip to content

Commit 71f83af

Browse files
committed
FreeBSD build script and patches
1 parent 9d94746 commit 71f83af

File tree

3 files changed

+160
-3
lines changed

3 files changed

+160
-3
lines changed

c/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ LDFLAGS=-L../src -lvosk -ldl -lpthread -Wl,-rpath=../src
44
all: test_vosk test_vosk_speaker
55

66
test_vosk: test_vosk.o
7-
g++ $^ -o $@ $(LDFLAGS)
7+
$(CXX) $^ -o $@ $(LDFLAGS)
88

99
test_vosk_speaker: test_vosk_speaker.o
10-
g++ $^ -o $@ $(LDFLAGS)
10+
$(CXX) $^ -o $@ $(LDFLAGS)
1111

1212
%.o: %.c
13-
g++ $(CFLAGS) -c -o $@ $<
13+
$(CC) $(CFLAGS) -c -o $@ $<
1414

1515
clean:
1616
rm -f *.o *.a test_vosk test_vosk_speaker

misc/freebsd_build.sh

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# freebsd 12.3 vosk-api build
2+
3+
echo '
4+
Build Vosk-API for FreeBSD 12.3 (and possibly later too).
5+
6+
Please review this script before executing. A number of packages
7+
will be installed, and some soft links made in /bin and /usr/local/{bin,lib}.
8+
9+
Expect 20-120 minutes to build everything. Sudo is required for installing
10+
packages and making soft links.
11+
12+
Press ^c to exit, or return to start building.
13+
'
14+
read junk
15+
16+
set -ex
17+
18+
# pkgs required
19+
sudo pkg install git cmake gmake libtool automake autoconf autotools \
20+
libatomic_ops gsed python38 py38-setuptools py38-wheel py38-pip-run \
21+
wget bash curl sox
22+
23+
24+
# required:
25+
# skullduggery soft links to make build run smoother and less patching
26+
sudo ln -s /usr/local/lib/libatomic_ops.a /usr/lib/libatomic.a
27+
sudo ln -s /usr/local/bin/bash /bin/bash
28+
sudo ln -s /usr/local/bin/gmake /usr/local/bin/make
29+
sudo ln -s /usr/local/bin/python3.8 /usr/local/bin/python3
30+
# make sure to pick up our soft link first
31+
PATH=/usr/local/bin:$PATH
32+
33+
34+
# create a build dir for everything
35+
mkdir build
36+
cd build
37+
BUILD_ROOT=$PWD
38+
39+
40+
# from here, mostly from vosk-api/travis/Dockerfile.manylinux
41+
# sed and patch used to include FreeBSD as supported OS and to make minor adjustments
42+
43+
git clone https://github.com/alphacep/vosk-api.git
44+
git clone -b vosk --single-branch https://github.com/alphacep/kaldi
45+
46+
# Build kaldi tools
47+
cd $BUILD_ROOT/kaldi/tools
48+
git clone -b v0.3.13 --single-branch https://github.com/xianyi/OpenBLAS
49+
git clone -b v3.2.1 --single-branch https://github.com/alphacep/clapack
50+
51+
gmake -C OpenBLAS ONLY_CBLAS=1 DYNAMIC_ARCH=1 TARGET=NEHALEM USE_LOCKING=1 USE_THREAD=0 all
52+
gmake -C OpenBLAS PREFIX=$PWD/OpenBLAS/install install
53+
54+
mkdir -p clapack/BUILD && cd clapack/BUILD && cmake .. && gmake -j 10 && cp `find . -name "*.a"` ../../OpenBLAS/install/lib
55+
56+
cd $BUILD_ROOT/kaldi/tools
57+
git clone --single-branch https://github.com/alphacep/openfst openfst
58+
cd openfst
59+
autoreconf -i
60+
CFLAGS="-g -O3" ./configure --prefix=$BUILD_ROOT/kaldi/tools/openfst --enable-static --enable-shared --enable-far --enable-ngram-fsts --enable-lookahead-fsts --with-pic --disable-bin
61+
gmake -j 10
62+
gmake install
63+
64+
65+
# Build kaldi main
66+
cd $BUILD_ROOT/kaldi/src
67+
68+
# PATCH: Allow FreeBSD in ./configure
69+
cp configure configure.bak
70+
sed -i -e 's/"`uname`" == "Linux"/"`uname`" == "Linux" -o "`uname`" == "FreeBSD" /' configure
71+
./configure --mathlib=OPENBLAS_CLAPACK --shared --use-cuda=no
72+
gsed -i 's:-msse -msse2:-msse -msse2:g' kaldi.mk
73+
gsed -i 's: -O1 : -O3 :g' kaldi.mk
74+
75+
# PATCH: Allow FreeBSD in default_rules.mk
76+
cp makefiles/default_rules.mk makefiles/default_rules.mk.bak
77+
patch -d makefiles <<'EOF'
78+
*** makefiles/default_rules.mk.bak Mon Feb 14 16:56:09 2022
79+
--- makefiles/default_rules.mk Mon Feb 14 16:57:30 2022
80+
***************
81+
*** 21,26 ****
82+
--- 21,32 ----
83+
endif
84+
LDFLAGS += -Wl,-rpath=$(shell readlink -f $(KALDILIBDIR))
85+
EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))lib$(notdir $(basename $(dep))).so)
86+
+ else ifeq ($(shell uname), FreeBSD)
87+
+ ifdef LIBNAME
88+
+ LIBFILE = lib$(LIBNAME).so
89+
+ endif
90+
+ LDFLAGS += -Wl,-rpath=$(shell readlink -f $(KALDILIBDIR))
91+
+ EXTRA_LDLIBS += $(foreach dep,$(ADDLIBS), $(dir $(dep))lib$(notdir $(basename $(dep))).so)
92+
else # Platform not supported
93+
$(error Dynamic libraries not supported on this platform. Run configure with --static flag.)
94+
endif
95+
***************
96+
*** 48,53 ****
97+
--- 54,63 ----
98+
$(CXX) -dynamiclib -o $@ -install_name @rpath/$@ $(LDFLAGS) $(OBJFILES) $(LDLIBS)
99+
ln -sf $(shell pwd)/$@ $(KALDILIBDIR)/$@
100+
else ifeq ($(shell uname), Linux)
101+
+ # Building shared library from static (static was compiled with -fPIC)
102+
+ $(CXX) -shared -o $@ -Wl,--as-needed -Wl,-soname=$@,--whole-archive $(LIBNAME).a -Wl,--no-whole-archive $(LDFLAGS) $(LDLIBS)
103+
+ ln -sf $(shell pwd)/$@ $(KALDILIBDIR)/$@
104+
+ else ifeq ($(shell uname), FreeBSD)
105+
# Building shared library from static (static was compiled with -fPIC)
106+
$(CXX) -shared -o $@ -Wl,--as-needed -Wl,-soname=$@,--whole-archive $(LIBNAME).a -Wl,--no-whole-archive $(LDFLAGS) $(LDLIBS)
107+
ln -sf $(shell pwd)/$@ $(KALDILIBDIR)/$@
108+
EOF
109+
110+
gmake -j 4 online2 lm rnnlm
111+
112+
113+
114+
# Build vosk-api shared lib
115+
116+
cd $BUILD_ROOT/vosk-api/src
117+
# FreeBSD needs -lexecinfo for python interface
118+
KALDI_ROOT=$BUILD_ROOT/kaldi EXTRA_LDFLAGS='-lexecinfo' gmake
119+
120+
121+
# optional- build and test vosk C interface
122+
cd $BUILD_ROOT/vosk-api/c
123+
gmake
124+
125+
wget https://alphacephei.com/kaldi/models/vosk-model-small-en-us-0.15.zip
126+
unzip vosk-model-small-en-us-0.15.zip
127+
mv vosk-model-small-en-us-0.15 model
128+
cp ../python/example/test.wav .
129+
./test_vosk
130+
131+
# install the python interface
132+
cd $BUILD_ROOT/vosk-api/python
133+
# install python module
134+
sudo python3.8 setup.py install
135+
136+
137+
# test the python interface
138+
cd examples
139+
# wget https://alphacephei.com/kaldi/models/vosk-model-small-en-us-0.15.zip
140+
# or, if you tested the vosk C interface, above, just grab the model.zip from there
141+
cp ../../c/vosk-model-small-en-us-0.15.zip .
142+
unzip vosk-model-small-en-us-0.15.zip
143+
mv vosk-model-small-en-us-0.15 model
144+
145+
python3.8 test_simple.py test.wav
146+
147+
148+
# clean up soft links
149+
sudo rm /usr/lib/libatomic.a
150+
sudo rm /bin/bash
151+
sudo rm /usr/local/bin/make
152+
sudo rm /usr/local/bin/python3
153+
154+
# done
155+

python/vosk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def open_dll():
1313
return _ffi.dlopen(os.path.join(dlldir, "libvosk.dll"))
1414
elif sys.platform == 'linux':
1515
return _ffi.dlopen(os.path.join(dlldir, "libvosk.so"))
16+
elif sys.platform[0:7] == 'freebsd':
17+
return _ffi.dlopen(os.path.join(dlldir, "libvosk.so"))
1618
elif sys.platform == 'darwin':
1719
return _ffi.dlopen(os.path.join(dlldir, "libvosk.dyld"))
1820
else:

0 commit comments

Comments
 (0)