Skip to content

Commit

Permalink
1. Libtiff update, so it is built for architectures specified in ARCH…
Browse files Browse the repository at this point in the history
…S environment variable only.

2. Makefile updated to support ARCHS environment variable only for building specified architectures only.
3. README_howto_compile_libraries.md updated to explain above changes.
4. Prebuilt script changed to build only active architectures of dependent libraries in Travis CI build environment.
  • Loading branch information
ws233 committed Sep 13, 2015
1 parent 1667960 commit a800676
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 43 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ xcode_sdk:
xcode_scheme:
- Template Framework Project
- TestsProject
env:
- BUILD_DEPENDENT_LIBRARIES=true
- BUILD_DEPENDENT_LIBRARIES=false
before_install:
sudo pip install PyYAML; sudo pip install cpp-coveralls; cd TesseractOCR; make; cd ..
sudo pip install PyYAML; sudo pip install cpp-coveralls
after_success:
./scripts/coveralls.rb --extension m --extension mm --exclude-folder include --exclude-folder TestsProject

2 changes: 1 addition & 1 deletion Tesseract OCR iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export PATH=\"$PATH:/usr/local/bin\" # That's the path where the aclocal is installed\ncd TesseractOCR\n#make\n";
shellScript = "# just uncomment the following line if you wish to make dependent libraries from xcode\n#export BUILD_DEPENDENT_LIBRARIES=\"true\"\nif [ $BUILD_DEPENDENT_LIBRARIES = \"true\" ]\nthen\n cd TesseractOCR\n make\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
73 changes: 35 additions & 38 deletions TesseractOCR/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ libjpegfiles = libjpeg.a
libtifffiles = libtiff.a

sdks = $(SDK_IPHONEOS_PATH) $(SDK_IPHONEOS_PATH) $(SDK_IPHONEOS_PATH) $(SDK_IPHONESIMULATOR_PATH) $(SDK_IPHONESIMULATOR_PATH)
archs = armv7 armv7s arm64 i386 x86_64
arch_names = arm-apple-darwin7 arm-apple-darwin7s arm-apple-darwin64 i386-apple-darwin x86_64-apple-darwin
archs_all = armv7 armv7s arm64 i386 x86_64
arch_names_all = arm-apple-darwin7 arm-apple-darwin7s arm-apple-darwin64 i386-apple-darwin x86_64-apple-darwin
arch_names = $(foreach arch, $(ARCHS), $(call swap, $(arch), $(archs_all), $(arch_names_all) ) )
ARCHS ?= $(archs_all)

libleptfolders = $(foreach arch, $(arch_names), $(LEPTON_SRC)/$(arch)/)
libtessfolders = $(foreach arch, $(arch_names), $(TESSERACT_SRC)/$(arch)/)
libleptfolders_all = $(foreach arch, $(arch_names_all), $(LEPTON_SRC)/$(arch)/)
libtessfolders_all = $(foreach arch, $(arch_names_all), $(TESSERACT_SRC)/$(arch)/)

libleptmakefile = $(foreach folder, $(libleptfolders), $(addprefix $(folder), Makefile) )
libtessmakefile = $(foreach folder, $(libtessfolders), $(addprefix $(folder), Makefile) )
Expand Down Expand Up @@ -63,6 +67,8 @@ swap = $(word $(call index,$(1),$(2)),$(3))

dependant_libs = $(libtessfat) $(libleptfat) $(libpngfat) $(libjpegfat) $(libtifffat)

common_cflags = -L$(LIB_FAT_DIR) -Qunused-arguments -arch $(call swap, $*, $(arch_names_all), $(archs_all)) -pipe -no-cpp-precomp -isysroot $$SDKROOT -miphoneos-version-min=$(IOS_DEPLOY_TGT) -O2

.PHONY : all
all : $(dependant_libs)

