Cross Compile Script of Tesseract

The script on internet is both too old and has issues on compiling. I enhance it and it's suitable for XCode 7.3.1

#!/bin/sh
# build.sh

GLOBAL_OUTDIR="`pwd`/dependencies"
LOCAL_OUTDIR="./outdir"
LEPTON_LIB="`pwd`/leptonica-1.73"
TIFF_LIB="`pwd`/tiff-4.0.6"
TESSERACT_LIB="`pwd`/tesseract-3.04.01"

IOS_BASE_SDK="9.3"
IOS_DEPLOY_TGT="9.3"

setenv_all()
{
	# Add internal libs
	export CFLAGS="-O2 $CFLAGS -I$GLOBAL_OUTDIR/include -L$GLOBAL_OUTDIR/lib"

    export TOOLCHAINROOT=/Applications/Xcode731.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
    export CXX="$TOOLCHAINROOT/usr/bin/clang"
    export CC="$TOOLCHAINROOT/usr/bin/clang"

    export LD=$TOOLCHAINROOT/usr/bin/ld
    export AR=$TOOLCHAINROOT/usr/bin/ar
    export AS=$TOOLCHAINROOT/usr/bin/as
    export NM=$TOOLCHAINROOT/usr/bin/nm
    export RANLIB=$TOOLCHAINROOT/usr/bin/ranlib
    export LDFLAGS="-L$SDKROOT/usr/lib -L/usr/local/lib -lz"
# export LDFLAGS="-L/usr/lib/ -L$GLOBAL_OURDIR/lib -lz"
	
	export CPPFLAGS=$CFLAGS
	export CXXFLAGS=$CFLAGS
}

setenv_arm6()
{
	unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
	
	export DEVROOT=/Applications/Xcode731.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
	export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
	
	export CFLAGS="-arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"
	
	setenv_all
    echo "compile arm6"
}

setenv_arm7()
{
	unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
	
	export DEVROOT=//Applications/Xcode731.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
	export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
	
	export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"
	
	setenv_all
    echo "compile arm7"
}

setenv_i386()
{
	unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
	
export DEVROOT=/Applications/Xcode731.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
	export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator$IOS_BASE_SDK.sdk
	
	export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT"
	
	setenv_all
    echo "compile i386"
}

create_outdir_lipo()
{
    echo "create_outdir_lipo"
	for lib_i386 in `find $LOCAL_OUTDIR/i386 -name "lib*\.a"`; do
#lib_arm6=`echo $lib_i386 | sed "s/i386/arm6/g"`
		lib_arm7=`echo $lib_i386 | sed "s/i386/arm7/g"`
		lib=`echo $lib_i386 | sed "s/i386\///g"`
#lipo -arch armv6 $lib_arm6 -arch armv7 $lib_arm7 -arch i386 $lib_i386 -create -output $lib
        lipo -arch armv7 $lib_arm7 -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 -
}

#######################
# LIBTIFF
#######################

#cd $TIFF_LIB
#rm -rf $LOCAL_OUTDIR
#mkdir -p $LOCAL_OUTDIR/arm6 $LOCAL_OUTDIR/arm7 $LOCAL_OUTDIR/i386
#
##make clean 2> /dev/null
##make distclean 2> /dev/null
##setenv_arm6
##./configure --host=arm-apple-darwin6 --enable-shared=no --prefix=`pwd`/$LOCAL_OUTDIR/arm6
##make -j4
##make install
#
#make clean 2> /dev/null
#make distclean 2> /dev/null
#setenv_arm7
#./configure --host=arm-apple-darwin7 --enable-shared=no --prefix=`pwd`/$LOCAL_OUTDIR/arm7
#make -j4
#make install
#
#make clean 2> /dev/null
#make distclean 2> /dev/null
#setenv_i386
#./configure --host=x86_64 --enable-shared=no --prefix=`pwd`/$LOCAL_OUTDIR/i386
#make -j4
#make install
#
## since we're installing the libraries into LOCAL_OUTDIR/<arch>/lib
## create_outdir_lipo will try to put them in LOCAL_OUTDIR/lib
#mkdir -p $LOCAL_OUTDIR/lib
#create_outdir_lipo
#mkdir -p $GLOBAL_OUTDIR/include && cp -rvf $LOCAL_OUTDIR/i386/include/*.h $GLOBAL_OUTDIR/include
#mkdir -p $GLOBAL_OUTDIR/lib && cp -rvf $LOCAL_OUTDIR/lib/lib*.a $GLOBAL_OUTDIR/lib
#cd ..


