[project @ 2001-03-29 17:56:18 by qrczak]
[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 $@ -osuf $(subst .,,$(suffix $@))
41         $(HC_POST_OPTS)
42
43 %.$(way_)o : %.lhs       
44         $(HC_PRE_OPTS)
45         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
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 $@ -osuf $(subst .,,$(suffix $@))
59         $(HC_POST_OPTS)
60
61 %.$(way_)o : %.hc 
62         $(HC_PRE_OPTS)
63         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
64         $(HC_POST_OPTS)
65
66 %.$(way_)s : %.$(way_)hc 
67         $(HC_PRE_OPTS)
68         $(HC) $(HC_OPTS) -S $< -o $@ -osuf $(subst .,,$(suffix $@))
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 %_hsc.c %_hsc.h %.hs : %.hsc
116         $(HSC2HS) $<
117
118 #-----------------------------------------------------------------------------
119 # Lx Suffix Rules
120 #
121
122 %.hs : %.lx
123         $(LX) $(LX_OPTS) $<
124
125 #-----------------------------------------------------------------------------
126 # Green-card Suffix Rules
127 #
128
129 .PRECIOUS: %.gc
130
131 %.hs : %.gc
132         $(GREENCARD) $(GC_OPTS) $< -o $@
133
134 %.lhs : %.gc
135         $(GREENCARD) $(GC_OPTS) $< -o $@
136
137 %.gc : %.pgc
138         $(CPP) $(GC_CPP_OPTS) $< | perl -pe 's#\\n#\n#g' > $@
139
140 #-----------------------------------------------------------------------------
141 # C-related suffix rules
142
143 %.$(way_)o : %.$(way_)s
144         @$(RM) $@
145         $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
146
147 %.$(way_)o : %.c
148         @$(RM) $@
149         $(CC) $(CC_OPTS) -c $< -o $@
150
151 %.$(way_)o : %.S
152         @$(RM) $@
153         $(CC) $(CC_OPTS) -c $< -o $@
154
155 #%.$(way_)s : %.c
156 #       @$(RM) $@
157 #       $(CC) $(CC_OPTS) -S $< -o $@
158
159 %.c : %.flex
160         @$(RM) $@
161         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
162 %.c : %.lex
163         @$(RM) $@
164         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
165
166 # stubs are automatically generated and compiled by GHC
167 %_stub.$(way_)o: %.o
168         @:
169
170 #-----------------------------------------------------------------------------
171 # Yacc stuff
172
173 %.tab.c %.tab.h : %.y
174         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
175         $(YACC) $(YACC_OPTS) $<
176         $(MV) y.tab.c $*.tab.c
177         @chmod 444 $*.tab.c
178         $(MV) y.tab.h $*.tab.h
179         @chmod 444 $*.tab.h
180
181
182 #-----------------------------------------------------------------------------
183 # Runtest rules for calling $(HC) on a single-file Haskell program
184
185 %.runtest : %.hs
186         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
187
188 #-----------------------------------------------------------------------------
189 # Doc processing suffix rules
190 #
191 # ToDo: make these more robust
192 #
193 %.ps : %.dvi
194         @$(RM) $@
195         dvips $< -o $@
196
197 %.tex : %.tib
198         @$(RM) $*.tex $*.verb-t.tex
199         $(TIB) $*.tib
200         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
201         @$(RM) $*.tib-t.tex
202
203 %.ps : %.fig
204         @$(RM) $@
205         fig2dev -L ps $< $@
206
207 %.tex : %.fig
208         @$(RM) $@
209         fig2dev -L latex $< $@
210
211 #-----------------------------------------------------------------------------
212 # SGML suffix rules
213 #
214 %.dvi : %.sgml
215         @$(RM) $@
216         $(SGML2DVI) $(SGML2DVI_OPTS) $<
217
218 %.ps : %.sgml
219         @$(RM) $@
220         $(SGML2PS) $(SGML2PS_OPTS) $<
221
222 %.html : %.sgml
223         @$(RM) $@
224 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
225 #       $(JADE) -t sgml -V html-index -d $(SGMLSTYLESHEET) -c $(DOCBOOK_CATALOG) $<
226 #       $(PERL) $(COLLATEINDEX) -N -o index.sgml
227         $(SGML2HTML) $(SGML2HTML_OPTS) $<
228
229 %.html : %.tex
230         @$(RM) $@
231         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
232         $(HEVEA) $(HEVEA_OPTS) $(patsubst %.tex,%.hva,$<) $<
233         $(HACHA) $(HACHA_OPTS) $(patsubst %.tex,%.html,$<)
234 # Run HeVeA twice to resolve labels
235
236 %.rtf : %.sgml
237         @$(RM) $@
238         $(SGML2RTF) $(SGML2RTF_OPTS) $<
239
240 #-----------------------------------------------------------------------------
241 # Literate suffix rules
242
243 %.prl : %.lprl
244         @$(RM) $@
245         $(UNLIT) $(UNLIT_OPTS) $< $@
246         @chmod 444 $@
247
248 %.c : %.lc
249         @$(RM) $@
250         $(UNLIT) $(UNLIT_OPTS) $< $@
251         @chmod 444 $@
252
253 %.h : %.lh
254         @$(RM) $@
255         $(UNLIT) $(UNLIT_OPTS) $< $@
256         @chmod 444 $@
257
258 #-----------------------------------------------------------------------------
259 # Win32 resource files
260 #
261 # The default is to use the GNU resource compiler.
262 #
263
264 %.$(way_)o : %.$(way_)rc
265         @$(RM) $@
266         windres $< $@