Expand All @@ -71,19 +77,17 @@ all : $(dependant_libs)
#######################
$(libtessfat) : $(libtess)
mkdir -p $(LIB_FAT_DIR)
xcrun lipo $^ -create -output $@
xcrun lipo $(realpath $(addsuffix lib/$(@F), $(libtessfolders_all)) ) -create -output $@
mkdir -p $(TESS_INC_DIR)
cp -rvf $(firstword $(libtessfolders))/include/tesseract $(TESS_INC_DIR)

$(libtess) : $(liblept) $(libtessmakefile)
echo $(libtess)
cd $(abspath $(@D)/..) ; \
$(MAKE) -sj8 && $(MAKE) install
$(libtess) : $(libtessmakefile)
cd $(abspath $(@D)/..) && $(MAKE) -sj8 && $(MAKE) install

$(TESSERACT_SRC)/%/Makefile : $(libtessconfig)
$(TESSERACT_SRC)/%/Makefile : $(libtessconfig) $(libleptfat)
export LIBS="-lz -lpng -ljpeg -ltiff" ; \
export SDKROOT="$(call swap, $*, $(arch_names), $(sdks))" ; \
export CFLAGS="-I$(TESSERACT_SRC)/$*/ -L$(LIB_FAT_DIR) -Qunused-arguments -arch $(call swap, $*, $(arch_names), $(archs)) -pipe -no-cpp-precomp -isysroot $$SDKROOT -miphoneos-version-min=$(IOS_DEPLOY_TGT) -O2" ; \
export SDKROOT="$(call swap, $*, $(arch_names_all), $(sdks))" ; \
export CFLAGS="-I$(TESSERACT_SRC)/$*/ $(common_cflags)" ; \
export CPPFLAGS=$$CFLAGS ; \
export CXXFLAGS="$$CFLAGS -Wno-deprecated-register"; \
export LDFLAGS="-L$$SDKROOT/usr/lib/ -L$(LEPTON_SRC)/$*/src/.libs" ; \
Expand All @@ -94,26 +98,25 @@ $(TESSERACT_SRC)/%/Makefile : $(libtessconfig)
../configure --host=$* --prefix=`pwd` --enable-shared=no --disable-graphics

$(libtessconfig) : $(libtessautogen)
cd $(@D) ; \
./autogen.sh
cd $(@D) && ./autogen.sh 2> /dev/null

#######################
# LEPTONLIB
#######################
$(libleptfat) : $(liblept)
mkdir -p $(LIB_FAT_DIR)
xcrun lipo $^ -create -output $@
xcrun lipo $(realpath $(addsuffix lib/$(@F), $(libleptfolders_all)) ) -create -output $@
mkdir -p $(LEPT_INC_DIR)
cp -rvf $(firstword $(libleptfolders))/include/leptonica $(LEPT_INC_DIR)

$(liblept) : $(libleptmakefile)
cd $(abspath $(@D)/..) ; \
$(MAKE) -s && $(MAKE) install
$(MAKE) -sj8 && $(MAKE) install

$(LEPTON_SRC)/%/Makefile : $(imagesfat) $(libleptconfig)
export LIBS="-lz -lpng -ljpeg -ltiff" ; \
export SDKROOT="$(call swap, $*, $(arch_names), $(sdks))" ; \
export CFLAGS="-I$(INCLUDE_DIR) -L$(LIB_FAT_DIR) -Qunused-arguments -arch $(call swap, $*, $(arch_names), $(archs)) -pipe -no-cpp-precomp -isysroot $$SDKROOT -miphoneos-version-min=$(IOS_DEPLOY_TGT) -O2" ; \
export SDKROOT="$(call swap, $*, $(arch_names_all), $(sdks))" ; \
export CFLAGS="-I$(INCLUDE_DIR) $(common_cflags)" ; \
export CPPFLAGS=$$CFLAGS ; \
export CXXFLAGS="$$CFLAGS -Wno-deprecated-register"; \
export LDFLAGS="-L$$SDKROOT/usr/lib/ -L$(LIB_FAT_DIR)" ; \
Expand All @@ -130,9 +133,9 @@ $(imagesfat) : $(images)
mkdir -p $(INCLUDE_DIR)
cp -rvf $(IMAGE_INC_DIR) $(INCLUDE_DIR)