#######################
# LEPTONLIB
#######################
#cd $LEPTON_LIB
#rm -rf $LOCAL_OUTDIR
#mkdir -p $LOCAL_OUTDIR/arm6 $LOCAL_OUTDIR/arm7 $LOCAL_OUTDIR/i386
##
##make clean 2> /dev/null
##make distclean 2> /dev/null
##setenv_arm6
##./configure --host=arm-apple-darwin6 --enable-shared=no --disable-programs --without-zlib --without-libpng --without-jpeg --without-giflib --with-libtiff
##make -j4
##cp -rvf src/.libs/lib*.a $LOCAL_OUTDIR/arm6
#
#make clean 2> /dev/null
#make distclean 2> /dev/null
#setenv_arm7
#./configure --host=arm-apple-darwin7 --enable-shared=no --disable-programs --without-zlib --without-libpng --without-jpeg --without-giflib --with-libtiff
#make -j4
#cp -rvf src/.libs/lib*.a $LOCAL_OUTDIR/arm7
#
#make clean 2> /dev/null
#make distclean 2> /dev/null
#setenv_i386
#./configure --host=x86_64 --enable-shared=no --disable-programs --without-zlib --without-libpng --without-jpeg --without-giflib --with-libtiff
#make -j4
#cp -rvf src/.libs/lib*.a $LOCAL_OUTDIR/i386
#
#create_outdir_lipo
#mkdir -p $GLOBAL_OUTDIR/include/leptonica && cp -rvf src/*.h $GLOBAL_OUTDIR/include/leptonica
#mkdir -p $GLOBAL_OUTDIR/lib && cp -rvf $LOCAL_OUTDIR/lib*.a $GLOBAL_OUTDIR/lib
#cd ..


#######################
# TESSERACT-OCR (v3)
#######################
cd $TESSERACT_LIB
rm -rf $LOCAL_OUTDIR
mkdir -p $LOCAL_OUTDIR/arm6 $LOCAL_OUTDIR/arm7 $LOCAL_OUTDIR/i386

#make clean 2> /dev/null
#make distclean 2> /dev/null
#setenv_arm6
#export LDFLAGS="$LDFLAGS -ltiff"
#bash autogen.sh
#echo $CC
##export LIBLEPT_HEADERSDIR=/usr/local/include
#./configure --host=arm-apple-darwin6 --enable-shared=no LIBLEPT_HEADERSDIR=$GLOBAL_OUTDIR/include/
##./configure --host=arm-apple-darwin6 --enable-shared=no --prefix=`pwd`/$LOCAL_OUTDIR/arm7/ --with-extra-libraries=/usr/local/lib LIBLEPT_HEADERSDIR=/usr/local/include
#make -j4
#for i in `find . -name "lib*.a"`; do cp -rvf $i $LOCAL_OUTDIR/arm6; done
#merge_libfiles $LOCAL_OUTDIR/arm6 libtesseract_all.a
#echo "Buidl for arm6"

make clean 2> /dev/null
make distclean 2> /dev/null
setenv_arm7
export LDFLAGS="$LDFLAGS -ltiff"
bash autogen.sh
export LIBLEPT_HEADERSDIR=/usr/local/include
./configure --host=arm-apple-darwin7 --enable-shared=no --prefix=/usr/local/ --with-extra-libraries=/usr/local/lib
make -j4
for i in `find . -name "lib*.a" | grep -v arm`; do cp -rvf $i $LOCAL_OUTDIR/arm7; done
merge_libfiles $LOCAL_OUTDIR/arm7 libtesseract_all.a
echo "Buidl for arm7"

make clean 2> /dev/null
make distclean 2> /dev/null
setenv_i386
export LDFLAGS="$LDFLAGS -ltiff"
bash autogen.sh
export LIBLEPT_HEADERSDIR=/usr/local/include
./configure --host=x86_64 --enable-shared=no --host=i386 --prefix=/usr/local/ --with-extra-libraries=/usr/local/lib
make -j4
for i in `find . -name "lib*.a" | grep -v arm`; do cp -rvf $i $LOCAL_OUTDIR/i386; done
merge_libfiles $LOCAL_OUTDIR/i386 libtesseract_all.a
echo "Buidl for i386"

create_outdir_lipo
mkdir -p $GLOBAL_OUTDIR/include/tesseract
tess_inc=( api/apitypes.h api/baseapi.h ccmain/thresholder.h ccstruct/publictypes.h ccutil/errcode.h
           ccutil/genericvector.h ccutil/helpers.h ccutil/host.h ccutil/ndminx.h ccutil/ocrclass.h
           ccutil/platform.h ccutil/tesscallback.h ccutil/unichar.h )
for i in "${tess_inc[@]}"; do
   cp -rvf $i $GLOBAL_OUTDIR/include/tesseract
done
mkdir -p $GLOBAL_OUTDIR/lib && cp -rvf $LOCAL_OUTDIR/lib*.a $GLOBAL_OUTDIR/lib
make clean 2> /dev/null
make distclean 2> /dev/null
rm -rf $LOCAL_OUTDIR
cd ..

echo "Finished!"

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值