From ac5a8a871b9dd24f1ec305c97a258b6d8b35057c Mon Sep 17 00:00:00 2001 From: "zdenop@gmail.com" Date: Sun, 26 Jan 2014 22:39:20 +0000 Subject: [PATCH] fix windows builds (mingw and VS2010) git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@1017 d0cd1f9f-072b-0410-8dd7-cf729c803f20 --- ccutil/Makefile.am | 4 +- configure.ac | 27 +++---- opencl/openclwrapper.cpp | 2 +- training/Makefile.am | 16 +++- training/degradeimage.cpp | 5 +- training/fileio.cpp | 35 ++++++--- training/pango_font_info.cpp | 21 +++++- vs2010/include/leptonica_versionnumbers.props | 6 +- vs2010/libtesseract/libtesseract.vcxproj | 7 +- .../libtesseract/libtesseract.vcxproj.filters | 3 - vs2010/port/strcasestr.cpp | 74 +++++++++++++++++++ vs2010/port/strcasestr.h | 59 +++++++++++++++ vs2010/port/strtok_r.h | 6 +- 13 files changed, 218 insertions(+), 47 deletions(-) create mode 100644 vs2010/port/strcasestr.cpp create mode 100644 vs2010/port/strcasestr.h diff --git a/ccutil/Makefile.am b/ccutil/Makefile.am index 5a4e4307b..aff72cfb2 100644 --- a/ccutil/Makefile.am +++ b/ccutil/Makefile.am @@ -46,6 +46,6 @@ endif if MINGW AM_CPPFLAGS += -I$(top_srcdir)/vs2008/port -DWINDLLNAME=\"lib@GENERIC_LIBRARY_NAME@\" -noinst_HEADERS += ../vs2008/port/strtok_r.h -libtesseract_ccutil_la_SOURCES += ../vs2008/port/strtok_r.cpp +noinst_HEADERS += ../vs2010/port/strtok_r.h +libtesseract_ccutil_la_SOURCES += ../vs2010/port/strtok_r.cpp endif diff --git a/configure.ac b/configure.ac index c1c7b3c80..6b2f6680b 100644 --- a/configure.ac +++ b/configure.ac @@ -78,24 +78,24 @@ case "${host_os}" in mingw32*) AC_DEFINE_UNQUOTED(MINGW,1,[This is a MinGW system]) AM_CONDITIONAL(MINGW, true) - AM_CONDITIONAL(ADD_RT, false) + AM_CONDITIONAL(ADD_RT, false) AC_SUBST([AM_LDFLAGS], ['-Wl,-no-undefined -Wl,--as-needed']) ;; solaris*) - LIBS="-lsocket -lnsl -lrt -lxnet" - AM_CONDITIONAL(ADD_RT, true) - ;; - *darwin*) - OPENCL_LIBS="-framework OpenCL" - OPENCL_INC="" - AM_CONDITIONAL(ADD_RT, false) + LIBS="-lsocket -lnsl -lrt -lxnet" + AM_CONDITIONAL(ADD_RT, true) + ;; + *darwin*) + OPENCL_LIBS="-framework OpenCL" + OPENCL_INC="" + AM_CONDITIONAL(ADD_RT, false) ;; powerpc-*-darwin*) OPENCL_LIBS="" ;; *) # default - AM_CONDITIONAL(ADD_RT, true) + AM_CONDITIONAL(ADD_RT, true) ;; esac @@ -285,10 +285,6 @@ AC_COMPILE_IFELSE( has_cpp11=no ]) CXXFLAGS="$OLD_CXXFLAGS" -if test "x$has_cpp11" = "xyes" -then - CXXFLAGS="$CXXFLAGS -std=c++11" -fi # ---------------------------------------- # Check for libraries @@ -382,6 +378,11 @@ else fi AM_CONDITIONAL(ENABLE_TRAINING, $have_cairo) +if test "x$has_cpp11" = "xyes" +then + CXXFLAGS="$CXXFLAGS -std=c++11" +fi + # ---------------------------------------- # Final Tasks and Output # ---------------------------------------- diff --git a/opencl/openclwrapper.cpp b/opencl/openclwrapper.cpp index f2770da9c..3eaa75ad3 100644 --- a/opencl/openclwrapper.cpp +++ b/opencl/openclwrapper.cpp @@ -1136,7 +1136,7 @@ TIFF *tif; } if (pagefound == FALSE) { - L_WARNING_INT("tiff page %d not found", procName, n); + L_WARNING("tiff page %d not found", procName, n); TIFFCleanup(tif); return NULL; } diff --git a/training/Makefile.am b/training/Makefile.am index 58953d0c9..016aa7d8e 100644 --- a/training/Makefile.am +++ b/training/Makefile.am @@ -7,6 +7,14 @@ AM_CPPFLAGS += \ -I$(top_srcdir)/classify -I$(top_srcdir)/display \ -I$(top_srcdir)/wordrec -I$(top_srcdir)/cutil +if MINGW +# try static build +#AM_LDFLAGS += -all-static +#libic=-lsicuin -licudt -lsicuuc +libicu=-licuin -licuuc +else +libicu=-licui18n -licuuc +endif # TODO: training programs can not be linked to shared library created # with -fvisibility if VISIBILITY @@ -167,7 +175,7 @@ set_unicharset_properties_SOURCES = set_unicharset_properties.cpp set_unicharset_properties_LDADD = \ libtesseract_training.la \ libtesseract_tessopt.la \ - -licuuc -licui18n + $(libicu) if USING_MULTIPLELIBS set_unicharset_properties_LDADD += \ ../textord/libtesseract_textord.la \ @@ -231,7 +239,7 @@ else text2image_LDADD += \ ../api/libtesseract.la endif -text2image_LDADD += -licuuc -licui18n -lpango-1.0 -lpangocairo-1.0 \ +text2image_LDADD += $(libicu) -lpango-1.0 -lpangocairo-1.0 \ -lgobject-2.0 -lglib-2.0 -lcairo -lpangoft2-1.0 unicharset_extractor_SOURCES = unicharset_extractor.cpp @@ -279,4 +287,8 @@ mftraining_LDADD += -lws2_32 shapeclustering_LDADD += -lws2_32 unicharset_extractor_LDADD += -lws2_32 wordlist2dawg_LDADD += -lws2_32 + +AM_CPPFLAGS += -I$(top_srcdir)/vs2010/port +noinst_HEADERS += ../vs2010/port/strcasestr.h +libtesseract_training_la_SOURCES += ../vs2010/port/strcasestr.cpp endif diff --git a/training/degradeimage.cpp b/training/degradeimage.cpp index 705072ced..ead8b1906 100644 --- a/training/degradeimage.cpp +++ b/training/degradeimage.cpp @@ -35,7 +35,10 @@ const int kSaltnPepper = 5; const int kMinRampSize = 1000; static unsigned int random_seed = 0x18273645; - +#ifndef rand_r // _MSC_VER, ANDROID +#define rand_r(random_seed) rand() +#endif // _MSC_VER + // Degrade the pix as if by a print/copy/scan cycle with exposure > 0 // corresponding to darkening on the copier and <0 lighter and 0 not copied. // Exposures in [-2,2] are most useful, with -3 and 3 being extreme. diff --git a/training/fileio.cpp b/training/fileio.cpp index ddf28e946..2a197245b 100644 --- a/training/fileio.cpp +++ b/training/fileio.cpp @@ -14,19 +14,21 @@ * language governing permissions and limitations under the License. * **********************************************************************/ -#include "fileio.h" +#ifdef _WIN32 +#include +#ifndef unlink +#include +#endif +#else +#include +#include +#endif #include -#include #include #include -#ifdef _WIN32 -#include -#else -#include -#endif - +#include "fileio.h" #include "tprintf.h" namespace tesseract { @@ -156,16 +158,29 @@ InputBuffer::~InputBuffer() { bool InputBuffer::ReadLine(string* out) { ASSERT_HOST(stream_ != NULL); char* line = NULL; + int len = -1; +#ifdef _WIN32 + char line_buf[BUFSIZ]; + if ((line = fgets(line_buf, BUFSIZ, stream_)) != NULL) { + len = strlen(line); + if (line_buf[0] != '\0' && line_buf[len - 1] == '\n') + line_buf[len - 1] = '\0'; + } else { + return false; + } + *out = string(line); +#else size_t line_size; - int len = getline(&line, &line_size, stream_); - + len = getline(&line, &line_size, stream_); if (len < 0) { return false; } + if (len >= 1 && line[len - 1] == '\n') line[len - 1] = '\0'; *out = string(line); free(line); +#endif // _WIN32 return true; } diff --git a/training/pango_font_info.cpp b/training/pango_font_info.cpp index a427181a5..3d7bbe555 100644 --- a/training/pango_font_info.cpp +++ b/training/pango_font_info.cpp @@ -17,14 +17,23 @@ * **********************************************************************/ -#include "pango_font_info.h" + // Include automatically generated configuration file if running autoconf. +#ifdef HAVE_CONFIG_H +#include "config_auto.h" +#endif -#include +#ifdef MINGW +// workaround for stdlib.h and putenv +#undef __STRICT_ANSI__ +#include "strcasestr.h" +#endif // MINGW #include +#include #include #include #include +#include "pango_font_info.h" #include "commandlineflags.h" #include "fileio.h" #include "normstrngs.h" @@ -133,13 +142,19 @@ static void InitFontconfig() { string fonts_conf_file = File::JoinPath(FLAGS_fontconfig_tmpdir.c_str(), "fonts.conf"); File::WriteStringToFileOrDie(fonts_conf_template, fonts_conf_file); +#ifdef _WIN32 + std::string env("FONTCONFIG_PATH="); + env.append(FLAGS_fontconfig_tmpdir.c_str()); + putenv(env.c_str()); + putenv("LANG=en_US.utf8"); +#else setenv("FONTCONFIG_PATH", FLAGS_fontconfig_tmpdir.c_str(), true); // Fix the locale so that the reported font names are consistent. setenv("LANG", "en_US.utf8", true); +#endif // _WIN32 init_fontconfig = true; } - static void ListFontFamilies(PangoFontFamily*** families, int* n_families) { InitFontconfig(); diff --git a/vs2010/include/leptonica_versionnumbers.props b/vs2010/include/leptonica_versionnumbers.props index 082b3418f..162b77ac7 100644 --- a/vs2010/include/leptonica_versionnumbers.props +++ b/vs2010/include/leptonica_versionnumbers.props @@ -3,9 +3,9 @@ 416 8c - 168 - 1,68,0,0 - 1.68 + 170 + 1,70,0,0 + 1.70 143 394 125 diff --git a/vs2010/libtesseract/libtesseract.vcxproj b/vs2010/libtesseract/libtesseract.vcxproj index 0529c4559..be844f4b7 100644 --- a/vs2010/libtesseract/libtesseract.vcxproj +++ b/vs2010/libtesseract/libtesseract.vcxproj @@ -91,7 +91,7 @@ false $(ProjectName)-static-debug $(ProjectName)-static - $(ProjectName)-static + $(ProjectName)-opencl-static $(ProjectName)d false true @@ -154,7 +154,6 @@ copy "$(TargetPath)" ..\..\..\lib $(OutDir)$(TargetName)$(TargetExt) - MachineX86 copy library to lib directory @@ -188,7 +187,6 @@ copy "$(TargetPath)" ..\..\..\lib $(OutDir)$(TargetName)$(TargetExt) - MachineX86 copy library to lib directory @@ -225,7 +223,6 @@ copy "$(TargetPath)" ..\..\..\lib $(LIBTESS_NUMBER) ..\..\..\lib;%(AdditionalLibraryDirectories) UseLinkTimeCodeGeneration - MachineX86 true true @@ -266,7 +263,6 @@ copy "$(TargetDir)$(TargetName).lib" ..\..\..\lib $(LIBTESS_NUMBER) ..\..\..\lib;%(AdditionalLibraryDirectories) true - MachineX86 copy library to lib directory @@ -315,7 +311,6 @@ copy "$(TargetDir)$(TargetName).lib" ..\..\..\lib - diff --git a/vs2010/libtesseract/libtesseract.vcxproj.filters b/vs2010/libtesseract/libtesseract.vcxproj.filters index 549697927..ccf473c91 100644 --- a/vs2010/libtesseract/libtesseract.vcxproj.filters +++ b/vs2010/libtesseract/libtesseract.vcxproj.filters @@ -118,9 +118,6 @@ Source Files - - Source Files - Source Files diff --git a/vs2010/port/strcasestr.cpp b/vs2010/port/strcasestr.cpp new file mode 100644 index 000000000..ddaf2adda --- /dev/null +++ b/vs2010/port/strcasestr.cpp @@ -0,0 +1,74 @@ +/* +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies of the Software and its Copyright notices. In addition publicly +documented acknowledgment must be given that this software has been used if no +source code of this software is made available publicly. Making the source +available publicly means including the source for this software with the +distribution, or a method to get this software via some reasonable mechanism +(electronic transfer via a network or media) as well as making an offer to +supply the source on request. This Copyright notice serves as an offer to +supply the source on on request as well. Instead of this, supplying +acknowledgments of use of this software in either Copyright notices, Manuals, +Publicity and Marketing documents or any documentation provided with any +product containing this software. This License does not apply to any software +that links to the libraries provided by this software (statically or +dynamically), but only to the software provided. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Source: +Evil 1.7.4 +The Evil library tried to port some convenient Unix functions +to the Windows (XP or CE) platform. They are planned to be used + +http://git.enlightenment.org/legacy/evil.git/tree/src/lib/evil_string.c?id=eeaddf80d0d547d4c216974038c0599b34359695 +*/ + +#include +#include +#include + +char *strcasestr(const char *haystack, const char *needle) { + size_t length_needle; + size_t length_haystack; + size_t i; + + if (!haystack || !needle) + return NULL; + + length_needle = strlen(needle); + length_haystack = strlen(haystack) - length_needle + 1; + + for (i = 0; i < length_haystack; i++) + { + size_t j; + + for (j = 0; j < length_needle; j++) + { + unsigned char c1; + unsigned char c2; + + c1 = haystack[i+j]; + c2 = needle[j]; + if (toupper(c1) != toupper(c2)) + goto next; + } + return (char *) haystack + i; + next: + ; + } + + return NULL; +} \ No newline at end of file diff --git a/vs2010/port/strcasestr.h b/vs2010/port/strcasestr.h new file mode 100644 index 000000000..0472241fd --- /dev/null +++ b/vs2010/port/strcasestr.h @@ -0,0 +1,59 @@ +/* +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies of the Software and its Copyright notices. In addition publicly +documented acknowledgment must be given that this software has been used if no +source code of this software is made available publicly. Making the source +available publicly means including the source for this software with the +distribution, or a method to get this software via some reasonable mechanism +(electronic transfer via a network or media) as well as making an offer to +supply the source on request. This Copyright notice serves as an offer to +supply the source on on request as well. Instead of this, supplying +acknowledgments of use of this software in either Copyright notices, Manuals, +Publicity and Marketing documents or any documentation provided with any +product containing this software. This License does not apply to any software +that links to the libraries provided by this software (statically or +dynamically), but only to the software provided. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Source: +Evil 1.7.4 +The Evil library tried to port some convenient Unix functions +to the Windows (XP or CE) platform. They are planned to be used + +http://git.enlightenment.org/legacy/evil.git/tree/src/lib/evil_string.h?id=eeaddf80d0d547d4c216974038c0599b34359695 +*/ + +#ifndef VS2010_PORT_STRCASESTR_H_ +#define VS2010_PORT_STRCASESTR_H_ +/** + * @brief Locatea substring into a string, ignoring case. + * + * @param haystack The string to search in. + * @param needle The substring to find. + * @return + * + * This function locates the string @p needle into the string @p haystack, + * ignoring the case of the characters. It returns apointer to the + * beginning of the substring, or NULL if the substring is not found. + * If @p haystack or @p needle are @c NULL, this function returns @c NULL. + * + * Conformity: Non applicable. + * + * Supported OS: Windows XP, Windows CE + */ +char *strcasestr(const char *haystack, const char *needle); + +#endif /* VS2010_PORT_STRCASESTR_H_ */ diff --git a/vs2010/port/strtok_r.h b/vs2010/port/strtok_r.h index 15cec6aae..bbdae34f3 100644 --- a/vs2010/port/strtok_r.h +++ b/vs2010/port/strtok_r.h @@ -19,9 +19,9 @@ // /////////////////////////////////////////////////////////////////////// -#ifndef VS2008_PORT_STRTOK_R_H_ -#define VS2008_PORT_STRTOK_R_H_ +#ifndef VS2010_PORT_STRTOK_R_H_ +#define VS2010_PORT_STRTOK_R_H_ char *strtok_r(char *s1, const char *s2, char **lasts); -#endif // VS2008_PORT_STRTOK_R_H_ +#endif // VS2010_PORT_STRCASESTR_H_