$(images) : $(imagesmakefile)
$(images) : $(imagesmakefile) FORCE
cd $(IMAGE_SRC) ; \
$(MAKE) -s
until `$(MAKE) -s`; do sleep 5; done

#######################
# Download dependencies
Expand Down Expand Up @@ -163,41 +166,33 @@ cleanimages :

.PHONY : cleanlept
cleanlept :
for folder in $(libleptfolders); do \
if [ -d $$folder ]; then \
cd $$folder; \
$(MAKE) clean; \
fi; \
for folder in $(realpath $(libleptfolders_all) ); do \
cd $$folder; \
$(MAKE) clean; \
done ;

.PHONY : cleantess
cleantess :
for folder in $(libtessfolders); do \
if [ -d $$folder ]; then \
cd $$folder; \
$(MAKE) clean; \
fi; \
for folder in $(realpath $(libtessfolders_all) ); do \
cd $$folder; \
$(MAKE) clean; \
done ;

.PHONY : mostlycleanimages
mostlycleanimages :

.PHONY : mostlycleanlept
mostlycleanlept :
for folder in $(libleptfolders); do \
if [ -d $$folder ]; then \
cd $$folder; \
$(MAKE) mostlyclean; \
fi; \
for folder in $(realpath $(libleptfolders) ); do \
cd $$folder; \
$(MAKE) mostlyclean; \
done ;

.PHONY : mostlycleantess
mostlycleantess :
for folder in $(libtessfolders); do \
if [ -d $$folder ]; then \
cd $$folder; \
$(MAKE) mostlyclean; \
fi; \
for folder in $(realpath $(libtessfolders_all) ); do \
cd $$folder; \
$(MAKE) mostlyclean; \
done ;

.PHONY : distcleanimages
Expand All @@ -216,3 +211,5 @@ distcleantess :
-rm -rf $(libtessfat)
-rm -rf $(TESSERACT_SRC)

.PHONY : FORCE
FORCE :
8 changes: 6 additions & 2 deletions TesseractOCR/README_howto_compile_libaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ First you need to install these tools:
- Libtool

### Step 2 - Build
Run `make` in the `TesseractOCR` subfolder. This first compiles dependent libraries (png, jpeg, tiff, leptonica) and then tesseract for every architecture iOS/simulator uses (arm7 arm7s arm64 i386 x86_64), and then combines the resulting libs into one library file. It does this for both dependent libraries and tesseract, so the final results of the script are "libpng.a", "libjpeg.a", "libtiff.a", "libtesseract_all.a", "liblept.a", and "include" directories for both leptonica, tesseract and image libraries. Finally, the script copies these results into the "lib" and "include" directories inside `TesseractOCR` directory.
Run `make` in the `TesseractOCR` subfolder. This first compiles dependent libraries (png, jpeg, tiff, leptonica) and then tesseract for every architecture iOS/simulator uses (arm7 arm7s arm64 i386 x86_64), and then combines the resulting libs into one library file. It does this for both dependent libraries and tesseract, so the final results of the script are "libpng.a", "libjpeg.a", "libtiff.a", "libtesseract.a", "liblept.a", and "include" directories for both leptonica, tesseract and image libraries. Finally, the script copies these results into the "lib" and "include" directories inside `TesseractOCR` directory.

The very first build may take half an hour or so depending on the processing power, but the later builds will not build dependencies until any files being changed.
The very first total build (includinf all architectures) may take half an hour or so depending on the processing power, but the later builds will not build dependencies until any files being changed.

By default every "fat" library will contain all architectures specified above. So it can be linked with apps either for devices or simulator. If you don't need all architectures above (for example, for AppStore submittion), just specify the necessary architectures in the `ARCHS` environement variable as follows:

export ARCHS=armv7, armv7s, arm64
2 changes: 1 addition & 1 deletion TesseractOCR/libtiff-ios
Submodule libtiff-ios updated 2 files
+38 −45 Makefile
+5 −1 README.md

0 comments on commit a800676

Please sign in to comment.