forked from augustss/MicroHs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.old
136 lines (118 loc) · 4.6 KB
/
Makefile.old
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
# installtion prefix
PREFIX=/usr/local
BIN=bin
BOOTDIR=ghc-boot
OUTDIR=ghc-out
TOOLS=Tools
PROF= -prof -fprof-late #-prof -fprof-auto
EXTS= -XScopedTypeVariables -XTupleSections
GHCB=ghc $(PROF) -outputdir $(BOOTDIR)
GHCFLAGS=-i -ighc -ilib -i$(BOOTDIR) -hide-all-packages -XNoImplicitPrelude -XRebindableSyntax $(EXTS) -F -pgmF $(TOOLS)/convertY.sh
GHCC=$(GHCB) $(GHCFLAGS)
GHC=ghc
# $(CURDIR) might not be quite right
GHCE=$(GHC) $(EXTS) -package mtl -package pretty -F -pgmF Tools/convertX.sh -outputdir $(OUTDIR)
GCC=gcc
UPX=upx
ALLSRC=src/*/*.hs lib/*.hs lib/*/*.hs ghc/*.hs ghc/*/*.hs
MHS=mhs
COMB=comb/
EVAL=$(BIN)/mhseval
.PHONY: all alltest everytest runtest bootcombtest $(MHS)test test alltest time example bootstraptest
all: $(EVAL) $(BIN)/$(MHS)
everytest: runtest example examplecomb bootcombtest
###
### Build evaluator (runtime system)
###
# On MINGW you might need the additional flags -Wl,--stack,50000000 to increase stack space.
$(EVAL): src/runtime/eval.c
@mkdir -p bin
$(GCC) -Wall -Wno-deprecated-declarations -O3 src/runtime/eval.c src/runtime/comb.c -lm -o $(EVAL)
###
### Build the compiler with ghc, using standard libraries (Prelude, Data.List, etc)
###
$(BIN)/$(MHS): src/*/*.hs $(TOOLS)/convertX.sh
$(GHCE) -ighc -isrc -Wall -Wno-unrecognised-warning-flags -Wno-x-partial -O src/MicroHs/Main.hs -main-is MicroHs.Main -o $(BIN)/$(MHS)
# Self compile using comb/mhs.comb
$(COMB)$(MHS)-new.comb: $(EVAL)
$(EVAL) +RTS -r$(COMB)$(MHS).comb -RTS -ilib -isrc -o$(COMB)$(MHS)-new.comb MicroHs.Main
# Compare version compiled with GHC, and bootstrapped combinator version
bootcombtest: $(BIN)/$(MHS) $(EVAL) $(COMB)$(MHS).comb
$(BIN)/$(MHS) -ilib -isrc -omain-$(MHS).comb MicroHs.Main
$(EVAL) +RTS -v -r$(COMB)$(MHS).comb -RTS -ilib -isrc -omain-comb.comb MicroHs.Main
cmp main-$(MHS).comb main-comb.comb
###
### Run test examples with ghc-compiled compiler
###
runtest: $(EVAL) $(BIN)/$(MHS) tests/*.hs
cd tests; make alltest
###
### Run test examples with MicroHs compiler
###
runtestcomb: $(EVAL) $(COMB)$(MHS).comb
cd tests; make MHS='../$(EVAL) +RTS -r../$(COMB)$(MHS).comb -RTS -i../lib'
###
### Build combinator file for the compiler, using ghc-compiled compiler
###
$(COMB)$(MHS).comb: $(BIN)/$(MHS) $(ALLSRC)
$(BIN)/$(MHS) -ilib -isrc -o$(COMB)$(MHS).comb MicroHs.Main
time: $(EVAL) $(BIN)/$(MHS) tests/*.hs
cd tests; make time
example: $(EVAL) $(BIN)/$(MHS) Example.hs
$(BIN)/$(MHS) -ilib Example && $(EVAL)
# does not work
exampleboot: $(BIN)/boot$(MHS) Example.hs
$(BIN)/boot$(MHS) -r -ilib Example && $(EVAL)
examplecomb: $(EVAL) $(COMB)$(MHS).comb Example.hs
$(EVAL) +RTS -r$(COMB)$(MHS).comb -RTS -r -ilib Example
clean:
rm -rf src/*/*.hi src/*/*.o eval Main *.comb *.tmp *~ $(BIN)/* a.out $(BOOTDIR) $(OUTDIR) tmp/eval.c Tools/*.o Tools/*.hi dist-newstyle
cd tests; make clean
###
### Make an eval.c that contains the combinator code.
###
tmp/eval.c: src/runtime/eval.c $(EVAL) $(COMB)$(MHS).comb
@mkdir -p tmp
cp src/runtime/eval.c tmp/eval.c
$(EVAL) +RTS -r$(COMB)$(MHS).comb -o$(COMB)$(MHS)-gc.comb -RTS
$(EVAL) +RTS -K10M -r$(COMB)$(MHS).comb -RTS -ilib -iTools -r Compress < $(COMB)$(MHS)-gc.comb | \
$(EVAL) +RTS -K10M -r$(COMB)$(MHS).comb -RTS -ilib -iTools -r Addcombs >> tmp/eval.c
###
### Make an executable that contains the combinator code.
###
$(BIN)/cmhs: tmp/eval.c
$(GCC) -Wall -O3 tmp/eval.c -o $(BIN)/cmhs
strip $(BIN)/cmhs
###
### Compress the binary (broken on MacOS)
###
$(BIN)/umhs: $(BIN)/cmhs
rm -f $(BIN)/umhs
$(UPX) -q -q -o$(BIN)/umhs $(BIN)/cmhs
###
### Test that the compiler can bootstrap
###
bootstraptest: $(EVAL)
@mkdir -p tmp
@echo Build stage 1 with distribution combinator file
$(EVAL) +RTS -rcomb/mhs.comb -RTS -ilib -isrc -otmp/mhs.comb.1 MicroHs.Main
@echo Build stage 2 with output from stage 1
$(EVAL) +RTS -rtmp/mhs.comb.1 -RTS -ilib -isrc -otmp/mhs.comb.2 MicroHs.Main
cmp tmp/mhs.comb.1 tmp/mhs.comb.2 && echo Success
# installs linraries the the following binaries:
# bin/mhseval - the evaluator that can read a combinator file and run it
# bin/mhsc - a compiler that produces a proper binary
# bin/mhs - a compiler/repl that can compile to combinators
install: $(EVAL)
mkdir -p $(PREFIX)/bin
cp $(EVAL) $(PREFIX)/bin
(echo "prefix=$(PREFIX)"; cat Tools/mhsc.sh) > $(PREFIX)/bin/mhsc
chmod +x $(PREFIX)/bin/mhsc
mkdir -p $(PREFIX)/lib/mhs/Tools
mkdir -p $(PREFIX)/lib/mhs/comb
mkdir -p $(PREFIX)/lib/mhs/src/runtime
cp Tools/* $(PREFIX)/lib/mhs/Tools
cp comb/mhs.comb $(PREFIX)/lib/mhs/comb
cp src/runtime/eval.c $(PREFIX)/lib/mhs/src/runtime
cp -r lib $(PREFIX)/lib/mhs
$(PREFIX)/bin/mhsc -isrc -o$(PREFIX)/bin/mhs MicroHs.Main