[project @ 2000-09-29 15:59:28 by sewardj]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.93 2000/09/29 15:59:28 sewardj Exp $
3
4 TOP = ..
5 include $(TOP)/mk/boilerplate.mk
6
7 #-----------------------------------------------------------------------------
8 # Building hsc different ways (default is just `normal' sequential)
9 WAYS=$(GhcCompilerWays)
10
11 # -----------------------------------------------------------------------------
12 #               Set HS_PROG, LIBRARY
13
14 # Note: there have been reports of people running up against the ARG_MAX limit
15 # when linking hsc with all its constituent object files. The likely source of 
16 # the problem is that the environment is a bit too big, so a workaround could
17 # be to do ` env PATH=$(PATH) make hsc 'to minimise the environment. (or the
18 # equivalent of `env' if it doesn't exist locally).
19 #
20 ifneq "$(way)" "dll"
21 HS_PROG=hsc$(_way)
22 else
23 HS_PROG=hsc
24 endif
25
26
27 # -----------------------------------------------------------------------------
28 #               Compilation history for Patrick
29
30 # Make the sources first, because that's what the compilation history needs
31 $(HS_PROG) :: $(HS_SRCS)
32
33
34 # -----------------------------------------------------------------------------
35 #               Set SRCS, LOOPS, HCS, OBJS
36 #
37 # First figure out DIRS, the source sub-directories
38 # Then derive SRCS by looking in them
39 #
40
41 DIRS = \
42   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
43   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
44   profiling parser usageSP cprAnalysis javaGen ghci
45
46
47 ifeq ($(GhcWithNativeCodeGen),YES)
48 DIRS += nativeGen
49 else
50 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
51 ifeq ($(GhcWithIlx),YES)
52 DIRS += ilxGen
53 SRC_HC_OPTS += -DILX
54 endif
55 endif
56
57
58 HS_SRCS = $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
59
60 ifneq "$(GhcWithHscBuiltViaC)" "YES"
61 HS_SRCS += rename/ParseIface.hs parser/Parser.hs
62 endif
63
64 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
65
66 # ParseIface.hs ain't part of HS_SRCS when this is on..
67 ifeq "$(GhcWithHscBuiltViaC)" "YES"
68 HCS      += rename/ParseIface.hc parser/Parser.hc
69 endif
70
71 HS_OBJS  = \
72   $(patsubst %.hc, %.o, $(HCS)) \
73   parser/hschooks.o
74
75
76 DESTDIR       = $(INSTALL_LIBRARY_DIR_GHC)
77
78 #
79 # Add misc .c helper code (used by the frontend.)
80 #
81 C_SRCS += parser/hschooks.c
82
83 #
84 # Big Fudge to get around inherent problem that Makefile setup
85 # has got with 'mkdependC'.
86
87 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
88
89 # stuff you get for free in a source distribution
90
91 # SRC_DIST_FILES += rename/ParseIface.hs rename/Parser.hs
92
93 # -----------------------------------------------------------------------------
94 #               Haskell compilations
95
96 #
97 # Compiler to use for building hsc, use the build tree
98 # driver when booting.
99 #
100 ifneq "$(GhcWithHscBuiltViaC)" "YES"
101 HC=$(WithGhcHc)
102 else
103 HC=$(GHC_INPLACE)
104 endif
105
106 # magic from GNU make manual to convert a list of values
107 # into a colon-separated list
108 empty:=
109 space:= $(empty) $(empty)
110
111 SRC_HC_OPTS += \
112   -cpp -fglasgow-exts -Rghc-timing \
113   -I. -IcodeGen -InativeGen -Iparser \
114   -i$(subst $(space),:,$(DIRS)) 
115
116 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
117
118 SRC_HC_OPTS += -recomp $(GhcHcOpts)
119
120 #       Special flags for particular modules
121 #       The standard suffix rule for compiling a Haskell file
122 #       adds these flags to the command line
123
124 # Was 6m with 2.10
125 absCSyn/PprAbsC_HC_OPTS         = -H10m
126
127 basicTypes/IdInfo_HC_OPTS       = -K2m
128 codeGen/CgCase_HC_OPTS          = -fno-prune-tydecls
129 hsSyn/HsExpr_HC_OPTS            = -K2m
130 main/Main_HC_OPTS               = 
131 main/Constants_HC_OPTS          = -DHscIfaceFileVersion=$(HscIfaceFileVersion)
132
133 ifneq "$(GhcWithHscBuiltViaC)" "YES"
134 ifeq "$(GhcReportCompiles)" "YES"
135 main/Main_HC_OPTS               += -syslib misc -DREPORT_TO_MOTHERLODE
136 endif
137 endif
138
139 main/CmdLineOpts_HC_OPTS        =  -K6m
140 nativeGen/PprMach_HC_OPTS       = -K2m
141 nativeGen/MachMisc_HC_OPTS      = -K2m 
142 nativeGen/MachCode_HC_OPTS      = -H10m
143
144 # Avoids Bug in 3.02, it seems
145 usageSP/UsageSPInf_HC_OPTS      = -Onot
146
147 prelude/PrimOp_HC_OPTS          = -H12m -K3m
148 prelude/PrelRules_HC_OPTS       = -fvia-C
149
150 parser/Lex_HC_OPTS              = -fvia-C -K2m -H16m 
151 parser/Ctype_HC_OPTS            = -K2m -fvia-C
152
153 rename/ParseIface_HC_OPTS       += -Onot -H45m -K2m -fno-warn-incomplete-patterns
154
155 parser/Parser_HC_OPTS           += -Onot -H80m -optCrts-M80m -K2m -fno-warn-incomplete-patterns
156
157 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
158 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
159 endif
160
161 rename/RnEnv_HC_OPTS            = 
162 rename/RnSource_HC_OPTS         = -H12m
163 rename/RnIfaces_HC_OPTS         = -H8m 
164 rename/RnExpr_HC_OPTS           = -H10m
165 rename/RnNames_HC_OPTS          = -H12m
166 rename/RnMonad_HC_OPTS          = 
167 specialise/Specialise_HC_OPTS   = -Onot -H12m
168 simplCore/Simplify_HC_OPTS      = -H15m 
169 simplCore/OccurAnal_HC_OPTS     = -H10m
170 typecheck/TcGenDeriv_HC_OPTS    = -H10m
171
172 # tmp, -- SDM
173 specialise/Specialise_HC_OPTS   += -fno-prune-tydecls
174 hsSyn/HsBasic_HC_OPTS           += -fno-prune-tydecls
175 simplCore/SimplMonad_HC_OPTS    += -fno-prune-tydecls
176 absCSyn/AbsCSyn_HC_OPTS         += -fno-prune-tydecls
177 absCSyn/AbsCUtils_HC_OPTS       += -fno-prune-tydecls
178 codeGen/CgBindery_HC_OPTS       += -fno-prune-tydecls
179 codeGen/CgLetNoEscape_HC_OPTS   += -fno-prune-tydecls
180 codeGen/CgExpr_HC_OPTS          += -fno-prune-tydecls
181 nativeGen/AbsCStixGen_HC_OPTS   += -fno-prune-tydecls
182
183 # Was 10m for 2.10
184 typecheck/TcHsSyn_HC_OPTS       = -H15m 
185
186
187 # Was 10m for 2.10
188 typecheck/TcExpr_HC_OPTS        = -H15m
189 typecheck/TcBinds_HC_OPTS       = -H10m
190
191 typecheck/TcEnv_HC_OPTS         = -H10m
192 utils/Argv_HC_OPTS              = -fvia-C
193 utils/SST_HC_OPTS               = 
194 utils/StringBuffer_HC_OPTS      = -fvia-C -fno-prune-tydecls
195 utils/Digraph_HC_OPTS           = -fglasgow-exts 
196 utils/DirUtils_HC_OPTS          = 
197
198 # temporary, due to bug in NCG  (SDM, 1/6/2000)
199 utils/FastString_HC_OPTS        = -fvia-C
200
201 ifeq "$(alpha_HOST_ARCH)" "1"
202 # "stbu" bug in alpha native code generator...
203 basicTypes/Unique_HC_OPTS       = 
204 endif
205
206 # flags for PrimPacked:
207 #
208 # -monly-3-regs 
209 #       because it contains a 'ccall strlen', which gets inlined by
210 #       gcc, causing a lack of registers.
211 #
212 # -optC-funfolding-interface-threshold7
213 #       To stop the definition of 'strLength', which calls strlen, getting
214 #       into the interface file and spreading the -monly-3-regs virus.
215 #       We need -optC here because the driver before 3.02 didn't understand
216 #       the -funfolding flags.
217
218 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs -optC-funfolding-interface-threshold7
219
220 # Strictness analyser misbehaving in 2.10, fails to terminate on
221 # UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
222 # separate bugfix to the fixpoint finder.
223 simplStg/UpdAnal_HC_OPTS        = -fno-strictness
224
225 stgSyn/StgInterp_HC_OPTS        = -fvia-C
226
227 # ----------------------------------------------------------------------------
228 #               C compilations
229
230 SRC_C_OPTS     += -O -I. -IcodeGen
231
232
233 # ----------------------------------------------------------------------------
234 #               Generate supporting stuff for prelude/PrimOp.lhs 
235 #               from prelude/primops.txt
236
237 GENPOC=$(TOP)/utils/genprimopcode/genprimopcode
238
239 PRIMOP_BITS=primop-data-decl.hs-incl \
240             primop-tag.hs-incl  \
241             primop-list.hs-incl  \
242             primop-has-side-effects.hs-incl  \
243             primop-out-of-line.hs-incl  \
244             primop-commutable.hs-incl  \
245             primop-needs-wrapper.hs-incl  \
246             primop-can-fail.hs-incl  \
247             primop-strictness.hs-incl  \
248             primop-usage.hs-incl  \
249             primop-primop-info.hs-incl
250
251 prelude/PrimOp.o: $(PRIMOP_BITS)
252
253 depend :: $(PRIMOP_BITS)
254
255 primop-data-decl.hs-incl: prelude/primops.txt
256         $(GENPOC) --data-decl          < $< > $@
257 primop-tag.hs-incl: prelude/primops.txt
258         $(GENPOC) --primop-tag         < $< > $@
259 primop-list.hs-incl: prelude/primops.txt
260         $(GENPOC) --primop-list        < $< > $@
261 primop-has-side-effects.hs-incl: prelude/primops.txt
262         $(GENPOC) --has-side-effects   < $< > $@
263 primop-out-of-line.hs-incl: prelude/primops.txt
264         $(GENPOC) --out-of-line        < $< > $@
265 primop-commutable.hs-incl: prelude/primops.txt
266         $(GENPOC) --commutable         < $< > $@
267 primop-needs-wrapper.hs-incl: prelude/primops.txt
268         $(GENPOC) --needs-wrapper      < $< > $@
269 primop-can-fail.hs-incl: prelude/primops.txt
270         $(GENPOC) --can-fail           < $< > $@
271 primop-strictness.hs-incl: prelude/primops.txt
272         $(GENPOC) --strictness         < $< > $@
273 primop-usage.hs-incl: prelude/primops.txt
274         $(GENPOC) --usage              < $< > $@
275 primop-primop-info.hs-incl: prelude/primops.txt
276         $(GENPOC) --primop-primop-info < $< > $@
277
278
279
280 # ----------------------------------------------------------------------------
281 #               Parsers/lexers
282
283 parser/hschooks.o : parser/hschooks.c
284         @$(RM) $@
285         $(HC) -c -o $@ $(HC_OPTS) parser/hschooks.c
286
287
288 # Interface-file parser uses Happy
289 SRC_HAPPY_OPTS += +RTS -K2m -H16m -RTS  $(GHC_HAPPY_OPTS)
290
291 rename/ParseIface.hs : rename/ParseIface.y
292         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
293         $(HAPPY) $(HAPPY_OPTS) rename/ParseIface.y
294         @chmod 444 rename/ParseIface.hs
295
296 parser/Parser.hs : parser/Parser.y
297         @$(RM) parser/Parser.hs parser/ParseIface.hinfo
298         $(HAPPY) $(HAPPY_OPTS) parser/Parser.y
299         @chmod 444 parser/Parser.hs
300
301 #-----------------------------------------------------------------------------
302 #               Linking
303
304 SRC_LD_OPTS += -no-link-chk
305
306 ifneq "$(GhcWithHscBuiltViaC)" "YES"
307 ifeq "$(GhcReportCompiles)" "YES"
308 SRC_LD_OPTS += -syslib misc -syslib exts
309 endif
310 endif
311
312 #-----------------------------------------------------------------------------
313 #               install
314
315 # We don't want hsc treated as an ordinary executable,
316 # but put it together with the libraries.
317 # Also don't want any interface files intstalled
318
319 INSTALL_LIBEXECS += hsc
320
321 #-----------------------------------------------------------------------------
322 #               depend
323
324 #
325 # Before doing `make depend', need to build all derived Haskell source files
326 #
327 depend :: $(LOOPS)
328
329 ifneq "$(GhcWithHscBuiltViaC)" "YES"
330 depend :: rename/ParseIface.hs
331 endif
332
333 #-----------------------------------------------------------------------------
334 #               clean
335
336 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi)
337 CLEAN_FILES += $(PRIMOP_BITS)
338
339 # Extra tidy, remove the .hc files (if you've got them).
340 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc) \
341         parser/Parser.hs rename/ParseIface.hs
342
343
344 #-----------------------------------------------------------------------------
345 #               TAGS setup
346
347 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
348 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
349 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
350
351 #-----------------------------------------------------------------------------
352 #               Include target-rule boilerplate
353
354 include $(TOP)/mk/target.mk
355
356 parser/%.o : parser/%.c
357