-
-
Save williamsodell/8846486 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
GLOBAL_OUTDIR="`pwd`/dependencies" | |
LOCAL_OUTDIR="./outdir" | |
LEPTON_LIB="`pwd`/leptonica-1.70" | |
TESSERACT_LIB="`pwd`/tesseract-3.03" | |
IOS_BASE_SDK="7.0" | |
IOS_DEPLOY_TGT="7.0" | |
export CXX=`xcrun -find c++` | |
export CC=`xcrun -find cc` | |
export LD=`xcrun -find ld` | |
export AR=`xcrun -find ar` | |
export AS=`xcrun -find as` | |
export NM=`xcrun -find nm` | |
export RANLIB=`xcrun -find ranlib` | |
XCODE_DEVELOPER_PATH=/Applications/Xcode.app/Contents/Developer | |
XCODETOOLCHAIN_PATH=$XCODE_DEVELOPER_PATH/Toolchains/XcodeDefault.xctoolchain | |
SDK_IPHONEOS_PATH=$(xcrun --sdk iphoneos --show-sdk-path) | |
SDK_IPHONESIMULATOR_PATH=$(xcrun --sdk iphonesimulator --show-sdk-path) | |
export PATH="$XCODETOOLCHAIN_PATH/usr/bin:$PATH" | |
declare -a archs | |
archs=(arm7 arm7s arm64 i386 x86_64) | |
declare -a arch_name | |
arch_names=(arm-apple-darwin7 arm-apple-darwin7s arm-apple-darwin64 i386-apple-darwin x86_64-apple-darwin) | |
setenv_all() { | |
# Add internal libs | |
export CFLAGS="$CFLAGS -I$GLOBAL_OUTDIR/include -L$GLOBAL_OUTDIR/lib" | |
export LDFLAGS="-L$SDKROOT/usr/lib/" | |
export CPPFLAGS=$CFLAGS | |
export CXXFLAGS=$CFLAGS | |
} | |
setenv_arm7() { | |
unset DEVROOT SDKROOT CFLAGS CPP CXXCPP LDFLAGS CPPFLAGS CXXFLAGS | |
export SDKROOT=$SDK_IPHONEOS_PATH | |
export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/" | |
setenv_all | |
} | |
setenv_arm7s() { | |
unset DEVROOT SDKROOT CFLAGS CPP CXXCPP LDFLAGS CPPFLAGS CXXFLAGS | |
export SDKROOT=$SDK_IPHONEOS_PATH | |
export CFLAGS="-arch armv7s -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/" | |
setenv_all | |
} | |
setenv_arm64() { | |
unset DEVROOT SDKROOT CFLAGS CPP CXXCPP LDFLAGS CPPFLAGS CXXFLAGS | |
export SDKROOT=$SDK_IPHONEOS_PATH | |
export CFLAGS="-arch arm64 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/" | |
setenv_all | |
} | |
setenv_i386() { | |
unset DEVROOT SDKROOT CFLAGS CPP CXXCPP LDFLAGS CPPFLAGS CXXFLAGS | |
export SDKROOT=$SDK_IPHONESIMULATOR_PATH | |
export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT" | |
setenv_all | |
} | |
setenv_x86_64() { | |
unset DEVROOT SDKROOT CFLAGS CPP CXXCPP LDFLAGS CPPFLAGS CXXFLAGS | |
export SDKROOT=$SDK_IPHONESIMULATOR_PATH | |
export CFLAGS="-arch x86_64 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT" | |
setenv_all | |
} | |
create_outdir_lipo() { | |
for file in `find $LOCAL_OUTDIR/i386 -name "lib*.a"`; do | |
lib_arm7=`echo $file | sed "s/i386/arm7/g"` | |
lib_arm7s=`echo $file | sed "s/i386/arm7s/g"` | |
lib_arm64=`echo $file | sed "s/i386/arm64/g"` | |
lib_x86_64=`echo $file | sed "s/i386/x86_64/g"` | |
lib_i386=`echo $file` | |
lib=`echo $file | sed "s/i386//g"` | |
xcrun -sdk iphoneos lipo -arch armv7s $lib_arm7s -arch armv7 $lib_arm7 -arch arm64 $lib_arm64 -arch i386 $lib_i386 -create -output $lib | |
done | |
} | |
merge_libfiles() { | |
DIR=$1 | |
LIBNAME=$2 | |
cd $DIR | |
for i in `find . -name "lib*.a"`; do | |
$AR -x $i | |
done | |
$AR -r $LIBNAME *.o | |
rm -rf *.o __* | |
cd - | |
} | |
####################### | |
# LEPTONLIB | |
####################### | |
cd $LEPTON_LIB | |
rm -rf $LOCAL_OUTDIR | |
for n in "${!archs[@]}" | |
do | |
mkdir -p "$LOCAL_OUTDIR/${archs[$n]}" | |
make clean 2> /dev/null | |
make distclean 2> /dev/null | |
eval "setenv_${archs[$n]}" | |
./configure --host="${arch_names[$n]}" --enable-shared=no --disable-programs --without-zlib --without-libpng --without-jpeg --without-giflib --without-libtiff | |
make -j12 | |
cp -rvf src/.libs/lib*.a "$LOCAL_OUTDIR/${archs[$n]}" | |
done | |
create_outdir_lipo | |
mkdir -p $GLOBAL_OUTDIR/include/leptonica && find ./ -name '*.h' -exec cp {} $GLOBAL_OUTDIR/include/leptonica/ \; | |
mkdir -p $GLOBAL_OUTDIR/lib && cp -rvf $LOCAL_OUTDIR/lib*.a $GLOBAL_OUTDIR/lib | |
cd .. | |
####################### | |
# TESSERACT-OCR | |
####################### | |
cd $TESSERACT_LIB | |
rm -rf $LOCAL_OUTDIR | |
for n in "${!archs[@]}" | |
do | |
mkdir -p "$LOCAL_OUTDIR/${archs[$n]}" | |
make clean 2> /dev/null | |
make distclean 2> /dev/null | |
eval "setenv_${archs[$n]}" | |
bash autogen.sh | |
./configure --host="${arch_names[$n]}" --enable-shared=no LIBLEPT_HEADERSDIR=$GLOBAL_OUTDIR/include/ | |
make -j12 | |
for i in `find . -name "lib*.a" | grep -v arm`; do cp -rvf $i "$LOCAL_OUTDIR/${archs[$n]}"; done | |
merge_libfiles "$LOCAL_OUTDIR/${archs[$n]}" libtesseract_all.a | |
done | |
create_outdir_lipo | |
mkdir -p $GLOBAL_OUTDIR/include/tesseract && find ./ -name '*.h' -exec cp {} $GLOBAL_OUTDIR/include/tesseract/ \; | |
mkdir -p $GLOBAL_OUTDIR/lib && cp -rvf $LOCAL_OUTDIR/lib*.a $GLOBAL_OUTDIR/lib | |
make clean 2> /dev/null | |
make distclean 2> /dev/null | |
cd .. | |
echo "Finished!" |
Added arm64 and tried adding x86_64 but having issues. Some updates come from https://github.com/gali8/Tesseract-OCR-iOS/blob/master/TesseractOCR/build_dependencies.sh
Awesome!
A quick question:
This build script generates several libs, instead of one "fat library". I take that to mean that I can't just include one particular version of the library and expect all ARM archs to be covered, or... ?
Sorry for the super late reply. It builds each individually and then combines them into one big lib to be included in your app.
Thanks so much for your work on this, @williamsodell. I was able to add support for x86_64 in my fork. The only change that was needed was on the inverted grep command in line 157 above; it was causing the i386 libs to be copied into the x86_64 directory, which caused the x86_64 merge_libfiles
call to fail. This has allowed us to upgrade Tesseract-OCR-iOS to Tesseract 3.03. 😄
Need to add arm64 support..