summaryrefslogtreecommitdiff
path: root/Makefile
blob: 69f776f130e861b22eddce52d453926e81150a53 (plain)
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
# Example commands:
#   make build=debug test
#   make build=debug-opt
#   make build=opt
#


# Build flags.
#
build = debug
flags_link      = -W -Wall -lm
flags_compile   = -W -Wall -MMD -MP

ifeq ($(build),)
    $(error Need to specify build=debug|opt|debug-opt|memento)
else ifeq ($(build),debug)
    flags_link      += -g
    flags_compile   += -g
else ifeq ($(build),opt)
    flags_link      += -O2
    flags_compile   += -O2
else ifeq ($(build),debug-opt)
    flags_link      += -g -O2
    flags_compile   += -g -O2
else ifeq ($(build),memento)
    flags_link      += -g
    flags_compile   += -g -D MEMENTO
else
    $(error unrecognised $$(build)=$(build))
endif


# Source code.
#
src = extract.c

ifeq ($(build),memento)
    src += memento.c
endif


# Build files.
#
exe = build/extract-$(build).exe
obj = $(src:.c=.c-$(build).o)
obj := $(addprefix build/, $(obj))
dep = $(obj:.o=.d)


# Test rules.
#
# We assume that mutool and gs are available at hard-coded paths.
#
test: test-mu test-gs test-mu-as

test-mu: Python2.pdf-test-mu zlib.3.pdf-test-mu
test-mu-as: Python2.pdf-test-mu-as zlib.3.pdf-test-mu-as

%.pdf-test: %.pdf-test-mu %.pdf-test-gs

%.pdf-test-mu: %.pdf $(exe)
	@echo
	@echo === Testing $<
	mkdir -p test
	@echo == Generating intermediate with mutool.
	../mupdf/build/debug/mutool draw -F xmltext -o test/$<.mu-raw.intermediate.xml $<
	@echo == Generating output.
	./$(exe) -i test/$<.mu-raw.intermediate.xml --o-content test/$<.mu-raw.content.xml -o test/$<.mu-raw.docx -p 1 -t template.docx
	@echo == Comparing output with reference output.
	diff -u test/$<.mu-raw.content.xml $<.mu-raw.content.ref.xml
	@echo == Test succeeded.

# Run extract.exe with --autosplit, to stress joining of spans. Compare with
# the default .ref file.
%.pdf-test-mu-as: %.pdf $(exe)
	@echo
	@echo === Testing $<
	mkdir -p test
	@echo == Generating intermediate with mutool.
	../mupdf/build/debug/mutool draw -F xmltext -o test/$<.mu-raw.intermediate.xml $<
	@echo == Generating output.
	./$(exe) --autosplit 1 -i test/$<.mu-raw.intermediate.xml --o-content test/$<.mu-raw.as.content.xml -o test/$<.mu-raw.as.docx -p 1 -t template.docx
	@echo == Comparing output with reference output.
	diff -u test/$<.mu-raw.as.content.xml $<.mu-raw.content.ref.xml
	@echo == Test succeeded.

%.pdf-test-gs: %.pdf $(exe)
	@echo
	@echo === Testing $<
	mkdir -p test
	@echo == Generating intermediate with gs.
	../ghostpdl/debug-bin/gs -sDEVICE=txtwrite -dTextFormat=4 -o test/$<.gs.intermediate.xml $<
	@echo == Generating output.
	./$(exe) -i test/$<.gs.intermediate.xml --o-content test/$<.gs.content.xml -o test/$<.gs.docx -p 1 -t template.docx
	@echo == Comparing output with reference output.
	diff -u test/$<.gs.content.xml $<.gs.content.ref.xml
	@echo == Test succeeded.

test-gs: zlib.3.pdf-test-gs Python2.pdf-test-gs

test-as: Python2.pdf-test4-mu Python2.pdf-test4as-mu
	diff -u test/Python2.pdf.mu-raw4.content.xml test/Python2.pdf.mu-raw4as.content.xml

# Build rules.
#
$(exe): $(obj)
	mkdir -p build
	cc $(flags_link) -o $@ $^

build/%.c-$(build).o: %.c
	mkdir -p build
	cc -c $(flags_compile) -o $@ $<


# Clean rule.
#
.PHONY: clean
clean:
	rm $(obj) $(dep) $(exe)

clean-all:
	rm -r build test 


# Copy generated files to website.
#
web:
	rsync -ai test/*.docx *.pdf julian@casper.ghostscript.com:public_html/extract/

# Dynamic dependencies.
#
-include $(dep)