# Patch for Ocrad 0.27 to enable build of shared library and fix tests run for it
# Copyright (C) 2010-2019 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.27-orig/Makefile.in ocrad-0.27/Makefile.in
--- ocrad-0.27-orig/Makefile.in	2019-01-10 21:06:05.000000000 +0200
+++ ocrad-0.27/Makefile.in	2019-01-17 11:16:12.904943417 +0200
@@ -14,7 +14,7 @@
            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 \
@@ -23,16 +23,16 @@
          uninstall uninstall-bin uninstall-info uninstall-man \
          doc info man check dist clean distclean
 
-all : $(progname) lib$(libname).a
+all : $(progname) lib$(libname).so
 
-lib$(libname).a: $(ocr_objs) $(lib_objs)
-	$(AR) -crs $@ $(ocr_objs) $(lib_objs)
+lib$(libname).so: $(ocr_objs) $(lib_objs)
+	$(CXX) -shared -Wl,-soname,$@ -o $@ $(ocr_objs) $(lib_objs)
 
-$(progname) : $(ocr_objs) $(objs)
-	$(CXX) $(LDFLAGS) $(CXXFLAGS) -o $@ $(ocr_objs) $(objs)
+$(progname) : $(prg_objs) lib$(libname).so
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ -L. -locrad $(prg_objs)
 
-ocradcheck : ocradcheck.o lib$(libname).a
-	$(CXX) $(LDFLAGS) $(CXXFLAGS) -o $@ ocradcheck.o lib$(libname).a
+ocradcheck : ocradcheck.o lib$(libname).so
+	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ -L. -locrad ocradcheck.o
 
 ocradcheck.o : ocradcheck.cc
 	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(pkgversion)\" -c -o $@ $<
@@ -41,11 +41,12 @@
 	$(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     : segment.h user_filter.h character.h profile.h feats.h
 character_r11.o : segment.h character.h profile.h feats.h
 character_r12.o : segment.h character.h profile.h feats.h
@@ -88,7 +89,7 @@
 	./config.status
 
 check : all ocradcheck
-	@$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
+	$(VPATH)/testsuite/check.sh $(VPATH)/testsuite $(pkgversion)
 
 install : install-bin install-info install-man
 install-strip : install-bin-strip install-info install-man
@@ -101,7 +102,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-bin-strip : all
 	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin
@@ -130,7 +131,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 :
 	-if $(CAN_RUN_INSTALLINFO) ; then \
@@ -168,7 +169,7 @@
 
 clean :
 	-rm -f $(progname) $(objs)
-	-rm -f ocradcheck ocradcheck.o $(ocr_objs) $(lib_objs) *.a
+	-rm -f ocradcheck ocradcheck.o $(lib_objs) *.a *.so
 
 distclean : clean
 	-rm -f Makefile config.status *.tar *.tar.lz
diff -urNad ocrad-0.27-orig/testsuite/check.sh ocrad-0.27/testsuite/check.sh
--- ocrad-0.27-orig/testsuite/check.sh	2019-01-10 13:23:19.000000000 +0200
+++ ocrad-0.27/testsuite/check.sh	2019-01-17 11:05:07.843994109 +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
