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