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