Skip to content

Commit

Permalink
fix windows builds (mingw and VS2010)
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@1017 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
zdenop@gmail.com committed Jan 26, 2014
1 parent 644c817 commit ac5a8a8
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 46 deletions.
4 changes: 2 additions & 2 deletions ccutil/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 14 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
# ----------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion opencl/openclwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 14 additions & 2 deletions training/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion training/degradeimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 24 additions & 9 deletions training/fileio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
* language governing permissions and limitations under the License.
*
**********************************************************************/
#include "fileio.h"

#include <stdlib.h>
#include <unistd.h>
#include <cstdio>
#include <string>

#ifdef _WIN32
#include <windows.h>
#ifndef unlink
#include <io.h>
#endif
#else
#include <glob.h>
#include <unistd.h>
#endif

#include <stdlib.h>
#include <cstdio>
#include <string>

#include "fileio.h"
#include "tprintf.h"

namespace tesseract {
Expand Down Expand Up @@ -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;
}

Expand Down
21 changes: 18 additions & 3 deletions training/pango_font_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions vs2010/include/leptonica_versionnumbers.props
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
7 changes: 1 addition & 6 deletions vs2010/libtesseract/libtesseract.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down
3 changes: 0 additions & 3 deletions vs2010/libtesseract/libtesseract.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
74 changes: 74 additions & 0 deletions vs2010/port/strcasestr.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit ac5a8a8

Please sign in to comment.