fix windows builds (mingw and VS2010)

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@1017 d0cd1f9f-072b-0410-8dd7-cf729c803f20
This commit is contained in:
zdenop@gmail.com 2014-01-26 22:39:20 +00:00
parent 644c817f85
commit ac5a8a871b
13 changed files with 218 additions and 47 deletions

View File

@ -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

View File

@ -78,12 +78,12 @@ 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)
AM_CONDITIONAL(ADD_RT, true)
;;
*darwin*)
OPENCL_LIBS="-framework OpenCL"
@ -95,7 +95,7 @@ case "${host_os}" in
;;
*)
# 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
# ----------------------------------------

View File

@ -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;
}

View File

@ -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

View File

@ -35,6 +35,9 @@ 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.

View File

@ -14,19 +14,21 @@
* language governing permissions and limitations under the License.
*
**********************************************************************/
#include "fileio.h"
#ifdef _WIN32
#include <windows.h>
#ifndef unlink
#include <io.h>
#endif
#else
#include <glob.h>
#include <unistd.h>
#endif
#include <stdlib.h>
#include <unistd.h>
#include <cstdio>
#include <string>
#ifdef _WIN32
#include <windows.h>
#else
#include <glob.h>
#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;
}

View File

@ -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 <stdio.h>
#ifdef MINGW
// workaround for stdlib.h and putenv
#undef __STRICT_ANSI__
#include "strcasestr.h"
#endif // MINGW
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/param.h>
#include <algorithm>
#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();

View File

@ -3,9 +3,9 @@
<PropertyGroup Label="UserMacros">
<GIFLIB_VERSION>416</GIFLIB_VERSION>
<LIBJPEG_VERSION>8c</LIBJPEG_VERSION>
<LIBLEPT_VERSION>168</LIBLEPT_VERSION>
<LIBLEPT_VERSION_R>1,68,0,0</LIBLEPT_VERSION_R>
<LIBLEPT_NUMBER>1.68</LIBLEPT_NUMBER>
<LIBLEPT_VERSION>170</LIBLEPT_VERSION>
<LIBLEPT_VERSION_R>1,70,0,0</LIBLEPT_VERSION_R>
<LIBLEPT_NUMBER>1.70</LIBLEPT_NUMBER>
<LIBPNG_VERSION>143</LIBPNG_VERSION>
<LIBTIFF_VERSION>394</LIBTIFF_VERSION>
<ZLIB_VERSION>125</ZLIB_VERSION>

View File

@ -91,7 +91,7 @@
<EnableManagedIncrementalBuild Condition="'$(Configuration)|$(Platform)'=='DLL_Debug|Win32'">false</EnableManagedIncrementalBuild>
<TargetName Condition="'$(Configuration)|$(Platform)'=='LIB_Debug|Win32'">$(ProjectName)-static-debug</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='LIB_Release|Win32'">$(ProjectName)-static</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='LIB_OpenCL_Release|Win32'">$(ProjectName)-static</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='LIB_OpenCL_Release|Win32'">$(ProjectName)-opencl-static</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='DLL_Debug|Win32'">$(ProjectName)d</TargetName>
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='DLL_Debug|Win32'">false</GenerateManifest>
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='DLL_Release|Win32'">true</GenerateManifest>
@ -154,7 +154,6 @@ copy "$(TargetPath)" ..\..\..\lib
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<Name>
</Name>
<TargetMachine>MachineX86</TargetMachine>
</Lib>
<PostBuildEvent>
<Message>copy library to lib directory</Message>
@ -188,7 +187,6 @@ copy "$(TargetPath)" ..\..\..\lib
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<Name>
</Name>
<TargetMachine>MachineX86</TargetMachine>
</Lib>
<PostBuildEvent>
<Message>copy library to lib directory</Message>
@ -225,7 +223,6 @@ copy "$(TargetPath)" ..\..\..\lib
<Version>$(LIBTESS_NUMBER)</Version>
<AdditionalLibraryDirectories>..\..\..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<TargetMachine>MachineX86</TargetMachine>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
@ -266,7 +263,6 @@ copy "$(TargetDir)$(TargetName).lib" ..\..\..\lib
<Version>$(LIBTESS_NUMBER)</Version>
<AdditionalLibraryDirectories>..\..\..\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation>
<TargetMachine>MachineX86</TargetMachine>
</Link>
<PostBuildEvent>
<Message>copy library to lib directory</Message>
@ -315,7 +311,6 @@ copy "$(TargetDir)$(TargetName).lib" ..\..\..\lib
<ClCompile Include="..\..\cube\char_samp_enum.cpp" />
<ClCompile Include="..\..\cube\char_samp_set.cpp" />
<ClCompile Include="..\..\cube\char_set.cpp" />
<ClCompile Include="..\..\classify\chartoname.cpp" />
<ClCompile Include="..\..\wordrec\chop.cpp" />
<ClCompile Include="..\..\wordrec\chopper.cpp" />
<ClCompile Include="..\..\textord\cjkpitch.cpp" />

View File

@ -118,9 +118,6 @@
<ClCompile Include="..\..\cube\char_set.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\classify\chartoname.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\wordrec\chop.cpp">
<Filter>Source Files</Filter>
</ClCompile>

View File

@ -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 <stdlib.h>
#include <string.h>
#include <ctype.h>
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;
}

59
vs2010/port/strcasestr.h Normal file
View File

@ -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_ */

View File

@ -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_