[buildout]
extends =
  ../automake/buildout.cfg
  ../libtool/buildout.cfg
  ../leptonica/buildout.cfg

parts =
  tesseract-eng-traineddata-unzip
  tesseract

[tesseract-share]
# XXX: tesseract seems not easy configurable on runtime about where to find
# its trained data, so just move out its datadir to own controlled location
recipe = plone.recipe.command
location = ${buildout:parts-directory}/${:_buildout_section_name_}
command = mkdir -p ${:location} && mkdir -p ${:location}/tessdata
update-command = ${:command}
stop-on-error = yes


[tesseract-gcc-4.7-build-patch]
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
download-only = true
filename = tesseract-3.00-gcc-4.7-build.patch
md5sum = ca80db3ec489c547b03f3ee48879c1b1

[tesseract]
recipe = hexagonit.recipe.cmmi
url = http://tesseract-ocr.googlecode.com/files/tesseract-3.01.tar.gz
md5sum = 1ba496e51a42358fb9d3ffe781b2d20a
patch-options =
  -p1
patches =
  ${tesseract-gcc-4.7-build-patch:location}/${tesseract-gcc-4.7-build-patch:filename}
configure-command =
  aclocal -I ${libtool:location}/share/aclocal -I config
  libtoolize -f -c
  libtoolize --automake
  autoheader -f
  automake -c -a -f
  autoconf -c -Wno-portability
  autoreconf -i
  ./configure --prefix=${buildout:parts-directory}/${:_buildout_section_name_} --disable-static --datarootdir=${tesseract-share:location}

# tesseract has a non-standard way of testing for leptonica, hence the
# LIBLEPT_HEADERSDIR entry below:
environment =
  PATH=${autoconf:location}/bin:${automake-1.11:location}/bin:${libtool:location}/bin:%(PATH)s
  ACLOCAL_ARGS=-I${libtool:location}/share/aclocal
  LIBLEPT_HEADERSDIR=${leptonica:location}/include
  CPPFLAGS=-I${leptonica:location}/include
  LDFLAGS =-L${leptonica:location}/lib -Wl,-rpath=${leptonica:location}/lib

[tesseract-eng-traineddata]
recipe = hexagonit.recipe.download
download-only = true
url = http://tesseract-ocr.googlecode.com/files/eng.traineddata.gz
md5sum = d91041ad156cf2db36664e91ef799451

[tesseract-eng-traineddata-unzip]
location = ${buildout:parts-directory}/${:_buildout_section_name_}
recipe = plone.recipe.command
command = gunzip ${tesseract-eng-traineddata:location}/eng.traineddata.gz -c > ${tesseract-share:location}/tessdata/eng.traineddata
update-command = ${:command}
stop-on-error = yes