Blob Blame History Raw
Name:           openfst
Version:        1.2.7
Release:        2%{?dist}
Summary:        Weighted finite-state transducer library

Group:          Development/Libraries
License:        ASL 2.0
URL:            http://www.openfst.org/
Source0:        http://openfst.cs.nyu.edu/twiki/pub/FST/FstDownload/openfst-%{version}.tar.gz
Source1:        http://openfst.cs.nyu.edu/twiki/pub/Contrib/OpenFstBashComp/openfstbc
# Man pages written by Jerry James.  The text of the man pages is lifted from
# the sources, so it is under the same copyright and license.  In short, I
# contributed the formatting, but none of the text (with a few very small
# exceptions).
Source2:        openfst-man.tar.xz
# This patch corrects some format specifiers that are correct for 32-bit
# systems, but incorrect for 64-bit systems.  It was last sent upstream
# 6 Jan 2011.
Patch0:         openfst-format.patch

BuildRequires:  libicu-devel%{?_isa}

%description
OpenFst is a library for constructing, combining, optimizing, and searching
weighted finite-state transducers (FSTs).  Weighted finite-state transducers
are automata where each transition has an input label, an output label, and a
weight.  The more familiar finite-state acceptor is represented as a
transducer with each transition's input and output label equal.  Finite-state
acceptors are used to represent sets of strings (specifically, regular or
rational sets); finite-state transducers are used to represent binary
relations between pairs of strings (specifically, rational transductions).
The weights can be used to represent the cost of taking a particular
transition.

FSTs have key applications in speech recognition and synthesis, machine
translation, optical character recognition, pattern matching, string
processing, machine learning, information extraction and retrieval among
others.  Often a weighted transducer is used to represent a probabilistic
model (e.g., an n-gram model, pronunciation model).  FSTs can be optimized by
determinization and minimization, models can be applied to hypothesis sets
(also represented as automata) or cascaded by finite-state composition, and
the best results can be selected by shortest-path algorithms.

%package devel
Summary:        Development files for OpenFst
Group:          Development/Libraries
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description devel
This package includes the necessary files to develop systems with OpenFst.

%package tools
Summary:        Command-line tools for working with FSTs
Group:          Applications/Multimedia
Requires:       %{name}%{?_isa} = %{version}-%{release}

%description tools
This package contains command-line tools that give access to OpenFst
functionality.

%prep
%setup -q
%patch0

# Add missing linkage, remove unnecessary linkage, and make sure libraries
# are built in the correct order so linkage is possible.
sed -e 's|^LIBS = |LIBS = -ldl|' -i src/lib/Makefile.in
sed -e 's|^LIBS = |LIBS = ../lib/libfst.la -ldl|' -i src/script/Makefile.in
sed -e 's|^LIBS = |LIBS = ../../lib/libfst.la -ldl|' \
    -i src/extensions/compact/Makefile.in
sed -e 's|^LIBS = |LIBS = ../../lib/libfst.la -ldl|' \
     -i src/extensions/const/Makefile.in
sed -e 's|^LIBS = |LIBS = ../../lib/libfst.la -ldl|' \
     -i src/extensions/lookahead/Makefile.in
sed -e 's|^LIBS = |LIBS = ../../lib/libfst.la -ldl|' \
    -e 's|^libfstpdtscript_la_LIBADD.*|libfstpdtscript_la_LIBADD = ../../script/libfstscript.la|' \
    -i src/extensions/pdt/Makefile.in
sed -e 's|-lm -ldl|-ldl|' \
    -e 's|^libfstfarscript_la_LIBADD.*|libfstfarscript_la_LIBADD = ../../lib/libfs libfstfar.la -ldl -licuuc|' \
    -e 's|^@HAVE_SCRIPT_TRUE@libfst_LTLIBRARIES =.*|@HAVE_SCRIPT_TRUE@libfst_LTLIBRARIES = libfstfar.la libfstfarscript.la|' \
    -i src/extensions/far/Makefile.in

%build
%configure --disable-static --enable-bin --enable-compact-fsts \
  --enable-const-fsts --enable-lookahead-fsts --enable-far --enable-pdt \
  --with-icu

# libicu pkgconfig says that -licu* requires -lm; rpmlint disagrees.
# See bz 681941.
sed -i 's|^ICU_LIBS.*|ICU_LIBS = -licui18n -licuuc -licudata -lpthread -ldl|' \
    Makefile src/extensions/Makefile src/extensions/far/Makefile

# Libtool thinks that EVERYTHING must be linked with -lm.
sed -i 's/-lstdc++ -lm/-lstdc++/' libtool

# Get rid of undesirable hardcoded rpaths
sed -i -e 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' \
       -e 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool

make %{?_smp_mflags}

%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

# Get rid of libtool files
find $RPM_BUILD_ROOT%{_libdir} -name '*.la' | xargs rm -f

# Install the bash completion file
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d
cp -p %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/bash_completion.d

# Install the man pages
mkdir -p $RPM_BUILD_ROOT%{_mandir}/man1
cd $RPM_BUILD_ROOT%{_mandir}/man1
tar xf %{SOURCE2}

# Move libraries that are actually used by binaries out of the private dir.
# Leave symbolic links behind, since they are dlopen()ed.

# libfstfar and libfstfarscript
mv $RPM_BUILD_ROOT%{_libdir}/fst/libfstfar* $RPM_BUILD_ROOT%{_libdir}
ln -s ../libfstfar.so $RPM_BUILD_ROOT%{_libdir}/fst/libfstfar.so
ln -s ../libfstfar.so.0 $RPM_BUILD_ROOT%{_libdir}/fst/libfstfar.so.0
ln -s ../libfstfarscript.so $RPM_BUILD_ROOT%{_libdir}/fst/libfstfarscript.so
ln -s ../libfstfarscript.so.0 $RPM_BUILD_ROOT%{_libdir}/fst/libfstfarscript.so.0

# libfstpdtscript
mv $RPM_BUILD_ROOT%{_libdir}/fst/libfstpdtscript* $RPM_BUILD_ROOT%{_libdir}
ln -s ../libfstpdtscript.so $RPM_BUILD_ROOT%{_libdir}/fst/libfstpdtscript.so
ln -s ../libfstpdtscript.so.0 $RPM_BUILD_ROOT%{_libdir}/fst/libfstpdtscript.so.0

%clean
rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

%files
%defattr(-,root,root,-)
%doc AUTHORS COPYING NEWS README
%dir %{_libdir}/fst
%{_libdir}/fst/*.so.*
%{_libdir}/*.so.*

%files devel
%defattr(-,root,root,-)
%{_includedir}/fst
%{_libdir}/fst/*.so
%{_libdir}/*.so

%files tools
%defattr(-,root,root,-)
%{_bindir}/*
%{_mandir}/man1/*
%config(noreplace) %{_sysconfdir}/bash_completion.d

%changelog
* Wed May 18 2011 Jerry James <loganjerry@gmail.com> - 1.2.7-2
- Fix incorrect target order in far extension Makefile.  Thanks to Dan HorĂ¡k
  for the analysis.

* Wed Mar  2 2011 Jerry James <loganjerry@gmail.com> - 1.2.7-1
- Initial RPM