forked from koreader/koreader-base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
282 lines (243 loc) · 10.3 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
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
include Makefile.defs
DO_STRIP := $(if $(or $(EMULATE_READER),$(KODEBUG)),,1)
DO_STRIP := $(if $(or $(DO_STRIP),$(APPIMAGE),$(DEBIAN)),1,)
$(info ************ Building for MACHINE: "$(MACHINE)" **********)
$(info ************ PATH: "$(PATH)" **********)
$(info ************ CHOST: "$(CHOST)" **********)
# main target
all: $(OUTPUT_DIR)/libs $(if $(ANDROID),,$(LUAJIT)) \
$(if $(USE_LUAJIT_LIB),$(LUAJIT_LIB),) \
$(LUAJIT_JIT) \
libs $(K2PDFOPT_LIB) \
$(OUTPUT_DIR)/spec/base $(OUTPUT_DIR)/common $(OUTPUT_DIR)/rocks \
$(OUTPUT_DIR)/plugins $(LUASOCKET) \
$(OUTPUT_DIR)/ffi $(OUTPUT_DIR)/data \
$(if $(WIN32),,$(LUASEC)) \
$(if $(ANDROID),$(LUACOMPAT52) $(LUALONGNUMBER),) \
$(if $(WIN32),,$(EVERNOTE_LIB)) \
$(LUASERIAL_LIB) \
$(TURBOJPEG_LIB) \
$(LODEPNG_LIB) \
$(GIF_LIB) \
$(if $(USE_LJ_WPACLIENT),$(LJ_WPACLIENT),) \
$(TURBO_FFI_WRAP_LIB) \
$(LUA_HTMLPARSER_ROCK) \
$(LUA_RAPIDJSON_ROCK) \
$(LUA_SPORE_ROCK) \
$(if $(ANDROID),$(LPEG_DYNLIB) $(LPEG_RE),) \
$(if $(WIN32),,$(ZMQ_LIB) $(CZMQ_LIB) $(FILEMQ_LIB) $(ZYRE_LIB)) \
$(if $(WIN32),,$(OUTPUT_DIR)/sdcv) \
$(if $(MACOS),$(OUTPUT_DIR)/koreader,) \
$(if $(MACOS),$(SDL2_LIB),) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/dropbear,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/sftp-server,) \
$(if $(or $(DARWIN),$(WIN32)),,$(OUTPUT_DIR)/tar) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(REMARKABLE)),$(OUTPUT_DIR)/fbink,) \
$(if $(KOBO),$(OUTPUT_DIR)/data/KoboUSBMS.tar.gz,) \
$(if $(REMARKABLE),$(OUTPUT_DIR)/button-listen,) \
$(SQLITE_LIB) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK),$(REMARKABLE),$(SONY_PRSTUX)),$(CURL_LIB),) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK),$(REMARKABLE),$(SONY_PRSTUX)),$(OUTPUT_DIR)/zsync2,) \
$(LUA_LJ_SQLITE) $(OUTPUT_DIR)/common/xsys.lua
ifeq ($(DO_STRIP),1)
STRIP_FILES="\
$(if $(WIN32),,$(OUTPUT_DIR)/sdcv) \
$(if $(WIN32),,$(OUTPUT_DIR)/tar) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/dropbear,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/sftp-server,) \
$(if $(or $(KINDLE),$(KOBO)),$(OUTPUT_DIR)/scp,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(REMARKABLE)),$(OUTPUT_DIR)/fbink,) \
$(if $(REMARKABLE),$(OUTPUT_DIR)/button-listen,) \
$(if $(or $(KOBO),$(REMARKABLE)),$(OUTPUT_DIR)/fbdepth,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK),$(REMARKABLE),$(SONY_PRSTUX)),$(OUTPUT_DIR)/zsync2,) \
$(if $(ANDROID),,$(LUAJIT)) \
$(OUTPUT_DIR)/plugins/evernote.koplugin/lib/$(if $(WIN32),*.dll,*.so*) \
$(OUTPUT_DIR)/rocks/lib/lua/5.1/$(if $(WIN32),*.dll,*.so*) \
$(OUTPUT_DIR)/libs/$(if $(WIN32),*.dll,*.so*)" ;\
$(STRIP) --strip-unneeded $${STRIP_FILES} ;\
touch -r $${STRIP_FILES} # let all files have the same mtime
find $(OUTPUT_DIR)/common -name "$(if $(WIN32),*.dll,*.so*)" | \
xargs $(STRIP) --strip-unneeded
endif
# set up some needed paths and links
install -d $(OUTPUT_DIR)/{cache,history,clipboard,fonts} $(CURDIR)/$(EVERNOTE_THRIFT_DIR)
ln -sf $(CURDIR)/$(THIRDPARTY_DIR)/kpvcrlib/cr3.css $(OUTPUT_DIR)/data/
ifndef DARWIN
# setup Evernote SDK
cd $(EVERNOTE_SDK_DIR) && \
$(RCP) *.lua evernote $(CURDIR)/$(EVERNOTE_PLUGIN_DIR) && \
cp thrift/*.lua $(CURDIR)/$(EVERNOTE_THRIFT_DIR)
endif
test -e $(LPEG_RE) && chmod 664 $(LPEG_RE) || true # hot fix re.lua permission
$(OUTPUT_DIR)/libs:
install -d $(OUTPUT_DIR)/libs
$(OUTPUT_DIR)/common:
install -d $(OUTPUT_DIR)/common
$(OUTPUT_DIR)/rocks:
install -d $(OUTPUT_DIR)/rocks
$(OUTPUT_DIR)/plugins:
install -d $(OUTPUT_DIR)/plugins
$(OUTPUT_DIR)/ffi:
ln -sf ../../ffi $(OUTPUT_DIR)/
$(OUTPUT_DIR)/data:
ln -sf $(CRENGINE_SRC_DIR)/cr3gui/data $(OUTPUT_DIR)/data
# our own Lua/C/C++ interfacing:
libs: \
$(if $(or $(SDL),$(ANDROID)),,$(OUTPUT_DIR)/libs/libkoreader-input.so) \
$(if $(or $(SDL),$(ANDROID),$(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK),$(REMARKABLE),$(SONY_PRSTUX)),$(OUTPUT_DIR)/libs/libblitbuffer.so,) \
$(if $(APPIMAGE),$(OUTPUT_DIR)/libs/libXss.so.1,) \
$(if $(POCKETBOOK),$(OUTPUT_DIR)/libs/libinkview-compat.so,) \
$(OUTPUT_DIR)/libs/libkoreader-lfs.so \
$(OUTPUT_DIR)/libs/libkoreader-djvu.so \
$(OUTPUT_DIR)/libs/libkoreader-cre.so \
$(OUTPUT_DIR)/libs/libkoreader-xtext.so \
$(OUTPUT_DIR)/libs/libwrap-mupdf.so
$(OUTPUT_DIR)/libs/libinkview-compat.so: input/inkview-compat.c
$(CC) $(DYNLIB_CFLAGS) -linkview -o $@ $<
$(OUTPUT_DIR)/libs/libkoreader-input.so: input/*.c input/*.h $(if $(KINDLE),$(POPEN_NOSHELL_LIB),)
@echo "Building koreader input module..."
$(CC) $(DYNLIB_CFLAGS) -I$(POPEN_NOSHELL_DIR) -I./input \
$(if $(CERVANTES),-DCERVANTES,) $(if $(KOBO),-DKOBO,) $(if $(KINDLE),-DKINDLE,) $(if $(POCKETBOOK),-DPOCKETBOOK,) $(if $(REMARKABLE),-DREMARKABLE,) $(if $(SONY_PRSTUX),-DSONY_PRSTUX,)\
-o $@ \
input/input.c \
$(if $(KINDLE),$(POPEN_NOSHELL_LIB),) \
$(if $(POCKETBOOK),-linkview,)
$(OUTPUT_DIR)/libs/libkoreader-lfs.so: \
$(if $(USE_LUAJIT_LIB),$(LUAJIT_LIB),) \
luafilesystem/src/lfs.c
$(CC) $(DYNLIB_CFLAGS) -o $@ $^
ifdef DARWIN
install_name_tool -change \
`otool -L "$@" | grep "libluajit" | awk '{print $$1}'` \
libs/$(notdir $(LUAJIT_LIB)) \
$@
endif
# put all the libs to the end of compile command to make ubuntu's tool chain
# happy
$(OUTPUT_DIR)/libs/libkoreader-djvu.so: djvu.c \
$(if $(USE_LUAJIT_LIB),$(LUAJIT_LIB),) \
$(DJVULIBRE_LIB) $(K2PDFOPT_LIB)
$(CC) -I$(DJVULIBRE_DIR) -I$(MUPDF_DIR)/include $(K2PDFOPT_CFLAGS) \
$(DYNLIB_CFLAGS) -o $@ $^ $(if $(ANDROID),,-lpthread)
ifdef DARWIN
install_name_tool -change \
`otool -L "$@" | grep "libluajit" | awk '{print $$1}'` \
libs/$(notdir $(LUAJIT_LIB)) \
$@
install_name_tool -change \
`otool -L "$@" | grep "$(notdir $(DJVULIBRE_LIB)) " | awk '{print $$1}'` \
libs/$(notdir $(DJVULIBRE_LIB)) \
$@
install_name_tool -change \
`otool -L "$@" | grep "$(notdir $(K2PDFOPT_LIB)) " | awk '{print $$1}'` \
libs/$(notdir $(K2PDFOPT_LIB)) \
$@
endif
$(OUTPUT_DIR)/libs/libkoreader-cre.so: cre.cpp \
$(if $(USE_LUAJIT_LIB),$(LUAJIT_LIB),) \
$(CRENGINE_LIB)
$(CXX) -I$(CRENGINE_SRC_DIR)/crengine/include/ $(DYNLIB_CXXFLAGS) \
-DLDOM_USE_OWN_MEM_MAN=$(if $(WIN32),0,1) \
$(if $(WIN32),-DQT_GL=1) -static-libstdc++ -o $@ $^
ifdef DARWIN
install_name_tool -change \
`otool -L "$@" | grep "libluajit" | awk '{print $$1}'` \
libs/$(notdir $(LUAJIT_LIB)) \
$@
install_name_tool -change \
`otool -L "$@" | grep "$(notdir $(CRENGINE_LIB)) " | awk '{print $$1}'` \
libs/$(notdir $(CRENGINE_LIB)) \
$@
endif
$(OUTPUT_DIR)/libs/libkoreader-xtext.so: xtext.cpp \
$(if $(USE_LUAJIT_LIB),$(LUAJIT_LIB),) \
$(FREETYPE_LIB) $(HARFBUZZ_LIB) $(FRIBIDI_LIB) $(LIBUNIBREAK_LIB)
$(CXX) -I$(FREETYPE_DIR)/include/freetype2 \
-I$(HARFBUZZ_DIR)/include/harfbuzz \
-I$(FRIBIDI_DIR)/include \
-I$(LIBUNIBREAK_DIR)/include \
$(DYNLIB_CXXFLAGS) -static-libstdc++ -Wall -o $@ $^
ifdef DARWIN
install_name_tool -change \
`otool -L "$@" | grep "libluajit" | awk '{print $$1}'` \
libs/$(notdir $(LUAJIT_LIB)) \
$@
install_name_tool -change \
`otool -L "$@" | grep "$(notdir $(HARFBUZZ_LIB)) " | awk '{print $$1}'` \
libs/$(notdir $(HARFBUZZ_LIB)) \
$@
install_name_tool -change \
`otool -L "$@" | grep "$(notdir $(FRIBIDI_LIB)) " | awk '{print $$1}'` \
libs/$(notdir $(FRIBIDI_LIB)) \
$@
endif
$(OUTPUT_DIR)/libs/libblitbuffer.so: blitbuffer.c
$(CC) $(DYNLIB_CFLAGS) $(VECTO_CFLAGS) -o $@ $^
$(OUTPUT_DIR)/libs/libwrap-mupdf.so: wrap-mupdf.c \
$(MUPDF_LIB)
$(CC) -I$(MUPDF_DIR)/include $(DYNLIB_CFLAGS) -o $@ $^
ifdef DARWIN
install_name_tool -id \
libs/libwrap-mupdf.so \
$@
endif
$(OUTPUT_DIR)/libs/libXss.so.1: libxss-dummy.c
$(CC) $(DYNLIB_CFLAGS) -o $@ $^
ffi/mupdf_h.lua: ffi-cdecl/mupdf_decl.c $(MUPDF_DIR)/include
CPPFLAGS="$(CFLAGS) -I. -I$(MUPDF_DIR)/include" $(FFI_CDECL) gcc ffi-cdecl/mupdf_decl.c $@
ffi/SDL2_0_h.lua: ffi-cdecl/SDL2_0_decl.c
CPPFLAGS="$(CFLAGS) -I. -LSDL2" $(FFI_CDECL) gcc ffi-cdecl/SDL2_0_decl.c $@
ffi/lodepng_h.lua: ffi-cdecl/lodepng_decl.c $(LODEPNG_DIR)
CPPFLAGS="$(CFLAGS) -I. -I$(LODEPNG_DIR)" $(FFI_CDECL) gcc ffi-cdecl/lodepng_decl.c $@
# include all third party libs
include Makefile.third
# ===========================================================================
# entry point for the application in OSX
$(OUTPUT_DIR)/koreader: osx_loader.c
$(CC) -pagezero_size 10000 -image_base 100000000 \
-I$(LUAJIT_DIR)/src $(LUAJIT_STATIC) -o $@ $^
# ===========================================================================
# very simple "launcher" for koreader on the remarkable
$(OUTPUT_DIR)/button-listen: button-listen.c
$(CC) $(CFLAGS) -o $@ $^
# ===========================================================================
# the attachment extraction tool:
$(OUTPUT_DIR)/extr: extr.c $(MUPDF_LIB) $(MUPDF_DIR)/include $(JPEG_LIB) $(FREETYPE_LIB)
$(CC) -I$(MUPDF_DIR) -I$(MUPDF_DIR)/include \
$(CFLAGS) -Wl,-rpath,'libs' -o $@ $^
# ===========================================================================
# helper target for creating standalone android toolchain from NDK
# NDK variable should be set in your environment and it should point to
# the root directory of the NDK
#
# --deprecated-headers is necessary in NDK 15, but will fail in 12-14
android-toolchain:
ifneq ($(wildcard $(NDK)/build/tools),)
$(NDK)/build/tools/make_standalone_toolchain.py --force --install-dir=$(ANDROID_TOOLCHAIN) \
--arch $(ANDROID_ARCH) --api $(NDKABI) --deprecated-headers || \
$(NDK)/build/tools/make_standalone_toolchain.py --force --install-dir=$(ANDROID_TOOLCHAIN) \
--arch $(ANDROID_ARCH) --api $(NDKABI)
endif
# ===========================================================================
# helper target for initializing third-party code
clean:
-rm -rf $(OUTPUT_DIR)/*
-rm -rf $(THIRDPARTY_DIR)/{$(CMAKE_THIRDPARTY_LIBS)}/build/$(MACHINE)
distclean:
-rm -rf build
-rm -rf $(THIRDPARTY_DIR)/{$(CMAKE_THIRDPARTY_LIBS)}/build
# ===========================================================================
# start of unit tests section
$(OUTPUT_DIR)/.busted:
test -e $(OUTPUT_DIR)/.busted || \
ln -sf ../../.busted $(OUTPUT_DIR)/
$(OUTPUT_DIR)/spec/base:
install -d $(OUTPUT_DIR)/spec
test -e $(OUTPUT_DIR)/spec/base || \
ln -sf ../../../spec $(OUTPUT_DIR)/spec/base
test: $(OUTPUT_DIR)/spec $(OUTPUT_DIR)/.busted
cd $(OUTPUT_DIR) && \
./luajit $(shell which busted) \
--exclude-tags=notest \
-o gtest ./spec/base/unit
.PHONY: all android-toolchain clean distclean test