-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHowto.cook
114 lines (95 loc) · 1.88 KB
/
Howto.cook
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
#include "functions"
set match-mode-cook;
function defined-or-environment-or-default =
{
if [defined [@1]] then
return [[@1]];
if [defined [getenv [@1]]] then
return [getenv [@1]];
return [tail [arg]];
}
function keep-lowercase =
{
rv = ;
loop word = [arg] {
if [is-lowercase [word]] then
rv = [rv] [word];
}
return [rv] ;
}
function is-lowercase =
{
word = [@1] ;
dc = [downcase [word]] ;
return [matches [dc] [word]];
}
function replace-haskell-source-suffix =
{
local replacement = [head [arg]] ;
local vals = [tail [arg]] ;
/* set match-mode-regex ; */
/* local rv = [fromto \\(.*\\)\\.l\\?hs \\1[replacement] [vals]] ; */
rv = [fromto %.hs %[replacement] [vals]] ;
rv = [fromto %.lhs %[replacement] [rv]] ;
return [rv];
}
hc = [defined-or-default HC ghc] ;
hc_opts = ;
sources = [glob "*.lhs" "*.hs"] ;
objects = [replace-haskell-source-suffix ".o" [sources]] ;
programs = [replace-haskell-source-suffix "" [keep-lowercase [sources]]] ;
[print "sources:" [sources]] ;
[print "objects:" [objects]] ;
[print "progs:" [programs]] ;
all : [programs] ;
#if [and [defined depends] [not [matches %1clean%2 [command-line-goals]]]]
deps = [fromto % %.d [sources]] ;
#include-cooked-nowarn [deps]
#endif
% : %.hs
{
[hc] --make [target] -o [target] [hc_opts];
}
% : %.lhs
{
[hc] --make [target] -o [target] [hc_opts];
}
%.o %.hi : %.lhs
{
[hc] -c [need] [hc_opts] ;
}
%.o %.hi : %.hs
{
[hc] -c [need] [hc_opts] ;
}
clobber : clean
{
rm -f [programs] ;
}
clean :
{
rm -f *.hi *.o *.d ;
}
#if [defined depends]
if [matches ghc [depends]] then
{
%.hs.d : %.hs
{
[hc] -M -optdep-f -optdep[target] [hc_opts] ;
}
}
else
{
if [matches hmake [depends]] then
{
%.hs.d : %.hs
{
hmake -M %.hs > %.hs.d ;
}
}
else
{
fail "Variable depends not set to suitable value :" [depends] ;
}
}
#endif