maxlocals: store it in new data type RawMethod, with MapBB & Co
[mate.git] / Makefile
1 SHELL := bash
2
3 JAVAC := javac
4 JAVA_FILES := $(wildcard jmate/lang/*.java jmate/io/*.java java/lang/*.java java/io/*.java)
5 CLASS_FILES := $(JAVA_FILES:.java=.class)
6 TEST_JAVA_FILES := $(wildcard tests/*.java)
7 TEST_CLASS_FILES := $(TEST_JAVA_FILES:.java=.test)
8 HS_FILES := $(wildcard Mate/*.hs)
9 HS_BOOT := $(wildcard Mate/*.hs-boot)
10 BUILD := build
11 B_RELEASE := $(BUILD)/release
12 B_STATIC := $(BUILD)/static
13 B_DEBUG := $(BUILD)/debug
14 PACKAGES_ := bytestring harpy hs-java plugins
15 PACKAGES := $(addprefix -package ,$(PACKAGES_))
16
17
18 # use `cpphs'
19 GHC_CPP := -cpp -pgmP cpphs -optP --cpp
20
21 GHC_OPT  = -I. -O0 -Wall -fno-warn-unused-do-bind
22 # see *.gdb target. also useful for profiling (-p at call)
23 GHC_OPT += -rtsopts # -prof -auto-all
24 GHC_OPT += $(GHC_CPP)
25
26 # dunno anymore? some linker stuff regarding GHCi
27 GHC_LD := -optl-Xlinker -optl-x
28
29
30 .PHONY: all tests clean ghci hlint
31
32 all: mate
33
34 %: %.class mate
35         ./mate $(basename $<)
36
37
38 tests: mate $(TEST_JAVA_FILES:.java=.class) $(TEST_CLASS_FILES)
39
40 CALLF = $(basename $@).call
41 testcase = ./tools/openjdktest.sh "$(1) $(basename $@)"
42 %.test: %.class mate
43         @if [ -f $(CALLF) ]; \
44                 then $(call testcase,`cat $(CALLF)`); \
45                 else $(call testcase, ); fi
46
47 COMPILEF = $(basename $@).compile
48 %.class: %.java
49         @if [ -f $(COMPILEF) ]; \
50                 then $(SHELL) $(COMPILEF); \
51                 else $(JAVAC) $(JAVA_FILES) $<; fi
52         @echo "JAVAC $<"
53
54 ffi/native.o: ffi/native.c
55         ghc -Wall -O2 -c $< -o $@
56
57 GHCCALL = ghc --make $(GHC_OPT) Mate.hs ffi/trap.c -o $@ $(GHC_LD) -outputdir
58 mate: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILES)
59         @mkdir -p $(B_RELEASE)
60         $(GHCCALL) $(B_RELEASE) -dynamic
61
62 mate.static: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILES)
63         @mkdir -p $(B_STATIC)
64         $(GHCCALL) $(B_STATIC) -static
65
66 %.dbg: %.class mate.dbg
67         ./mate.dbg $(basename $<)
68
69 %.gdb: %.class mate.dbg
70         gdb -x .gdbcmds -q --args mate.dbg $(basename $<) +RTS -V0 --install-signal-handlers=no
71
72 ifeq (${DBGFLAGS},)
73 DEBUGFLAGS = -DDBG_JIT -DDBG_MP
74 else
75 DEBUGFLAGS = ${DBGFLAGS}
76 endif
77 mate.dbg: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o
78         @mkdir -p $(B_DEBUG)/{ffi,Mate,}
79         gcc -Wall $(DEBUGFLAGS) -O0 -c ffi/trap.c -o $(B_DEBUG)/ffi/trap.o
80         ghc --make $(DEBUGFLAGS) $(GHC_OPT) Mate.hs $(B_DEBUG)/ffi/trap.o -o $@ $(GHC_LD) -outputdir $(B_DEBUG)
81
82 clean:
83         rm -rf $(BUILD) mate mate.static mate.dbg ffi/native.o \
84                 tests/*.class Mate/*_stub.* \
85                 jmate/lang/*.class jmate/io/*.class java/io/*.class \
86                 java/lang/{Integer,Character,String,System}.class
87
88 ghci: mate.static
89         ghci -I. $(PACKAGES) -outputdir $(B_STATIC) Mate.hs $(GHC_CPP)
90
91 tags: mate.static
92         @# @-fforce-recomp, see
93         @# http://stackoverflow.com/questions/7137414/how-do-i-force-interpretation-in-hint
94         @# @-fobject-code: force to generate native code (necessary for ffi stuff)
95         ghc -I. -fforce-recomp -fobject-code $(PACKAGES) Mate.hs -outputdir $(B_STATIC) -e :ctags $(GHC_CPP)
96
97 hlint:
98         @# hlint isn't able to evaluate CPP comments correctly *sigh*
99         @cp debug.h debug_tmp.h
100         @# so we remove them "by hand", for hlint
101         @gcc -E -x c -fpreprocessed -dD -E debug_tmp.h | grep -v 'debug_tmp.h' > debug.h
102         @# ignore error code from hlint
103         -hlint Mate.hs Mate/
104         @mv debug_tmp.h debug.h