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