[project @ 2000-10-10 13:13:17 by simonmar]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.94 2000/10/10 13:13:17 simonmar 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 # Create compiler configuration
28
29 CONFIG_HS = main/Config.hs
30 boot :: $(CONFIG_HS)
31
32 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
33         @$(RM) -f $(CONFIG_HS)
34         @echo -n "Creating $(CONFIG_HS) ... "
35         @echo "module Config where" >>$(CONFIG_HS)
36         @echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
37         @echo "cProjectVersion       = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
38         @echo "cProjectVersionInt    = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
39         @echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
40         @echo "cHOSTPLATFORM         = \"$(HOSTPLATFORM)\"" >> $(CONFIG_HS)
41         @echo "cTARGETPLATFORM       = \"$(TARGETPLATFORM)\"" >> $(CONFIG_HS)
42         @echo "cCURRENT_DIR          = \"$(CURRENT_DIR)\"" >> $(CONFIG_HS)
43         @echo "cGHC_LIB_DIR          = \"$(GHC_LIB_DIR)\"" >> $(CONFIG_HS)
44         @echo "cGHC_RUNTIME_DIR      = \"$(GHC_RUNTIME_DIR)\"" >> $(CONFIG_HS)
45         @echo "cGHC_UTILS_DIR        = \"$(GHC_UTILS_DIR)\"" >> $(CONFIG_HS)
46         @echo "cGHC_INCLUDE_DIR      = \"$(GHC_INCLUDE_DIR)\"" >> $(CONFIG_HS)
47         @echo "cGHC_DRIVER_DIR       = \"$(GHC_DRIVER_DIR)\"" >> $(CONFIG_HS)
48         @echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
49         @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
50         @echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
51         @echo "cGHC_UNLIT            = \"$(GHC_UNLIT)\"" >> $(CONFIG_HS)
52         @echo "cGHC_HSC              = \"$(GHC_HSC)\"" >> $(CONFIG_HS)
53         @echo "cGHC_MANGLER          = \"$(GHC_MANGLER)\"" >> $(CONFIG_HS)
54         @echo "cGHC_SPLIT            = \"$(GHC_SPLIT)\"" >> $(CONFIG_HS)
55         @echo "cGHC_STATS            = \"$(GHC_STATS)\"" >> $(CONFIG_HS)
56         @echo "cGHC_SYSMAN           = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
57         @echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
58         @echo "cCP                   = \"$(CP)\"" >> $(CONFIG_HS)
59         @echo "cRM                   = \"$(RM)\"" >> $(CONFIG_HS)
60         @echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
61         @echo "cHaveLibGmp           = \"$(HaveLibGmp)\"" >> $(CONFIG_HS)
62         @echo "cGhcWithRegisterised  = \"$(GhcWithRegisterised)\"" >> $(CONFIG_HS)
63         @echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
64         @echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
65         @echo "clibdir               = \"$(libdir)\"" >> $(CONFIG_HS)
66         @echo "clibexecdir           = \"$(libexecdir)\"" >> $(CONFIG_HS)
67         @echo "cdatadir              = \"$(datadir)\"" >> $(CONFIG_HS)
68         @echo "cbindir               = \"$(bindir)\"" >> $(CONFIG_HS)
69         @echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
70         @echo "cFPTOOLS_TOP_ABS      = \"$(FPTOOLS_TOP_ABS)\"" >> $(CONFIG_HS)
71         @echo "cRAWCPP               = \"$(RAWCPP)\"" >> $(CONFIG_HS)
72         @echo done.
73
74 CLEAN_FILES += $(CONFIG_HS)
75
76 # -----------------------------------------------------------------------------
77 #               Compilation history for Patrick
78
79 # Make the sources first, because that's what the compilation history needs
80 $(HS_PROG) :: $(HS_SRCS)
81
82
83 # -----------------------------------------------------------------------------
84 #               Set SRCS, LOOPS, HCS, OBJS
85 #
86 # First figure out DIRS, the source sub-directories
87 # Then derive SRCS by looking in them
88 #
89
90 DIRS = \
91   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
92   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
93   profiling parser usageSP cprAnalysis javaGen ghci
94
95
96 ifeq ($(GhcWithNativeCodeGen),YES)
97 DIRS += nativeGen
98 else
99 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
100 ifeq ($(GhcWithIlx),YES)
101 DIRS += ilxGen
102 SRC_HC_OPTS += -DILX
103 endif
104 endif
105
106
107 HS_SRCS = $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs) $(wildcard $(dir)/*.hs))
108
109 ifneq "$(GhcWithHscBuiltViaC)" "YES"
110 HS_SRCS += rename/ParseIface.hs parser/Parser.hs
111 endif
112
113 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
114
115 # ParseIface.hs ain't part of HS_SRCS when this is on..
116 ifeq "$(GhcWithHscBuiltViaC)" "YES"
117 HCS      += rename/ParseIface.hc parser/Parser.hc
118 endif
119
120 HS_OBJS  = \
121   $(patsubst %.hc, %.o, $(HCS)) \
122   parser/hschooks.o
123
124
125 DESTDIR       = $(INSTALL_LIBRARY_DIR_GHC)
126
127 #
128 # Add misc .c helper code (used by the frontend.)
129 #
130 C_SRCS += parser/hschooks.c
131
132 #
133 # Big Fudge to get around inherent problem that Makefile setup
134 # has got with 'mkdependC'.
135
136 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
137
138 # stuff you get for free in a source distribution
139
140 # SRC_DIST_FILES += rename/ParseIface.hs rename/Parser.hs
141
142 # -----------------------------------------------------------------------------
143 #               Haskell compilations
144
145 #
146 # Compiler to use for building hsc, use the build tree
147 # driver when booting.
148 #
149 ifneq "$(GhcWithHscBuiltViaC)" "YES"
150 HC=$(WithGhcHc)
151 else
152 HC=$(GHC_INPLACE)
153 endif
154
155 # magic from GNU make manual to convert a list of values
156 # into a colon-separated list
157 empty:=
158 space:= $(empty) $(empty)
159
160 SRC_HC_OPTS += \
161   -cpp -fglasgow-exts \
162   -Rghc-timing -I. -IcodeGen -InativeGen -Iparser \
163   -i$(subst $(space),:,$(DIRS)) 
164
165 ghc_407_at_least = $(shell expr "$(GhcMinVersion)" \>= 7)
166 ifeq "$(ghc_407_at_least)" "1"
167 ifneq "$(mingw32_TARGET_OS)" "1"
168 SRC_HC_OPTS += -package concurrent -package posix -package text
169 else
170 SRC_HC_OPTS += -package concurrent -package text
171 endif
172 else
173 SRC_HC_OPTS += -syslib concurrent -syslib posix -syslib misc
174 endif
175
176 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
177
178 SRC_HC_OPTS += -recomp $(GhcHcOpts)
179
180 #       Special flags for particular modules
181 #       The standard suffix rule for compiling a Haskell file
182 #       adds these flags to the command line
183
184 # Was 6m with 2.10
185 absCSyn/PprAbsC_HC_OPTS         = -H10m
186
187 basicTypes/IdInfo_HC_OPTS       = -K2m
188 codeGen/CgCase_HC_OPTS          = -fno-prune-tydecls
189 hsSyn/HsExpr_HC_OPTS            = -K2m
190 main/Main_HC_OPTS               = 
191 main/Constants_HC_OPTS          = -DHscIfaceFileVersion=$(HscIfaceFileVersion)
192
193 ifneq "$(GhcWithHscBuiltViaC)" "YES"
194 ifeq "$(GhcReportCompiles)" "YES"
195 main/Main_HC_OPTS               += -syslib misc -DREPORT_TO_MOTHERLODE
196 endif
197 endif
198
199 main/CmdLineOpts_HC_OPTS        =  -K6m
200 nativeGen/PprMach_HC_OPTS       = -K2m
201 nativeGen/MachMisc_HC_OPTS      = -K2m 
202 nativeGen/MachCode_HC_OPTS      = -H10m
203
204 # Avoids Bug in 3.02, it seems
205 usageSP/UsageSPInf_HC_OPTS      = -Onot
206
207 prelude/PrimOp_HC_OPTS          = -H12m -K3m
208 prelude/PrelRules_HC_OPTS       = -fvia-C
209
210 parser/Lex_HC_OPTS              = -fvia-C -K2m -H16m 
211 parser/Ctype_HC_OPTS            = -K2m -fvia-C
212
213 rename/ParseIface_HC_OPTS       += -Onot -H45m -K2m -fno-warn-incomplete-patterns
214
215 parser/Parser_HC_OPTS           += -Onot -H80m -optCrts-M80m -K2m -fno-warn-incomplete-patterns
216
217 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
218 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
219 endif
220
221 rename/RnEnv_HC_OPTS            = 
222 rename/RnSource_HC_OPTS         = -H12m
223 rename/RnIfaces_HC_OPTS         = -H8m 
224 rename/RnExpr_HC_OPTS           = -H10m
225 rename/RnNames_HC_OPTS          = -H12m
226 rename/RnMonad_HC_OPTS          = 
227 specialise/Specialise_HC_OPTS   = -Onot -H12m
228 simplCore/Simplify_HC_OPTS      = -H15m 
229 simplCore/OccurAnal_HC_OPTS     = -H10m
230 typecheck/TcGenDeriv_HC_OPTS    = -H10m
231
232 # tmp, -- SDM
233 specialise/Specialise_HC_OPTS   += -fno-prune-tydecls
234 hsSyn/HsBasic_HC_OPTS           += -fno-prune-tydecls
235 simplCore/SimplMonad_HC_OPTS    += -fno-prune-tydecls
236 absCSyn/AbsCSyn_HC_OPTS         += -fno-prune-tydecls
237 absCSyn/AbsCUtils_HC_OPTS       += -fno-prune-tydecls
238 codeGen/CgBindery_HC_OPTS       += -fno-prune-tydecls
239 codeGen/CgLetNoEscape_HC_OPTS   += -fno-prune-tydecls
240 codeGen/CgExpr_HC_OPTS          += -fno-prune-tydecls
241 nativeGen/AbsCStixGen_HC_OPTS   += -fno-prune-tydecls
242
243 # Was 10m for 2.10
244 typecheck/TcHsSyn_HC_OPTS       = -H15m 
245
246
247 # Was 10m for 2.10
248 typecheck/TcExpr_HC_OPTS        = -H15m
249 typecheck/TcBinds_HC_OPTS       = -H10m
250
251 typecheck/TcEnv_HC_OPTS         = -H10m
252 utils/Argv_HC_OPTS              = -fvia-C
253 utils/SST_HC_OPTS               = 
254 utils/StringBuffer_HC_OPTS      = -fvia-C -fno-prune-tydecls
255 utils/Digraph_HC_OPTS           = -fglasgow-exts 
256 utils/DirUtils_HC_OPTS          = 
257
258 # temporary, due to bug in NCG  (SDM, 1/6/2000)
259 utils/FastString_HC_OPTS        = -fvia-C
260
261 ifeq "$(alpha_HOST_ARCH)" "1"
262 # "stbu" bug in alpha native code generator...
263 basicTypes/Unique_HC_OPTS       = 
264 endif
265
266 # flags for PrimPacked:
267 #
268 # -monly-3-regs 
269 #       because it contains a 'ccall strlen', which gets inlined by
270 #       gcc, causing a lack of registers.
271 #
272 # -optC-funfolding-interface-threshold7
273 #       To stop the definition of 'strLength', which calls strlen, getting
274 #       into the interface file and spreading the -monly-3-regs virus.
275 #       We need -optC here because the driver before 3.02 didn't understand
276 #       the -funfolding flags.
277
278 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs -optC-funfolding-interface-threshold7
279
280 # Strictness analyser misbehaving in 2.10, fails to terminate on
281 # UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
282 # separate bugfix to the fixpoint finder.
283 simplStg/UpdAnal_HC_OPTS        = -fno-strictness
284
285 stgSyn/StgInterp_HC_OPTS        = -fvia-C
286
287 # ----------------------------------------------------------------------------
288 #               C compilations
289
290 SRC_C_OPTS     += -O -I. -IcodeGen
291
292
293 # ----------------------------------------------------------------------------
294 #               Generate supporting stuff for prelude/PrimOp.lhs 
295 #               from prelude/primops.txt
296
297 GENPOC=$(TOP)/utils/genprimopcode/genprimopcode
298
299 PRIMOP_BITS=primop-data-decl.hs-incl \
300             primop-tag.hs-incl  \
301             primop-list.hs-incl  \
302             primop-has-side-effects.hs-incl  \
303             primop-out-of-line.hs-incl  \
304             primop-commutable.hs-incl  \
305             primop-needs-wrapper.hs-incl  \
306             primop-can-fail.hs-incl  \
307             primop-strictness.hs-incl  \
308             primop-usage.hs-incl  \
309             primop-primop-info.hs-incl
310
311 prelude/PrimOp.o: $(PRIMOP_BITS)
312
313 depend :: $(PRIMOP_BITS)
314
315 primop-data-decl.hs-incl: prelude/primops.txt
316         $(GENPOC) --data-decl          < $< > $@
317 primop-tag.hs-incl: prelude/primops.txt
318         $(GENPOC) --primop-tag         < $< > $@
319 primop-list.hs-incl: prelude/primops.txt
320         $(GENPOC) --primop-list        < $< > $@
321 primop-has-side-effects.hs-incl: prelude/primops.txt
322         $(GENPOC) --has-side-effects   < $< > $@
323 primop-out-of-line.hs-incl: prelude/primops.txt
324         $(GENPOC) --out-of-line        < $< > $@
325 primop-commutable.hs-incl: prelude/primops.txt
326         $(GENPOC) --commutable         < $< > $@
327 primop-needs-wrapper.hs-incl: prelude/primops.txt
328         $(GENPOC) --needs-wrapper      < $< > $@
329 primop-can-fail.hs-incl: prelude/primops.txt
330         $(GENPOC) --can-fail           < $< > $@
331 primop-strictness.hs-incl: prelude/primops.txt
332         $(GENPOC) --strictness         < $< > $@
333 primop-usage.hs-incl: prelude/primops.txt
334         $(GENPOC) --usage              < $< > $@
335 primop-primop-info.hs-incl: prelude/primops.txt
336         $(GENPOC) --primop-primop-info < $< > $@
337
338
339
340 # ----------------------------------------------------------------------------
341 #               Parsers/lexers
342
343 parser/hschooks.o : parser/hschooks.c
344         @$(RM) $@
345         $(HC) -c -o $@ $(HC_OPTS) parser/hschooks.c
346
347
348 # Interface-file parser uses Happy
349 SRC_HAPPY_OPTS += +RTS -K2m -H16m -RTS  $(GHC_HAPPY_OPTS)
350
351 rename/ParseIface.hs : rename/ParseIface.y
352         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
353         $(HAPPY) $(HAPPY_OPTS) rename/ParseIface.y
354         @chmod 444 rename/ParseIface.hs
355
356 parser/Parser.hs : parser/Parser.y
357         @$(RM) parser/Parser.hs parser/ParseIface.hinfo
358         $(HAPPY) $(HAPPY_OPTS) parser/Parser.y
359         @chmod 444 parser/Parser.hs
360
361 #-----------------------------------------------------------------------------
362 #               Linking
363
364 SRC_LD_OPTS += -no-link-chk
365
366 ifneq "$(GhcWithHscBuiltViaC)" "YES"
367 ifeq "$(GhcReportCompiles)" "YES"
368 SRC_LD_OPTS += -syslib misc -syslib exts
369 endif
370 endif
371
372 #-----------------------------------------------------------------------------
373 #               install
374
375 # We don't want hsc treated as an ordinary executable,
376 # but put it together with the libraries.
377 # Also don't want any interface files intstalled
378
379 INSTALL_LIBEXECS += hsc
380
381 #-----------------------------------------------------------------------------
382 #               depend
383
384 #
385 # Before doing `make depend', need to build all derived Haskell source files
386 #
387 depend :: $(LOOPS)
388
389 ifneq "$(GhcWithHscBuiltViaC)" "YES"
390 depend :: rename/ParseIface.hs
391 endif
392
393 #-----------------------------------------------------------------------------
394 #               clean
395
396 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi)
397 CLEAN_FILES += $(PRIMOP_BITS)
398
399 # Extra tidy, remove the .hc files (if you've got them).
400 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc) \
401         parser/Parser.hs rename/ParseIface.hs
402
403
404 #-----------------------------------------------------------------------------
405 #               TAGS setup
406
407 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
408 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
409 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
410
411 #-----------------------------------------------------------------------------
412 #               Include target-rule boilerplate
413
414 include $(TOP)/mk/target.mk
415
416 parser/%.o : parser/%.c
417