~mcf/mupdf

ref: e27ceb2b0e64b9a56ba79d844ea96553d87dc113 mupdf/platform/java/Makefile -rw-r--r-- 3.9 KiB
e27ceb2b — Robin Watts OSS-Fuzz 29728: Avoid buffer overflow. 1 year, 6 months ago
                                                                                
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
# GNU Makefile

-include ../../user.make

OS ?= $(shell uname)

JAVA := java
JAVAC := javac

ifndef build
  build := release
endif

ifeq ($(build),debug)
  BUILD_FLAGS := -DDEBUG -O0 -g
else ifeq ($(build),memento)
  BUILD_FLAGS := -DDEBUG -O0 -g -DMEMENTO
else
  BUILD_FLAGS := -DNDEBUG -O2
endif

ifndef OUT
  OUT := build/java/$(build)
endif

ifeq ($(OS),Darwin)
MUPDF_JAVA := ../../$(OUT)/libmupdf_java64.jnilib
JAVA_VM := $(shell /usr/libexec/java_home)
JAVA_CFLAGS := \
	-I $(JAVA_VM)/include \
	-I $(JAVA_VM)/include/darwin
JAVA_LDFLAGS :=

else

BITS := $(shell getconf LONG_BIT)

JAVA_HOME ?= /usr/lib/jvm/default-java

MUPDF_JAVA := ../../$(OUT)/libmupdf_java$(BITS).so
JAVA_CFLAGS := \
	-I $(JAVA_HOME)/include \
	-I $(JAVA_HOME)/include/linux \
	$(shell pkg-config --cflags freetype2) \
	$(shell pkg-config --cflags libcrypto)
JAVA_LIBS := \
	$(shell pkg-config --libs freetype2) \
	$(shell pkg-config --libs libcrypto) \
	-lz
JAVA_LDFLAGS := \
	-z noexecstack

ifeq ($(USE_TESSERACT), yes)
ifeq ($(USE_SYSTEM_TESSERACT), yes)
JAVA_LIBS += \
	$(shell pkg-config --libs lept) \
	$(shell pkg-config --libs tesseract)

CONFIGFLAGS += USE_SYSTEM_TESSERACT=yes
else
CONFIGFLAGS += USE_TESSERACT=yes
endif
endif
endif

MUPDF_JAR := ../../$(OUT)/libmupdf.jar

default: $(MUPDF_JAVA) $(MUPDF_JAR) $(EXAMPLE_JAVA_SOURCES)

MUPDF_CORE := ../../$(OUT)/libmupdf.a ../../$(OUT)/libmupdf-third.a
ifeq "$(OS)" "Linux"
$(MUPDF_CORE) : .FORCE
	$(MAKE) -C ../.. OUT=$(OUT) XCFLAGS=-fPIC build=$(build) USE_SYSTEM_FREETYPE=yes USE_SYSTEM_ZLIB=yes $(CONFIGFLAGS) libs
else
$(MUPDF_CORE) : .FORCE
	$(MAKE) -C ../.. OUT=$(OUT) XCFLAGS=-fPIC build=$(build) $(CONFIGFLAGS) libs
endif

LIBRARY_JAVA_SOURCES := $(sort $(wildcard src/com/artifex/mupdf/fitz/*.java))
LIBRARY_JAVA_OBJECTS := $(subst src/,../../$(OUT)/,$(LIBRARY_JAVA_SOURCES:%.java=%.class))
LIBRARY_JAVA_CLASSES := $(subst src/com/artifex/mupdf/fitz/,com.artifex.mupdf.fitz.,$(LIBRARY_JAVA_SOURCES:%.java=%))

JAVAC_FLAGS := $(JAVAC_XFLAGS) -source 1.7 -target 1.7

$(LIBRARY_JAVA_OBJECTS) : $(LIBRARY_JAVA_SOURCES)
	mkdir -p ../../$(OUT)
	$(JAVAC) $(JAVAC_FLAGS) -h ../../$(OUT)/ -d ../../$(OUT)/ $^

EXAMPLE_JAVA_SOURCES := $(sort $(wildcard example/*.java))
EXAMPLE_JAVA_OBJECTS := $(subst example/,../../$(OUT)/example/,$(EXAMPLE_JAVA_SOURCES:%.java=%.class))

$(EXAMPLE_JAVA_OBJECTS): $(EXAMPLE_JAVA_SOURCES)
	$(JAVAC) $(JAVAC_FLAGS) -classpath ../../$(OUT) -d ../../$(OUT)/ $^

REPATHED_LIBRARY_JAVA_OBJECTS := $(subst src/,,$(LIBRARY_JAVA_SOURCES:%.java=%.class))
$(MUPDF_JAR) : $(LIBRARY_JAVA_OBJECTS)
	rm -f $@
	cd ../../$(OUT) && jar cf libmupdf.jar $(REPATHED_LIBRARY_JAVA_OBJECTS)

mupdf_native.h : $(LIBRARY_JAVA_OBJECTS)
	rm -f $@
	cat $(sort $(wildcard ../../$(OUT)/*.h)) > mupdf_native.h

../../$(OUT)/mupdf_native.o : mupdf_native.c mupdf_native.h $(wildcard jni/*.c) $(MUPDF_CORE)
	$(CC) -g -o $@ -c $< -fPIC -Wall -Wextra -Wno-unused-parameter -Wpedantic -I ../../include \
		$(JAVA_CFLAGS) $(BUILD_FLAGS)

$(MUPDF_JAVA) : ../../$(OUT)/mupdf_native.o $(MUPDF_CORE)
	$(CC) -shared $(JAVA_LDFLAGS) -o $(MUPDF_JAVA) $^ $(JAVA_LIBS) $(BUILD_FLAGS)

run: $(MUPDF_JAVA) $(EXAMPLE_JAVA_OBJECTS) $(MUPDF_JAR)
	$(JAVA) -classpath ../../$(OUT)/ -Djava.library.path="../../$(OUT)" example.Viewer $$MUPDF_ARGS

gdb: $(MUPDF_JAVA) $(EXAMPLE_JAVA_OBJECTS) $(MUPDF_JAR)
	gdb --args $(JAVA) -classpath ../../$(OUT) -Djava.library.path="../../$(OUT)" example.Viewer $$MUPDF_ARGS

clean:
	rm -f $(LIBRARY_JAVA_OBJECTS) $(subst .class,\$$*.class,$(LIBRARY_JAVA_OBJECTS))
	rm -f $(EXAMPLE_JAVA_OBJECTS) $(subst .class,\$$*.class,$(EXAMPLE_JAVA_OBJECTS))
	rm -f ../../$(OUT)/mupdf_native.o
	rm -fr ../../$(OUT)/resources
	rm -fr ../../$(OUT)/source
	rm -fr ../../$(OUT)/thirdparty
	rm -f $(MUPDF_JAR)
	rm -f $(MUPDF_JAVA)
	rm -f ../../$(OUT)/*.h

nuke: clean
	$(MAKE) -C ../.. OUT=$(OUT) build=$(build) clean

.NOTPARALLEL : # disable -j option (it breaks since javac compiles all class files in one command)
.PHONY: .FORCE