1# Capstone Disassembler Engine
2# By Nguyen Anh Quynh <aquynh@gmail.com>, 2013>
3
4ifndef BUILDDIR
5BLDIR = .
6OBJDIR = .
7else
8BLDIR = $(abspath $(BUILDDIR))/bindings/java
9OBJDIR = $(abspath $(BUILDDIR))/obj/bindings/java
10endif
11
12JNA = /usr/share/java/jna/jna.jar
13
14ifneq ($(wildcard $(JNA)),)
15else
16  ifneq ($(wildcard /usr/share/java/jna.jar),)
17    JNA = /usr/share/java/jna.jar
18  else
19    JNA =
20  endif
21endif
22
23PYTHON2 ?= python
24
25CAPSTONE_JAVA = Capstone.java Arm_const.java Arm64_const.java Mips_const.java \
26				X86_const.java Xcore_const.java Ppc_const.java Sparc_const.java\
27				Sysz_const.java M680x_const.java \
28				Arm.java Arm64.java Mips.java X86.java Xcore.java Ppc.java\
29				Sparc.java Systemz.java M680x.java
30
31all: gen_const capstone tests
32
33capstone: capstone_class
34	@mkdir -p $(BLDIR)
35	cd $(OBJDIR) && jar cf $(BLDIR)/capstone.jar capstone/*.class
36
37capstone_class: jna
38ifdef BUILDDIR
39	@mkdir -p $(OBJDIR)
40	cd capstone && javac -d $(OBJDIR) -classpath $(JNA) $(CAPSTONE_JAVA)
41else
42	cd capstone && javac -classpath $(JNA) $(CAPSTONE_JAVA)
43endif
44
45tests: capstone_class jna
46	@mkdir -p $(OBJDIR)
47	javac -d $(OBJDIR) -classpath "$(JNA):$(BLDIR)/capstone.jar" TestBasic.java\
48		TestArm.java TestArm64.java TestMips.java TestX86.java TestXcore.java\
49		TestPpc.java TestSparc.java TestSystemz.java TestM680x.java
50
51gen_const:
52	cd ../ && $(PYTHON2) const_generator.py java
53
54jna:
55	@if [ ! $(JNA) ]; then echo "*** Unable to find JNA ***"; exit 1; fi
56
57clean:
58	rm -rf $(OBJDIR)/capstone/*.class
59	rm -rf $(OBJDIR)/*.class $(OBJDIR)/*.log $(BLDIR)/*.jar
60ifdef BUILDDIR
61	rm -rf $(BLDIR)
62	rm -rf $(OBJDIR)
63endif
64
65TESTS = testbasic arm arm64 m680x mips ppc sparc systemz x86 xcore
66check:
67	@for t in $(TESTS); do \
68		echo Check $$t ... ; \
69		./run.sh $$t > /dev/null && echo OK || echo FAILED; \
70	done
71
72