Skip to content

Instantly share code, notes, and snippets.

@tingley
Created April 3, 2012 18:09
Show Gist options
  • Save tingley/2294294 to your computer and use it in GitHub Desktop.
Save tingley/2294294 to your computer and use it in GitHub Desktop.
Modified script to x-compile tesseract-3.0.1 for iOS-5.1 from Xcode 4.3
#!/bin/sh
# build_fat.sh
#
# Created by Robert Carlsen on 15.07.2009. Updated 24.9.2010
# build an arm / i386 lib of standard linux project
#
# initially configured for tesseract-ocr v2.0.4
# updated for tesseract prerelease v3
outdir=outdir
mkdir -p $outdir/arm $outdir/i386
libdirs=( api ccutil ccmain ccstruct classify cutil dict image textord training viewer wordrec )
libs=( api ccutil main ccstruct classify cutil dict image textord training viewer wordrec )
count=${#libdirs[@]}
make distclean
unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD
# XXX Do I need to do anything to pull in the iOS headers? Maybe add
# /usr/llvm-gcc-4.2/include/gcc/darwin/4.2?
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS5.1.sdk
export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot$SDKROOT -I$SDKROOT/usr/include/"
#export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=5.0 -I$SDKROOT/usr/include/"
export CPPFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L$SDKROOT/usr/lib/ -L$SDKROOT/usr/lib/system"
export LD="$DEVROOT/usr/bin/ld"
export CPP="$DEVROOT/usr/bin/llvm-gcc -E $CPPFLAGS"
export CXX="$DEVROOT/usr/bin/llvm-g++-4.2"
export CC="$DEVROOT/usr/bin/llvm-gcc-4.2"
# --build=i686-apple-darwin11
# --host=x86_64-apple-darwin11
# --target=i686-apple-darwin11
# configure: WARNING: If you wanted to set the --build type, don't use --host.
# If a cross compiler is detected then cross compile mode will be used.
#./configure --host=arm-apple-darwin
./configure --host=arm-apple-darwin --enable-shared=no LIBLEPT_HEADERSDIR=$GLOBAL_OUTDIR/include/
make -j3
# index=0
# while [ "$index" -lt "$count" ]
# do
# cp ${libdirs[index]}/.libs/libtesseract_${libs[index]}.a $outdir/arm/libtesseract_${libs[index]}_armv6.a
# ((index++))
# done
#
# make distclean
# unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD
#
# #export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
# #export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.1.sdk
# #export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/"
# export CFLAGS="-arch i386 -pipe -no-cpp-precomp -miphoneos-version-min=3.0"
# export CPPFLAGS="$CFLAGS"
# export CXXFLAGS="$CFLAGS"
# export LDFLAGS="-L$SDKROOT/usr/lib/"
# export LD="/usr/bin/ld"
# export CPP="/usr/bin/cpp"
# export CXX="/usr/bin/g++"
# export CC="/usr/bin/gcc"
# ./configure
# make -j3
#
# index=0
# while [ "$index" -lt "$count" ]
# do
# cp ${libdirs[index]}/.libs/libtesseract_${libs[index]}.a $outdir/i386/libtesseract_${libs[index]}_i386.a
# ((index++))
# done
#
# # are the fat libs making the bundle too big?
# index=0
# while [ "$index" -lt "$count" ]
# do
# /usr/bin/lipo -arch armv6 $outdir/arm/libtesseract_${libs[index]}_armv6.a -arch i386 $outdir/i386/libtesseract_${libs[index]}_i386.a -create -output $outdir/libtesseract_${libs[index]}.a
# ((index++))
# done
unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT
@johnservinis
Copy link

glad you've done a revision for this script to account for xcode 4.3. i'm having trouble compiling, however. i'm far from competent when it comes to this, but quickly looking over the script, i have a feeling it might be something to do with "LIBLEPT_HEADERSDIR=$GLOBAL_OUTDIR/include/" at line 39. again, i'm no pro here, but i can't see where it is declared and the build error is "leptonica not found" so given that this is the parameter for the leptonica path, i assumed there may be an association. any help appreciated! thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment