[project @ 2001-08-16 22:54:24 by sof]
[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 # Turn off all the Haskell suffix rules if we're booting from .hc
34 # files.  The file bootstrap.mk contains alternative suffix rules in
35 # this case.
36 ifneq "$(BootingFromHc)" "YES"
37
38 %.$(way_)o : %.hs
39         $(HC_PRE_OPTS)
40         $(HC) $(HC_OPTS) -c $< -o $@
41         $(HC_POST_OPTS)
42
43 %.$(way_)o : %.lhs       
44         $(HC_PRE_OPTS)
45         $(HC) $(HC_OPTS) -c $< -o $@
46         $(HC_POST_OPTS)
47
48 %.$(way_)hc : %.lhs      
49         $(RM) $@
50         $(HC) $(HC_OPTS) -C $< -o $@
51
52 %.$(way_)hc : %.hs       
53         $(RM) $@
54         $(HC) $(HC_OPTS) -C $< -o $@
55
56 %.$(way_)o : %.$(way_)hc 
57         $(HC_PRE_OPTS)
58         $(HC) $(HC_OPTS) -c $< -o $@
59         $(HC_POST_OPTS)
60
61 %.$(way_)o : %.hc 
62         $(HC_PRE_OPTS)
63         $(HC) $(HC_OPTS) -c $< -o $@
64         $(HC_POST_OPTS)
65
66 %.$(way_)s : %.$(way_)hc 
67         $(HC_PRE_OPTS)
68         $(HC) $(HC_OPTS) -S $< -o $@
69         $(HC_POST_OPTS)
70
71 %.$(way_)hc : %.lhc
72         @$(RM) $@
73         $(UNLIT) $< $@
74         @chmod 444 $@
75
76
77 # Here's an interesting rule!
78 # The .hi file depends on the .o file,
79 # so if the .hi file is dated earlier than the .o file (commonly the case,
80 # when interfaces are stable) this rule just makes sure that the .o file,
81 # is up to date.  Then it does nothing to generate the .hi file from the 
82 # .o file, because the act of making sure the .o file is up to date also
83 # updates the .hi file (if necessary).
84
85 %.$(way_)hi : %.$(way_)o
86         @if [ ! -f $@ ] ; then \
87             echo Panic! $< exists, but $@ does not.; \
88             exit 1; \
89         else exit 0 ; \
90         fi                                                      
91
92 %.$(way_)hi : %.$(way_)hc
93         @if [ ! -f $@ ] ; then \
94             echo Panic! $< exists, but $@ does not.; \
95             exit 1; \
96         else exit 0 ; \
97         fi
98
99 endif # BootingViaC
100
101 #-----------------------------------------------------------------------------
102 # Happy Suffix Rules
103 #
104 .PRECIOUS: %.hs
105
106 %.hs : %.ly
107         $(HAPPY) $(HAPPY_OPTS) $<
108
109 %.hs : %.y
110         $(HAPPY) $(HAPPY_OPTS) $<
111
112 #-----------------------------------------------------------------------------
113 # hsc2hs Suffix Rules
114 #
115 ifneq "$(BootingFromHc)" "YES"
116 %_hsc.c %_hsc.h %.hs : %.hsc
117         $(HSC2HS) $(HSC2HS_OPTS) $<
118         @touch $(patsubst %.hsc,%_hsc.c,$<)
119 endif
120
121 #-----------------------------------------------------------------------------
122 # Lx Suffix Rules
123 #
124
125 %.hs : %.lx
126         $(LX) $(LX_OPTS) $<
127
128 #-----------------------------------------------------------------------------
129 # Green-card Suffix Rules
130 #
131
132 .PRECIOUS: %.gc
133
134 %.hs : %.gc
135         $(GREENCARD) $(GC_OPTS) $< -o $@
136
137 %.lhs : %.gc
138         $(GREENCARD) $(GC_OPTS) $< -o $@
139
140 %.gc : %.pgc
141         $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
142
143 #-----------------------------------------------------------------------------
144 # C-related suffix rules
145
146 %.$(way_)o : %.$(way_)s
147         @$(RM) $@
148         $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
149
150 %.$(way_)o : %.c
151         @$(RM) $@
152         $(CC) $(CC_OPTS) -c $< -o $@
153
154 %.$(way_)o : %.S
155         @$(RM) $@
156         $(CC) $(CC_OPTS) -c $< -o $@
157
158 #%.$(way_)s : %.c
159 #       @$(RM) $@
160 #       $(CC) $(CC_OPTS) -S $< -o $@
161
162 %.c : %.flex
163         @$(RM) $@
164         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
165 %.c : %.lex
166         @$(RM) $@
167         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
168
169 # stubs are automatically generated and compiled by GHC
170 %_stub.$(way_)o: %.o
171         @:
172
173 #-----------------------------------------------------------------------------
174 # Yacc stuff
175
176 %.tab.c %.tab.h : %.y
177         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
178         $(YACC) $(YACC_OPTS) $<
179         $(MV) y.tab.c $*.tab.c
180         @chmod 444 $*.tab.c
181         $(MV) y.tab.h $*.tab.h
182         @chmod 444 $*.tab.h
183
184
185 #-----------------------------------------------------------------------------
186 # Runtest rules for calling $(HC) on a single-file Haskell program
187
188 %.runtest : %.hs
189         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
190
191 #-----------------------------------------------------------------------------
192 # Doc processing suffix rules
193 #
194 # ToDo: make these more robust
195 #
196 %.ps : %.dvi
197         @$(RM) $@
198         dvips $< -o $@
199
200 %.tex : %.tib
201         @$(RM) $*.tex $*.verb-t.tex
202         $(TIB) $*.tib
203         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
204         @$(RM) $*.tib-t.tex
205
206 %.ps : %.fig
207         @$(RM) $@
208         fig2dev -L ps $< $@
209
210 %.tex : %.fig
211         @$(RM) $@
212         fig2dev -L latex $< $@
213
214 #-----------------------------------------------------------------------------
215 # SGML suffix rules
216 #
217 %.dvi : %.sgml
218         @$(RM) $@
219         $(SGML2DVI) $(SGML2DVI_OPTS) $<
220
221 %.ps : %.sgml
222         @$(RM) $@
223         $(SGML2PS) $(SGML2PS_OPTS) $<
224
225 %.html : %.sgml
226         @$(RM) $@
227 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
228 #       $(JADE) -t sgml -V html-index -d $(SGMLSTYLESHEET) -c $(DOCBOOK_CATALOG) $<
229 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
230         $(SGML2HTML) $(SGML2HTML_OPTS) $<
231
232 %.html : %.tex
233         @$(RM) $@
234         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
235         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
236         $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
237 # Run HeVeA twice to resolve labels
238
239 %.rtf : %.sgml
240         @$(RM) $@
241         $(SGML2RTF) $(SGML2RTF_OPTS) $<
242
243 %.pdf : %.sgml
244         @$(RM) $@
245         $(SGML2PDF) $(SGML2PDF_OPTS) $<
246
247 #-----------------------------------------------------------------------------
248 # Literate suffix rules
249
250 %.prl : %.lprl
251         @$(RM) $@
252         $(UNLIT) $(UNLIT_OPTS) $< $@
253         @chmod 444 $@
254
255 %.c : %.lc
256         @$(RM) $@
257         $(UNLIT) $(UNLIT_OPTS) $< $@
258         @chmod 444 $@
259
260 %.h : %.lh
261         @$(RM) $@
262         $(UNLIT) $(UNLIT_OPTS) $< $@
263         @chmod 444 $@
264
265 #-----------------------------------------------------------------------------
266 # Win32 resource files
267 #
268 # The default is to use the GNU resource compiler.
269 #
270
271 %.$(way_)o : %.$(way_)rc
272         @$(RM) $@
273         windres $< $@
274
275 #-----------------------------------------------------------------------------
276 # Preprocessor suffix rule
277
278 % : %.pp
279         rm -f $@
280         $(CPP) $(CPP_OPTS) -x c $< | $(SED) -e '/^#/d' > $@