Skip to content

Commit

Permalink
jni: Update build files for moved java sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccxvii committed Feb 29, 2016
1 parent e45a2f4 commit e171662
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Make* tabs
*.[chm] tabs
*.java tabs
*.xml tabs
build.xml spaces
memento.* spaces
*.vcxproj* spaces
jmem* spaces
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ build
DerivedData
generated
cscope.*
*.class
*.jar
*.o
*.so
*.epub
*.pdf
*.pnm
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ tarball:

# --- Clean and Default ---

java:
$(MAKE) -C platform/java

tags: $(shell find include source platform -name '*.[ch]')
ctags $^

Expand Down
4 changes: 4 additions & 0 deletions platform/android/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default:
$(MAKE) -C ../java -f Makejar
ndk-build
ant debug
18 changes: 18 additions & 0 deletions platform/android/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@
application and should be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />

<!-- This somewhat bulky and unpleasant piece of code is lifted
from stackoverflow, and serves to add the
platform/java/libmupdf.jar file to the produced .apk -->
<target name="-pre-compile">

<echo>ORIGINAL jars.path : ${toString:project.all.jars.path}</echo>
<path id="project.all.jars.path.hacked">
<path path="${toString:project.all.jars.path}"/>
<path path="../java/libmupdf.jar"/>
</path>

<path id="project.all.jars.path">
<path path="${toString:project.all.jars.path.hacked}"/>
</path>
<echo>HACKED jars.path : ${toString:project.all.jars.path}</echo>

</target>

<!-- quick check on sdk.dir -->
<fail
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project'"
Expand Down
10 changes: 6 additions & 4 deletions platform/android/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ LOCAL_C_INCLUDES := \
jni/andprof \
$(MUPDF_ROOT)/include \
$(MUPDF_ROOT)/source/fitz \
$(MUPDF_ROOT)/source/pdf
LOCAL_CFLAGS :=
LOCAL_MODULE := mupdf
LOCAL_SRC_FILES := mupdf.c mupdf_native.c
$(MUPDF_ROOT)/source/pdf \
$(MUPDF_ROOT)/platform/java
LOCAL_CFLAGS := -DHAVE_ANDROID
LOCAL_MODULE := mupdf_java
LOCAL_SRC_FILES := mupdf.c \
$(MUPDF_ROOT)/java/mupdf_native.c
LOCAL_STATIC_LIBRARIES := mupdfcore mupdfthirdparty
ifdef NDK_PROFILER
LOCAL_CFLAGS += -pg -DNDK_PROFILER
Expand Down
4 changes: 2 additions & 2 deletions platform/android/jni/mupdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ JNI_FN(MuPDFCore_openFile)(JNIEnv * env, jobject thiz, jstring jfilename)
jclass clazz;

#ifdef NDK_PROFILER
monstartup("libmupdf.so");
monstartup("libmupdf_java.so");
#endif

clazz = (*env)->GetObjectClass(env, thiz);
Expand Down Expand Up @@ -440,7 +440,7 @@ JNI_FN(MuPDFCore_openBuffer)(JNIEnv * env, jobject thiz, jstring jmagic)
const char *magic;

#ifdef NDK_PROFILER
monstartup("libmupdf.so");
monstartup("libmupdf_java.so");
#endif

clazz = (*env)->GetObjectClass(env, thiz);
Expand Down
2 changes: 1 addition & 1 deletion platform/android/src/com/artifex/mupdfdemo/MuPDFCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class MuPDFCore
private static boolean gs_so_available = false;
static {
System.out.println("Loading dll");
System.loadLibrary("mupdf");
System.loadLibrary("mupdf_java");
System.out.println("Loaded dll");
if (gprfSupportedInternal())
{
Expand Down
51 changes: 51 additions & 0 deletions platform/java/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
default: libmupdf_java.so libmupdf.jar

MUPDF_CORE = ../../build/java/libmupdf.a ../../build/java/libmupdfthird.a

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

VIEWER_JAVA_SOURCES := $(sort $(wildcard *.java))
VIEWER_JAVA_OBJECTS := $(VIEWER_JAVA_SOURCES:%.java=%.class)

$(MUPDF_CORE) :
$(MAKE) -C ../.. OUT=build/java XCFLAGS=-fPIC build=release libs

$(LIBRARY_JAVA_OBJECTS) : $(LIBRARY_JAVA_SOURCES)
javac $^

libmupdf.jar : $(LIBRARY_JAVA_OBJECTS)
rm -f $@
jar cf $@ $^

mupdf_native.h : $(LIBRARY_JAVA_OBJECTS)
rm -f $@
javah -o $@ $(LIBRARY_JAVA_CLASSES)

mupdf_native.o : mupdf_native.c mupdf_native.h
$(CC) -g -fPIC -Wall -Wextra -Wno-unused-parameter \
-I /usr/lib/jvm/java-7-openjdk-amd64/include \
-I /usr/lib/jvm/java-7-openjdk-amd64/include/linux \
-I ../../include \
-o $@ -c $<

libmupdf_java.so : mupdf_native.o $(MUPDF_CORE)
$(CC) -shared -o $@ $^ -lcrypto

$(VIEWER_JAVA_OBJECTS) : $(VIEWER_JAVA_SOURCES)
javac $^

viewer: libmupdf_java.so $(LIBRARY_JAVA_OBJECTS) $(VIEWER_JAVA_OBJECTS)
LD_LIBRARY_PATH=. java Viewer

clean:
rm -f com/artifex/mupdf/fitz/*.class
rm -f *.class
rm -f mupdf_native.o
rm -f libmupdf_java.so

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

.NOTPARALLEL : # disable -j option (it breaks since javac compiles all class files in one command)
3 changes: 3 additions & 0 deletions platform/java/Makejar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
default:
javac com/artifex/mupdf/fitz/*.java
jar cf libmupdf.jar com/artifex/mupdf/fitz/*.class

0 comments on commit e171662

Please sign in to comment.