-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathMakefile
262 lines (213 loc) · 10.7 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# installation prefix
PREFIX=/usr/local
# Unix-like system, 64 bit words
CONF=unix-64
#
CCWARNS= -Wall
CCOPTS= -O3
CCLIBS= -lm
CCEVAL= $(CC) $(CCWARNS) $(CCOPTS) -Isrc/runtime src/runtime/eval-$(CONF).c $(CCLIBS)
#
GHC= ghc
GHCINCS= -ighc -isrc -ipaths
GHCWARNS= -Wall -Wno-unrecognised-warning-flags -Wno-x-partial -Wno-deprecations
GHCOPTS= -O
GHCEXTS= -DNOTCABAL -XScopedTypeVariables -XTypeSynonymInstances -XMultiParamTypeClasses -XFlexibleInstances -XBangPatterns
GHCPKGS= -package mtl -package pretty -package haskeline -package process -package time -package ghc-prim -package containers -package deepseq -package directory -package text
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)
#
EMCC=emcc -sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sNODERAWFS -sSINGLE_FILE -DUSE_SYSTEM_RAW
#
MHSINCNP= -i -imhs -isrc -ilib
MHSINC=$(MHSINCNP) -ipaths
#
.PHONY: clean bootstrap install ghcgen newmhs newmhsz cachelib timecompile exampletest cachetest runtest runtestmhs everytest everytestmhs nfibtest info
all: bin/mhs bin/cpphs bin/mcabal
targets.conf:
echo [default] > targets.conf
echo cc = \"$(CC)\" >> targets.conf
echo conf = \"$(CONF)\" >> targets.conf
echo '' >> targets.conf
echo [emscripten] >> targets.conf
echo cc = \"$(EMCC)\" >> targets.conf
echo conf = \"$(CONF)\" >> targets.conf
newmhs: ghcgen targets.conf
$(CCEVAL) generated/mhs.c -o bin/mhs
$(CC) $(CCWARNS) -g -Isrc/runtime src/runtime/eval-$(CONF).c $(CCLIBS) generated/mhs.c -o bin/mhsgdb
newmhsz: newmhs
rm generated/mhs.c
make generated/mhs.c
sanitizemhs: ghcgen targets.conf
$(CCEVAL) -fsanitize=undefined -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract generated/mhs.c -o bin/mhssane
# Compile mhs from distribution, with C compiler
bin/mhs: src/runtime/*.c src/runtime/*.h targets.conf #generated/mhs.c
@mkdir -p bin
$(CCEVAL) generated/mhs.c -o bin/mhs
# Compile cpphs from distribution, with C compiler
bin/cpphs: src/runtime/*.c src/runtime/config*.h generated/cpphs.c
@mkdir -p bin
$(CCEVAL) generated/cpphs.c -o bin/cpphs
# Compile mcabal from distribution, with C compiler
bin/mcabal: src/runtime/*.c src/runtime/config*.h generated/mcabal.c
@mkdir -p bin
$(CCEVAL) generated/mcabal.c -o bin/mcabal
# 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 -z $(MHSINC) MicroHs.Main -ogenerated/mhs.c
ghcgen: bin/gmhs src/*/*.hs lib/*.hs lib/*/*.hs lib/*/*/*.hs
bin/gmhs $(MHSINC) MicroHs.Main -ogenerated/mhs.c
#
generated/mcabal.c:
bin/mhs -z -i../MicroCabal/src -ilib -ogenerated/mcabal.c MicroCabal.Main
# Flags to read local file system, generate a single .js file, and to avoid ioctl()
mhs.js: src/*/*.hs src/runtime/*.[ch] targets.conf
bin/mhs $(MHSINC) -temscripten MicroHs.Main -o mhs.js
# 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 -z $(MHSINC) 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 -z $(MHSINC) 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
cpphssrc/malcolm-wallace-universe:
mkdir -p cpphssrc
cd cpphssrc; git clone [email protected]:hackage-trustees/malcolm-wallace-universe.git
# Use this cpphs for bootstrapping
USECPPHS=bin/cpphs
bootstrapcpphs: bin/mhs cpphssrc/malcolm-wallace-universe $(USECPPHS)
MHSCPPHS=$(USECPPHS) bin/mhs -z -XCPP '-DMIN_VERSION_base(x,y,z)=((x)<4||(x)==4&&(y)<19||(x)==4&&(y)==19&&(z)<=1)' -icpphscompat -icpphssrc/malcolm-wallace-universe/polyparse-1.12/src -icpphssrc/malcolm-wallace-universe/cpphs-1.20.9 cpphssrc/malcolm-wallace-universe/cpphs-1.20.9/cpphs.hs -ogenerated/cpphs.c
# Run test examples with ghc-compiled compiler
runtest: bin/mhseval bin/gmhs tests/*.hs
cd tests; make alltest
# Run test examples with mhs-compiled compiler
runtestmhs: bin/mhseval bin/mhs
cd tests; make MHS=../bin/mhs cache; make MHS="../bin/mhs +RTS -H4M -RTS -CR" info test errtest
# Run test examples going via JavaScript
runtestemscripten: bin/mhseval bin/mhs
cd tests; make MHS=../bin/mhs cache; MHSDIR=.. make MHS="../bin/mhs -CR -temscripten -oout.js" EVAL="node out.js" info test errtest
# 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 -s $(MHSINC) MicroHs.Main
#
timecachecompile: bin/mhs
@-rm -f .mhscache
time bin/mhs +RTS -v -RTS -CW AllOfLib
time bin/mhs +RTS -v -RTS -CR -s $(MHSINC) MicroHs.Main
#
cachelib:
@-rm -f .mhscache
bin/mhs -CW AllOfLib
#
clean:
rm -rf src/*/*.hi src/*/*.o *.comb *.js *.tmp *~ bin/* a.out $(GHCOUTDIR) Tools/*.o Tools/*.hi dist-newstyle generated/*-stage* .mhscache targets.conf .mhscache dist-mcabal cpphssrc Interactive.hs .mhsi
cd tests; make clean
-cabal clean
oldinstall:
mkdir -p $(PREFIX)/bin
cp bin/mhs $(PREFIX)/bin
-cp bin/cpphs $(PREFIX)/bin
mkdir -p $(PREFIX)/lib/mhs/src/runtime
cp -r lib $(PREFIX)/lib/mhs
cp src/runtime/* $(PREFIX)/lib/mhs/src/runtime
cp targets.conf $(PREFIX)/lib/mhs/targets.conf
@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
bootcombtest: bin/gmhs bin/mhseval
bin/gmhs $(MHSINC) -ogmhs.comb MicroHs.Main
bin/mhseval +RTS -v -rgmhs.comb -RTS $(MHSINC) -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 $(MHSINC) -CR MicroHs.Main
rm -f .mhscache
nfibtest: bin/mhs bin/mhseval
bin/mhs -itests Nfib && bin/mhseval
######
VERSION=0.11.2.3
HVERSION=0,11,2,3
MCABAL=$(HOME)/.mcabal
MCABALMHS=$(MCABAL)/mhs-$(VERSION)
MDATA=$(MCABALMHS)/packages/mhs-$(VERSION)/data
MRUNTIME=$(MDATA)/src/runtime
MCABALBIN=$(MCABAL)/bin
MDIST=dist-mcabal
BASE=base-$(VERSION)
BASEMODULES=Control.Applicative Control.Arrow Control.Category Control.DeepSeq Control.Error Control.Exception Control.Exception.Base Control.Monad Control.Monad.Fail Control.Monad.Fix Control.Monad.IO.Class Control.Monad.ST Control.Monad.Zip Data.Array Data.Bifoldable Data.Bifunctor Data.Bitraversable Data.Bits Data.Bool Data.Bounded Data.ByteString Data.Char Data.Complex Data.Constraint Data.Data Data.Double Data.Dynamic Data.Either Data.Enum Data.Eq Data.Fixed Data.Float Data.FloatW Data.Floating Data.Foldable Data.Foldable1 Data.Fractional Data.Function Data.Functor Data.Functor.Classes Data.Functor.Compose Data.Functor.Const Data.Functor.Contravariant Data.Functor.Identity Data.Functor.Product Data.Functor.Sum Data.Hashable Data.IOArray Data.IORef Data.Int Data.Integer Data.Integral Data.Ix Data.Kind Data.List Data.List.NonEmpty Data.Maybe Data.Monoid Data.Num Data.Ord Data.Proxy Data.Ratio Data.Real Data.RealFloat Data.RealFrac Data.Records Data.STRef Data.Semigroup Data.String Data.Text Data.Traversable Data.Tuple Data.Tuple.Instances Data.Type.Equality Data.TypeLits Data.Typeable Data.Version Data.Void Data.Word Data.ZipList Debug.Trace Foreign Foreign.C Foreign.C.Error Foreign.C.String Foreign.C.Types Foreign.ForeignPtr Foreign.Marshal Foreign.Marshal.Alloc Foreign.Marshal.Array Foreign.Marshal.Error Foreign.Marshal.Utils Foreign.Ptr Foreign.Storable GHC.Generics GHC.Stack GHC.Types Language.Haskell.TH.Syntax Mhs.Builtin Numeric Numeric.FormatFloat Numeric.Natural Prelude System.Cmd System.Console.GetOpt System.Compress System.Directory System.Environment System.Exit System.IO System.IO.Error System.IO.MD5 System.IO.PrintOrRun System.IO.Serialize System.IO.TimeMilli System.IO.Unsafe System.Info System.Process Text.Printf Text.ParserCombinators.ReadP Text.ParserCombinators.ReadPrec Text.Read Text.Read.Lex Text.Show Unsafe.Coerce
$(MCABALBIN)/mhs: bin/mhs src/runtime/*.[ch] targets.conf
@mkdir -p $(MCABALBIN)
@mkdir -p $(MDIST)
@echo 'module Paths_MicroHs where { import Prelude(); import MHSPrelude; import Data.Version; version :: Version; version = makeVersion [$(HVERSION)]; getDataDir :: IO FilePath; getDataDir = return "$(MDATA)" }' > $(MDIST)/Paths_MicroHs.hs
bin/mhs -z $(MHSINCNP) -i$(MDIST) MicroHs.Main -o$(MCABALBIN)/mhs
@mkdir -p $(MRUNTIME)
cp targets.conf $(MDATA)
cp src/runtime/*.[ch] $(MRUNTIME)
$(MCABALBIN)/cpphs: bin/cpphs
@mkdir -p $(MCABALBIN)
cp bin/cpphs $(MCABALBIN)
$(MCABALBIN)/mcabal: bin/mcabal
@mkdir -p $(MCABALBIN)
cp bin/mcabal $(MCABALBIN)
$(MCABALMHS)/packages/$(BASE).pkg: bin/mhs lib/*.hs lib/*/*.hs lib/*/*/*.hs
bin/mhs -P$(BASE) -o$(BASE).pkg -ilib $(BASEMODULES)
bin/mhs -Q $(BASE).pkg $(MCABALMHS)
@rm $(BASE).pkg
install: $(MCABALBIN)/mhs $(MCABALBIN)/cpphs $(MCABALBIN)/mcabal $(MCABALMHS)/packages/$(BASE).pkg
@echo $$PATH | tr ':' '\012' | grep -q $(MCABALBIN) || echo '***' Add $(MCABALBIN) to the PATH
# mkdir ~/.mcabal/packages/array-0.5.6.0
preparedist: newmhsz bootstrapcpphs
rm -f generated/mcabal.c
make generated/mcabal.c
minstall: bin/cpphs bin/mcabal $(MCABALBIN)/mhs
cp bin/cpphs bin/mcabal $(MCABALBIN)
cd lib; PATH=$(MCABALBIN):"$$PATH" mcabal install
PATH=$(MCABALBIN):"$$PATH" mcabal install
@echo $$PATH | tr ':' '\012' | grep -q $(MCABALBIN) || echo '***' Add $(MCABALBIN) to the PATH