[project @ 2000-04-17 11:39:56 by simonmar]
[ghc-hetmet.git] / mk / suffix.mk
1 #################################################################################
2 #
3 #                           suffix.mk
4 #
5 #               Suffix rules for fptools
6 #
7 #################################################################################
8
9
10 # This file contain the default suffix rules for all the fptools projects.
11 #
12
13
14 # No need to define .SUFFIXES because we don't use any suffix rules
15 # Instead we use gmake's pattern rules exlusively
16
17 .SUFFIXES:
18
19 # However, if $(way) is set then we have to define $(way_) and $(_way)
20 # from it in the obvious fashion.
21 # This must be done here (or earlier), but not in target.mk with the other
22 # way management, because the pattern rules in this file take a snapshot of
23 # the value of $(way_) and $(_way), and it's no good setting them later!
24
25 ifneq "$(way)" ""
26   way_ := $(way)_
27   _way := _$(way)
28 endif
29
30 #-----------------------------------------------------------------------------
31 # Haskell Suffix Rules
32
33 %.$(way_)o : %.hs
34         $(HC_PRE_OPTS)
35         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
36         $(HC_POST_OPTS)
37                          
38 %.$(way_)o : %.lhs       
39         $(HC_PRE_OPTS)
40         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
41         $(HC_POST_OPTS)
42                          
43 %.$(way_)hc : %.lhs      
44         $(RM) $@
45         $(HC) $(HC_OPTS) -C $< -o $@
46                          
47 %.$(way_)hc : %.hs       
48         $(RM) $@
49         $(HC) $(HC_OPTS) -C $< -o $@
50                          
51 %.$(way_)o : %.$(way_)hc 
52         $(HC_PRE_OPTS)
53         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
54         $(HC_POST_OPTS)
55
56 %.$(way_)o : %.hc 
57         $(HC_PRE_OPTS)
58         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
59         $(HC_POST_OPTS)
60
61 %.$(way_)s : %.$(way_)hc 
62         $(HC_PRE_OPTS)
63         $(HC) $(HC_OPTS) -S $< -o $@ -osuf $(subst .,,$(suffix $@))
64         $(HC_POST_OPTS)
65
66 %.$(way_)hc : %.lhc
67         @$(RM) $@
68         $(UNLIT) $< $@
69         @chmod 444 $@
70
71
72 # Here's an interesting rule!
73 # The .hi file depends on the .o file,
74 # so if the .hi file is dated earlier than the .o file (commonly the case,
75 # when interfaces are stable) this rule just makes sure that the .o file,
76 # is up to date.  Then it does nothing to generate the .hi file from the 
77 # .o file, because the act of making sure the .o file is up to date also
78 # updates the .hi file (if necessary).
79
80 %.$(way_)hi : %.$(way_)o
81         @if [ ! -f $@ ] ; then \
82             echo Panic! $< exists, but $@ does not. \
83             exit 1; \
84         else exit 0 ; \
85         fi                                                      
86
87 %.$(way_)hi : %.$(way_)hc
88         @if [ ! -f $@ ] ; then \
89             echo Panic! $< exists, but $@ does not. \
90             exit 1; \
91         else exit 0 ; \
92         fi
93
94 #-----------------------------------------------------------------------------
95 # Happy Suffix Rules
96 #
97 .PRECIOUS: %.hs
98
99 %.hs : %.ly
100         $(HAPPY) $(HAPPY_OPTS) $<
101
102 #-----------------------------------------------------------------------------
103 # Lx Suffix Rules
104 #
105
106 %.hs : %.lx
107         $(LX) $(LX_OPTS) $<
108
109 #-----------------------------------------------------------------------------
110 # Green-card Suffix Rules
111 #
112
113 %.hs : %.gc
114         $(GREENCARD) $(GREENCARD_OPTS) $< -o $@
115
116 %.lhs : %.gc
117         $(GREENCARD) $(GREENCARD_OPTS) $< -o $@
118
119 #-----------------------------------------------------------------------------
120 # C-related suffix rules
121
122 %.$(way_)o : %.$(way_)s
123         @$(RM) $@
124         $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
125
126 %.$(way_)o : %.c
127         @$(RM) $@
128         $(CC) $(CC_OPTS) -c $< -o $@
129
130 %.$(way_)o : %.S
131         @$(RM) $@
132         $(CC) $(CC_OPTS) -c $< -o $@
133
134 #%.$(way_)s : %.c
135 #       @$(RM) $@
136 #       $(CC) $(CC_OPTS) -S $< -o $@
137
138 %.c : %.flex
139         @$(RM) $@
140         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
141 %.c : %.lex
142         @$(RM) $@
143         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
144
145 #-----------------------------------------------------------------------------
146 # Yacc stuff
147
148 %.tab.c %.tab.h : %.y
149         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
150         $(YACC) $(YACC_OPTS) $<
151         $(MV) y.tab.c $*.tab.c
152         @chmod 444 $*.tab.c
153         $(MV) y.tab.h $*.tab.h
154         @chmod 444 $*.tab.h
155
156
157 #-----------------------------------------------------------------------------
158 # Runtest rules for calling $(HC) on a single-file Haskell program
159
160 %.runtest : %.hs
161         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
162
163 #-----------------------------------------------------------------------------
164 # Doc processing suffix rules
165 #
166 # ToDo: make these more robust
167 #
168 %.ps : %.dvi
169         @$(RM) $@
170         dvips $< -o $@
171
172 %.tex : %.tib
173         @$(RM) $*.tex $*.verb-t.tex
174         $(TIB) $*.tib
175         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
176         @$(RM) $*.tib-t.tex
177
178 %.ps : %.fig
179         @$(RM) $@
180         fig2dev -L ps $< $@
181
182 %.tex : %.fig
183         @$(RM) $@
184         fig2dev -L latex $< $@
185
186 #-----------------------------------------------------------------------------
187 # SGML suffix rules
188 #
189 %.sgml : %.vsgml
190         @$(RM) $@
191         expand $< | $(SGMLVERB) > $@
192
193 %.dvi : %.sgml
194         @$(RM) $@
195         $(SGML2DVI) $(SGML2DVI_OPTS) $<
196
197 %.ps : %.sgml
198         @$(RM) $@
199         $(SGML2PS) $(SGML2PS_OPTS) $<
200
201 %.html : %.sgml
202         @$(RM) $@
203         $(SGML2HTML) $(SGML2HTML_OPTS) $<
204
205 %.info : %.sgml
206         @$(RM) $@
207         $(SGML2INFO) $(SGML2INFO_OPTS) $<
208
209 %.rtf : %.sgml
210         @$(RM) $@
211         $(SGML2RTF) $(SGML2RTF_OPTS) $<
212
213 #-----------------------------------------------------------------------------
214 # Literate suffix rules
215
216 %.prl : %.lprl
217         @$(RM) $@
218         $(UNLIT) $(UNLIT_OPTS) $< $@
219         @chmod 444 $@
220
221 %.c : %.lc
222         @$(RM) $@
223         $(UNLIT) $(UNLIT_OPTS) $< $@
224         @chmod 444 $@
225
226 %.h : %.lh
227         @$(RM) $@
228         $(UNLIT) $(UNLIT_OPTS) $< $@
229         @chmod 444 $@
230
231 #-----------------------------------------------------------------------------
232 # Win32 resource files
233 #
234 # The default is to use the GNU resource compiler.
235 #
236
237 %.o : %.rc
238         @$(RM) $@
239         windres $< $@