forked from koreader/koreader-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.defs
982 lines (881 loc) · 37.2 KB
/
Makefile.defs
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
SHELL:=/bin/bash
# Use ccache in build system by default. Define USE_NO_CCACHE=1 to force disable it.
ifeq ($(USE_NO_CCACHE), 1)
CCACHE:=
else
CCACHE?=$(shell command -v ccache)
endif
UNAME:=$(shell uname -s)
# use MAKEFILE_DIR instead of CURDIR for variables that are exported through -include
MAKEFILE_DIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
TOOLCHAIN_DIR=$(MAKEFILE_DIR)toolchain
# Android API level 14 is the minimum target for NDK 15
ANDROID_ARCH?=arm
ANDROID_TOOLCHAIN=$(TOOLCHAIN_DIR)/android-toolchain-$(ANDROID_ARCH)
NDK?=$(TOOLCHAIN_DIR)/android-ndk-r15c
NDKABI?=14
# Detect LuaRocks 3
LR_VER_NUM := $(shell luarocks --version | grep -o [0-9].[0-9])
LR_GT_3_0 := $(shell awk -v LR_VER_NUM=$(LR_VER_NUM) 'BEGIN { print (LR_VER_NUM >= 3.0); }')
# Some CMake flags
CMAKE_BUILD_TYPE?=Release
# set debug-related variables to cascade down
ifdef KODEBUG
DEBUG:=$(KODEBUG)
export DEBUG
# will have to be passed as -DCMAKE_BUILD_TYPE to $(CMAKE) invocations
CMAKE_BUILD_TYPE:=Debug
endif
export CMAKE_BUILD_TYPE
# CMAKE:=cmake --no-warn-unused-cli
CMAKE := cmake
ifdef VERBOSE
CMAKE_ARGS := -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
endif
CMAKE+=$(CMAKE_ARGS)
NINJA := $(shell command -v ninja)
ifneq ($(NINJA),)
ifeq ($(USE_MAKE),)
USE_NINJA := 1
endif
endif
ifneq ($(USE_NINJA),)
CMAKE_FLAGS := -G Ninja
CMAKE_MAKE_PROGRAM := $(NINJA)
ifdef VERBOSE
NINJA_FLAGS := -v
endif
CMAKE_MAKE_PROGRAM_FLAGS ?= $(NINJA_FLAGS)
else
CMAKE_MAKE_PROGRAM := $(MAKE)
ifdef VERBOSE
MAKE_FLAGS := VERBOSE=1
endif
CMAKE_MAKE_PROGRAM_FLAGS ?= $(MAKE_FLAGS)
endif
$(info ************ CMAKE_MAKE_PROGRAM: "$(CMAKE_MAKE_PROGRAM)" **********)
# set this to your ARM cross compiler:
# set CC CXX AR LD RANLIB
ifeq ($(TARGET), arm-generic)
CHOST?=arm-linux-gnueabi
else ifeq ($(TARGET), kindle)
export KINDLE=1
HAS_KINDLE5_TC:=$(shell command -v arm-kindle5-linux-gnueabi-gcc 2> /dev/null)
ifdef HAS_KINDLE5_TC
#Use the custom build TC
CHOST?=arm-kindle5-linux-gnueabi
else
#Use the generic linaro TC for debugging
CHOST?=arm-linux-gnueabi
endif
else ifeq ($(TARGET), kindlepw2)
export KINDLE=1
HAS_KINDLEPW2_TC:=$(shell command -v arm-kindlepw2-linux-gnueabi-gcc 2> /dev/null)
ifdef HAS_KINDLEPW2_TC
CHOST?=arm-kindlepw2-linux-gnueabi
else
CHOST?=arm-linux-gnueabi
endif
else ifeq ($(TARGET), kindle-legacy)
export KINDLE=1
CHOST?=arm-kindle-linux-gnueabi
export LEGACY=1
else ifeq ($(TARGET), kobo)
export KOBO=1
HAS_KOBO_TC:=$(shell command -v arm-kobo-linux-gnueabihf-gcc 2> /dev/null)
ifdef HAS_KOBO_TC
CHOST?=arm-kobo-linux-gnueabihf
else
CHOST?=arm-linux-gnueabihf
endif
export USE_LJ_WPACLIENT=1
else ifeq ($(TARGET), ubuntu-touch)
CHOST?=arm-linux-gnueabihf
export SDL=1
export UBUNTUTOUCH=1
else ifeq ($(TARGET), appimage)
export EMULATE_READER=1
export SDL=1
export APPIMAGE=1
else ifeq ($(TARGET), debian)
export SDL=1
export DEBIAN=1
export EMULATE_READER=1
else ifeq ($(TARGET), debian-armel)
CHOST?=arm-linux-gnueabi
export SDL=1
export DEBIAN_CROSS=1
else ifeq ($(TARGET), debian-armhf)
CHOST?=arm-linux-gnueabihf
export SDL=1
export DEBIAN_CROSS=1
else ifeq ($(TARGET), debian-arm64)
CHOST?=aarch64-linux-gnu
export SDL=1
export DEBIAN_CROSS=1
else ifeq ($(TARGET), macos)
export SDL=1
export MACOS=1
export EMULATE_READER=1
else ifeq ($(TARGET), android)
export ANDROID=1
export PATH:=$(ANDROID_TOOLCHAIN)/bin:$(PATH)
export SYSROOT=$(NDK)/platforms/android-$(NDKABI)/arch-$(ANDROID_ARCH)
ifeq ($(ANDROID_ARCH), x86)
CHOST?=i686-linux-android
else
CHOST?=arm-linux-androideabi
endif
# Needed for OpenSSL, c.f., NOTES.ANDROID
export ANDROID_NDK_HOME=$(ANDROID_TOOLCHAIN)
else ifeq ($(TARGET), win32)
CHOST?=x86_64-w64-mingw32
export WIN32=1
export SDL=1
else ifeq ($(TARGET), pocketbook)
CHOST?=arm-pocketbook-linux-gnueabi
export POCKETBOOK=1
HAS_POCKETBOOK_TC:=$(shell command -v arm-pocketbook-linux-gnueabi-gcc 2> /dev/null)
ifdef HAS_POCKETBOOK_TC
CHOST?=arm-pocketbook-linux-gnueabi
else
CHOST?=arm-linux-gnueabi
endif
else ifeq ($(TARGET), remarkable)
CHOST?=arm-remarkable-linux-gnueabihf
export REMARKABLE=1
export USE_LJ_WPACLIENT=1
else ifeq ($(TARGET), sony-prstux)
CHOST?=arm-linux-gnueabihf
export SONY_PRSTUX=1
export USE_LJ_WPACLIENT=1
else ifeq ($(TARGET), cervantes)
export CERVANTES=1
HAS_CERVANTES_TC:=$(shell command -v arm-cervantes-linux-gnueabi-gcc 2> /dev/null)
ifdef HAS_CERVANTES_TC
CHOST?=arm-cervantes-linux-gnueabi
else
CHOST?=arm-linux-gnueabi
endif
export USE_LJ_WPACLIENT=1
else ifndef TARGET
# if TARGET is not defined we will build an emulator on current machine
export EMULATE_READER=1
export SDL=1
else
$(error Invalid TARGET: "$(TARGET)")
endif
ifneq (,$(filter $(UNAME), Darwin))
export DARWINHOST=1
ifdef EMULATE_READER
export DARWIN=1
endif
endif
# ccache still has tons of problems when cross-compiling Android port on Darwin
ifdef DARWINHOST
ifdef ANDROID
CCACHE=
endif
endif
# NOTE: This is necessary (at least on Android), because some early API levels will not put DT_NEEDED libraries in the global namespace.
# Ensuring Lua/C modules have their own DT_NEEDED entry to the shared LuaJIT library works around this quirk (and is otherwise mostly harmless).
# Saner APIs behave like Linux, and wouldn't require this hack.
USE_LUAJIT_LIB=$(or $(DARWIN),$(ANDROID),$(WIN32))
SKIP_LUAJIT_BIN=$(or $(ANDROID),$(MACOS))
# handle utility params on different host systems
ifdef DARWINHOST
RCP:=cp -R
ISED:=sed -i '' -e
else
RCP:=cp -r
ISED:=sed -i -e
endif
# unknown device
ifdef SBOX_UNAME_MACHINE
CC:=gcc
CXX:=g++
endif
# set cross-compiler/host CC and CXX
ifneq (,$(findstring clang, $(CC)))
ifdef CHOST
CC:=$(CHOST)-clang
CXX:=$(CHOST)-clang++
else
CC:=clang
CXX:=clang++
endif
HOSTCC:=clang
HOSTCXX:=clang++
# quiet flag
QFLAGS:=-Wno-ignored-optimization-argument -Wno-unknown-warning-option
# Tone down some very verbose Clang 5 warnings, too.
# This one can be *extremely* verbose
QFLAGS+=-Wno-array-bounds
# This one checks if -I flags are actually used, even at steps where it makes little sense.
# Since we massively pass -I/-L flags ourselves, this becomes insane really quick.
QFLAGS+=-Wno-unused-command-line-argument
# Let FreeType do its thing...
QFLAGS+=-Wno-self-assign
# Also extremely verbose...
QFLAGS+=-Wno-parentheses-equality
# For dropbear's libtom...
QFLAGS+=-Wno-macro-redefined
# Note that things appear to be better with Clang >= 6 ;).
export CLANG=1
else
ifdef CHOST
CC:=$(CHOST)-gcc
CXX:=$(CHOST)-g++
else
CC:=gcc
CXX:=g++
endif
HOSTCC:=gcc
HOSTCXX:=g++
QFLAGS:=
endif
# set cross-compiler/host AR LD RANLIB
ifdef CHOST
STRIP:=$(CHOST)-strip
AR:=$(CHOST)-ar
LD:=$(CHOST)-ld
RC:=$(CHOST)-windres
RANLIB:=$(CHOST)-ranlib
else
STRIP:=strip
AR:=ar
LD:=ld
RC:=windres
RANLIB:=ranlib
endif
HOSTSTRIP:=strip
HOSTAR:=ar
HOSTLD:=ld
HOSTRANLIB:=ranlib
LIBTOOL:=$(if $(DARWIN),glibtool,libtool)
LIBTOOLIZE:=$(if $(DARWIN),glibtoolize,libtoolize)
# Static libstdc++, because libtool filters flags at link-time, and drops -static-libstdc++ on GNU/Linux...
# NOTE: We default to libtool's preferred workaround of putting those extra flags we really want to keep in CC/CXX
# But to add insult to injury, libtool also links with -nostdlib, which renders -static-lib* useless, so we
# need this ugly workaround, even on recent (>= 4.5) GCC versions where any sane person would imagine -static-libstdc++ to be enough...
ifndef DARWIN
# we need to set PATH manually here because export PATH in gmake only takes
# effect for for sub shells
STATIC_LIBSTDCPP=$(shell PATH='$(PATH)' $(CC) -print-file-name=libstdc++.a)
else
STATIC_LIBSTDCPP=
endif
# Base CFLAGS, without arch. We'll need it for luajit, because its
# Makefiles do some tricky stuff to differentiate HOST/TARGET
BASE_CFLAGS:=-O2 -ffast-math -pipe -fomit-frame-pointer
# For ricers.
#BASE_CFLAGS:=-O3 -ffast-math -pipe -fomit-frame-pointer -frename-registers -fweb
# Used to enforce aggressive optimizations in some components
VECTO_CFLAGS:=-O3 -ffast-math -pipe -fomit-frame-pointer -frename-registers -fweb -ftree-vectorize -funroll-loops
# And for an aggressive LTO build
#BASE_CFLAGS:=$(VECTO_CFLAGS) -flto=8 -fuse-linker-plugin
# Use this for debugging:
ifdef KODEBUG
BASE_CFLAGS:=-Og -g -pipe -fno-omit-frame-pointer
# Prevent runaway buildsystems from screwing with us and stripping stuff behind our backs...
STRIP:=true
# Don't enforce extra CFLAGS in debug builds
VECTO_CFLAGS:=
endif
# Misc GCC tricks to ensure backward compatibility with the K2,
# even when using a fairly recent TC (Linaro/MG).
# NOTE: -mno-unaligned-access is needed for TC based on Linaro 4.6/4.7
# or GCC 4.7, or weird crap happens on FW 2.x. We unfortunately can't
# set it by default, since it's a new flag.
# A possible workaround would be to set the alignment trap to
# fixup (echo 2 > /proc/cpu/alignment) in the launch script,
# but that's terribly ugly, and might severly nerf performance...
# That said, MG 2012.03 is still using GCC 4.6.3, so we're good ;).
#
# For ref:
## no-ssp & killing FORTIFY_SOURCE are for the *_chk private GLIBC symbols [@GLIBC_2.11 & @GLIBC_2.15]
## no-finite-maths-only is for the *_finite LM symbols (byproduct of using ffast-maths) [@GLIBC_2.15]
## GNU_SOURCE is a very heavy-handed way of getting rid of the __isoc99_sscanf stuff [@GLIBC_2.7]
## no-use-cxa-atexit is to get rid of cxa_atexit
#
MG2K12_COMPAT_CFLAGS:=-fno-stack-protector -U_FORTIFY_SOURCE -D_GNU_SOURCE -fno-finite-math-only
MG2K12_COMPAT_CXXFLAGS:=-fno-use-cxa-atexit
# My legacy TC is based on glibc 2.9, that should be enough :).
NILUJE_COMPAT_CFLAGS:=-fno-stack-protector -U_FORTIFY_SOURCE -D_GNU_SOURCE -mno-unaligned-access
# As for PB, despite the old TC targeting glibc 2.9, some devices are apparently still running glibc 2.5... (#5939)
PB_COMPAT_CFLAGS:=-D_GNU_SOURCE
# Same deal, but when targeting the K5/Kobo & using Ubuntu's Linaro TCs
UBUNTU_COMPAT_CFLAGS:=-fno-finite-math-only -fno-stack-protector -U_FORTIFY_SOURCE
# When we can't avoid pulling in the system's libstdc++ on a platform using GCC < 5.1
# The potential for actual runtime issues is fairly low, though,
# c.f., https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html
STLABI_COMPAT_CFLAGS:=-D_GLIBCXX_USE_CXX11_ABI=0
# ARM 1136JF-S (Legacy Kidle devices [K2/K3/DX/DXG])
ARMV6_1136_ARCH:=-march=armv6j -mtune=arm1136jf-s -mfpu=vfp -marm
# Generic armv6
ARMV6_GENERIC_ARCH:=-march=armv6 -mtune=generic-armv6 -marm
# Generic armv7
ARMV7_GENERIC_ARCH:=-march=armv7-a -mtune=generic-armv7-a -mfpu=vfpv3 -mthumb
# Generic arm 64 bits
ARM64_GENERIC_ARCH:=-march=armv8-a
# Cortex A8 (K4, Kindle Touch, PW1, Kobos since the Touch)
ARMV7_A8_ARCH:=-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mthumb
# Cortex A9 (Kindle PW2)
ARMV7_A9_ARCH:=-march=armv7-a -mtune=cortex-a9 -mfpu=neon -mthumb
# Android.
ANDROID_COMPAT_CFLAGS:=--sysroot $(SYSROOT)
ANDROID_COMPAT_CXXFLAGS:=--sysroot $(SYSROOT)
# Mirror the NDK's armeabi-v7a APP_ABI (cf. #201)
ifeq ($(ANDROID_ARCH), arm)
ANDROID_ARM_ARCH:=-march=armv7-a -mfpu=vfpv3-d16
ANDROID_ARM_ARCH+=-mthumb
ANDROID_ARM_ARCH+=-ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes
endif
# Use target-specific CFLAGS
ifeq ($(TARGET), kobo)
# NOTE: If we only care about Kobos w/ a Touch screen, we're good.
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=hard
ifeq ($(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null), arm-linux-gnueabihf)
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
endif
else ifeq ($(TARGET), ubuntu-touch)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=hard
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
else ifeq ($(TARGET), pocketbook)
# NOTE: The TC itself is built in ARM mode (otherwise glibc 2.9 fails to build).
# We prefer Thumb mode for our own binaries, though, much like on every other i.MX device ;).
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
# NOTE: Because of course everything is terrible, newer FW (5.19+) use GCC 6.3.0's libstdc++,
# so, ideally, we shouldn't be using this on those newer devices...
COMPAT_CFLAGS:=$(STLABI_COMPAT_CFLAGS) $(PB_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(STLABI_COMPAT_CFLAGS) $(PB_COMPAT_CFLAGS)
ifeq ($(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null), arm-linux-gnueabi)
COMPAT_CFLAGS+=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS+=$(UBUNTU_COMPAT_CFLAGS)
endif
else ifeq ($(TARGET), kindle)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
ifeq ($(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null), arm-linux-gnueabi)
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
endif
else ifeq ($(TARGET), kindlepw2)
ARM_ARCH:=$(ARMV7_A9_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
ifeq ($(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null), arm-linux-gnueabi)
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
endif
else ifeq ($(TARGET), kindle-legacy)
ARM_ARCH:=$(ARMV6_1136_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
ifeq ($(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null), arm-linux-gnueabi)
COMPAT_CFLAGS:=$(MG2K12_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(MG2K12_COMPAT_CXXFLAGS)
endif
COMPAT_CFLAGS:=$(NILUJE_COMPAT_CFLAGS)
# Avoid pulling stuff from GLIBC_2.7 & 2.9 in glib
export glib_cv_eventfd=no
export ac_cv_func_pipe2=no
# Avoid pulling stuff from GLIBC_2.6 in tar
export ac_cv_func_utimensat=no
export ac_cv_func_futimens=no
else ifeq ($(TARGET), android)
COMPAT_CFLAGS:=$(ANDROID_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(ANDROID_COMPAT_CXXFLAGS)
ifeq ($(ANDROID_ARCH), arm)
ARM_ARCH:=$(ANDROID_ARM_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
export ac_cv_type_in_port_t=yes
endif
else ifeq ($(TARGET), remarkable)
ARM_ARCH:=$(ARMV7_A9_ARCH)
ARM_ARCH+=-mfloat-abi=hard
else ifeq ($(TARGET), sony-prstux)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=hard
else ifeq ($(TARGET), cervantes)
ARM_ARCH:=$(ARMV7_GENERIC_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
ifeq ($(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null), arm-linux-gnueabi)
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
endif
else ifeq ($(TARGET), arm-generic)
# Defaults to generic crap
ARM_ARCH:=$(ARMV6_GENERIC_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
else ifeq ($(TARGET), debian-armel)
ARM_ARCH:=$(ARMV7_GENERIC_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
else ifeq ($(TARGET), debian-armhf)
ARM_ARCH:=$(ARMV7_GENERIC_ARCH)
ARM_ARCH+=-mfloat-abi=hard
else ifeq ($(TARGET), debian-arm64)
ARM_ARCH:=$(ARM64_GENERIC_ARCH)
else
# else, we are compiling emulator on x86
ARM_ARCH:=
endif
HOST_ARCH:=-march=native
ifdef APPIMAGE
# We want to run the AppImage on any 64-bit CPU
HOST_ARCH:=-mtune=generic -march=x86-64
endif
ifdef DEBIAN
HOST_ARCH:=-mtune=generic
endif
ifdef MACOS
HOST_ARCH:=-mtune=generic
endif
# Anything below GCC 6 gets to be forcefully switched to decent standards, because some of our deps require C11 & C++11 support.
# NOTE: Technically, this also means we require Clang >= 3.2, but that should more or less hold true on our end, because that's truly ancient.
# Tests heavily inspired from Linux's build system ;).
CC_IS_CLANG:=$(shell PATH='$(PATH)' $(CC) -v 2>&1 | grep -q "clang version" && echo 1 || echo 0)
CC_VERSION:=$(shell PATH='$(PATH)' printf "%02d%02d%02d" `echo __GNUC__ | $(CC) -E -x c - | tail -n 1` `echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1` `echo __GNUC_PATCHLEVEL__ | $(CC) -E -x c - | tail -n 1`)
# Detect Clang's SA, too...
ifeq "$(CC_IS_CLANG)" "0"
ifeq "$(lastword $(subst /, ,$(CC)))" "ccc-analyzer"
CC_IS_CLANG:=1
endif
endif
ifeq "$(CC_IS_CLANG)" "0"
# NOTE: GCC 6.1.0 switched to gnu11 & gnu++14, so only tweak older ones.
# c.f., https://stackoverflow.com/q/14737104 for a nice recap.
ifeq "$(shell expr $(CC_VERSION) \< 060100)" "1"
CSTD_FLAGS:=-std=gnu11
CXXSTD_FLAGS:=-std=gnu++11
endif
else
# NOTE: Enforce the current default everywhere, otherwise XCode does stupid things on Darwin.
# c.f., https://clang.llvm.org/docs/CommandGuide/clang.html#language-selection-and-mode-options
# & https://github.com/llvm/llvm-project/blob/1c4b5a8dfed853ca8cbee98f274ff0a173186586/clang/lib/Frontend/CompilerInvocation.cpp#L2136-L2164
# FWIW, the C++ move to gnu++14 by default dates back to Clang 6:
# c.f., https://github.com/llvm-mirror/clang/commit/466d8da5f89b1a780f735c86f414fa69ce63221b
CSTD_FLAGS:=-std=gnu11
CXXSTD_FLAGS:=-std=gnu++14
endif
HOSTCFLAGS:=$(HOST_ARCH) $(BASE_CFLAGS) $(QFLAGS)
CFLAGS:=$(BASE_CFLAGS) $(QFLAGS) $(CSTD_FLAGS)
CXXFLAGS:=$(BASE_CFLAGS) $(QFLAGS) $(CXXSTD_FLAGS)
ifndef DARWIN
LDFLAGS:=-Wl,-O1 -Wl,--as-needed -static-libstdc++
else
LDFLAGS:=
endif
# NOTE: Follow the NDK's lead
ifeq ($(TARGET), android)
LDFLAGS+=-no-canonical-prefixes -Wl,--fix-cortex-a8
ifeq ($(ANDROID_ARCH), arm)
LDFLAGS+=-march=armv7-a
endif
endif
ifeq ($(TARGET), win32)
LDFLAGS+=-Wl,--allow-multiple-definition -static-libgcc
endif
# in case the libstdc++ is to be linked statically, the location of the static
# library can be specified in the STATICLIBSTDCPP variable.
# the default is to link a shared library:
DYNAMICLIBSTDCPP:=-lstdc++
ifdef STATICLIBSTDCPP
DYNAMICLIBSTDCPP:=
endif
# this will create a path named build/arm-none-linux-gnueabi or similar
TARGET_MARCHINE:=$(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null)
ifdef KODEBUG
MACHINE=$(TARGET_MARCHINE)-debug
else
MACHINE=$(TARGET_MARCHINE)
endif
OUTPUT_DIR=build/$(MACHINE)
# We'll want a machine-specific staging directory *outside* of OUTPUT_DIR, so we don't pickup random build artifacts in packages...
CMAKE_STAGING_DIR=build/staging-$(MACHINE)
# you can configure an emulation for the (eink) framebuffer here.
# the application won't use the framebuffer (and the special e-ink ioctls)
# in that case.
ifdef EMULATE_READER
# CMake is difficult about CC and CXX, especially when it's not just a full path
CMAKE_C_COMPILER:=$(shell command -v $(strip $(HOSTCC)))
CMAKE_CXX_COMPILER:=$(shell command -v $(strip $(HOSTCXX)))
ifdef CCACHE
CMAKE_C_COMPILER_LAUNCHER:=$(CCACHE)
CMAKE_CXX_COMPILER_LAUNCHER:=$(CCACHE)
endif
# Regular
REALCC:=$(HOSTCC)
REALCXX:=$(HOSTCXX)
HOSTCC:=$(strip $(CCACHE) $(HOSTCC))
HOSTCXX:=$(strip $(CCACHE) $(HOSTCXX))
CC:=$(HOSTCC)
CXX:=$(HOSTCXX)
STRIP:=$(HOSTSTRIP)
AR:=$(HOSTAR)
LD:=$(HOSTLD)
RANLIB:=$(HOSTRANLIB)
CFLAGS+=$(HOST_ARCH)
CXXFLAGS+=$(HOST_ARCH)
else
# Use a CMake toolchain file to avoid all kinds of CMake insanity
export CROSS_TC:=$(CHOST)
ifndef SYSROOT
export SYSROOT:=$(shell PATH='$(PATH)' $(CC) -print-sysroot)
endif
export CROSS_STAGING:=$(CMAKE_STAGING_DIR)
export CMAKE_TCF:=-DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/thirdparty/cmake_modules/CMakeCross.cmake
CMAKE+=$(CMAKE_TCF)
ifdef CCACHE
CMAKE_C_COMPILER_LAUNCHER:=$(CCACHE)
CMAKE_CXX_COMPILER_LAUNCHER:=$(CCACHE)
endif
REALCC:=$(CC)
REALCXX:=$(CXX)
# Don't let libtool piss on our parade...
# See what was mentioned around STATIC_LIBSTDCPP on ~L#93 for more details
# (cf. https://www.gnu.org/software/libtool/manual/html_node/Stripped-link-flags.html#Stripped-link-flags)
CC:=$(CC) -static-libstdc++
CXX:=$(strip $(CCACHE) $(CXX)) -static-libstdc++
CFLAGS+=$(ARM_ARCH) $(COMPAT_CFLAGS) -static-libstdc++
CXXFLAGS+=$(ARM_ARCH) $(COMPAT_CXXFLAGS) -static-libstdc++
LDFLAGS+=-static-libstdc++
# Make sure we always have mmap() support.
# This is critical for FreeType, since the usage of platform-specific code depends on this,
# and without it, we don't get CLOEXEC handling, which is problematic on Kobos, where we spawn stuff that might
# survive us, and if they inherit some of our fds pointing to the removable user area, bad things happen when it
# gets unmounted for USBMS handling....
export ac_cv_func_mmap_fixed_mapped=yes
# Never let pkg-config pickup native libraries (we don't actually rely on pkg-config anywhere, we do it all by hand).
# NOTE: Let people shoot themselves in the foot with custom pkg-config wrappers?
#undefine PKG_CONFIG
#unexport PKG_CONFIG
export PKG_CONFIG_PATH=""
export PKG_CONFIG_LIBDIR=""
endif
# not necessary to use PIC flag for win32 which has relocation table in dll
ifneq ($(TARGET), win32)
CFLAGS+=-fPIC
CXXFLAGS+=-fPIC
endif
# Try to make sure CMake picks up our flags...
export CFLAGS
export CXXFLAGS
export LDFLAGS
# And that our TC is honored
export CC
export CXX
export AR
export RANLIB
export LD
export STRIP
ifdef WIN32
export RC
endif
# FIXME: If we cared, we'd probably need to do something to convince libzmq not
# to enable support for eventfd [@GLIBC_2.7]
# FIXED: To cross compile libzmq for GLIBC_2.4 you need to configure with the
# option '--disable-eventfd'
#
# In the same vein, see base#421 for how to deal with an updated glibc symbol
# for a function which did NOT change its signature, and where we don't have
# access to a public definition of the old implementation, only a compat
# versioned symbol.
# With the added confusing quirk that the compat symbol (here, fmemopen) is
# pinned to a different GLIBC version on arm than on x86... (cf. #2188).
ifndef DARWIN
ifndef ANDROID
ifndef WIN32
# We're a glibc system... Find the actual libc used by our TC, and check if it's >= 2.22...
# We only care about that on non-emulated builds (i.e., arm), because compat symbols may be pinned
# to different versions on different arches, and we only account for arm in our patches.
ifndef EMULATE_READER
GLIBC_FILE=$(basename $(notdir $(realpath $(shell PATH='$(PATH)' $(CC) -print-file-name=libc.so.6))))
GLIBC_VER=$(shell echo $(GLIBC_FILE) | cut -f2 -d'-')
GLIBC_2_22_SORT=$(shell echo -e "$(GLIBC_VER)\n2.22" | sort -V | head -n1)
ifeq ($(GLIBC_2_22_SORT), 2.22)
ARM_GLIBC_GTE_2_22=1
endif
endif
endif
endif
endif
# NOTE: We generally want SIMD/ASM juicy stuff everywhere
export WANT_SIMD=1
# ... but on ARM targets that are not NEON capable, that obviously won't fly...
ifneq (,$(findstring march=arm,$(CFLAGS)))
# We're on ARM
ifeq (,$(findstring fpu=neon,$(CFLAGS)))
# We don't support NEON
# NOTE: undefine is new to GNU make 3.82, so, do without because Android...
#undefine WANT_SIMD
WANT_SIMD=
unexport WANT_SIMD
endif
endif
# ... ditto on Android x86, because the TC is old as hell, and that upsets libjpeg-turbo...
ifeq ($(TARGET), android)
ifeq ($(ANDROID_ARCH), x86)
WANT_SIMD=
unexport WANT_SIMD
endif
endif
LIB_EXT=$(if $(WIN32),.dll,$(if $(DARWIN),.dylib,.so))
# you can probably leave these settings alone:
THIRDPARTY_DIR=thirdparty
LUAFILESYSTEM_DIR=luafilesystem
ZLIB_BUILD_DIR=$(THIRDPARTY_DIR)/zlib/build/$(MACHINE)
ZLIB_DIR=$(CURDIR)/$(ZLIB_BUILD_DIR)/zlib-prefix/src/zlib
ZLIB_STATIC=$(ZLIB_DIR)/libz.a
ZSTD_BUILD_DIR=$(THIRDPARTY_DIR)/zstd/build/$(MACHINE)
ZSTD_DIR=$(CURDIR)/$(ZSTD_BUILD_DIR)/zstd-prefix/src/zstd
ZSTD_DESTDIR=$(CURDIR)/$(ZSTD_BUILD_DIR)/zstd-prefix/src/zstd-build
ZSTD_LIB_EXT=$(if $(WIN32),.dll,$(if $(DARWIN),.1.dylib,.so.1))
ZSTD_LIB=$(OUTPUT_DIR)/libs/libzstd$(ZSTD_LIB_EXT)
MINIZIP_BUILD_DIR=$(THIRDPARTY_DIR)/minizip/build/$(MACHINE)
MINIZIP_DIR=$(CURDIR)/$(MINIZIP_BUILD_DIR)/minizip-prefix/src/minizip
AES_LIB_DIR=$(MINIZIP_DIR)/aes
AES_LIB=$(MINIZIP_DIR)/libaes.a
MUPDF_BUILD_DIR=$(CURDIR)/$(THIRDPARTY_DIR)/mupdf/build/$(MACHINE)
MUPDF_DIR=$(MUPDF_BUILD_DIR)/mupdf-prefix/src/mupdf
MUPDF_LIB_DIR=$(MUPDF_DIR)/build/$(if $(KODEBUG),debug,release)
MUPDF_LIB_STATIC=$(MUPDF_LIB_DIR)/libmupdf.a
MUPDF_THIRDPARTY_LIBS=$(MUPDF_LIB_DIR)/libmupdfthird.a \
$(AES_LIB)
MUPDF_LIB=$(OUTPUT_DIR)/libs/libmupdf$(LIB_EXT)
DJVULIBRE_BUILD_DIR=$(THIRDPARTY_DIR)/djvulibre/build/$(MACHINE)
DJVULIBRE_DIR=$(CURDIR)/$(DJVULIBRE_BUILD_DIR)/djvulibre-prefix/src/djvulibre
DJVULIBRE_LIB_EXT=$(if $(WIN32),-21.dll,$(if $(DARWIN),.21.dylib,.so.21))
DJVULIBRE_LIB=$(OUTPUT_DIR)/libs/libdjvulibre$(DJVULIBRE_LIB_EXT)
DJVULIBRE_LIB_DIR=$(DJVULIBRE_DIR)/libdjvu/.libs
CRENGINE_BUILD_DIR=$(THIRDPARTY_DIR)/kpvcrlib/build/$(MACHINE)
CRENGINE_DIR=$(CURDIR)/$(CRENGINE_BUILD_DIR)
CRENGINE_SRC_DIR=$(CURDIR)/$(THIRDPARTY_DIR)/kpvcrlib/crengine
CRENGINE_SRC_FILES=$(wildcard $(CRENGINE_SRC_DIR)/crengine/src/*.cpp)
CRENGINE_SRC_FILES+=$(wildcard $(CRENGINE_SRC_DIR)/crengine/include/*.h)
CRENGINE_SRC_FILES+=$(wildcard $(CRENGINE_SRC_DIR)/crengine/src/*.h)
CRENGINE_SRC_FILES+=$(wildcard $(CRENGINE_SRC_DIR)/crengine/src/*_h.*)
CRENGINE_LIB=$(OUTPUT_DIR)/libs/libcrengine$(LIB_EXT)
LUAJIT_BUILD_DIR=$(THIRDPARTY_DIR)/luajit/build/$(MACHINE)
LUAJIT_DIR=$(CURDIR)/$(LUAJIT_BUILD_DIR)/luajit-prefix/src/luajit
LUAJIT=$(OUTPUT_DIR)/$(if $(WIN32),luajit.exe,luajit)
LUAJIT_JIT=$(OUTPUT_DIR)/jit
LUAJIT_LIB=$(OUTPUT_DIR)/$(if $(WIN32),lua51.dll,libs/libluajit.so)
LUAJIT_STATIC=$(LUAJIT_DIR)/src/libluajit.a
POPEN_NOSHELL_BUILD_DIR=$(THIRDPARTY_DIR)/popen-noshell/build/$(MACHINE)
POPEN_NOSHELL_DIR=$(CURDIR)/$(POPEN_NOSHELL_BUILD_DIR)/popen-noshell-prefix/src/popen-noshell
POPEN_NOSHELL_LIB=$(POPEN_NOSHELL_DIR)/libpopen_noshell.a
LEPTONICA_BUILD_DIR=$(THIRDPARTY_DIR)/leptonica/build/$(MACHINE)
LEPTONICA_DIR=$(CURDIR)/$(LEPTONICA_BUILD_DIR)/leptonica-prefix/src/leptonica
TESSERACT_BUILD_DIR=$(THIRDPARTY_DIR)/tesseract/build/$(MACHINE)
TESSERACT_DIR=$(CURDIR)/$(TESSERACT_BUILD_DIR)/tesseract-prefix/src/tesseract
K2PDFOPT_BUILD_DIR=$(THIRDPARTY_DIR)/libk2pdfopt/build/$(MACHINE)
K2PDFOPT_DIR=$(CURDIR)/$(K2PDFOPT_BUILD_DIR)/libk2pdfopt-prefix/src/libk2pdfopt
K2PDFOPT_LIB_EXT=$(if $(WIN32),-2.dll,$(if $(DARWIN),.2.dylib,.so.2))
K2PDFOPT_LIB=$(OUTPUT_DIR)/libs/libk2pdfopt$(K2PDFOPT_LIB_EXT)
K2PDFOPT_CFLAGS=-I$(K2PDFOPT_DIR)/willuslib \
-I$(K2PDFOPT_DIR)/k2pdfoptlib -I$(K2PDFOPT_DIR) \
-I$(K2PDFOPT_DIR)/include_mod
FREETYPE_LIB_EXT=$(if $(WIN32),-6.dll,$(if $(DARWIN),.6.dylib,.so.6))
FREETYPE_LIB=$(OUTPUT_DIR)/libs/libfreetype$(FREETYPE_LIB_EXT)
FREETYPE_BUILD_DIR=$(THIRDPARTY_DIR)/freetype2/build/$(MACHINE)
FREETYPE_DIR=$(CURDIR)/$(FREETYPE_BUILD_DIR)/freetype2-prefix/src/freetype2-build
HARFBUZZ_LIB_EXT=$(if $(WIN32),-0.dll,$(if $(DARWIN),.0.dylib,.so.0))
HARFBUZZ_LIB=$(OUTPUT_DIR)/libs/libharfbuzz$(HARFBUZZ_LIB_EXT)
HARFBUZZ_BUILD_DIR=$(THIRDPARTY_DIR)/harfbuzz/build/$(MACHINE)
HARFBUZZ_DIR=$(CURDIR)/$(HARFBUZZ_BUILD_DIR)/harfbuzz-prefix/src/harfbuzz-build
FRIBIDI_LIB_EXT=$(if $(WIN32),-0.dll,$(if $(DARWIN),.0.dylib,.so.0))
FRIBIDI_LIB=$(OUTPUT_DIR)/libs/libfribidi$(FRIBIDI_LIB_EXT)
FRIBIDI_BUILD_DIR=$(THIRDPARTY_DIR)/fribidi/build/$(MACHINE)
FRIBIDI_DIR=$(CURDIR)/$(FRIBIDI_BUILD_DIR)/fribidi-prefix/src/fribidi-build
LIBUNIBREAK_LIB_EXT=$(if $(WIN32),-3.dll,$(if $(DARWIN),.3.dylib,.so.3))
LIBUNIBREAK_LIB=$(OUTPUT_DIR)/libs/libunibreak$(LIBUNIBREAK_LIB_EXT)
LIBUNIBREAK_BUILD_DIR=$(THIRDPARTY_DIR)/libunibreak/build/$(MACHINE)
LIBUNIBREAK_DIR=$(CURDIR)/$(LIBUNIBREAK_BUILD_DIR)/libunibreak-prefix/src/libunibreak-build
UTF8PROC_LIB_EXT=$(if $(WIN32),-2.dll,$(if $(DARWIN),.2.dylib,.so.2))
UTF8PROC_LIB=$(OUTPUT_DIR)/libs/libutf8proc$(UTF8PROC_LIB_EXT)
UTF8PROC_BUILD_DIR=$(THIRDPARTY_DIR)/utf8proc/build/$(MACHINE)
UTF8PROC_DIR=$(CURDIR)/$(UTF8PROC_BUILD_DIR)/utf8proc-prefix/src/utf8proc
JPEG_LIB_EXT=$(if $(WIN32),-8.dll,$(if $(DARWIN),.8.dylib,.so.8))
JPEG_LIB=$(OUTPUT_DIR)/libs/libjpeg$(JPEG_LIB_EXT)
TURBOJPEG_LIB=$(OUTPUT_DIR)/libs/libturbojpeg$(if $(WIN32),.dll,$(if $(DARWIN),.dylib,.so))
JPEG_BUILD_DIR=$(THIRDPARTY_DIR)/libjpeg-turbo/build/$(MACHINE)
JPEG_DIR=$(CURDIR)/$(JPEG_BUILD_DIR)/libjpeg-turbo-prefix/src/libjpeg-turbo-build
PNG_LIB_EXT=$(if $(WIN32),-16.dll,$(if $(DARWIN),.16.dylib,.so.16))
PNG_LIB=$(OUTPUT_DIR)/libs/libpng16$(PNG_LIB_EXT)
PNG_BUILD_DIR=$(THIRDPARTY_DIR)/libpng/build/$(MACHINE)
PNG_DIR=$(CURDIR)/$(PNG_BUILD_DIR)/libpng-prefix/src/libpng-build
LODEPNG_LIB=$(OUTPUT_DIR)/libs/liblodepng$(LIB_EXT)
LODEPNG_BUILD_DIR=$(THIRDPARTY_DIR)/lodepng/build/$(MACHINE)
LODEPNG_DIR=$(CURDIR)/$(LODEPNG_BUILD_DIR)/lodepng-prefix/src/lodepng
GIF_LIB_EXT=$(if $(WIN32),-7.dll,$(if $(DARWIN),.7.dylib,.so.7))
GIF_LIB=$(OUTPUT_DIR)/libs/libgif$(GIF_LIB_EXT)
GIF_BUILD_DIR=$(THIRDPARTY_DIR)/giflib/build/$(MACHINE)
GIF_DIR=$(CURDIR)/$(GIF_BUILD_DIR)/giflib-prefix/src/giflib-build
LIBWEBP_LIB_EXT=$(if $(WIN32),-7.dll,$(if $(DARWIN),.7.dylib,.so.7))
LIBWEBP_LIB=$(OUTPUT_DIR)/libs/libwebp$(LIBWEBP_LIB_EXT)
LIBWEBPDEMUX_LIB_EXT=$(if $(WIN32),-2.dll,$(if $(DARWIN),.2.dylib,.so.2))
LIBWEBPDEMUX_LIB=$(OUTPUT_DIR)/libs/libwebpdemux$(LIBWEBPDEMUX_LIB_EXT)
LIBWEBP_BUILD_DIR=$(THIRDPARTY_DIR)/libwebp/build/$(MACHINE)
LIBWEBP_DIR=$(CURDIR)/$(LIBWEBP_BUILD_DIR)/libwebp-prefix/src/libwebp-build
LIBFFI_BUILD_DIR=$(THIRDPARTY_DIR)/libffi/build/$(MACHINE)
LIBFFI_DIR=$(CURDIR)/$(LIBFFI_BUILD_DIR)/libffi-prefix/src/libffi-build
SDCV_BUILD_DIR=$(THIRDPARTY_DIR)/sdcv/build/$(MACHINE)
SDCV_DIR=$(CURDIR)/$(SDCV_BUILD_DIR)/sdcv-build
GLIB_BUILD_DIR=$(THIRDPARTY_DIR)/glib/build/$(MACHINE)
GLIB_DIR=$(CURDIR)/$(GLIB_BUILD_DIR)/glib-prefix/src/glib-build
LIBICONV_BUILD_DIR=$(THIRDPARTY_DIR)/libiconv/build/$(MACHINE)
LIBICONV_DIR=$(CURDIR)/$(LIBICONV_BUILD_DIR)/libiconv-prefix/src/libiconv-build
GETTEXT_BUILD_DIR=$(THIRDPARTY_DIR)/gettext/build/$(MACHINE)
GETTEXT_DIR=$(CURDIR)/$(GETTEXT_BUILD_DIR)/gettext-prefix/src/gettext-build
SDL2_BUILD_DIR=$(THIRDPARTY_DIR)/sdl2/build/$(MACHINE)
SDL2_DIR=$(CURDIR)/$(SDL2_BUILD_DIR)/sdl2-build
SDL2_LIB_ORIG=$(OUTPUT_DIR)/libs/libSDL2-2.0$(if $(KODEBUG),d,)$(LIB_EXT)
SDL2_LIB=$(OUTPUT_DIR)/libs/libSDL2$(LIB_EXT)
LIBICONV=$(LIBICONV_DIR)/lib/libiconv.a
LIBGETTEXT=$(GETTEXT_DIR)/lib/libintl.a
GLIB=$(GLIB_DIR)/lib/libglib-2.0$(if $(DARWIN),.dylib,.so.0)
GLIB_STATIC=$(GLIB_DIR)/lib/libglib-2.0.a
ZLIB=$(OUTPUT_DIR)/libs/$(if $(WIN32),zlib1.dll,$(if $(DARWIN),libz.1.dylib,libz.so.1))
LEPT_LIB_EXT=$(if $(WIN32),-5.dll,$(if $(DARWIN),.5.dylib,.so.5))
LEPTONICA_LIB=$(OUTPUT_DIR)/libs/liblept$(LEPT_LIB_EXT)
TESS_LIB_EXT=$(if $(WIN32),-3.dll,$(if $(DARWIN),.3.dylib,.so.3))
TESSERACT_LIB=$(OUTPUT_DIR)/libs/libtesseract$(TESS_LIB_EXT)
OPENSSL_BUILD_DIR=$(THIRDPARTY_DIR)/openssl/build/$(MACHINE)
OPENSSL_DIR=$(CURDIR)/$(OPENSSL_BUILD_DIR)/openssl-prefix/src/openssl
OPENSSL_LIB=$(OPENSSL_DIR)/libssl.$(if $(WIN32),a,so)
SSL_LIB=$(OUTPUT_DIR)/libs/libssl$(if $(WIN32),-1.dll,$(if $(DARWIN),.1.1.dylib,.so.1.1))
CRYPTO_LIB=$(OUTPUT_DIR)/libs/libcrypto$(if $(WIN32),-1.dll,$(if $(DARWIN),.1.1.dylib,.so.1.1))
LUASOCKET_BUILD_DIR=$(THIRDPARTY_DIR)/luasocket/build/$(MACHINE)
LUASOCKET_DIR=$(CURDIR)/luasocket-prefix/src/luasocket
LUASEC_BUILD_DIR=$(THIRDPARTY_DIR)/luasec/build/$(MACHINE)
LUASEC_DIR=$(CURDIR)/$(LUASEC_BUILD_DIR)/luasec-prefix/src/luasec
LUASOCKET=$(OUTPUT_DIR)/common/socket
LUASEC=$(OUTPUT_DIR)/common/ssl
ZMQ_BUILD_DIR=$(THIRDPARTY_DIR)/libzmq/build/$(MACHINE)
ZMQ_DIR=$(CURDIR)/$(ZMQ_BUILD_DIR)/libzmq-prefix/src/libzmq-build
ZMQ_LIB_EXT=$(if $(WIN32),.dll,$(if $(DARWIN),.4.dylib,.so.4))
ZMQ_LIB=$(OUTPUT_DIR)/libs/libzmq$(ZMQ_LIB_EXT)
CZMQ_BUILD_DIR=$(THIRDPARTY_DIR)/czmq/build/$(MACHINE)
CZMQ_DIR=$(CURDIR)/$(CZMQ_BUILD_DIR)/czmq-prefix/src/czmq-build
FILEMQ_BUILD_DIR=$(THIRDPARTY_DIR)/filemq/build/$(MACHINE)
FILEMQ_DIR=$(CURDIR)/$(FILEMQ_BUILD_DIR)/filemq-prefix/src/filemq-build
ZYRE_BUILD_DIR=$(THIRDPARTY_DIR)/zyre/build/$(MACHINE)
ZYRE_DIR=$(CURDIR)/$(ZYRE_BUILD_DIR)/zyre-prefix/src/zyre-build
CZMQ_FMQ_ZYRE_LIB_EXT=$(if $(WIN32),.dll,$(if $(DARWIN),.1.dylib,.so.1))
CZMQ_LIB=$(OUTPUT_DIR)/libs/libczmq$(CZMQ_FMQ_ZYRE_LIB_EXT)
FILEMQ_LIB=$(OUTPUT_DIR)/libs/libfmq$(CZMQ_FMQ_ZYRE_LIB_EXT)
ZYRE_LIB=$(OUTPUT_DIR)/libs/libzyre$(CZMQ_FMQ_ZYRE_LIB_EXT)
TAR_BUILD_DIR=$(THIRDPARTY_DIR)/tar/build/$(MACHINE)
TAR_DIR=$(CURDIR)/$(TAR_BUILD_DIR)/tar-prefix/src/tar-build
DROPBEAR_BUILD_DIR=$(THIRDPARTY_DIR)/dropbear/build/$(MACHINE)
DROPBEAR_DIR=$(CURDIR)/$(DROPBEAR_BUILD_DIR)/dropbear-prefix/src/dropbear-build
OPENSSH_BUILD_DIR=$(THIRDPARTY_DIR)/openssh/build/$(MACHINE)
OPENSSH_DIR=$(CURDIR)/$(OPENSSH_BUILD_DIR)/openssh-prefix/src/openssh-build
FBINK_BUILD_DIR=$(THIRDPARTY_DIR)/fbink/build/$(MACHINE)
FBINK_DIR=$(CURDIR)/$(FBINK_BUILD_DIR)/fbink-prefix/src/fbink-build
KOBO_USBMS_BUILD_DIR=$(THIRDPARTY_DIR)/kobo-usbms/build/$(MACHINE)
KOBO_USBMS_DIR=$(CURDIR)/$(KOBO_USBMS_BUILD_DIR)/kobo-usbms-prefix/src/kobo-usbms-build
CURL_BUILD_DIR=$(THIRDPARTY_DIR)/curl/build/$(MACHINE)
CURL_DIR=$(CURDIR)/$(CURL_BUILD_DIR)/curl-prefix/src/curl-build
# NOTE: We rename cURL on PB because everything is terrible (c.f., #5861)
CURL_LIB_EXT=$(if $(WIN32),.dll,$(if $(DARWIN),.dylib,$(if $(POCKETBOOK),_ko.so.4,.so.4)))
CURL_LIB=$(OUTPUT_DIR)/libs/libcurl$(CURL_LIB_EXT)
ZSYNC2_BUILD_DIR=$(THIRDPARTY_DIR)/zsync2/build/$(MACHINE)
ZSYNC2_DIR=$(CURDIR)/$(ZSYNC2_BUILD_DIR)/zsync2-prefix/src/zsync2-build
TURBO_BUILD_DIR=$(THIRDPARTY_DIR)/turbo/build/$(MACHINE)
TURBO_DIR=$(CURDIR)/$(TURBO_BUILD_DIR)/turbo-prefix/src/turbo
TURBO_FFI_WRAP_LIB=$(OUTPUT_DIR)/common/libtffi_wrap$(LIB_EXT)
# Unversioned LR 2 path and binary
LUAROCKS_DIR=$(OUTPUT_DIR)/rocks/lib/luarocks/rocks
LUAROCKS_BINARY=luarocks
# Versioned LR 3 path and binary, see koreader-base/pull/1003
ifeq ($(LR_GT_3_0),1)
LUAROCKS_DIR=$(OUTPUT_DIR)/rocks/lib/luarocks/rocks-5.1
LUAROCKS_BINARY+=--lua-version=5.1
endif
LUA_INCDIR=$(if $(DARWINHOST),/usr/local/include/lua5.1,"$(LUAJIT_DIR)/src")
LUA_LIBDIR=$(if $(DARWINHOST),/usr/local/lib,"$(CURDIR)/$(dir $(LUAJIT_LIB))")
LUA_HTMLPARSER_VER=scm-0
LUA_HTMLPARSER_BUILD_DIR=$(THIRDPARTY_DIR)/lua-htmlparser/build/$(MACHINE)
LUA_HTMLPARSER_ROCK=$(LUAROCKS_DIR)/htmlparser/$(LUA_HTMLPARSER_VER)/htmlparser-$(LUA_HTMLPARSER_VER).rockspec
LUA_RAPIDJSON_VER=0.7.1-1
LUA_RAPIDJSON_BUILD_DIR=$(THIRDPARTY_DIR)/lua-rapidjson/build/$(MACHINE)
LUA_RAPIDJSON_ROCK=$(LUAROCKS_DIR)/rapidjson/$(LUA_RAPIDJSON_VER)/rapidjson-$(LUA_RAPIDJSON_VER).rockspec
LUA_SPORE_BUILD_DIR=$(THIRDPARTY_DIR)/lua-Spore/build/$(MACHINE)
LUA_SPORE_DIR=$(CURDIR)/$(LUA_SPORE_BUILD_DIR)/lua-Spore-prefix/src/lua-Spore
SPORE_VER=0.3.1-1
LUA_SPORE_VER=$(SPORE_VER)
LUA_SPORE_ROCK=$(LUAROCKS_DIR)/lua-spore/$(SPORE_VER)/lua-spore-$(SPORE_VER).rockspec
SQLITE_BUILD_DIR=$(THIRDPARTY_DIR)/sqlite/build/$(MACHINE)
SQLITE_DIR=$(CURDIR)/$(SQLITE_BUILD_DIR)/sqlite-prefix/src/sqlite-build
SQLITE_LIB_EXT=$(if $(WIN32),.dll,$(if $(DARWIN),.dylib,.so))
SQLITE_LIB=$(OUTPUT_DIR)/libs/libsqlite3$(SQLITE_LIB_EXT)
LUA_LJ_SQLITE_DIR=$(CURDIR)/$(THIRDPARTY_DIR)/lua-ljsqlite3
LUA_LJ_SQLITE_INSTALL_DIR=$(OUTPUT_DIR)/common/lua-ljsqlite3
LUA_LJ_SQLITE=$(LUA_LJ_SQLITE_INSTALL_DIR)/init.lua
# pure LuaJIT module, so no need to separate build dir by MACHINE
LJ_WPACLIENT_FILES=consts_h.lua poll_h.lua select_h.lua socket_h.lua socket.lua time_h.lua wpaclient.lua wpa_ctrl.lua
LJ_WPACLIENT_BUILD_DIR=$(THIRDPARTY_DIR)/lj-wpaclient/build
LJ_WPACLIENT_DIR=$(CURDIR)/$(LJ_WPACLIENT_BUILD_DIR)/lj-wpaclient-prefix/src/lj-wpaclient
LJ_WPACLIENT=$(addprefix $(OUTPUT_DIR)/common/lj-wpaclient/, $(LJ_WPACLIENT_FILES))
# Nanosvg headers (that include code)
NANOSVG_HEADER_FILES=nanosvg.h nanosvgrast.h stb_image_write.h
NANOSVG_BUILD_DIR=$(THIRDPARTY_DIR)/nanosvg/build/
NANOSVG_DIR=$(CURDIR)/$(NANOSVG_BUILD_DIR)/nanosvg-prefix/src
NANOSVG_INCLUDE_DIR=$(CURDIR)/$(NANOSVG_BUILD_DIR)/include
NANOSVG_HEADERS=$(addprefix $(NANOSVG_INCLUDE_DIR)/, $(NANOSVG_HEADER_FILES))
# Srell headers (that include code)
SRELL_DIR=$(CURDIR)/$(THIRDPARTY_DIR)/srell
SRELL_INCLUDE_DIR=$(SRELL_DIR)
# CFLAGS for the Lua/C/C++ modules:
#
# setting the rpath to '$ORIGIN' will make the dynamic linker search
# for the library in the same path as the executable that references
# them.
#
# also, dynamic libraries must be compiled with "-shared" and "-fPIC".
# having all symbols included (-E) won't hurt, too.
DYNLIB_CFLAGS=-L$(CURDIR)/$(OUTPUT_DIR)/libs $(CFLAGS) -I$(LUAJIT_DIR)/src -shared
DYNLIB_CXXFLAGS=-L$(CURDIR)/$(OUTPUT_DIR)/libs $(CXXFLAGS) -I$(LUAJIT_DIR)/src -shared
DYNLIB_CMAKE_CFLAGS=-L$(CURDIR)/$(OUTPUT_DIR)/libs $(CFLAGS) -I$(LUAJIT_DIR)/src -shared
DYNLIB_CMAKE_CXXFLAGS=-L$(CURDIR)/$(OUTPUT_DIR)/libs $(CXXFLAGS) -I$(LUAJIT_DIR)/src -shared
ifdef DARWIN
DYNLIB_CFLAGS+=-dynamiclib -undefined dynamic_lookup
DYNLIB_CXXFLAGS+=-dynamiclib -undefined dynamic_lookup
else
DYNLIB_CFLAGS+=-Wl,-E -Wl,-rpath,'$$ORIGIN'
DYNLIB_CXXFLAGS+=-Wl,-E -Wl,-rpath,'$$ORIGIN'
endif
# RPATH for all libraries in koreader/libs. The expand path looks like below:
# make -> shell -> cmake -> configure -> make -> linker
# \\\$$\\\$$ORIGIN \\\$\\\$ORIGIN \$\$ORIGIN $$ORIGIN $$ORIGIN $ORIGIN
ORIGIN_CMAKE_TO_AUTOCFG=\\\$$\\\$$ORIGIN
ifdef DARWIN
DYNLIB_CMAKE_CFLAGS+=-dynamiclib -undefined dynamic_lookup
DYNLIB_CMAKE_CXXFLAGS+=-dynamiclib -undefined dynamic_lookup
else
DYNLIB_CMAKE_CFLAGS+=-Wl,-E -Wl,-rpath,'$(ORIGIN_CMAKE_TO_AUTOCFG)'
DYNLIB_CMAKE_CXXFLAGS+=-Wl,-E -Wl,-rpath,'$(ORIGIN_CMAKE_TO_AUTOCFG)'
endif
# Used by our custom Lua modules, where we want to hide private symbols by default
SYMVIS_FLAGS+=-fvisibility=hidden
LPEG_BUILD_DIR=$(THIRDPARTY_DIR)/lpeg/build/$(MACHINE)
LPEG_DIR=$(CURDIR)/$(LPEG_BUILD_DIR)/lpeg-prefix/src/lpeg
LPEG_RE=$(OUTPUT_DIR)/rocks/share/lua/5.1/re.lua
LPEG_DYNLIB=$(OUTPUT_DIR)/rocks/lib/lua/5.1/lpeg.so
CMAKE_THIRDPARTY_LIBS := kpvcrlib,nanosvg,zstd
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),luajit,lpeg,turbo
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),zyre,czmq,filemq,libzmq
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),libk2pdfopt,tesseract,leptonica
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),lj-wpaclient
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),lua-htmlparser,lua-rapidjson,lua-Spore,luasec,luasocket,libffi,glib,lodepng,minizip
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),djvulibre,mupdf,freetype2,harfbuzz,giflib,libpng,zlib,libwebp,libwebpdemux
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),tar,sdcv,libiconv,gettext,libjpeg-turbo,popen-noshell,sqlite
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),openssl,dropbear,openssh
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),curl,zsync2
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),fbink
CMAKE_THIRDPARTY_LIBS := $(CMAKE_THIRDPARTY_LIBS),kobo-usbms