From 0e680fbafaf4d4dc8a28857f96d9a36b4b4ba00a Mon Sep 17 00:00:00 2001 From: Chris Eagle Date: Thu, 24 Sep 2015 22:45:59 -0700 Subject: [PATCH] Hack to make gen_const work even if java not installed --- bindings/java/Makefile | 84 +++++++----------------------------- bindings/java/Makefile.build | 78 +++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 68 deletions(-) create mode 100644 bindings/java/Makefile.build diff --git a/bindings/java/Makefile b/bindings/java/Makefile index 4d3af3e5..6d274add 100644 --- a/bindings/java/Makefile +++ b/bindings/java/Makefile @@ -1,78 +1,26 @@ +.PHONY: gen_const clean jar all lib samples install -.PHONY: gen_const clean +all: gen_const + $(MAKE) -f Makefile.build all -JAVA_HOME := $(shell jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));') +lib: + $(MAKE) -f Makefile.build lib -JAVA_INC := $(shell realpath $(JAVA_HOME)/../include) +samples: + $(MAKE) -f Makefile.build samples -JAVA_PLATFORM_INC := $(shell dirname `find $(JAVA_INC) -name jni_md.h`) - -UNICORN_INC=../../include - -SAMPLES := $(shell ls samples/*.java) -SRC := $(shell ls unicorn/*.java) - -OS := $(shell uname) -ifeq ($(OS),Darwin) - LIB_EXT=.dylib -endif -ifeq ($(OS),Linux) - LIB_EXT=.so -else - LIB_EXT=.dll -endif - -CC=gcc -CFLAGS=-fPIC -LDFLAGS=-shared -fPIC -LIBS=-lunicorn -LIBDIR=-L../../ -INCS=-I$(JAVA_INC) -I$(JAVA_PLATFORM_INC) -I$(UNICORN_INC) - -JC=javac -CLASSPATH=./ - -.SUFFIXES: .java .class - -%.class: %.java - $(JC) $(JFLAGS) $< - -OBJS=unicorn_Unicorn.o - -JARFILE=unicorn.jar - -all: lib jar samples - -%.o: %.c - $(CC) -c $(CFLAGS) $(INCS) $< -o $@ - -unicorn_Unicorn.h: unicorn/Unicorn.java - javah unicorn.Unicorn - -unicorn_Unicorn.o: unicorn_Unicorn.c unicorn_Unicorn.h - $(CC) -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) -jarfiles: $(SRC:.java=.class) - -jar: jarfiles - jar cf $(JARFILE) unicorn/*.class +jar: + $(MAKE) -f Makefile.build jar install: lib jar - cp libunicorn_java$(LIB_EXT) $(JAVA_HOME)/lib/ext - cp $(JARFILE) $(JAVA_HOME)/lib/ext + $(MAKE) -f Makefile.build install gen_const: - cd .. && python const_generator.py java + cd .. && python const_generator.py java clean: - rm unicorn/*.class - rm samples/*.class - rm *.so - rm *.dylib - rm *.dll \ No newline at end of file + rm -f unicorn/*.class + rm -f samples/*.class + rm -f *.so + rm -f *.dylib + rm -f *.dll diff --git a/bindings/java/Makefile.build b/bindings/java/Makefile.build new file mode 100644 index 00000000..4d3af3e5 --- /dev/null +++ b/bindings/java/Makefile.build @@ -0,0 +1,78 @@ + +.PHONY: gen_const clean + +JAVA_HOME := $(shell jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));') + +JAVA_INC := $(shell realpath $(JAVA_HOME)/../include) + +JAVA_PLATFORM_INC := $(shell dirname `find $(JAVA_INC) -name jni_md.h`) + +UNICORN_INC=../../include + +SAMPLES := $(shell ls samples/*.java) +SRC := $(shell ls unicorn/*.java) + +OS := $(shell uname) +ifeq ($(OS),Darwin) + LIB_EXT=.dylib +endif +ifeq ($(OS),Linux) + LIB_EXT=.so +else + LIB_EXT=.dll +endif + +CC=gcc +CFLAGS=-fPIC +LDFLAGS=-shared -fPIC +LIBS=-lunicorn +LIBDIR=-L../../ +INCS=-I$(JAVA_INC) -I$(JAVA_PLATFORM_INC) -I$(UNICORN_INC) + +JC=javac +CLASSPATH=./ + +.SUFFIXES: .java .class + +%.class: %.java + $(JC) $(JFLAGS) $< + +OBJS=unicorn_Unicorn.o + +JARFILE=unicorn.jar + +all: lib jar samples + +%.o: %.c + $(CC) -c $(CFLAGS) $(INCS) $< -o $@ + +unicorn_Unicorn.h: unicorn/Unicorn.java + javah unicorn.Unicorn + +unicorn_Unicorn.o: unicorn_Unicorn.c unicorn_Unicorn.h + $(CC) -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) +jarfiles: $(SRC:.java=.class) + +jar: jarfiles + jar cf $(JARFILE) unicorn/*.class + +install: lib jar + cp libunicorn_java$(LIB_EXT) $(JAVA_HOME)/lib/ext + cp $(JARFILE) $(JAVA_HOME)/lib/ext + +gen_const: + cd .. && python const_generator.py java + +clean: + rm unicorn/*.class + rm samples/*.class + rm *.so + rm *.dylib + rm *.dll \ No newline at end of file