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