refactor stuff
[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)/release
14 O_STATIC_FILES = $(shell ls $(B_STATIC)/Mate/*.o) $(wildcard $(B_STATIC)/ffi/*.o)
15 PACKAGES_ := bytestring harpy hs-java plugins
16 PACKAGES := $(addprefix -package ,$(PACKAGES_))
17
18 GHC_OPT := -I. -Wall -O0 -fno-warn-unused-do-bind
19 GHC_LD := -optl-Xlinker -optl-x
20
21
22 .PHONY: all test clean ghci
23
24 all: mate
25
26 %: %.class mate
27         ./mate $(basename $<)
28
29
30 tests: mate $(TEST_JAVA_FILES:.java=.class) $(TEST_CLASS_FILES)
31
32 CALLF = $(basename $@).call
33 testcase = ./tools/openjdktest.sh "$(1) $(basename $@)"
34 %.test: %.class mate
35         @if [ -f $(CALLF) ]; \
36                 then $(call testcase,`cat $(CALLF)`); \
37                 else $(call testcase, ); fi
38
39 COMPILEF = $(basename $@).compile
40 %.class: %.java
41         @if [ -f $(COMPILEF) ]; \
42                 then $(SHELL) $(COMPILEF); \
43                 else $(JAVAC) $<; fi
44         @echo "JAVAC $<"
45
46 ffi/native.o: ffi/native.c
47         ghc -Wall -O2 -c $< -o $@
48
49 GHCCALL = ghc --make $(GHC_OPT) Mate.hs ffi/trap.c -o $@ $(GHC_LD) -outputdir
50 mate: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILES)
51         @mkdir -p $(B_RELEASE)
52         $(GHCCALL) $(B_RELEASE) -dynamic
53
54 mate.static: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o $(CLASS_FILES)
55         @mkdir -p $(B_STATIC)
56         $(GHCCALL) $(B_STATIC) -static
57
58 %.dbg: %.class mate.dbg
59         ./mate.dbg $(basename $<)
60
61 ifeq (${DBGFLAGS},)
62 DEBUGFLAGS = -DDBG_JIT -DDBG_MP
63 else
64 DEBUGFLAGS = ${DBGFLAGS}
65 endif
66 mate.dbg: Mate.hs ffi/trap.c $(HS_FILES) $(HS_BOOT) ffi/native.o
67         @mkdir -p $(B_DEBUG)/{ffi,Mate,}
68         gcc -Wall $(DEBUGFLAGS) -O0 -c ffi/trap.c -o $(B_DEBUG)/ffi/trap.o
69         ghc --make $(DEBUGFLAGS) $(GHC_OPT) Mate.hs $(B_DEBUG)/ffi/trap.o -o $@ $(GHC_LD) -outputdir $(B_DEBUG)
70
71 clean:
72         rm -rf $(BUILD) mate mate.static mate.dbg tags ffi/native.o \
73                 tests/*.class Mate/*_stub.* \
74                 jmate/lang/*.class jmate/io/*.class java/io/*.class \
75                 java/lang/{Integer,Character,String,System}.class
76
77 ghci: mate.static
78         ghci -I. $(PACKAGES) $(O_STATIC_FILES) -outputdir $(B_STATIC) Mate.hs
79
80 tags: mate
81         @# @-fforce-recomp, see
82         @# http://stackoverflow.com/questions/7137414/how-do-i-force-interpretation-in-hint
83         @# @-fobject-code: force to generate native code (necessary for ffi stuff)
84         ghc -I. -fforce-recomp -fobject-code $(PACKAGES) Mate.hs $(O_STATIC_FILES) -outputdir $(B_STATIC) -e :ctags
85
86 hlint:
87         @# hlint isn't able to evaluate CPP comments correctly *sigh*
88         @cp debug.h debug_tmp.h
89         @# so we remove them "by hand", for hlint
90         @gcc -E -x c -fpreprocessed -dD -E debug_tmp.h | grep -v 'debug_tmp.h' > debug.h
91         @# ignore error code from hlint
92         -hlint Mate.hs Mate/
93         @mv debug_tmp.h debug.h