Switch to Maven to build the Java bits.
Maven is now used to update the constants, build the Java code, call make to build the native library, and run all the tests. I have removed the "install" and "uninstall" targets; instead, the expectation will be that the JNI library will be placed somewhere on java.library.path and the JAR file will be used as usual (e.g. in a downstream Maven project, or placed on the classpath of your project). Since Maven is now running our tests, this eliminates the need to bundle test dependencies in `testdep`, and makes the project structured more like a typical Java project.
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
all: jar lib samples
|
||||
# Makefile for the native JNI library. Automatically called by Maven.
|
||||
|
||||
JC=javac
|
||||
JAVA_HOME ?= $(shell java -XshowSettings:properties -version 2>&1 | sed -n 's/ *java.home = //p')
|
||||
|
||||
JAVA_HOME := $(shell readlink -f `which $(JC)` | sed "s:/bin/$(JC)::")
|
||||
|
||||
JAVA_INC := $(shell realpath $(JAVA_HOME)/include)
|
||||
ifeq ($(JAVA_HOME),)
|
||||
$(error JAVA_HOME could not be determined; please set it manually (make JAVA_HOME=...))
|
||||
endif
|
||||
|
||||
JAVA_INC := $(JAVA_HOME)/include
|
||||
JAVA_PLATFORM_INC := $(shell dirname `find $(JAVA_INC) -name jni_md.h`)
|
||||
|
||||
UNICORN_INC=../../include
|
||||
|
||||
SAMPLES := $(shell ls samples/*.java)
|
||||
TESTS := $(shell ls tests/*.java)
|
||||
SRC := $(shell ls unicorn/*.java)
|
||||
UNICORN_INC := ../../include
|
||||
|
||||
OS := $(shell uname)
|
||||
ifeq ($(OS),Darwin)
|
||||
@@ -23,67 +19,29 @@ else
|
||||
LIB_EXT=.dll
|
||||
endif
|
||||
|
||||
all: libunicorn_java$(LIB_EXT)
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-fPIC
|
||||
LDFLAGS=-shared -fPIC
|
||||
LIBS=-lunicorn
|
||||
LIBDIR=-L../../
|
||||
# May also use -lunicorn to dynamically link against the installed unicorn
|
||||
LIBS=../../build/libunicorn.a
|
||||
INCS=-I$(JAVA_INC) -I$(JAVA_PLATFORM_INC) -I$(UNICORN_INC)
|
||||
|
||||
CLASSPATH=./
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
|
||||
tests/%.class: tests/%.java
|
||||
$(JC) -Xlint:deprecation -classpath .:unicorn.jar:testdep/junit-4.13.2.jar $(JFLAGS) $<
|
||||
|
||||
%.class: %.java
|
||||
$(JC) -Xlint:deprecation -classpath .:unicorn.jar $(JFLAGS) $<
|
||||
|
||||
OBJS=unicorn_Unicorn.o
|
||||
|
||||
JARFILE=unicorn.jar
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -c $(CFLAGS) $(INCS) $< -o $@
|
||||
|
||||
unicorn_Unicorn.h: unicorn/Unicorn.java
|
||||
$(JC) -h . $<
|
||||
unicorn_Unicorn.h: src/main/java/unicorn/Unicorn.java
|
||||
javah -cp src/main/java -o $@ unicorn.Unicorn
|
||||
|
||||
unicorn_Unicorn.o: unicorn_Unicorn.c unicorn_Unicorn.h
|
||||
$(CC) -O2 -Wall -Wextra -Wno-unused-parameter -c $(CFLAGS) $(INCS) $< -o $@
|
||||
|
||||
libunicorn_java$(LIB_EXT): unicorn_Unicorn.o
|
||||
|
||||
lib: libunicorn_java$(LIB_EXT) unicorn_Unicorn.h
|
||||
$(CC) -o $< $(LDFLAGS) $(OBJS) $(LIBDIR) $(LIBS)
|
||||
|
||||
samples: $(SAMPLES:.java=.class)
|
||||
tests: $(TESTS:.java=.class)
|
||||
jarfiles: $(SRC:.java=.class)
|
||||
|
||||
jar: jarfiles
|
||||
jar cf $(JARFILE) unicorn/*.class
|
||||
|
||||
test: lib samples tests
|
||||
java -Xcheck:jni -cp .:testdep/hamcrest-2.2.jar:testdep/junit-4.13.2.jar org.junit.runner.JUnitCore $(subst /,.,$(TESTS:.java=))
|
||||
|
||||
install: lib jar
|
||||
cp libunicorn_java$(LIB_EXT) /usr/lib
|
||||
cp $(JARFILE) /usr/share/java
|
||||
|
||||
uninstall:
|
||||
rm -f /usr/lib/libunicorn_java$(LIB_EXT)
|
||||
rm -f /usr/share/java/$(JARFILE)
|
||||
|
||||
gen_const:
|
||||
cd .. && python3 const_generator.py java
|
||||
libunicorn_java$(LIB_EXT): $(OBJS)
|
||||
$(CC) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
|
||||
|
||||
clean:
|
||||
rm -f unicorn/*.class
|
||||
rm -f samples/*.class
|
||||
rm -f *.so
|
||||
rm -f *.dylib
|
||||
rm -f *.dll
|
||||
rm -f libunicorn_java$(LIB_EXT)
|
||||
rm -f unicorn_Unicorn.h
|
||||
rm -f $(OBJS)
|
||||
|
||||
.PHONY: all lib samples jar install uninstall gen_const clean
|
||||
.PHONY: all clean
|
||||
|
||||
Reference in New Issue
Block a user