-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmakefile
executable file
·276 lines (247 loc) · 9.11 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
.SUFFIXES: .lhs .mkd .htm .tex .pdf .hs
.PHONY: verb pretty update clean
PANDOC := pandoc --wrap=none -N --atx-headers
HSCOLOUR := hscolour -lit
TESTS=SimpleTest.hs \
SubstituteTest.hs \
DeclareTest.hs \
IntBoolTest.hs \
TopLevelFunctionsTest.hs \
IncorrectFunctionsTest.hs \
FirstClassFunctionsTest.hs \
CheckedMonadTest.hs \
StatefulTest.hs \
StatefulMonadTest.hs \
FunExamples.hs \
ErrorCheckingTest.hs \
FixedPoints.hs
PARSERS=\
SimpleParse.y \
SubstituteParse.y \
IntBoolParse.y \
DeclareParse.y \
TopLevelFunctionsParse.y \
IncorrectFunctionsParse.y \
FirstClassFunctionsParse.y \
StatefulParse.y \
LambdaParse.y
SOURCES=$(TESTS) \
$(addsuffix .js, $(basename $(TESTS))) \
$(addsuffix .hs, $(basename $(PARSERS))) \
Base.hs \
Lexer.hs \
CheckedMonad.hs \
ErrorChecking.hs \
Examples.hs \
FirstClassFunctions.hs \
FirstClassFunctionsTyping.hs \
FunctionalEnvironment.hs \
IncorrectFunctions.hs \
IntBool.hs \
Declare.hs \
DeclareSubstitute.hs \
Operators.hs \
Stateful.hs \
StatefulMonad.hs \
Simple.hs \
Substitute.hs \
TopLevelFunctions.hs \
Value.hs \
Lambda.hs \
IntBoolTyping.hs
all: anatomy.pdf anatomyVerbatim.pdf anatomy.htm
verb: anatomyVerbatim.pdf
open anatomyVerbatim.pdf
pretty: anatomy.pdf
open anatomy.pdf
diff: new.lhs
diff anatomy.lhs new.lhs
new.lhs: anatomy.lhs output/*.out
ruby includes.rb "src/*.hs" "src/*.y" "src/*.js" "output/*.out" ">" < anatomy.lhs \
| perl -pe "s/ +$$//" \
> new.lhs
# modify the core anatomy.lhs file to have updated paragraph marks
fixup: anatomy.lhs new.lhs
cp anatomy.lhs backup/archive`date "+%m%d%H%M%Y%S"`.lhs
cp new.lhs anatomy.lhs
src/%.hs : src/%.y makefile
cd src
happy $<
code/%.js : src/%.js makefile
@mkdir -p code
cat $< \
| sed '/BEGIN:/d' \
| sed '/END:/d' \
> $@
# code is generated by removing BEGIN/END pairs, and creating HTML versions of code
code/%.hs : src/%.hs makefile
@mkdir -p code
cat $< \
| sed '/BEGIN:/d' \
| sed '/END:/d' \
> $@
# identical processing for grammar files
code/%.y : src/%.y makefile $(addprefix src/,$(SOURCES))
@mkdir -p code
cat $< \
| sed '/BEGIN:/d' \
| sed '/END:/d' \
> $@
# generate code from the sources and parsers
code: $(addprefix code/,$(SOURCES)) $(addprefix code/,$(PARSERS))
# generate the output
output/%.out : code/%.hs makefile $(addprefix code/,$(SOURCES))
@mkdir -p output
cd code; runghc $(notdir $<) $(addsuffix .js, $(basename $(notdir $<))) > ../output/$(addsuffix .out, $(basename $(notdir $<)))
# run all the code and build the tests
execute: code $(addprefix output/, $(addsuffix .out, $(basename $(notdir $(TESTS)))))
# update the server copy (requires server access)
update: anatomy.pdf anatomyVerbatim.pdf anatomy.htm packages
cp index.htm ~/Public/web/anatomy/
cp anatomyVerbatim.pdf ~/Public/web/anatomy/
cp anatomy.pdf ~/Public/web/anatomy/
cp anatomy.htm ~/Public/web/anatomy/
cp anatomy.css ~/Public/web/anatomy/
mkdir -p ~/Public/web/anatomy/figures
mkdir -p ~/Public/web/anatomy/packages
cp packages/* ~/Public/web/anatomy/packages
cp figures/*.png ~/Public/web/anatomy/figures
rsync -rvz ~/Public/web/anatomy firefly.cs.utexas.edu:public_html
rm temp.lhs
# build the anatomy.mkd file by including all the code, then removing the INCLUDE markers
# Change the header markers to remove space before them
anatomy.mkd: anatomy.lhs makefile # template.tex anatomy.bib figures/*.eps execute output/*.out
ruby includes.rb "src/*.hs" "src/*.y" "src/*.js" "output/*.out" ">" < anatomy.lhs \
| sed "/^INCLUDE:/d" \
| sed "s/^ #/#/" \
| sed "s/'[0-9][0-9a-z]*//g" \
| sed "s/^> test[^= ][^= ]* =/> /g" \
| sed '/--BEGIN-HIDE--/,/--END-HIDE--/d' \
> anatomy.mkd
# build the HTML version.
# First deal with |foo| -> `foo` and ||-> ||
# then run panddoc to convert markdown+lhs to html
# finally perform some cleanups, and implement the paragraph comment system
anatomy.htm: anatomy.mkd makefile
# convert | to ` for inline haskell
cat anatomy.mkd \
| sed 's/||/VERTICAL_BAR/g' \
| perl -pe 's/\|([^ ][^|]*)\|/\`$$1\`/g;' \
| sed 's/VERTICAL_BAR/||/g' \
> foo.mkd
# process markdown+lhs to html
cat foo.mkd \
| $(PANDOC) -H header.htm --toc -f markdown+lhs -t html --css anatomy.css --filter pandoc-citeproc --top-level-division=chapter \
| sed 's/\.eps/.png/' \
> foo2.mkd
# fix problems in HTML
cat header.htm foo2.mkd \
| sed 's/@@/@/g' \
| sed 's/BAR/|/g' \
| sed 's/STAR/*/g' \
| sed 's/OPENB/{/g' \
| sed 's/CLOSEB/}/g' \
| sed 's/BIND/\>\>=/g' \
| sed 's|<p><span style="color:red"><.p>|<span style="color:red">|' \
| sed 's|<p><span style="END"><.p>|<\/span>|' \
| tr '$$' '\f' \
| perl -pe 's|\f\\sqrt\{x\}\f|√x|g;' \
| perl -pe 's|\fx = \\sqrt\{5\}\f|x = √5|g;' \
| tr '\f' '$$' \
> anatomy.htm
rm foo.mkd foo2.mkd
# the last thing here is to convert $\sqrt{x}$ into a math representation.
# we have to chnage $ to something else, because otherwise is messes things up terrribly.
# convert the markdown+lhs into a latex+lhs file
# first, remove the HTML paragraph markdown
# Then perform translations that are common to both PDF formats
temp.lhs: anatomy.mkd template.tex
cat anatomy.mkd \
| sed "s/@@/AtX/g" \
| sed "s/@/ATSIGN/g" \
> foo.lhs
cat foo.lhs \
| $(PANDOC) -f markdown+lhs -t latex+lhs --template=template.tex -V documentclass=report --filter pandoc-citeproc --top-level-division=chapter \
> foo2.lhs
cat foo2.lhs \
| sed "s/{verbatim}/{spec}/g" \
| sed "s/@/@@/g" \
| sed "s/\\\\textbar{}/|/g" \
| sed "s/\\\\textbar /|/g" \
| sed "s/\\\\textbar/|/g" \
| sed "s/\\\\textless{}/</g" \
| sed "s/\\\\textgreater{}/>/g" \
| sed "s/\\\\textgreater/>/g" \
| sed "s/\\\\textless{}/</g" \
| sed "s/\\\\textless/</g" \
| sed "s/\\\\ldots{}/.../g" \
| sed "s/\\\\textbackslash{}/\\\\/g" \
| sed "/|/s/\\\\_/_/g" \
| sed "s/{\[}/[/g" \
| sed "s/{\]}/]/g" \
| sed "s/BAR/||/g" \
| sed "s/STAR/*/g" \
| sed "s/AtX/@/g" \
| sed "s/ATSIGN/@@/g" \
| sed "s/BIND/>>=/g" \
| sed "/|/s/\\\\{/{/g" \
| sed "/|/s/\\\\}/}/g" \
| sed "s/\\\\newcommand{\\\\VerbBar}{|}/%VerbBar/g" \
> temp.lhs
rm foo.lhs foo2.lhs
# convert temp.lhs into Verbatim PDF, coverting various character sequences
# from fancy format to normal text, so that the verbatim PDF will look more verbatim
anatomyVerbatim.pdf: temp.lhs packages
lhs2TeX --verb temp.lhs \
| sed "s/\\\\char'31/\\\\char45{}\\\\char62{}/g" \
| sed "s|\\\\char'32|/=|g" \
| sed "s/\\\\char'10/\\\\char92{}/g" \
| sed "s/\\\\char'06/\\\\char60{}\\\\char45{}/g" \
| sed "s/\\\\char'36/==/g" \
| sed "s/\\\\char'00/./g" \
| sed "s/\\\\char'05/not/g" \
| sed "s/\\\\char'04/and/g" \
| sed "s/\\\\char'37/or/g" \
| sed "s/\\\\char'24/forall/g" \
| sed "s/\\\\char'07/pi/g" \
> anatomyVerbatim.tex
pdflatex anatomyVerbatim.tex
pdflatex anatomyVerbatim.tex
pdflatex anatomyVerbatim.tex
anatomyCheck.tex: temp.lhs
lhs2TeX --verb temp.lhs > anatomyCheck.tex
# create the anatomy PDF directly from the temp.lhs
anatomy.pdf: temp.lhs packages
lhs2TeX --poly temp.lhs > anatomy.tex
pdflatex anatomy.tex
pdflatex anatomy.tex
pdflatex anatomy.tex
packages: $(addprefix code/,$(SOURCES))$
@mkdir -p packages
zip packages/Substitute.zip code/Base.hs code/Lexer.hs code/Substitute*
zip packages/Simple.zip code/Base.hs code/Lexer.hs code/Simple*
zip packages/Declare.zip code/Base.hs code/Lexer.hs code/Declare*
zip packages/IntBool.zip code/Base.hs code/Lexer.hs code/Operators.hs code/IntBool*
zip packages/IncorrectFunctions.zip code/Base.hs code/Lexer.hs code/Operators.hs code/IncorrectFunctions*
zip packages/TopLevelFunctions.zip code/Base.hs code/Lexer.hs code/Operators.hs code/TopLevelFunctions*
zip packages/FirstClassFunctions.zip code/Base.hs code/Lexer.hs code/Operators.hs code/FirstClassFunctions.hs code/FirstClassFunctionsParse.hs code/FirstClassFunctionsParse.y code/FirstClassFunctionsTest.hs code/FirstClassFunctionsTest.js
zip packages/ErrorChecking.zip code/Base.hs code/Lexer.hs code/Operators.hs \
code/FirstClassFunctions.hs code/FirstClassFunctionsParse.hs code/ErrorChecking*
zip packages/Stateful.zip code/Base.hs code/Lexer.hs code/Operators.hs \
code/Stateful.hs code/StatefulTest.hs code/StatefulParse.y
zip packages/StatefulMonad.zip code/Base.hs code/Lexer.hs code/Operators.hs \
code/StatefulMonad* code/Stateful.hs code/StatefulParse.y
zip packages/CheckedMonad.zip code/Base.hs code/Lexer.hs code/Operators.hs code/CheckedMonad* \
code/FirstClassFunctionsParse.y code/FirstClassFunctions.hs code/ErrorChecking.hs
zip packages/Typing.zip code/Base.hs code/Lexer.hs code/Operators.hs \
code/FirstClassFunctionsTyping* code/FirstClassFunctionsParse.y
zip packages/Examples.zip code/*Examples*
clean:
rm -rf abstract_syntax-eps-converted-to.pdf anatomy.mkd \
anatomyVerbatim.aux anatomyVerbatim.log anatomyVerbatim.out \
anatomyVerbatim.pdf anatomyVerbatim.tex anatomyVerbatim.toc \
scopes-eps-converted-to.pdf temp.lhs anatomy.pdf anatomy.tex \
anatomy.toc anatomy.aux anatomy.log anatomy.out anatomy.ptb \
anatomyCheck.tex anatomy.htm \
src/*Parse.hs src/*.o src/*.hi \
packages code output