-
Notifications
You must be signed in to change notification settings - Fork 316
/
Makerules
381 lines (336 loc) · 9.93 KB
/
Makerules
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# Configuration for the Makefile
# We use $OS from environment if set.
ifeq ($(OS),)
OS := $(shell uname)
OS := $(OS:MINGW%=MINGW)
OS := $(OS:MSYS%=MINGW)
OS := $(OS:Windows_NT=MINGW)
OS := $(OS:Darwin=MACOS)
endif
WARNING_CFLAGS := -Wall -Wsign-compare
# Feature configuration options
build_suffix :=
ifeq ($(tesseract),yes)
build_suffix := $(build_suffix)-tesseract
USE_TESSERACT := yes
endif
ifeq ($(tofu),yes)
build_suffix := $(build_suffix)-tofu
XCFLAGS += -DTOFU
endif
ifeq ($(tofu_cjk),yes)
build_suffix := $(build_suffix)-tofu_cjk
XCFLAGS += -DTOFU_CJK
endif
ifeq ($(tofu_cjk_ext),yes)
build_suffix := $(build_suffix)-tofu_cjk_ext
XCFLAGS += -DTOFU_CJK_EXT
endif
ifeq ($(tofu_cjk_lang),yes)
build_suffix := $(build_suffix)-tofu_cjk_lang
XCFLAGS += -DTOFU_CJK_LANG
endif
ifeq ($(archive),yes)
build_suffix := $(build_suffix)-archive
XCFLAGS += -DHAVE_LIBARCHIVE
HAVE_LIBARCHIVE := yes
endif
ifeq ($(commercial),yes)
build_suffix := $(build_suffix)-commercial
XCFLAGS += -DHAVE_SMARTOFFICE
HAVE_SMARTOFFICE := yes
endif
# System specific features
ifeq ($(findstring -fembed-bitcode,$(XCFLAGS)),)
# clang does not support these in combination with -fembed-bitcode
CFLAGS += -ffunction-sections -fdata-sections
endif
ifeq ($(OS),MACOS)
LDREMOVEUNREACH := -Wl,-dead_strip
SO := dylib
else
LDREMOVEUNREACH := -Wl,--gc-sections
ifeq ($(OS),MINGW)
SO := dll
EXE := .exe
else
SO := so
endif
endif
ifeq "$(OS)" "ios"
NEONFLAGS =
else
NEONFLAGS = -mneon
endif
SANITIZE_FLAGS += -fsanitize=address
SANITIZE_FLAGS += -fsanitize=leak
ifeq ($(shared),yes)
ifeq ($(findstring shared-, $(build_prefix)),)
override build_prefix := $(build_prefix)shared-
endif
LIB_CFLAGS = -fPIC
ifeq ($(OS),MACOS)
LIB_LDFLAGS = -dynamiclib
else ifeq ($(OS),wasm)
LIB_LDFLAGS = -shared -sSIDE_MODULE
EXE_LDFLAGS = -sMAIN_MODULE
else ifeq ($(OS),wasm-mt)
LIB_LDFLAGS = -shared -sSIDE_MODULE
EXE_LDFLAGS = -sMAIN_MODULE
else ifeq ($(OS),pyodide)
LIB_LDFLAGS = -shared -sSIDE_MODULE
EXE_LDFLAGS = -sMAIN_MODULE
# Pyodide's ld does not support -b so we cannot use it to create object
# files containing font data, so leave HAVE_OBJCOPY unset. And we need
# extra memory when linking.
LDFLAGS += -sTOTAL_MEMORY=48MB
else
LIB_LDFLAGS = -shared
endif
else
LIB_CFLAGS =
LIB_LDFLAGS =
endif
ifeq ($(build),debug)
CFLAGS += -pipe -g
LDFLAGS += -g
else ifeq ($(build),release)
CFLAGS += -pipe -O2 -DNDEBUG
LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
else ifeq ($(build),small)
CFLAGS += -pipe -Os -DNDEBUG
LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
else ifeq ($(build),valgrind)
CFLAGS += -pipe -O2 -DNDEBUG -DPACIFY_VALGRIND
LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
else ifeq ($(build),sanitize)
CFLAGS += -pipe -g $(SANITIZE_FLAGS)
LDFLAGS += -g $(SANITIZE_FLAGS)
else ifeq ($(build),sanitize-release)
CFLAGS += -pipe -O2 -DNDEBUG $(SANITIZE_FLAGS)
LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s $(SANITIZE_FLAGS)
else ifeq ($(build),profile)
CFLAGS += -pipe -O2 -DNDEBUG -pg
LDFLAGS += -pg
else ifeq ($(build),coverage)
CFLAGS += -pipe -g -pg -fprofile-arcs -ftest-coverage
LIBS += -lgcov
else ifeq ($(build),native)
CFLAGS += -pipe -O2 -DNDEBUG -march=native
LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
else ifeq ($(build),memento)
CFLAGS += -pipe -g -DMEMENTO -DMEMENTO_MUPDF_HACKS
LDFLAGS += -g -rdynamic
ifneq ($(HAVE_LIBDL),no)
CFLAGS += -DHAVE_LIBDL
ifeq ($(OS),OpenBSD)
LIBS += -L /usr/local/lib -l execinfo
else
LIBS += -ldl
endif
endif
else ifeq ($(build),gperf)
CFLAGS += -pipe -O2 -DNDEBUG -DGPERF
LIBS += -lprofiler
else
$(error unknown build setting: '$(build)')
endif
ifeq ($(OS),OpenBSD)
LDFLAGS += -pthread
endif
# Default system libraries
SYS_FREETYPE_LIBS := -lfreetype2
SYS_HARFBUZZ_LIBS := -lharfbuzz
SYS_JBIG2DEC_LIBS := -ljbig2dec
SYS_JPEGXR_LIBS := -ljpegxr
SYS_LCMS2_LIBS := -llcms2
SYS_LIBJPEG_LIBS := -ljpeg
SYS_MUJS_LIBS := -lmujs
SYS_OPENJPEG_LIBS := -lopenjp2
SYS_ZLIB_LIBS := -lz
SYS_TESSERACT_LIBS := -ltesseract
SYS_LEPTONICA_LIBS := -llept
SYS_LIBARCHIVE_LIBS := -larchive
ifneq "$(CLUSTER)" ""
CFLAGS += -DCLUSTER
endif
ifeq ($(OS),Linux)
LINUX_OR_OPENBSD := yes
endif
ifeq ($(OS),OpenBSD)
LINUX_OR_OPENBSD := yes
endif
ifeq ($(OS),MINGW)
WINDRES := windres
HAVE_WIN32 := yes
else ifeq ($(OS),MACOS)
HAVE_GLUT := yes
SYS_GLUT_CFLAGS := -Wno-deprecated-declarations
SYS_GLUT_LIBS := -framework GLUT -framework OpenGL
CC = xcrun cc
AR = xcrun ar
LD = xcrun ld
RANLIB = xcrun ranlib
ifneq ($(ARCHFLAGS),)
$(warning "MacOS with ARCHFLAGS set. Assuming we are building for arm64, and setting HAVE_LIBCRYPTO to no.")
HAVE_LIBCRYPTO := no
else ifeq (, $(shell command -v pkg-config))
$(warning "No pkg-config found, install it for proper integration of libcrypto")
else
HAVE_LIBCRYPTO := $(shell pkg-config --exists 'libcrypto >= 1.1.0' && echo yes)
ifeq ($(HAVE_LIBCRYPTO),yes)
LIBCRYPTO_CFLAGS := $(shell pkg-config --cflags libcrypto) -DHAVE_LIBCRYPTO
LIBCRYPTO_LIBS := $(shell pkg-config --libs libcrypto)
endif
endif
else ifeq ($(LINUX_OR_OPENBSD),yes)
ifeq ($(OS),Linux)
HAVE_OBJCOPY := yes
endif
ifeq ($(shell pkg-config --exists freetype2 && echo yes),yes)
SYS_FREETYPE_CFLAGS := $(shell pkg-config --cflags freetype2)
SYS_FREETYPE_LIBS := $(shell pkg-config --libs freetype2)
endif
ifeq ($(shell pkg-config --exists gumbo && echo yes),yes)
SYS_GUMBO_CFLAGS := $(shell pkg-config --cflags gumbo)
SYS_GUMBO_LIBS := $(shell pkg-config --libs gumbo)
endif
ifeq ($(shell pkg-config --exists harfbuzz && echo yes),yes)
SYS_HARFBUZZ_CFLAGS := $(shell pkg-config --cflags harfbuzz)
SYS_HARFBUZZ_LIBS := $(shell pkg-config --libs harfbuzz)
endif
ifeq ($(shell pkg-config --exists lcms2 && echo yes),yes)
SYS_LCMS2_CFLAGS := $(shell pkg-config --cflags lcms2)
SYS_LCMS2_LIBS := $(shell pkg-config --libs lcms2)
endif
ifeq ($(shell pkg-config --exists libjpeg && echo yes),yes)
SYS_LIBJPEG_CFLAGS := $(shell pkg-config --cflags libjpeg)
SYS_LIBJPEG_LIBS := $(shell pkg-config --libs libjpeg)
endif
ifeq ($(shell pkg-config --exists libopenjp2 && echo yes),yes)
SYS_OPENJPEG_CFLAGS := $(shell pkg-config --cflags libopenjp2)
SYS_OPENJPEG_LIBS := $(shell pkg-config --libs libopenjp2)
endif
ifeq ($(shell pkg-config --exists zlib && echo yes),yes)
SYS_ZLIB_CFLAGS := $(shell pkg-config --cflags zlib)
SYS_ZLIB_LIBS := $(shell pkg-config --libs zlib)
endif
HAVE_SYS_LEPTONICA := $(shell pkg-config --exists 'lept >= 1.7.4' && echo yes)
ifeq ($(HAVE_SYS_LEPTONICA),yes)
SYS_LEPTONICA_CFLAGS := $(shell pkg-config --cflags lept)
SYS_LEPTONICA_LIBS := $(shell pkg-config --libs lept)
endif
HAVE_SYS_TESSERACT := $(shell pkg-config --exists 'tesseract >= 4.0.0' && echo yes)
ifeq ($(HAVE_SYS_TESSERACT),yes)
SYS_TESSERACT_CFLAGS := $(shell pkg-config --cflags tesseract)
SYS_TESSERACT_LIBS := $(shell pkg-config --libs tesseract)
endif
HAVE_SYS_LIBARCHIVE := $(shell pkg-config --exists 'libarchive' && echo yes)
ifeq ($(HAVE_SYS_LIBARCHIVE),yes)
SYS_LIBARCHIVE_CFLAGS := $(shell pkg-config --cflags libarchive)
SYS_LIBARCHIVE_LIBS := $(shell pkg-config --libs libarchive)
endif
HAVE_SYS_CURL := $(shell pkg-config --exists libcurl && echo yes)
ifeq ($(HAVE_SYS_CURL),yes)
SYS_CURL_CFLAGS := $(shell pkg-config --cflags libcurl)
SYS_CURL_LIBS := $(shell pkg-config --libs libcurl)
endif
HAVE_GLUT := yes
ifeq ($(HAVE_GLUT),yes)
ifeq ($(OS),OpenBSD)
SYS_GLUT_CFLAGS := $(shell pkg-config --cflags glut gl)
SYS_GLUT_LIBS := $(shell pkg-config --libs glut gl)
else
SYS_GLUT_CFLAGS :=
SYS_GLUT_LIBS := -lglut -lGL
endif
endif
HAVE_X11 := $(shell pkg-config --exists x11 xext && echo yes)
ifeq ($(HAVE_X11),yes)
X11_CFLAGS := $(shell pkg-config --cflags x11 xext)
X11_LIBS := $(shell pkg-config --libs x11 xext)
endif
ifeq ($(HAVE_LIBCRYPTO),)
HAVE_LIBCRYPTO := $(shell pkg-config --exists 'libcrypto >= 1.1.0' && echo yes)
endif
ifeq ($(HAVE_LIBCRYPTO),yes)
LIBCRYPTO_CFLAGS := $(shell pkg-config --cflags libcrypto) -DHAVE_LIBCRYPTO
LIBCRYPTO_LIBS := $(shell pkg-config --libs libcrypto)
endif
HAVE_PTHREAD := yes
ifeq ($(HAVE_PTHREAD),yes)
PTHREAD_CFLAGS :=
PTHREAD_LIBS := -lpthread
endif
endif
# The following section has various cross compilation configurations.
#
# Invoke these as:
# make OS=mingw32-cross
#
# This does rely on the generated directory being populated with the font files.
# On a unix-like system, run 'make generate' before doing the cross compile.
# On Windows, run 'nmake -f scripts\fontdump.nmake' in a Visual Studio command prompt.
ifeq "$(OS)" "wasm"
build_prefix += wasm/
CC = emcc
CXX = em++
AR = emar
HAVE_GLUT=no
HAVE_X11=no
HAVE_OBJCOPY=no
HAVE_LIBCRYPTO=no
endif
ifeq "$(OS)" "wasm-mt"
build_prefix += wasm-mt/
CC = emcc
CXX = em++
AR = emar
HAVE_GLUT=no
HAVE_X11=no
HAVE_OBJCOPY=no
HAVE_LIBCRYPTO=no
CFLAGS += -pthread
endif
ifeq "$(OS)" "pyodide"
build_prefix += $(OS)/
# We use the provided $CC and $CXX.
AR = emar
HAVE_GLUT=no
HAVE_X11=no
HAVE_OBJCOPY=no
HAVE_LIBCRYPTO=no
CFLAGS += -pthread
endif
ifeq "$(OS)" "mingw32-cross"
build_prefix += $(OS)/
SO := dll
EXE := .exe
CC = i686-w64-mingw32-gcc
CXX = i686-w64-mingw32-g++
LD = i686-w64-mingw32-gcc
AR = i686-w64-mingw32-ar
WINDRES = i686-w64-mingw32-windres
HAVE_WIN32=yes
endif
ifeq "$(OS)" "mingw64-cross"
build_prefix += $(OS)/
SO := dll
EXE := .exe
CC = x86_64-w64-mingw32-gcc
CXX = x86_64-w64-mingw32-g++
LD = x86_64-w64-mingw32-gcc
AR = x86_64-w64-mingw32-ar
WINDRES = x86_64-w64-mingw32-windres
HAVE_WIN32=yes
endif
# Most variables when building for iOS are set up in ios/build_libs.sh,
# which is called from the Xcode project as a "Run Script" build step.
# The following section works for both device and simulator builds.
ifeq "$(OS)" "ios"
CC = xcrun cc
CXX = xcrun c++
AR = xcrun ar
LD = xcrun ld
RANLIB = xcrun ranlib
endif