Makerules 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. # Configuration for the Makefile
  2. # We use $OS from environment if set.
  3. ifeq ($(OS),)
  4. OS := $(shell uname)
  5. endif
  6. WARNING_CFLAGS := -Wall -Wsign-compare
  7. # Feature configuration options
  8. build_suffix :=
  9. ifeq ($(brotli),no)
  10. CFLAGS += -DFZ_ENABLE_BROTLI=0
  11. USE_BROTLI := no
  12. else
  13. USE_BROTLI := yes
  14. endif
  15. ifeq ($(mujs),no)
  16. CFLAGS += -DFZ_ENABLE_JS=0
  17. USE_MUJS := no
  18. else
  19. USE_MUJS := yes
  20. endif
  21. ifeq ($(html),no)
  22. USE_HARFBUZZ := no
  23. USE_GUMBO := no
  24. CFLAGS += -DFZ_ENABLE_HTML_ENGINE=0
  25. CFLAGS += -DFZ_ENABLE_HTML=0
  26. CFLAGS += -DFZ_ENABLE_EPUB=0
  27. CFLAGS += -DFZ_ENABLE_FB2=0
  28. CFLAGS += -DFZ_ENABLE_MOBI=0
  29. CFLAGS += -DFZ_ENABLE_OFFICE=0
  30. CFLAGS += -DFZ_ENABLE_TXT=0
  31. else
  32. USE_HARFBUZZ := yes
  33. USE_GUMBO := yes
  34. endif
  35. ifeq ($(xps),no)
  36. CFLAGS += -DFZ_ENABLE_XPS=0
  37. endif
  38. ifeq ($(svg),no)
  39. CFLAGS += -DFZ_ENABLE_SVG=0
  40. endif
  41. ifeq ($(extract),no)
  42. USE_EXTRACT := no
  43. CFLAGS += -DFZ_ENABLE_DOCX_OUTPUT=0
  44. else
  45. USE_EXTRACT := yes
  46. endif
  47. ifeq ($(tesseract),yes)
  48. build_suffix := $(build_suffix)-tesseract
  49. USE_TESSERACT := yes
  50. endif
  51. ifeq ($(barcode),yes)
  52. build_suffix := $(build_suffix)-barcode
  53. USE_ZXINGCPP := yes
  54. else
  55. CFLAGS += -DFZ_ENABLE_BARCODE=0
  56. endif
  57. ifeq ($(tofu),yes)
  58. build_suffix := $(build_suffix)-tofu
  59. CFLAGS += -DTOFU
  60. endif
  61. ifeq ($(tofu_cjk),yes)
  62. build_suffix := $(build_suffix)-tofu_cjk
  63. CFLAGS += -DTOFU_CJK
  64. endif
  65. ifeq ($(tofu_cjk_ext),yes)
  66. build_suffix := $(build_suffix)-tofu_cjk_ext
  67. CFLAGS += -DTOFU_CJK_EXT
  68. endif
  69. ifeq ($(tofu_cjk_lang),yes)
  70. build_suffix := $(build_suffix)-tofu_cjk_lang
  71. CFLAGS += -DTOFU_CJK_LANG
  72. endif
  73. ifeq ($(archive),yes)
  74. build_suffix := $(build_suffix)-archive
  75. USE_LIBARCHIVE := yes
  76. endif
  77. ifeq ($(commercial),yes)
  78. build_suffix := $(build_suffix)-commercial
  79. CFLAGS += -DHAVE_SMARTOFFICE
  80. HAVE_SMARTOFFICE := yes
  81. endif
  82. # System specific features
  83. ifeq ($(findstring -fembed-bitcode,$(XCFLAGS)),)
  84. # clang does not support these in combination with -fembed-bitcode
  85. CFLAGS += -ffunction-sections -fdata-sections
  86. endif
  87. ifeq ($(OS),Darwin)
  88. LDREMOVEUNREACH := -Wl,-dead_strip
  89. SO := dylib
  90. else
  91. LDREMOVEUNREACH := -Wl,--gc-sections
  92. SO := so
  93. endif
  94. SANITIZE_FLAGS += -fsanitize=address
  95. SANITIZE_FLAGS += -fsanitize=leak
  96. ifeq ($(shared),yes)
  97. ifeq ($(findstring shared-, $(build_prefix)),)
  98. override build_prefix := $(build_prefix)shared-
  99. endif
  100. LIB_CFLAGS = -fPIC
  101. ifeq ($(OS),Darwin)
  102. LIB_LDFLAGS = -dynamiclib
  103. else ifeq ($(OS),wasm)
  104. LIB_LDFLAGS = -shared -sSIDE_MODULE
  105. EXE_LDFLAGS = -sMAIN_MODULE
  106. else ifeq ($(OS),wasm-mt)
  107. LIB_LDFLAGS = -shared -sSIDE_MODULE
  108. EXE_LDFLAGS = -sMAIN_MODULE
  109. else ifeq ($(OS),pyodide)
  110. LIB_LDFLAGS = -shared -sSIDE_MODULE
  111. EXE_LDFLAGS = -sMAIN_MODULE
  112. # Pyodide's ld does not support -b so we cannot use it to create object
  113. # files containing font data, so leave HAVE_OBJCOPY unset. And we need
  114. # extra memory when linking.
  115. LDFLAGS += -sTOTAL_MEMORY=48MB
  116. else ifeq ($(OS),Linux)
  117. LIB_LDFLAGS = -shared -Wl,-soname,$(notdir $@)
  118. else
  119. LIB_LDFLAGS = -shared
  120. endif
  121. else
  122. LIB_CFLAGS =
  123. LIB_LDFLAGS =
  124. endif
  125. ifeq ($(build),debug)
  126. CFLAGS += -pipe -g
  127. LDFLAGS += -g
  128. else ifeq ($(build),release)
  129. CFLAGS += -pipe -O2 -DNDEBUG
  130. LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
  131. else ifeq ($(build),small)
  132. CFLAGS += -pipe -Os -DNDEBUG
  133. LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
  134. else ifeq ($(build),valgrind)
  135. CFLAGS += -pipe -O2 -DNDEBUG -DPACIFY_VALGRIND
  136. LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
  137. else ifeq ($(build),sanitize)
  138. CFLAGS += -pipe -g $(SANITIZE_FLAGS)
  139. LDFLAGS += -g $(SANITIZE_FLAGS)
  140. else ifeq ($(build),sanitize-release)
  141. CFLAGS += -pipe -O2 -DNDEBUG $(SANITIZE_FLAGS)
  142. LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s $(SANITIZE_FLAGS)
  143. else ifeq ($(build),profile)
  144. CFLAGS += -pipe -O2 -DNDEBUG -pg
  145. LDFLAGS += -pg
  146. else ifeq ($(build),coverage)
  147. CFLAGS += -pipe -g -pg -fprofile-arcs -ftest-coverage
  148. LIBS += -lgcov
  149. else ifeq ($(build),native)
  150. CFLAGS += -pipe -O2 -DNDEBUG -march=native
  151. LDFLAGS += $(LDREMOVEUNREACH) -Wl,-s
  152. else ifeq ($(build),memento)
  153. CFLAGS += -pipe -g -DMEMENTO -DMEMENTO_MUPDF_HACKS
  154. LDFLAGS += -g -rdynamic
  155. ifneq ($(HAVE_LIBDL),no)
  156. CFLAGS += -DHAVE_LIBDL
  157. ifeq ($(OS),OpenBSD)
  158. LIBS += -L /usr/local/lib -l execinfo
  159. else
  160. LIBS += -ldl
  161. endif
  162. endif
  163. else ifeq ($(build),gperf)
  164. CFLAGS += -pipe -O2 -DNDEBUG -DGPERF
  165. LIBS += -lprofiler
  166. else
  167. $(error unknown build setting: '$(build)')
  168. endif
  169. # Default system libraries
  170. SYS_FREETYPE_LIBS := -lfreetype2
  171. SYS_HARFBUZZ_LIBS := -lharfbuzz
  172. SYS_JBIG2DEC_LIBS := -ljbig2dec
  173. SYS_JPEGXR_LIBS := -ljpegxr
  174. SYS_LCMS2_LIBS := -llcms2
  175. SYS_LIBJPEG_LIBS := -ljpeg
  176. SYS_MUJS_LIBS := -lmujs
  177. SYS_OPENJPEG_LIBS := -lopenjp2
  178. SYS_ZLIB_LIBS := -lz
  179. SYS_BROTLI_LIBS := -lbrotlidec -lbrotlienc
  180. SYS_TESSERACT_LIBS := -ltesseract
  181. SYS_LEPTONICA_LIBS := -llept
  182. SYS_LIBARCHIVE_LIBS := -larchive
  183. SYS_ZXINGCPP_LIBS := -lzxing-cpp -lzint
  184. ifneq "$(CLUSTER)" ""
  185. CFLAGS += -DCLUSTER
  186. endif
  187. ifeq ($(OS),Darwin)
  188. HAVE_GLUT := yes
  189. SYS_GLUT_CFLAGS := -Wno-deprecated-declarations
  190. SYS_GLUT_LIBS := -framework GLUT -framework OpenGL
  191. CC = xcrun cc
  192. AR = xcrun ar
  193. LD = xcrun ld
  194. RANLIB = xcrun ranlib
  195. ifneq ($(ARCHFLAGS),)
  196. $(warning "MacOS with ARCHFLAGS set. Assuming we are building for arm64, and setting HAVE_LIBCRYPTO to no.")
  197. HAVE_LIBCRYPTO := no
  198. else ifeq (, $(shell command -v pkg-config))
  199. $(warning "No pkg-config found, install it for proper integration of libcrypto")
  200. else
  201. HAVE_LIBCRYPTO := $(shell pkg-config --exists 'libcrypto >= 1.1.0' && echo yes)
  202. ifeq ($(HAVE_LIBCRYPTO),yes)
  203. LIBCRYPTO_CFLAGS := $(shell pkg-config --cflags libcrypto) -DHAVE_LIBCRYPTO
  204. LIBCRYPTO_LIBS := $(shell pkg-config --libs libcrypto)
  205. endif
  206. endif
  207. else
  208. ifeq ($(OS),Linux)
  209. HAVE_OBJCOPY := yes
  210. endif
  211. ifeq ($(OS),OpenBSD)
  212. LDFLAGS += -pthread
  213. endif
  214. ifeq ($(shell pkg-config --exists 'freetype2 >= 18.3.12' && echo yes),yes)
  215. SYS_FREETYPE_CFLAGS := $(shell pkg-config --cflags freetype2)
  216. SYS_FREETYPE_LIBS := $(shell pkg-config --libs freetype2)
  217. endif
  218. ifeq ($(shell pkg-config --exists 'gumbo >= 0.10.0' && echo yes),yes)
  219. SYS_GUMBO_CFLAGS := $(shell pkg-config --cflags gumbo)
  220. SYS_GUMBO_LIBS := $(shell pkg-config --libs gumbo)
  221. endif
  222. ifeq ($(shell pkg-config --exists 'harfbuzz >= 2.0.0' && echo yes),yes)
  223. SYS_HARFBUZZ_CFLAGS := $(shell pkg-config --cflags harfbuzz)
  224. SYS_HARFBUZZ_LIBS := $(shell pkg-config --libs harfbuzz)
  225. endif
  226. ifeq ($(shell pkg-config --exists lcms2 && echo yes),yes)
  227. SYS_LCMS2_CFLAGS := $(shell pkg-config --cflags lcms2)
  228. SYS_LCMS2_LIBS := $(shell pkg-config --libs lcms2)
  229. endif
  230. ifeq ($(shell pkg-config --exists libjpeg && echo yes),yes)
  231. SYS_LIBJPEG_CFLAGS := $(shell pkg-config --cflags libjpeg)
  232. SYS_LIBJPEG_LIBS := $(shell pkg-config --libs libjpeg)
  233. endif
  234. ifeq ($(shell pkg-config --exists 'libopenjp2 >= 2.1.0' && echo yes),yes)
  235. SYS_OPENJPEG_CFLAGS := $(shell pkg-config --cflags libopenjp2)
  236. SYS_OPENJPEG_LIBS := $(shell pkg-config --libs libopenjp2)
  237. endif
  238. ifeq ($(shell pkg-config --exists 'zlib >= 1.2.6' && echo yes),yes)
  239. SYS_ZLIB_CFLAGS := $(shell pkg-config --cflags zlib)
  240. SYS_ZLIB_LIBS := $(shell pkg-config --libs zlib)
  241. endif
  242. ifeq ($(shell pkg-config --exists 'libbrotlidec libbrotlienc >= 0.6.0' && echo yes),yes)
  243. SYS_BROTLI_CFLAGS := $(shell pkg-config --cflags libbrotlidec libbrotlienc)
  244. SYS_BROTLI_LIBS := $(shell pkg-config --libs libbrotlidec libbrotlienc)
  245. endif
  246. HAVE_SYS_LEPTONICA := $(shell pkg-config --exists 'lept >= 1.7.4' && echo yes)
  247. ifeq ($(HAVE_SYS_LEPTONICA),yes)
  248. SYS_LEPTONICA_CFLAGS := $(shell pkg-config --cflags lept)
  249. SYS_LEPTONICA_LIBS := $(shell pkg-config --libs lept)
  250. endif
  251. HAVE_SYS_TESSERACT := $(shell pkg-config --exists 'tesseract >= 4.0.0' && echo yes)
  252. ifeq ($(HAVE_SYS_TESSERACT),yes)
  253. SYS_TESSERACT_CFLAGS := $(shell pkg-config --cflags tesseract)
  254. SYS_TESSERACT_LIBS := $(shell pkg-config --libs tesseract)
  255. endif
  256. HAVE_SYS_LIBARCHIVE := $(shell pkg-config --exists 'libarchive' && echo yes)
  257. ifeq ($(HAVE_SYS_LIBARCHIVE),yes)
  258. SYS_LIBARCHIVE_CFLAGS := $(shell pkg-config --cflags libarchive)
  259. SYS_LIBARCHIVE_LIBS := $(shell pkg-config --libs libarchive)
  260. endif
  261. HAVE_SYS_ZXINGCPP := $(shell pkg-config --exists 'zxing >= 2.0.0' && echo yes)
  262. ifeq ($(HAVE_SYS_ZXINGCPP),yes)
  263. SYS_ZXINGCPP_CFLAGS := $(shell pkg-config --cflags zxing)
  264. SYS_ZXINGCPP_LIBS := $(shell pkg-config --libs zxing)
  265. endif
  266. HAVE_SYS_CURL := $(shell pkg-config --exists libcurl && echo yes)
  267. ifeq ($(HAVE_SYS_CURL),yes)
  268. SYS_CURL_CFLAGS := $(shell pkg-config --cflags libcurl)
  269. SYS_CURL_LIBS := $(shell pkg-config --libs libcurl)
  270. endif
  271. ifeq ($(HAVE_GLUT),)
  272. HAVE_GLUT := $(shell pkg-config --exists gl x11 xrandr && echo yes)
  273. endif
  274. ifeq ($(HAVE_GLUT),yes)
  275. SYS_GL_CFLAGS := $(shell pkg-config --cflags gl x11 xrandr)
  276. SYS_GL_LIBS := $(shell pkg-config --libs gl x11 xrandr)
  277. ifeq ($(shell pkg-config --exists glut && echo yes),yes)
  278. SYS_GLUT_CFLAGS := $(shell pkg-config --cflags glut)
  279. SYS_GLUT_LIBS := $(shell pkg-config --libs glut)
  280. else
  281. SYS_GLUT_CFLAGS :=
  282. SYS_GLUT_LIBS := -lglut
  283. endif
  284. endif
  285. ifeq ($(HAVE_X11),)
  286. HAVE_X11 := $(shell pkg-config --exists x11 xext && echo yes)
  287. endif
  288. ifeq ($(HAVE_X11),yes)
  289. X11_CFLAGS := $(shell pkg-config --cflags x11 xext)
  290. X11_LIBS := $(shell pkg-config --libs x11 xext)
  291. endif
  292. ifeq ($(HAVE_LIBCRYPTO),)
  293. HAVE_LIBCRYPTO := $(shell pkg-config --exists 'libcrypto >= 1.1.0' && echo yes)
  294. endif
  295. ifeq ($(HAVE_LIBCRYPTO),yes)
  296. LIBCRYPTO_CFLAGS := $(shell pkg-config --cflags libcrypto) -DHAVE_LIBCRYPTO
  297. LIBCRYPTO_LIBS := $(shell pkg-config --libs libcrypto)
  298. endif
  299. HAVE_PTHREAD := yes
  300. ifeq ($(HAVE_PTHREAD),yes)
  301. PTHREAD_CFLAGS :=
  302. PTHREAD_LIBS := -lpthread
  303. endif
  304. endif
  305. # The following section has various cross compilation configurations.
  306. #
  307. # Invoke these as:
  308. # make OS=wasm
  309. #
  310. # This does rely on the generated directory being populated with the font files.
  311. # Run 'make generate' before doing the cross compile.
  312. ifeq "$(OS)" "wasm"
  313. build_prefix += wasm/
  314. CC = emcc
  315. CXX = em++
  316. AR = emar
  317. HAVE_GLUT=no
  318. HAVE_X11=no
  319. HAVE_OBJCOPY=no
  320. HAVE_LIBCRYPTO=no
  321. CFLAGS += -mno-nontrapping-fptoint
  322. CFLAGS += -fwasm-exceptions
  323. CFLAGS += -sSUPPORT_LONGJMP=wasm
  324. endif
  325. ifeq "$(OS)" "wasm-mt"
  326. build_prefix += wasm-mt/
  327. CC = emcc
  328. CXX = em++
  329. AR = emar
  330. HAVE_GLUT=no
  331. HAVE_X11=no
  332. HAVE_OBJCOPY=no
  333. HAVE_LIBCRYPTO=no
  334. CFLAGS += -mno-nontrapping-fptoint
  335. CFLAGS += -fwasm-exceptions
  336. CFLAGS += -sSUPPORT_LONGJMP=wasm
  337. CFLAGS += -pthread
  338. endif
  339. ifeq "$(OS)" "pyodide"
  340. build_prefix += $(OS)/
  341. # We use the provided $CC and $CXX.
  342. AR = emar
  343. HAVE_GLUT=no
  344. HAVE_X11=no
  345. HAVE_OBJCOPY=no
  346. HAVE_LIBCRYPTO=no
  347. CFLAGS += -pthread
  348. endif