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