# Patch for Ocrad 0.23 to enable build of shared library and fix tests run for it
# Copyright (C) 2010-2014 Georgi D. Sotirov <gdsotirov@dir.bg>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
diff -urNad ocrad-0.23-orig/Makefile.in ocrad-0.23/Makefile.in
--- ocrad-0.23-orig/Makefile.in	2014-01-02 15:11:43.000000000 +0200
+++ ocrad-0.23/Makefile.in	2014-03-29 13:05:14.000000000 +0200
@@ -13,26 +13,26 @@
            bitmap.o blob.o profile.o feats.o feats_test0.o feats_test1.o \
            character.o character_r11.o character_r12.o character_r13.o \
            textline.o textline_r2.o textblock.o textpage.o
-objs     = arg_parser.o main.o
+prg_objs = arg_parser.o main.o
 
 
 .PHONY : all install install-bin install-info install-man install-strip \
          uninstall uninstall-bin uninstall-info uninstall-man \
          doc info man check dist clean distclean
 
-all : $(progname) lib$(libname).a
+all : lib$(libname).so $(progname)
 
-lib$(libname).a: $(ocr_objs) $(lib_objs)
-	$(AR) -rcs $@ $(ocr_objs) $(lib_objs)
+lib$(libname).so: $(ocr_objs) $(lib_objs)
+	$(CXX) -shared -Wl,-soname,lib$(libname).so -o lib$(libname).so $(ocr_objs) $(lib_objs)
 
-$(progname) : $(ocr_objs) $(objs)
-	$(CXX) $(LDFLAGS) -o $@ $(ocr_objs) $(objs)
+$(progname) : lib$(libname).so $(prg_objs)
+	$(CXX) $(LDFLAGS) -o $(progname) -L. -locrad $(prg_objs)
 
-$(progname)_profiled : $(ocr_objs) $(objs)
-	$(CXX) $(LDFLAGS) -pg -o $@ $(ocr_objs) $(objs)
+$(progname)_profiled : lib$(libname).so $(prg_objs)
+	$(CXX) $(LDFLAGS) -pg -o $(progname)_profiled -L. -locrad $(prg_objs)
 
-ocrcheck : ocrcheck.o lib$(libname).a
-	$(CXX) $(LDFLAGS) -o $@ ocrcheck.o lib$(libname).a
+ocrcheck : ocrcheck.o lib$(libname).so
+	$(CXX) $(LDFLAGS) -o ocrcheck -L. -locrad ocrcheck.o
 
 ocrcheck.o : ocrcheck.cc
 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
@@ -41,11 +41,11 @@
 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
 
 %.o : %.cc
-	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -fPIC -c -o $@ $<
 
 $(lib_objs)     : Makefile ocradlib.h
 $(ocr_objs)     : Makefile bitmap.h blob.h common.h rectangle.h ucs.h
-$(objs)         : Makefile arg_parser.h
+$(prg_objs)     : Makefile arg_parser.h
 character.o     : character.h
 character_r11.o : segment.h character.h profile.h feats.h
 character_r12.o : segment.h character.h profile.h feats.h
@@ -85,7 +85,7 @@
 	./config.status
 
 check : all ocrcheck
-	@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
+	$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
 
 install : install-bin install-info install-man
 
@@ -95,7 +95,7 @@
 	if [ ! -d "$(DESTDIR)$(libdir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(libdir)" ; fi
 	$(INSTALL_PROGRAM) ./$(progname) "$(DESTDIR)$(bindir)/$(progname)"
 	$(INSTALL_DATA) $(VPATH)/$(libname)lib.h "$(DESTDIR)$(includedir)/$(libname)lib.h"
-	$(INSTALL_DATA) ./lib$(libname).a "$(DESTDIR)$(libdir)/lib$(libname).a"
+	$(INSTALL_DATA) ./lib$(libname).so "$(DESTDIR)$(libdir)/lib$(libname).so"
 
 install-info :
 	if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
@@ -114,7 +114,7 @@
 uninstall-bin :
 	-rm -f "$(DESTDIR)$(bindir)/$(progname)"
 	-rm -f "$(DESTDIR)$(includedir)/$(libname)lib.h"
-	-rm -f "$(DESTDIR)$(libdir)/lib$(libname).a"
+	-rm -f "$(DESTDIR)$(libdir)/lib$(libname).so"
 
 uninstall-info :
 	-install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(pkgname).info"
@@ -149,7 +149,7 @@
 
 clean :
 	-rm -f $(progname) $(progname)_profiled $(objs)
-	-rm -f ocrcheck ocrcheck.o $(ocr_objs) $(lib_objs) *.a
+	-rm -f ocrcheck ocrcheck.o $(lib_objs) *.a *.so
 
 distclean : clean
 	-rm -f Makefile config.status *.tar *.tar.lz
diff -urNad ocrad-0.23-orig/testsuite/check.sh ocrad-0.23/testsuite/check.sh
--- ocrad-0.23-orig/testsuite/check.sh	2014-01-22 17:58:40.000000000 +0200
+++ ocrad-0.23/testsuite/check.sh	2014-03-29 13:05:14.000000000 +0200
@@ -5,8 +5,8 @@
 # This script is free software: you have unlimited permission
 # to copy, distribute and modify it.
 
-LC_ALL=C
-export LC_ALL
+export LC_ALL=C
+export LD_LIBRARY_PATH="$LD_LIBRARY_PATH;.;.."
 objdir=`pwd`
 testdir=`cd "$1" ; pwd`
 OCRAD="${objdir}"/ocrad
