Makefile 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. # Example commands:
  2. #
  3. # make
  4. # make test
  5. # Runs all tests.
  6. #
  7. # make test-exe
  8. # Runs exe regression tests. These use $(gs) and $(mutool) to generate
  9. # intermediate data about pdf content, then uses $(exe) to convert to
  10. # docx.
  11. #
  12. # make test-mutool
  13. # Runs mutool regression tests. This uses $(mutool) to convert directly
  14. # from pdf to docx. We require that $(mutool) was built with extract=yes.
  15. #
  16. # make test-gs
  17. # Runs gs regression tests. This uses $(gs) to convert directly from pdf
  18. # to docx. We require that $(gs) was built with --with-extract-dir=... We
  19. # also do a simple test of output-file-per-page.
  20. #
  21. # make test-tables
  22. # Tests handling of tables, using mutool with docx device's html output.
  23. #
  24. # make test-buffer test-misc test-src
  25. # Runs unit tests etc.
  26. #
  27. # make build=debug-opt ...
  28. # Set build flags.
  29. #
  30. # make build=memento msqueeze
  31. # Run memento squeeze test.
  32. #
  33. # Assuming we are in mupdf/thirdparty/extract, and there is a ghostpdl at
  34. # the same level as mupdf, with a softlink from ghostpdl to extract:
  35. #
  36. # make test-rebuild-dependent-binaries
  37. # Clean/Configure/Rebuild the required mupdf and gs binaries.
  38. #
  39. # make test-build-dependent-binaries
  40. # Build the required mupdf and gs binaries.
  41. # Build flags.
  42. #
  43. # Note that OpenBSD's clang-8 appears to ignore -Wdeclaration-after-statement.
  44. #
  45. build = debug
  46. flags_link = -W -Wall -lm
  47. flags_compile = -W -Wall -Wextra -Wpointer-sign -Wmissing-declarations -Wmissing-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wconversion -Wno-sign-conversion -Werror -MMD -MP -Iinclude -Isrc
  48. uname = $(shell uname)
  49. ifeq ($(build),)
  50. $(error Need to specify build=debug|opt|debug-opt|memento)
  51. else ifeq ($(build),debug)
  52. flags_link += -g
  53. flags_compile += -g
  54. else ifeq ($(build),opt)
  55. flags_link += -O2
  56. flags_compile += -O2
  57. else ifeq ($(build),debug-opt)
  58. flags_link += -g -O2
  59. flags_compile += -g -O2
  60. else ifeq ($(build),memento)
  61. flags_link += -g -dl
  62. ifeq ($(uname),OpenBSD)
  63. flags_link += -l execinfo
  64. endif
  65. flags_compile += -g -D MEMENTO
  66. else
  67. $(error unrecognised $$(build)=$(build))
  68. endif
  69. regenerate ?= no
  70. ifeq ($(regenerate),yes)
  71. DIFF_OR_CP = rm -rf $(word 2,%$^); cp -r
  72. else
  73. DIFF_OR_CP = diff -ru
  74. endif
  75. gdb = gdb
  76. ifeq ($(uname),OpenBSD)
  77. flags_link += -L /usr/local/lib -l execinfo
  78. $(warning have added -L /usr/local/lib)
  79. gdb = egdb
  80. # For some reason OpenBSD's gmake defaults CXX to g++, which is not helpful.
  81. CXX = c++
  82. endif
  83. # Locations of mutool and gs. By default we assume these are not available.
  84. #
  85. # If this extract checkout is within a mupdf tree (typically as a git
  86. # submodule) we assume ghostpdl is checked out nearby and both mutool gs and gs
  87. # binaries are available and built with extract enabled.
  88. #
  89. # Disable this by running: make we_are_mupdf_thirdparty= ...
  90. #
  91. we_are_mupdf_thirdparty = $(findstring /mupdf/thirdparty/extract, $(abspath .))
  92. ifneq ($(we_are_mupdf_thirdparty),)
  93. $(warning we are mupdf thirdparty)
  94. ifeq ($(build),memento)
  95. mutool := ../../build/memento/mutool
  96. else
  97. mutool := ../../build/debug/mutool
  98. endif
  99. gs := ../../../ghostpdl/debug-extract-bin/gs
  100. libbacktrace = ../../../libbacktrace/.libs
  101. endif
  102. # If mutool/gs are specified, they must exist.
  103. #
  104. ifneq ($(mutool),)
  105. ifeq ($(wildcard $(mutool)),)
  106. $(error mutool does not exist: $(mutool))
  107. endif
  108. $(warning mutool=$(mutool))
  109. endif
  110. ifeq ($(build),memento)
  111. mutool_run := MEMENTO_ABORT_ON_LEAK=1 $(mutool)
  112. else
  113. mutool_run := $(mutool)
  114. endif
  115. ifneq ($(gs),)
  116. ifeq ($(wildcard $(gs)),)
  117. $(error gs does not exist: $(gs))
  118. endif
  119. $(warning gs=$(gs))
  120. endif
  121. # Default target - run all tests.
  122. #
  123. test: test-buffer test-misc test-src test-exe test-mutool test-gs test-html test-tables
  124. @echo $@: passed
  125. # Define the main test targets.
  126. #
  127. # test/Python2clipped.pdf is same as test/Python2.pdf except it as a modified
  128. # MediaBox that excludes some glyphs.
  129. #
  130. pdfs = test/Python2.pdf test/Python2clipped.pdf test/zlib.3.pdf test/text_graphic_image.pdf
  131. pdfs_generated = $(patsubst test/%, test/generated/%, $(pdfs))
  132. tests_exe := \
  133. $(patsubst %, %.extract.docx, $(tests_exe)) \
  134. $(patsubst %, %.extract-rotate.docx, $(tests_exe)) \
  135. $(patsubst %, %.extract-rotate-spacing.docx, $(tests_exe)) \
  136. $(patsubst %, %.extract-autosplit.docx, $(tests_exe)) \
  137. $(patsubst %, %.extract-template.docx, $(tests_exe)) \
  138. tests_exe := $(patsubst %, %.diff, $(tests_exe))
  139. ifneq ($(mutool),)
  140. # Targets that test direct conversion with mutool.
  141. #
  142. tests_mutool := \
  143. $(patsubst %, %.mutool.docx.dir.diff, $(pdfs_generated)) \
  144. $(patsubst %, %.mutool-norotate.docx.dir.diff, $(pdfs_generated)) \
  145. $(patsubst %, %.mutool.odt.dir.diff, $(pdfs_generated)) \
  146. $(patsubst %, %.mutool.text.diff, $(pdfs_generated)) \
  147. tests_mutool_odt := \
  148. $(patsubst %, %.mutool.odt.diff, $(pdfs_generated)) \
  149. tests_mutool_text := \
  150. $(patsubst %, %.mutool.text.diff, $(pdfs_generated)) \
  151. tests_html := test/generated/table.pdf.mutool.html.diff
  152. endif
  153. ifneq ($(gs),)
  154. # Targets that test direct conversion with gs.
  155. #
  156. tests_gs := \
  157. $(patsubst %, %.gs.docx.dir.diff, $(pdfs_generated)) \
  158. test_gs_fpp
  159. # We don't yet do clipping with gs so exclude Python2clipped.pdf.*:
  160. tests_gs := $(filter-out test/generated/Python2clipped.pdf.%, $(tests_gs))
  161. #$(warning tests_gs: $(tests_gs))
  162. endif
  163. #$(warning $(tests))
  164. test-exe: $(tests_exe)
  165. @echo $@: passed
  166. # Checks output of mutool conversion from .pdf to .docx/.odt.
  167. #
  168. test-mutool: $(tests_mutool)
  169. @echo $@: passed
  170. # Checks output of mutool conversion from .pdf to .odt.
  171. #
  172. test-mutool-odt: $(tests_mutool_odt)
  173. @echo $@: passed
  174. # Checks output of mutool conversion from .pdf to .text.
  175. #
  176. test-mutool-text: $(tests_mutool_text)
  177. @echo $@: passed
  178. # Checks output of gs conversion from .pdf to .docx. Requires that gs was built
  179. # with extract as a third-party library. As of 2021-02-10 this requires, for
  180. # example ghostpdl/extract being a link to an extract checkout and configuring
  181. # with --with-extract-dir=extract.
  182. #
  183. test-gs: $(tests_gs)
  184. @echo $@: passed
  185. # Check behaviour of gs when writing file-per-page.
  186. #
  187. test_gs_fpp: $(gs)
  188. @echo
  189. @echo == Testing gs file-page-page
  190. rm test/generated/text_graphic_image.pdf.gs.*.docx || true
  191. $(gs) -sDEVICE=docxwrite -o test/generated/Python2.pdf.gs.%i.docx test/Python2.pdf
  192. rm test/generated/text_graphic_image.pdf.gs.*.docx || true
  193. $(gs) -sDEVICE=docxwrite -o test/generated/zlib.3.pdf.gs.%i.docx test/zlib.3.pdf
  194. rm test/generated/text_graphic_image.pdf.gs.*.docx || true
  195. $(gs) -sDEVICE=docxwrite -o test/generated/text_graphic_image.pdf.gs.%i.docx test/text_graphic_image.pdf
  196. @echo Checking for correct number of generated files.
  197. ls -l test/generated/*.pdf.gs.*.docx
  198. ls test/generated/text_graphic_image.pdf.gs.*.docx | wc -l | grep '^ *1$$'
  199. ls test/generated/Python2.pdf.gs.*.docx | wc -l | grep '^ *1$$'
  200. ls test/generated/zlib.3.pdf.gs.*.docx | wc -l | grep '^ *2$$'
  201. test-html: $(tests_html)
  202. test-rebuild-dependent-binaries:
  203. @echo == Rebuilding gs and mupdf binaries
  204. cd ../../../ghostpdl && ./autogen.sh --with-extract-dir=extract && make -j 8 debugclean DEBUGDIRPREFIX=debug-extract- && make -j 8 debug DEBUGDIRPREFIX=debug-extract-
  205. cd ../.. && make -j 8 build=debug clean && make -j 8 build=debug
  206. test-build-dependent-binaries:
  207. @echo == Building gs and mupdf binaries
  208. cd ../../../ghostpdl && make -j 8 debug DEBUGDIRPREFIX=debug-extract-
  209. cd ../.. && make -j 8 build=debug
  210. ifneq ($(mutool),)
  211. test_tables_pdfs = \
  212. test/agstat.pdf \
  213. test/background_lines_1.pdf \
  214. test/background_lines_2.pdf \
  215. test/column_span_1.pdf \
  216. test/column_span_2.pdf \
  217. test/electoral_roll.pdf \
  218. test/rotated.pdf \
  219. test/row_span.pdf \
  220. test/table.pdf \
  221. test/twotables_1.pdf \
  222. test/twotables_2.pdf \
  223. test_tables_generated = $(patsubst test/%, test/generated/%, $(test_tables_pdfs))
  224. test_tables_html = $(patsubst test/%.pdf, test/generated/%.pdf.mutool.html.diff, $(test_tables_pdfs))
  225. test_tables_docx = $(patsubst test/%.pdf, test/generated/%.pdf.mutool.docx.dir.diff, $(test_tables_pdfs))
  226. test_tables_odt = $(patsubst test/%.pdf, test/generated/%.pdf.mutool.odt.dir.diff, $(test_tables_pdfs))
  227. test_tables = $(test_tables_html) $(test_tables_docx) $(test_tables_odt)
  228. endif
  229. test-tables-html: $(test_tables_html)
  230. test-tables-docx: $(test_tables_docx)
  231. test-tables-odt: $(test_tables_odt)
  232. test-tables: $(test_tables)
  233. @echo $@: passed
  234. test/generated/%.pdf.mutool.html.diff: test/generated/%.pdf.mutool.html test/%.pdf.mutool.html.ref
  235. @echo
  236. @echo == Checking $<
  237. $(DIFF_OR_CP) $^
  238. test/generated/%.pdf.mutool.cv.html.diff: test/generated/%.pdf.mutool.cv.html test/%.pdf.mutool.html.ref
  239. @echo
  240. @echo == Checking $<
  241. $(DIFF_OR_CP) $^
  242. test/generated/%.pdf.mutool.cv.html: test/%.pdf $(mutool)
  243. $(mutool) convert -O resolution=300 -o $<..png $<
  244. EXTRACT_OPENCV_IMAGE_BASE=$< $(mutool_run) convert -F docx -O html -o $@ $<
  245. test/generated/%.pdf.mutool.text.diff: test/generated/%.pdf.mutool.text test/%.pdf.mutool.text.ref
  246. @echo
  247. @echo == Checking $<
  248. $(DIFF_OR_CP) $^
  249. # Main executable.
  250. #
  251. exe = src/build/extract-$(build).exe
  252. exe_src = \
  253. src/alloc.c \
  254. src/astring.c \
  255. src/boxer.c \
  256. src/buffer.c \
  257. src/document.c \
  258. src/docx.c \
  259. src/docx_template.c \
  260. src/extract-exe.c \
  261. src/extract.c \
  262. src/html.c \
  263. src/join.c \
  264. src/mem.c \
  265. src/odt.c \
  266. src/odt_template.c \
  267. src/outf.c \
  268. src/rect.c \
  269. src/sys.c \
  270. src/text.c \
  271. src/xml.c \
  272. src/zip.c \
  273. ifeq ($(build),memento)
  274. exe_src += src/memento.c
  275. ifeq ($(uname),Linux)
  276. flags_compile += -D HAVE_LIBDL
  277. flags_link += -L $(libbacktrace) -l backtrace -l dl
  278. endif
  279. endif
  280. exe_obj := $(exe_src)
  281. exe_obj := $(patsubst src/%.c, src/build/%.c-$(build).o, $(exe_obj))
  282. exe_obj := $(patsubst src/%.cpp, src/build/%.cpp-$(build).o, $(exe_obj))
  283. exe_dep = $(exe_obj:.o=.d)
  284. exe: $(exe)
  285. $(exe): $(exe_obj)
  286. $(CXX) $(flags_link) -o $@ $^ -lz -lm
  287. run_exe = $(exe)
  288. ifeq ($(build),memento)
  289. ifeq ($(uname),Linux)
  290. run_exe = MEMENTO_ABORT_ON_LEAK=1 MEMENTO_HIDE_MULTIPLE_REALLOCS=1 LD_LIBRARY_PATH=$(libbacktrace) $(exe)
  291. #run_exe = LD_LIBRARY_PATH=../libbacktrace/.libs $(exe)
  292. endif
  293. ifeq ($(uname),OpenBSD)
  294. run_exe = MEMENTO_ABORT_ON_LEAK=1 MEMENTO_HIDE_MULTIPLE_REALLOCS=1 $(exe)
  295. endif
  296. endif
  297. exe_tables = src/build/extract-tables-$(build).exe
  298. exe-tables: $(exe_tables)
  299. exe-tables-test: $(exe_tables)
  300. $< test/agstat.pdf
  301. ifeq (0,1)
  302. # Do not commit changes to above line.
  303. #
  304. # Special rules for populating .ref directories with current output. Useful to
  305. # initialise references outputs for new output type.
  306. #
  307. test/%.docx.dir.ref/: test/generated/%.docx.dir/
  308. rsync -ai $< $@
  309. test/%.odt.dir.ref/: test/generated/%.odt.dir/
  310. rsync -ai $< $@
  311. test/%.text.ref: test/generated/%.text
  312. rsync -ai $< $@
  313. _update_tables_leafs = $(patsubst test/%, %, $(test_tables_pdfs))
  314. # Update all table docx reference outputs.
  315. #
  316. _update-docx-tables:
  317. for i in $(_update_tables_leafs); do rsync -ai test/generated/$$i.mutool.docx.dir/ test/$$i.mutool.docx.dir.ref/; done
  318. # Update all table odt reference outputs.
  319. #
  320. _update-odt-tables:
  321. for i in $(_update_tables_leafs); do rsync -ai test/generated/$$i.mutool.odt.dir/ test/$$i.mutool.odt.dir.ref/; done
  322. endif
  323. # Rules that make the various intermediate targets required by $(tests).
  324. #
  325. %.extract.docx: % $(exe)
  326. @echo
  327. @echo == Generating docx with extract.exe
  328. $(run_exe) -r 0 -i $< -f docx -o $@
  329. %.extract.odt: % $(exe)
  330. @echo
  331. @echo == Generating odt with extract.exe
  332. $(run_exe) -r 0 -i $< -f odt -o $@
  333. %.extract-rotate.docx: % $(exe) Makefile
  334. @echo
  335. @echo == Generating docx with rotation with extract.exe
  336. $(run_exe) -r 1 -s 0 -i $< -f docx -o $@
  337. %.extract-rotate-spacing.docx: % $(exe) Makefile
  338. @echo
  339. @echo == Generating docx with rotation with extract.exe
  340. $(run_exe) -r 1 -s 1 -i $< -f docx -o $@
  341. %.extract-autosplit.docx: % $(exe)
  342. @echo
  343. @echo == Generating docx with autosplit with extract.exe
  344. $(run_exe) -r 0 -i $< -f docx --autosplit 1 -o $@
  345. %.extract-template.docx: % $(exe)
  346. @echo
  347. @echo == Generating docx using src/template.docx with extract.exe
  348. $(run_exe) -r 0 -i $< -f docx -t src/template.docx -o $@
  349. test/generated/%.dir.diff: test/generated/%.dir test/%.dir.ref
  350. @echo
  351. @echo == Checking $<
  352. $(DIFF_OR_CP) $^
  353. #if diff -ruq $^; then true; else echo "@@@ failure... fix with: rsync -ai" $^; false; fi
  354. test/generated/%.html.diff: test/generated/%.html test/%.html.ref
  355. @echo
  356. @echo == Checking $<
  357. $(DIFF_OR_CP) $^
  358. # This checks that -t src/template.docx gives identical results.
  359. #
  360. test/generated/%.extract-template.docx.diff: test/generated/%.extract-template.docx.dir test/%.extract.docx.dir.ref
  361. @echo
  362. @echo == Checking $<
  363. $(DIFF_OR_CP) $^
  364. # Unzips .docx into .docx.dir/ directory, and prettyfies the .xml files.
  365. %.docx.dir: %.docx .ALWAYS
  366. @echo
  367. @echo == Extracting .docx into directory.
  368. @rm -r $@ 2>/dev/null || true
  369. unzip -q -d $@ $<
  370. # Unzips .odt into .odt.dir/ directory, and prettyfies the .xml files.
  371. %.odt.dir: %.odt
  372. @echo
  373. @echo == Extracting .odt into directory.
  374. @rm -r $@ 2>/dev/null || true
  375. unzip -q -d $@ $<
  376. %.xml.pretty.xml: %.xml
  377. xmllint --format $< > $@
  378. # Uses zip to create .docx file by zipping up a directory. Useful to recreate
  379. # .docx from reference directory test/*.docx.dir.ref.
  380. %.docx: %
  381. @echo
  382. @echo == Zipping directory into .docx file.
  383. @rm -r $@ 2>/dev/null || true
  384. cd $< && zip -r ../$(notdir $@) .
  385. # Uses zip to create .odt file by zipping up a directory. Useful to recreate
  386. # .docx from reference directory test/*.odt.dir.ref.
  387. %.odt: %
  388. @echo
  389. @echo == Zipping directory into .odt file.
  390. @rm -r $@ 2>/dev/null || true
  391. cd $< && zip -r ../$(notdir $@) .
  392. # Prettifies each .xml file within .docx.dir/ directory.
  393. %.docx.dir.pretty: %.docx.dir/
  394. @rm -r $@ $@- 2>/dev/null || true
  395. cp -pr $< $@-
  396. ./src/docx_template_build.py --pretty $@-
  397. mv $@- $@
  398. # Converts .pdf directly to .docx using mutool.
  399. test/generated/%.pdf.mutool.docx: test/%.pdf $(mutool)
  400. @echo
  401. @echo == Converting .pdf directly to .docx using mutool.
  402. @mkdir -p test/generated
  403. $(mutool_run) convert -O mediabox-clip=yes -o $@ $<
  404. test/generated/%.pdf.mutool-norotate.docx: test/%.pdf $(mutool)
  405. @echo
  406. @echo == Converting .pdf directly to .docx using mutool.
  407. @mkdir -p test/generated
  408. $(mutool_run) convert -O mediabox-clip=yes,rotation=no -o $@ $<
  409. test/generated/%.pdf.mutool-spacing.docx: test/%.pdf $(mutool)
  410. @echo
  411. @echo == Converting .pdf directly to .docx using mutool.
  412. @mkdir -p test/generated
  413. $(mutool_run) convert -O mediabox-clip=yes,spacing=yes -o $@ $<
  414. # Converts .pdf directly to .docx using gs.
  415. test/generated/%.pdf.gs.docx: test/%.pdf $(gs)
  416. @echo
  417. @echo == Converting .pdf directly to .docx using gs.
  418. @mkdir -p test/generated
  419. $(gs) -sDEVICE=docxwrite -o $@ $<
  420. # Converts .pdf directly to .odt using mutool.
  421. test/generated/%.pdf.mutool.odt: test/%.pdf $(mutool)
  422. @echo
  423. @echo == Converting .pdf directly to .odt using mutool.
  424. @mkdir -p test/generated
  425. $(mutool_run) convert -O mediabox-clip=no -o $@ $<
  426. # Converts .pdf directly to .html using mutool
  427. test/generated/%.pdf.mutool.html: test/%.pdf $(mutool)
  428. @echo
  429. @echo == Converting .pdf directly to .html using mutool.
  430. @mkdir -p test/generated
  431. $(mutool_run) convert -F docx -O html -o $@ $<
  432. # Converts .pdf directly to .text using mutool
  433. test/generated/%.pdf.mutool.text: test/%.pdf $(mutool)
  434. @echo
  435. @echo == Converting .pdf directly to .text using mutool.
  436. @mkdir -p test/generated
  437. $(mutool_run) convert -F docx -O text -o $@ $<
  438. # Valgrind test
  439. #
  440. #valgrind: $(exe) test/generated/Python2.pdf.intermediate-mu.xml
  441. # valgrind --leak-check=full $(exe) -h -r 1 -s 0 -i test/generated/Python2.pdf.intermediate-mu.xml -o test/generated/valgrind-out.docx
  442. # @echo $@: passed
  443. # Memento tests.
  444. #
  445. ifeq ($(build),memento)
  446. mutool_memento_extract = ../../build/memento/mutool
  447. memento_failat_gdb := $(gdb) -ex 'b Memento_breakpoint' -ex r -ex c -ex bt --args
  448. # Memento squeeze with test/text_graphic_image.pdf runs quickly - just 2,100 events taking 20s.
  449. #
  450. # test/Python2.pdf is much slower - 301,900 events, taking around 8h.
  451. #
  452. msqueeze-mutool-docx:
  453. MEMENTO_SQUEEZEAT=1 ./src/memento.py -q 100 $(mutool_run) convert -o $@.docx test/text_graphic_image.pdf
  454. msqueeze-mutool-docx-failat:
  455. MEMENTO_FAILAT=1960 $(memento_failat_gdb) $(mutool) convert -o $@.docx test/text_graphic_image.pdf
  456. msqueeze-mutool-odt:
  457. MEMENTO_SQUEEZEAT=1 ./src/memento.py -q 100 $(mutool_run) convert -o $@.docx test/text_graphic_image.pdf
  458. msqueeze-mutool-odt2:
  459. MEMENTO_SQUEEZEAT=4000 ./src/memento.py -q 100 $(mutool_run) convert -o $@.docx test/Python2.pdf
  460. msqueeze-mutool-table:
  461. MEMENTO_SQUEEZEAT=1 ./src/memento.py -q 100 $(mutool_run) convert -F docx -O html -o $@.html test/agstat.pdf
  462. msqueeze-mutool-table-docx:
  463. MEMENTO_SQUEEZEAT=1 ./src/memento.py -q 100 $(mutool_run) convert -o $@.docx test/agstat.pdf
  464. msqueeze-mutool-table-odt:
  465. MEMENTO_SQUEEZEAT=1 ./src/memento.py -q 100 $(mutool_run) convert -o $@.odt test/agstat.pdf
  466. msqueeze-mutool-table-failat:
  467. MEMENTO_FAILAT=296643 MEMENTO_HIDE_MULTIPLE_REALLOCS=1 $(gdb) -ex 'b Memento_breakpoint' -ex r -ex c -ex bt --args $(mutool_memento_extract) convert -F docx -O html -o $@.html test/agstat.pdf
  468. endif
  469. # Temporary rules for generating reference files.
  470. #
  471. #test/%.xml.extract-rotate-spacing.docx.dir.ref: test/generated/%.xml.extract-rotate-spacing.docx.dir
  472. # @echo
  473. # @echo copying $< to %@
  474. # rsync -ai $</ $@/
  475. # Buffer unit test.
  476. #
  477. exe_buffer_test = src/build/buffer-test-$(build).exe
  478. exe_buffer_test_src = src/buffer.c src/buffer-test.c src/outf.c src/alloc.c src/mem.c
  479. ifeq ($(build),memento)
  480. exe_buffer_test_src += src/memento.c
  481. endif
  482. exe_buffer_test_obj = $(patsubst src/%.c, src/build/%.c-$(build).o, $(exe_buffer_test_src))
  483. exe_buffer_test_dep = $(exe_buffer_test_obj:.o=.d)
  484. $(exe_buffer_test): $(exe_buffer_test_obj)
  485. $(CC) $(flags_link) -o $@ $^
  486. test-buffer: $(exe_buffer_test)
  487. @echo
  488. @echo == Running test-buffer
  489. mkdir -p test/generated
  490. ./$<
  491. @echo $@: passed
  492. test-buffer-valgrind: $(exe_buffer_test)
  493. @echo
  494. @echo == Running test-buffer with valgrind
  495. mkdir -p test/generated
  496. valgrind --leak-check=full ./$<
  497. @echo $@: passed
  498. ifeq ($(build),memento)
  499. test-buffer-msqueeze: $(exe_buffer_test)
  500. MEMENTO_SQUEEZEAT=1 ./src/memento.py -q 1 ./$<
  501. endif
  502. # Misc unit test.
  503. #
  504. exe_misc_test = src/build/misc-test-$(build).exe
  505. exe_misc_test_src = \
  506. src/alloc.c \
  507. src/astring.c \
  508. src/buffer.c \
  509. src/mem.c \
  510. src/misc-test.c \
  511. src/outf.c \
  512. src/xml.c \
  513. ifeq ($(build),memento)
  514. exe_misc_test_src += src/memento.c
  515. endif
  516. exe_misc_test_obj = $(patsubst src/%.c, src/build/%.c-$(build).o, $(exe_misc_test_src))
  517. exe_misc_test_dep = $(exe_buffer_test_obj:.o=.d)
  518. $(exe_misc_test): $(exe_misc_test_obj)
  519. $(CC) $(flags_link) -o $@ $^
  520. test-misc: $(exe_misc_test)
  521. @echo
  522. @echo == Running test-misc
  523. ./$<
  524. @echo $@: passed
  525. # Source code check.
  526. #
  527. test-src:
  528. @echo
  529. @echo == Checking for use of ssize_t in source.
  530. if grep -wn ssize_t src/*.c src/*.h include/*.h; then false; else true; fi
  531. @echo == Checking for use of strdup in source.
  532. if grep -wn strdup `ls -d src/*.c src/*.h|grep -v src/memento.` include; then false; else true; fi
  533. @echo == Checking for use of bzero in source.
  534. if grep -wn bzero src/*.c src/*.h include/*.h; then false; else true; fi
  535. @echo Checking for variables defined inside for-loop '(...)'.
  536. if egrep -wn 'for *[(] *[a-zA-Z0-9]+ [a-zA-Z0-9]' src/*.c src/*.h; then false; else true; fi
  537. @echo $@: passed
  538. # Check that all defined global symbols start with 'extract_'. This is not
  539. # included in the overall 'test' target because the use of '!egrep ...' appears
  540. # to break on some cluster machines.
  541. #
  542. test-obj:
  543. @echo
  544. nm -egPC $(exe_obj) | egrep '^[a-zA-Z0-9_]+ T' | grep -vw ^main | ! egrep -v ^extract_
  545. @echo $@: passed
  546. # Compile rule. We always include src/docx_template.c as a prerequisite in case
  547. # code #includes docx_template.h. We use -std=gnu90 to catch 'ISO C90 forbids
  548. # mixing declarations and code' errors while still supporting 'inline'.
  549. #
  550. src/build/%.c-$(build).o: src/%.c src/docx_template.c src/odt_template.c
  551. @mkdir -p src/build
  552. $(CC) -std=gnu90 -c $(flags_compile) -o $@ $<
  553. src/build/%.cpp-$(build).o: src/%.cpp
  554. @mkdir -p src/build
  555. $(CXX) -c -Wall -W -I /usr/local/include/opencv4 -o $@ $<
  556. # Rule for machine-generated source code, src/docx_template.c. Also generates
  557. # src/docx_template.h.
  558. #
  559. # These files are also in git to allow builds if python is not available.
  560. #
  561. src/docx_template.c: src/docx_template_build.py .ALWAYS
  562. @echo
  563. @echo == Building $@
  564. ./src/docx_template_build.py -i src/template.docx -n docx -o src/docx_template
  565. src/odt_template.c: src/docx_template_build.py .ALWAYS
  566. @echo
  567. @echo == Building $@
  568. ./src/docx_template_build.py -i src/template.odt -n odt -o src/odt_template
  569. .ALWAYS:
  570. .PHONY: .ALWAYS
  571. # Tell make to preserve all intermediate files.
  572. #
  573. .SECONDARY:
  574. # Rule for tags.
  575. #
  576. tags: .ALWAYS
  577. ectags -R --extra=+fq --c-kinds=+px .
  578. # Clean rule.
  579. #
  580. clean:
  581. rm -r src/build test/generated src/template.docx.dir 2>/dev/null || true
  582. # Cleans test/generated except for intermediate files, which are slow to create
  583. # (when using gs).
  584. clean2:
  585. rm -r test/generated/*.pdf.mutool*.docx* 2>/dev/null || true
  586. rm -r src/build 2>/dev/null || true
  587. .PHONY: clean
  588. # Include dynamic dependencies.
  589. #
  590. # We use $(sort ...) to remove duplicates
  591. #
  592. dep = $(sort $(exe_dep) $(exe_buffer_test_dep) $(exe_misc_test_dep) $(exe_ziptest_dep))
  593. -include $(dep)