Created
April 23, 2018 00:51
-
-
Save ic/eeef143db80557000b954f257a48675d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Build Tesseract with Autotools on Darwin. | |
# | |
# Tested with a MacPorts environment. | |
# | |
# Code for a Homebrew environment is here too, but little tested. | |
# It worked at some point, but it will probably fail for 4.x. It | |
# should look like the MacPorts command, though. | |
# | |
set -ex | |
# | |
# A long utility to get the equivalent to readlink -f | |
# | |
# TODO add reference from SO. | |
# | |
function get_realpath() { | |
local queue="$1" | |
if [ "${queue}" != "/*" ] | |
then | |
# Make sure we start with an absolute path. | |
queue="${PWD}/${queue}" | |
fi | |
local current="" | |
while [ -n "${queue}" ] | |
do | |
# Removing a trailing /. | |
queue="${queue#/}" | |
# Pull the first path segment off of queue. | |
local segment="${queue%%/*}" | |
# If this is the last segment. | |
if [ "${queue}" != "*/*" ] | |
then | |
segment="${queue}" | |
queue="" | |
else | |
# Remove that first segment. | |
queue="${queue#*/}" | |
fi | |
local link="${current}/${segment}" | |
if [ -h "${link}" ] | |
then | |
link="$(readlink "${link}")" | |
queue="${link}/${queue}" | |
if [ "${link}" == /* ] | |
then | |
current="" | |
fi | |
else | |
current="${link}" | |
fi | |
done | |
echo "${current}" | |
} | |
# | |
# The install procedure. | |
# | |
# Assuming: | |
# * The Tesseract repository in tess, under the current directory. | |
# * A Leptonica build in lept, under the current directory. | |
# | |
WDIR="$(get_realpath $(dirname "$0"))" | |
PREFIX=$WDIR/out | |
mkdir -p $PREFIX | |
LEPTONICA_HOME=$WDIR/lept | |
echo "Will build with Leptonica at $LEPTONICA_HOME" | |
pushd tess | |
./autogen.sh | |
if [ -x '/opt/local/bin/port' ] | |
then | |
echo "Building with MacPorts." | |
PKG_CONFIG_PATH=$LEPTONICA_HOME/lib/pkgconfig \ | |
LIBLEPT_HEADERSDIR=$LEPTONICA_HOME/include ./configure \ | |
--prefix=$PREFIX \ | |
--with-extra-libraries=/opt/local/lib \ | |
--with-extra-libraries=$LEPTONICA_HOME/lib \ | |
--with-extra-includes=/opt/local/include \ | |
--with-extra-includes=$LEPTONICA_HOME/include \ | |
LDFLAGS=-L/opt/local/lib \ | |
CPPFLAGS=-I/opt/local/include \ | |
CXXFLAGS=-Wa,-q | |
elif [ -x '/usr/local/bin/brew' ] | |
then | |
echo "UNTESTED" | |
PKG_CONFIG_PATH=$LEPTONICA_HOME/lib/pkgconfig \ | |
LIBLEPT_HEADERSDIR=$LEPTONICA_HOME/include ./configure \ | |
--prefix=$PREFIX \ | |
--with-extra-libraries=$LEPTONICA_HOME/lib \ | |
--with-extra-includes=$LEPTONICA_HOME/include \ | |
CC=clang \ | |
CXX=clang++ \ | |
CFLAGS="-m64" \ | |
LDFLAGS="-L/usr/local/opt/icu4c/lib -L$LEPTONICA_HOME/lib" \ | |
CPPFLAGS="-I/usr/local/opt/icu4c/include -I$LEPTONICA_HOME/include" | |
else | |
echo "Could not find whether to assume MacPorts or Homebrew, aborting." | |
popd | |
exit 1 | |
fi | |
make | |
make install | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment