forked from augustss/MicroHs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
159 lines (131 loc) · 4.81 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# installation prefix
PREFIX=/usr/local
# Unix-like system, 64 bit words
CONF=unix-64
#
CCWARNS= -Wall
CCOPTS= -O3
CCLIBS= -lm
CCEVAL= $(CC) $(CCWARNS) $(CCOPTS) src/runtime/eval-$(CONF).c $(CCLIBS)
#
GHC= ghc
GHCINCS= -ighc -isrc
GHCWARNS= -Wall -Wno-unrecognised-warning-flags -Wno-x-partial
GHCOPTS= -O
GHCEXTS= -DNOTCABAL -XScopedTypeVariables -XPatternGuards -XTupleSections -XTypeSynonymInstances -XFlexibleInstances -XNoFieldSelectors -XOverloadedRecordDot -XDisambiguateRecordFields
# -XOverloadedRecordUpdate
GHCPKGS= #-package mtl -package pretty -package temporary -package process
GHCTOOL= # -F -pgmF Tools/convertX.sh
GHCOUTDIR= ghc-out
GHCOUT= -outputdir $(GHCOUTDIR)
GHCPROF= # -prof -fprof-late #-prof -fprof-auto
GHCFLAGS= $(GHCEXTS) $(GHCINCS) $(GHCWARNS) $(GHCOPTS) $(GHCTOOL) $(GHCPKGS) $(GHCOUT) $(GHCPROF)
#
.PHONY: clean bootstrap install ghcgen newmhs cachelib timecompile exampletest cachetest runtest runtestmhs everytest everytestmhs nfibtest info
all: bin/mhs
newmhs: ghcgen
$(CCEVAL) generated/mhs.c -o bin/mhs
$(CC) $(CCWARNS) -g src/runtime/eval-$(CONF).c $(CCLIBS) generated/mhs.c -o bin/mhsgdb
# Compile mhs from distribution, with C compiler
bin/mhs: src/runtime/*.c src/runtime/config*.h #generated/mhs.c
@mkdir -p bin
$(CCEVAL) generated/mhs.c -o bin/mhs
# Compile combinator evaluator
bin/mhseval: src/runtime/*.c src/runtime/config*.h
@mkdir -p bin
$(CCEVAL) src/runtime/comb.c -o bin/mhseval
size bin/mhseval
bin/mhsevalgdb: src/runtime/*.c src/runtime/config*.h
@mkdir -p bin
$(CC) $(CCWARNS) -g src/runtime/eval-$(CONF).c $(CCLIBS) src/runtime/comb.c -o bin/mhsevalgdb
# Compile mhs with ghc
bin/gmhs: src/*/*.hs ghc/*.hs ghc/*/*.hs ghc/*/*/*.hs
@mkdir -p bin
$(GHC) $(GHCFLAGS) src/MicroHs/Main.hs -main-is MicroHs.Main -o bin/gmhs
# Compile mhs with ghc, with code coverage
bin/cmhs: src/*/*.hs ghc/*.hs ghc/*/*.hs
@mkdir -p bin
$(GHC) $(GHCFLAGS) -fhpc src/MicroHs/Main.hs -main-is MicroHs.Main -o bin/cmhs
# Generate distribution C file
generated/mhs.c: bin/mhs src/*/*.hs
@mkdir -p generated
bin/mhs -isrc MicroHs.Main -ogenerated/mhs.c
ghcgen: bin/gmhs src/*/*.hs lib/*.hs lib/*/*.hs lib/*/*/*.hs
bin/gmhs -isrc MicroHs.Main -ogenerated/mhs.c
# Make sure boottrapping works
bootstrap: bin/mhs-stage2
@echo "*** copy stage2 to bin/mhs"
cp bin/mhs-stage2 bin/mhs
cp generated/mhs-stage2.c generated/mhs.c
# Build stage1 compiler with existing compiler
bin/mhs-stage1: bin/mhs src/*/*.hs
@mkdir -p generated
@echo "*** Build stage1 compiler, using bin/mhs"
bin/mhs -isrc MicroHs.Main -ogenerated/mhs-stage1.c
$(CCEVAL) generated/mhs-stage1.c -o bin/mhs-stage1
# Build stage2 compiler with stage1 compiler, and compare
bin/mhs-stage2: bin/mhs-stage1 src/*/*.hs
@mkdir -p generated
@echo "*** Build stage2 compiler, with stage1 compiler"
bin/mhs-stage1 -isrc MicroHs.Main -ogenerated/mhs-stage2.c
cmp generated/mhs-stage1.c generated/mhs-stage2.c
@echo "*** stage2 equal to stage1"
$(CCEVAL) generated/mhs-stage2.c -o bin/mhs-stage2
# Run test examples with ghc-compiled compiler
runtest: bin/mhseval bin/gmhs tests/*.hs
cd tests; make alltest
# Compress the binary (broken on MacOS)
bin/umhs: bin/mhs
rm -f bin/umhs
upx -q -q -obin/umhs bin/mhs
#
timecompile: bin/mhs
time bin/mhs +RTS -v -RTS -isrc MicroHs.Main
#
timecachecompile: bin/mhs
@-rm -f .mhscache
time bin/mhs +RTS -v -RTS -CW AllOfLib
time bin/mhs +RTS -v -RTS -CR -isrc MicroHs.Main
#
cachelib:
@-rm -f .mhscache
bin/mhs -CW AllOfLib
#
clean:
rm -rf src/*/*.hi src/*/*.o *.comb *.tmp *~ bin/* a.out $(GHCOUTDIR) tmp/* Tools/*.o Tools/*.hi dist-newstyle generated/*-stage* .mhscache
make clean -f Makefile.emscripten
cd tests; make clean
install:
mkdir -p $(PREFIX)/bin
cp bin/mhs $(PREFIX)/bin
mkdir -p $(PREFIX)/lib/mhs/src/runtime
cp -r lib $(PREFIX)/lib/mhs
cp src/runtime/* $(PREFIX)/lib/mhs/src/runtime
@echo "***"
@echo "*** Installation complete"
@echo "*** Set environment variable MHSDIR to $(PREFIX)/lib/mhs"
@echo "***"
everytest: newmhs runtest exampletest cachetest bootcombtest nfibtest info
everytestmhs: bin/mhs bin/mhseval exampletest cachetest bootstrap runtestmhs nfibtest info
runtestmhs:
cd tests; make MHS=../bin/mhs cache; make MHS="../bin/mhs +RTS -H2M -RTS -CR" info test
bootcombtest: bin/gmhs bin/mhseval
bin/gmhs -isrc -ogmhs.comb MicroHs.Main
bin/mhseval +RTS -v -rgmhs.comb -RTS -isrc -omhs.comb MicroHs.Main
cmp gmhs.comb mhs.comb
exampletest: bin/mhs bin/mhseval Example.hs
bin/mhs -r Example
bin/mhs Example && bin/mhseval
bin/mhs Example -oEx && ./Ex && rm Ex
info: bin/mhs
bin/mhs -r -itests Info
cachetest: bin/mhs bin/mhseval Example.hs
rm -f .mhscache
bin/mhs -CW AllOfLib
bin/mhs -CR Example && bin/mhseval
bin/mhs +RTS -v -RTS -isrc -CR MicroHs.Main
rm -f .mhscache
nfibtest: bin/mhs bin/mhseval
bin/mhs -itests Nfib && bin/mhseval
emscripten: bin/mhs
make test -f Makefile.emscripten