[project @ 1999-10-07 13:31:49 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 HC_SPLIT_PRE= \
34  $(RM) $@ ; if [ ! -d $(basename $@) ]; then mkdir $(basename $@); else \
35  find $(basename $@) -name '*.$(way_)o' -print | xargs $(RM) __rm_food ; fi
36 HC_SPLIT_POST  = touch $@
37
38 HC_PRE__       = $(patsubst %,$(HC_SPLIT_PRE) ; ,$(filter -split-objs,$(HC_OPTS)))
39 HC_POST__      = $(patsubst %,$(HC_SPLIT_POST) ; ,$(filter -split-objs,$(HC_OPTS)))
40
41 SRC_HC_POST_OPTS += $(HC_POST__)
42 SRC_HC_PRE_OPTS  += $(HC_PRE__)
43
44 %.$(way_)o : %.hs
45         $(HC_PRE_OPTS)
46         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
47         $(HC_POST_OPTS)
48                          
49 %.$(way_)o : %.lhs       
50         $(HC_PRE_OPTS)
51         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
52         $(HC_POST_OPTS)
53                          
54 %.$(way_)hc : %.lhs      
55         $(RM) $@
56         $(HC) $(HC_OPTS) -C $< -o $@
57                          
58 %.$(way_)hc : %.hs       
59         $(RM) $@
60         $(HC) $(HC_OPTS) -C $< -o $@
61                          
62 %.$(way_)o : %.$(way_)hc 
63         $(HC_PRE_OPTS)
64         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
65         $(HC_POST_OPTS)
66
67 %.$(way_)o : %.hc 
68         $(HC_PRE_OPTS)
69         $(HC) $(HC_OPTS) -c $< -o $@ -osuf $(subst .,,$(suffix $@))
70         $(HC_POST_OPTS)
71
72 %.$(way_)s : %.$(way_)hc 
73         $(HC_PRE_OPTS)
74         $(HC) $(HC_OPTS) -S $< -o $@ -osuf $(subst .,,$(suffix $@))
75         $(HC_POST_OPTS)
76
77 %.$(way_)hc : %.lhc
78         @$(RM) $@
79         $(UNLIT) $< $@
80         @chmod 444 $@
81
82
83 # Here's an interesting rule!
84 # The .hi file depends on the .o file,
85 # so if the .hi file is dated earlier than the .o file (commonly the case,
86 # when interfaces are stable) this rule just makes sure that the .o file,
87 # is up to date.  Then it does nothing to generate the .hi file from the 
88 # .o file, because the act of making sure the .o file is up to date also
89 # updates the .hi file (if necessary).
90
91 %.$(way_)hi : %.$(way_)o
92         @if [ ! -f $@ ] ; then \
93             echo Panic! $< exists, but $@ does not. \
94             exit 1; \
95         else exit 0 ; \
96         fi                                                      
97
98 %.$(way_)hi : %.$(way_)hc
99         @if [ ! -f $@ ] ; then \
100             echo Panic! $< exists, but $@ does not. \
101             exit 1; \
102         else exit 0 ; \
103         fi
104
105 #-----------------------------------------------------------------------------
106 # Happy Suffix Rules
107 #
108 .PRECIOUS: %.hs
109
110 %.hs : %.ly
111         $(HAPPY) $(HAPPY_OPTS) $<
112
113 #-----------------------------------------------------------------------------
114 # Lx Suffix Rules
115 #
116
117 %.hs : %.lx
118         $(LX) $(LX_OPTS) $<
119
120 #-----------------------------------------------------------------------------
121 # Green-card Suffix Rules
122 #
123
124 %.hs : %.gc
125         $(GREENCARD) $(GREENCARD_OPTS) $< -o $@
126
127 %.lhs : %.gc
128         $(GREENCARD) $(GREENCARD_OPTS) $< -o $@
129
130 #-----------------------------------------------------------------------------
131 # C-related suffix rules
132
133 %.$(way_)o : %.$(way_)s
134         @$(RM) $@
135         $(AS) $(AS_OPTS) -o $@ $< || ( $(RM) $@ && exit 1 )
136
137 %.$(way_)o : %.c
138         @$(RM) $@
139         $(CC) $(CC_OPTS) -c $< -o $@
140
141 %.$(way_)o : %.S
142         @$(RM) $@
143         $(CC) $(CC_OPTS) -c $< -o $@
144
145 #%.$(way_)s : %.c
146 #       @$(RM) $@
147 #       $(CC) $(CC_OPTS) -S $< -o $@
148
149 %.c : %.flex
150         @$(RM) $@
151         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
152 %.c : %.lex
153         @$(RM) $@
154         $(FLEX) -t $(FLEX_OPTS) $< > $@ || ( $(RM) $@ && exit 1 )
155
156 #-----------------------------------------------------------------------------
157 # Yacc stuff
158
159 %.tab.c %.tab.h : %.y
160         @$(RM) $*.tab.h $*.tab.c y.tab.c y.tab.h y.output
161         $(YACC) $(YACC_OPTS) $<
162         $(MV) y.tab.c $*.tab.c
163         @chmod 444 $*.tab.c
164         $(MV) y.tab.h $*.tab.h
165         @chmod 444 $*.tab.h
166
167
168 #-----------------------------------------------------------------------------
169 # Runtest rules for calling $(HC) on a single-file Haskell program
170
171 %.runtest : %.hs
172         $(TIME) $(RUNTEST) $(HC) $(RUNTEST_OPTS) $<
173
174 #-----------------------------------------------------------------------------
175 # Doc processing suffix rules
176 #
177 # ToDo: make these more robust
178 #
179 %.dvi : %.tex
180         @$(RM) $@
181         $(LTX) $<
182
183 %.ps : %.dvi
184         @$(RM) $@
185         dvips $< -o $@
186
187 %.tex : %.verb
188         @$(RM) $*.tex
189         expand $*.verb | $(VERBATIM) > $*.tex
190
191 %.tex : %.tib
192         @$(RM) $*.tex $*.verb-t.tex
193         $(TIB) $*.tib
194         expand $*.tib-t.tex | $(VERBATIM) > $*.tex
195         @$(RM) $*.tib-t.tex
196
197 %.ps : %.fig
198         @$(RM) $@
199         fig2dev -L ps $< $@
200
201 %.tex : %.fig
202         @$(RM) $@
203         fig2dev -L latex $< $@
204
205 #-----------------------------------------------------------------------------
206 # SGML suffix rules
207 #
208 %.sgml : %.vsgml
209         @$(RM) $@
210         expand $< | $(SGMLVERB) > $@
211
212 %.tex : %.sgml
213         @$(RM) $@
214         $(SGML2LATEX) $(SGML2LATEX_OPTS) -m --output=tex $<
215
216 %.dvi : %.sgml
217         @$(RM) $@
218         $(SGML2LATEX) $(SGML2LATEX_OPTS) -m --output=dvi $<
219
220 %.ps : %.sgml
221         @$(RM) $@
222         $(SGML2LATEX) $(SGML2LATEX_OPTS) -m --output=ps $<
223
224 %.html : %.sgml
225         @$(RM) $@
226         $(SGML2HTML) $(SGML2HTML_OPTS) $<
227
228 %.info : %.sgml
229         @$(RM) $@
230         $(SGML2INFO) $(SGML2INFO_OPTS) $<
231
232 %.txt : %.sgml
233         @$(RM) $@
234         $(SGML2TXT) $(SGML2TXT_OPTS) $<
235
236 #-----------------------------------------------------------------------------
237 # Literate suffix rules
238
239 %.prl : %.lprl
240         @$(RM) $@
241         $(UNLIT) $(UNLIT_OPTS) $< $@
242         @chmod 444 $@
243
244 %.c : %.lc
245         @$(RM) $@
246         $(UNLIT) $(UNLIT_OPTS) $< $@
247         @chmod 444 $@
248
249 %.h : %.lh
250         @$(RM) $@
251         $(UNLIT) $(UNLIT_OPTS) $< $@
252         @chmod 444 $@
253
254 #-----------------------------------------------------------------------------
255 # Win32 resource files
256 #
257 # The default is to use the GNU resource compiler.
258 #
259
260 %.o : %.rc
261         @$(RM) $@
262         windres $< $@