Compiling Voikko With Hfst
Overview
These instructions are based on LibVoikko 3.3 (svn trunk as of r3995) on Snow Leopard (MacOS X 10.6.8). Other systems and older versions of LibVoikko have not been tested!
There are also somewhat older & outdated build instrcuctions on the Voikko home pages. These were made for LibVoikko 2.x on Leopard (MacOS 10.5.x).
If you are looking for usage info, that can be found here.
These installation instructions assume we're using the svn codebase. Start the build process by checking out voikko from svn (this will include Suomimalaga , see below).
svn co https://voikko.svn.sourceforge.net/svnroot/voikko/trunk voikko
Install dependencies
Install the following:
- pkg-config ≥ 0.23 ( sudo port install pkg-config )
- gettext ≥ 0.17 ( sudo port install gettext )
- Malaga
- Suomimalaga - part of the libvoikko checkout, see herefor details
- hfst
- hfst-ospell (see below)
hfst-ospell
hfst-ospell is a speller library (and testing frontent) to use hfst-based transducers as spellers. It is required for the hfst backend for Voikko to work. it is found in your hfst svn checkout in HFSTROOT/hfst-ospell/ .
Install hfst-ospell with the following ./configure options (required to get the libarchive package from MacPorts visible for ./configure ):
CPATH=/opt/local/include:/usr/local/include:/usr/include ./configure CXXFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib"
followed by the usual:
make sudo make install
Install all but the hfst dependencies
Somebody wrote a shell script buildmac.sh to configure and build everything for the Mac in one place, and make it available for inclusion in the LibVoikko build. It was found on the net but has since vanished. A commented and slightly reworked copy is available here).
This shell script assumes all components are installed locally, but it does the job of getting LibVoikko and all its components built. It also requires some manual work on the shell script itself to adapt to the local environment. It might help, but you are on your own :)
The hfst components are not covered by this script, and must be installed separately.
Install LibVoikko
The receipt is the standard one, with one additional flag to turn on support for hfst :
cd voikko/libvoikko ./autogen.sh ./configure --enable-hfst make sudo make install
Installation in other locations using --prefix is not recommended, especially for the dependent components. I have not been able to get it to work.
Gory details - how to compile hfst-ospell and libvoikko as universal binaries
First, ensure that you have universal binaries of the things that both hfst-ospell and libvoikko depends on (specify the +universal option in MacPorts). For hfst-ospell that means the following libraries (some of these might be on your system already, just check that they are universal binaries):
- libarchive
- liblzma
- libxml2
- libz
- libiconv
- libcrypto
Check the architecture of the installed libraries
To check that they really are universal, first get a list of which installed libraries hfst-ospell is dependent on:
$ otool -L /usr/local/lib/libhfstospell.1.dylib
Then, for each library in that list, use the following command:
$ file /usr/local/lib/libhfstospell.1.dylib /usr/local/lib/libhfstospell.1.dylib: Mach-O universal binary with 2 architectures /usr/local/lib/libhfstospell.1.dylib (for architecture i386): Mach-O dynamically linked shared library i386 /usr/local/lib/libhfstospell.1.dylib (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
For those libraries that give the above output, all is fine. But if you get a message that there is only one architecture for a library, you have to recompile and reinstall that library as a universal binary.
Build hfst-ospell as a universal binary
Next, configure and make hfst-ospell using the following options (the text is linewrapped here for readability, all commands should be on one line):
# If you have run make before, run make distclean just to ensure you start from scratch: make distclean # HFST-ospell, working univ. binary config: CPATH=/opt/local/include:/usr/local/include:/usr/include ./configure \ CFLAGS=" -arch i386 -arch x86_64" CXXFLAGS=" -arch i386 -arch x86_64 -I/opt/local/include" \ CPPFLAGS="-I/usr/local/include -I/opt/local/include" \ CFLAGS="-I/usr/local/include -I/opt/local/include \ -L/usr/local/lib -L/opt/local/lib -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LDFLAGS=" -arch i386 -arch x86_64 -L/opt/local/lib" --enable-static \ --disable-dependency-tracking --disable-shared # HFST-ospell, working univ. binary make: make CFLAGS="-I/usr/local/include -L/usr/local/lib -isysroot /Developer/SDKs/MacOSX10.5.sdk \ -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LINK="gcc -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64" \ LDFLAGS="-framework CoreFoundation -framework Cocoa" # Finaly, install the binaries: sudo make install CFLAGS="-I/usr/local/include -L/usr/local/lib -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LINK="gcc -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64" \ LDFLAGS="-framework CoreFoundation -framework Cocoa"
It is possible that these can be simplified a bit, but at least they work. Please note that --disable-dependency-tracking is required when configuring for a universal binary!
If you want to build hfst-ospell as a static library (e.g. as part of another component made for external distribution), there are a couple of changes. First, copy the following files to a separate dir (I have used /Users/sjur/alibs/ ):
libarchive.a libbz2.a libcrypto.a libiconv.a liblzma.a libxml2.a libz.a
Then configure it as follows:
CPATH=/opt/local/include:/usr/local/include:/usr/include \ ./configure CXXFLAGS=" -arch i386 -arch x86_64 -I/opt/local/include" \ CPPFLAGS="-I/usr/local/include -I/opt/local/include" \ CFLAGS="-I/usr/local/include -I/opt/local/include -L/Users/sjur/alibs \ -L/usr/local/lib -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch i386 \ -arch x86_64 -mmacosx-version-min=10.5" \ LDFLAGS=" -arch i386 -arch x86_64 -L/Users/sjur/alibs" \ --enable-static --disable-dependency-tracking --disable-shared
The essential point here is that the library flag -L now points to the separate dir we just made. This is required to force OSX to use static libraries when linking - if both a static and a dynamic version of a library is found in the same dir, OSX will always prefer the dynamic one. Hence the separate dir.
The make command line is modified in the same way:
make CFLAGS="-I/usr/local/include -L/Users/sjur/alibs -L/usr/local/lib -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LINK="gcc -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64" \ LDFLAGS="-framework CoreFoundation -framework Cocoa"
Finally install this using the same make command as we just used, but add sudo and install :
sudo make install ... [the rest as above]
When done, you should have a freshly compiled and installed file /usr/local/lib/libhfstospell.a . Copy it to the same library dir we made above, together with the rest of the library files (in my case /Users/sjur/alibs/ ).
Build libvoikko as a universal binary
# LibVoikko, working univ. binary + hfst configure: ./configure CXXFLAGS=" -arch i386 -arch x86_64" CPPFLAGS="-I/usr/local/include" \ CFLAGS="-I/usr/local/include -L/usr/local/lib -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 \ -mmacosx-version-min=10.5" LDFLAGS=" -arch i386 -arch x86_64" \ --enable-static --disable-dependency-tracking --enable-hfst # Libvoikko, working univ. binary + hfst make: make CFLAGS="-I/usr/local/include -L/usr/local/lib -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LINK="gcc -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64" \ LDFLAGS="-framework CoreFoundation -framework Cocoa" # Finally install the binaries: sudo make install CFLAGS="-I/usr/local/include -L/usr/local/lib -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LINK="gcc -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64" \ LDFLAGS="-framework CoreFoundation -framework Cocoa"
Now you should have in /usr/local/lib/ a file named libvoikko.1.dylib as a universal library including hfst support. This is the last step before making the VoikkoSpellService component, giving system-wide Voikko spellers.
Building libvoikko as a static library follows the same outline as for hfst-ospell . The details are as follows:
./configure CXXFLAGS=" -arch i386 -arch x86_64" \ CPPFLAGS="-I/usr/local/include -L/Users/sjur/alibs" \ CFLAGS="-I/usr/local/include -L/Users/sjur/alibs -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LDFLAGS=" -arch i386 -arch x86_64" \ --enable-static --disable-dependency-tracking --enable-hfst --disable-shared
Then make :
make CFLAGS="-I/usr/local/include -L/Users/sjur/alibs -isysroot \ /Developer/SDKs/MacOSX10.5.sdk -arch i386 -arch x86_64 -mmacosx-version-min=10.5" \ LINK="gcc -framework CoreFoundation -framework Cocoa -arch i386 -arch x86_64" \ LDFLAGS="-framework CoreFoundation -framework Cocoa"
And finally make install :
sudo make install ... [the rest as above]
Copy the resulting /usr/local/lib/libvoikko.a to the same static library dir we made above.
Compiling the VoikkoSpellService
Copy the file /usr/local/lib/libvoikko.1.dylib to your VoikkoSpellService source dir + Resources/voikko/ . Then open the XCode project, and compile. Hopefully that should be enough.
Building the LibreOffice extension
The first time you're compiling, you need to prepare your environment:
- download the LibreOffice SDK
- cd into the SDK dir
- run perl ./configure.pl `hostname` `pwd`
Then, each time you want to compile again, you need to do the following:
- in your home dir, source . $HOSTNAME/setsdkenv_unix.sh"
Then, follow the guidelines in the Makefile , pointing LIBVOIKKO_PATH to our static library dir. If you want a static build (which you want if you intend to distribute the extension), you also need to enable STANDALONE_EXTENSION_PATH , pointing it to a dir containing the required voikko dir structure and files for at least one supported language. One possible setup, using the default Malaga-based Finnish proofing tools is:
lib/
└── voikko
└── 2
└── mor-standard
├── voikko-fi_FI.lex_l
├── voikko-fi_FI.mor_l
├── voikko-fi_FI.pro
└── voikko-fi_FI.sym_l
In this case, STANDALONE_EXTENSION_PATH should be set to lib/voikko . When done, just make oxt and distribute the final .oxt file.
NB!!! The above build instructions are only tested on Snow Leopard, and the resulting OOo / LibreOffice extension is known to only work on Snow Leopard (aka MacOS X 10.6).

