-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
197 lines (159 loc) · 6.32 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
include ./include/config.mk
TESSERACT_SRC = $(shell pwd)/tesseract-$(TESSERACT_VERSION)
LEPTON_SRC = $(shell pwd)/$(LEPTON_NAME)
IMAGE_SRC = $(shell pwd)/libtiff-ios
IMAGE_LIB_DIR = $(IMAGE_SRC)/dependencies/lib/
IMAGE_INC_DIR = $(IMAGE_SRC)/dependencies/include/
INCLUDE_DIR = $(shell pwd)/dependencies/include
LEPT_INC_DIR = $(INCLUDE_DIR)
TESS_INC_DIR = $(INCLUDE_DIR)
LIB_FAT_DIR = $(shell pwd)/dependencies/lib
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) )
imagesmakefile = $(addprefix $(IMAGE_SRC)/, Makefile)
libleptfat = $(LIB_FAT_DIR)/$(libleptfiles)
libtessfat = $(LIB_FAT_DIR)/$(libtessfiles)
imagesfat = $(libpngfat) $(libjpegfat) $(libtifffat)
libpngfat = $(LIB_FAT_DIR)/$(libpngfiles)
libjpegfat = $(LIB_FAT_DIR)/$(libjpegfiles)
libtifffat = $(LIB_FAT_DIR)/$(libtifffiles)
libtess = $(foreach folder, $(libtessfolders), $(addprefix $(folder)/lib/, $(libtessfiles)) )
liblept = $(foreach folder, $(libleptfolders), $(addprefix $(folder)/lib/, $(libleptfiles)) )
images = $(libpng) $(libjpeg) $(libtiff)
libpng = $(addprefix $(IMAGE_LIB_DIR), $(libpngfiles))
libjpeg = $(addprefix $(IMAGE_LIB_DIR), $(libjpegfiles))
libtiff = $(addprefix $(IMAGE_LIB_DIR), $(libtifffiles))
libtessautogen = $(TESSERACT_SRC)/autogen.sh
libtessconfig = $(TESSERACT_SRC)/configure
libleptconfig = $(LEPTON_SRC)/configure
index = $(words $(shell a="$(2)";echo $${a/$(1)*/$(1)} ))
swap = $(word $(call index,$(1),$(2)),$(3))
dependant_libs = $(libtessfat) $(libleptfat) $(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)
#######################
# TESSERACT-OCR
#######################
$(libtessfat) : $(libtess)
mkdir -p $(LIB_FAT_DIR)
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) : $(libtessmakefile)
cd $(abspath $(@D)/..) && $(MAKE) -sj8 && $(MAKE) install
$(TESSERACT_SRC)/%/Makefile : $(libtessconfig) $(libleptfat)
export LIBS="-lz -lpng -ljpeg -ltiff" ; \
export SDKROOT="$(call swap, $*, $(arch_names_all), $(sdks))" ; \
export CFLAGS="-I$(TESSERACT_SRC)/$*/ $(common_cflags) -fembed-bitcode" ; \
export CPPFLAGS=$$CFLAGS ; \
export CXXFLAGS="-I$(TESSERACT_SRC)/$*/ $(common_cflags) -Wno-deprecated-register"; \
export LDFLAGS="-L$$SDKROOT/usr/lib/ -L$(LEPTON_SRC)/$*/src/.libs" ; \
export LEPTONICA_CFLAGS="-I$(TESSERACT_SRC)/$*/ $(common_cflags) -I$(LEPT_INC_DIR)/leptonica" ; \
export LEPTONICA_LIBS="-llept" ; \
mkdir -p $(@D) ; \
cd $(@D) ; \
ln -s $(LEPTON_SRC)/src/ leptonica ; \
../configure --host=$* --prefix=`pwd` --enable-shared=no --disable-graphics
$(libtessconfig) : $(libtessautogen)
cd $(@D) && ./autogen.sh 2> /dev/null
#######################
# LEPTONLIB
#######################
$(libleptfat) : $(liblept)
mkdir -p $(LIB_FAT_DIR)
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) -sj8 && $(MAKE) install
$(LEPTON_SRC)/%/Makefile : $(imagesfat) $(libleptconfig)
export LIBS="-lz -lpng -ljpeg -ltiff" ; \
export SDKROOT="$(call swap, $*, $(arch_names_all), $(sdks))" ; \
export CFLAGS="-I$(INCLUDE_DIR) $(common_cflags) -fembed-bitcode" ; \
export CPPFLAGS=$$CFLAGS ; \
export CXXFLAGS="-I$(INCLUDE_DIR) $(common_cflags) -Wno-deprecated-register"; \
export LDFLAGS="-L$$SDKROOT/usr/lib/ -L$(LIB_FAT_DIR)" ; \
mkdir -p $(@D) ; \
cd $(@D) ; \
../configure --host=$* --prefix=`pwd` --enable-shared=no --disable-programs --with-zlib --with-libpng --with-jpeg --without-giflib --without-libwebp --without-libopenjpeg --with-libtiff
#######################
# Build libtiff and all of it's dependencies
#######################
$(imagesfat) : $(images)
mkdir -p $(@D)
cp -rvf $? $(@D)
mkdir -p $(INCLUDE_DIR)
cp -rvf $(IMAGE_INC_DIR) $(INCLUDE_DIR)
$(images) : $(imagesmakefile) FORCE
cd $(IMAGE_SRC) ; \
until `$(MAKE) -s`; do sleep 5; done
#######################
# Download dependencies
#######################
$(imagesmakefile) $(libtessautogen) :
mkdir -p dependencies/include
mkdir -p dependencies/lib
cp -R ./include/curl/ dependencies/include/curl/
cp -rvf include/libcurl.a dependencies/lib/libcurl.a
$(libleptconfig) :
curl http://leptonica.org/source/$(LEPTON_NAME).tar.gz | tar -xpf-
#######################
# Clean
#######################
.PHONY : clean
clean : cleanimages cleanlept cleantess
.PHONY : distclean
distclean : distcleanimages distcleanlept distcleantess
.PHONY : mostlyclean
mostlyclean : mostlycleanimages mostlycleanlept mostlycleantess
.PHONY : cleanimages
cleanimages :
cd $(IMAGE_SRC) ; \
$(MAKE) clean
.PHONY : cleanlept
cleanlept :
for folder in $(realpath $(libleptfolders_all) ); do \
cd $$folder; \
$(MAKE) clean; \
done ;
.PHONY : cleantess
cleantess :
for folder in $(realpath $(libtessfolders_all) ); do \
cd $$folder; \
$(MAKE) clean; \
done ;
.PHONY : mostlycleanimages
mostlycleanimages :
.PHONY : mostlycleanlept
mostlycleanlept :
for folder in $(realpath $(libleptfolders) ); do \
cd $$folder; \
$(MAKE) mostlyclean; \
done ;
.PHONY : mostlycleantess
mostlycleantess :
for folder in $(realpath $(libtessfolders_all) ); do \
cd $$folder; \
$(MAKE) mostlyclean; \
done ;
.PHONY : distcleanimages
distcleanimages :
-rm -rf $(IMAGE_SRC)
PHONY : distcleanlept
distcleanlept :
-rm -rf $(LEPT_INC_DIR)/leptonica
-rm -rf $(libleptfat)
-rm -rf $(LEPTON_SRC)
.PHONY : distcleantess
distcleantess :
-rm -rf $(TESS_INC_DIR)/tesseract
-rm -rf $(libtessfat)
-rm -rf $(TESSERACT_SRC)
.PHONY : FORCE
FORCE :