[project @ 2005-03-01 11:51:14 by simonmar]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # Main ghc/compiler Makefile
3
4 # Targets:
5 #
6 #       all     builds stage1 compiler
7 #
8 #       boot stage=N   generate build dirs and dependencies for stage N.
9 #                      NB. Must be done before 'make stageN'.
10 #                      NB. Cannot 'make boot stage=2' until stage1 has
11 #                          been built (similarly for stage3).
12 #
13 #       stage1  (or stage=1) builds stage1 compiler
14 #       stage2  (or stage=2) builds stage2 compiler
15 #       stage3  (or stage=3) builds stage3 compiler
16 #
17
18 TOP = ..
19
20 # Use GHC for compiling C bits (NB. must be before boilerplate include)
21 #
22 UseGhcForCc = YES
23
24 include $(TOP)/mk/boilerplate.mk
25
26 #-----------------------------------------------------------------------------
27 # Counting source code lines
28
29 USER_SRCS = $(filter-out $(DERIVED_SRCS),$(SRCS))
30 count :
31         ./count_lines $(USER_SRCS)
32
33 #-----------------------------------------------------------------------------
34 # Building ghc different ways (default is just `normal' sequential)
35
36 WAYS=$(GhcCompilerWays)
37
38 # -----------------------------------------------------------------------------
39 # Bootstrapping
40
41 # The stage1/stage2/stage3 business is quite delicate.  Here's how it works:
42
43 #  - the variable $(stage) holds the current stage number.  To build a 
44 #    particular stage, you say 'make stage=N' where N is 1, 2, or 3.
45 #    N defaults to 1.
46 #
47 #  - for stage N, object files and .hi files are placed inside 
48 #    the directory stageN, in subdirectories as per the sources.
49 #
50 #  - .hi-boot files are *linked* into the stageN tree, because in GHC 5.05+
51 #    the .hi-boot file must reside in the same place as the .hi file.
52 #
53 #  - we use explicit -o and -ohi options to direct the output from C & 
54 #    Haskell compilations.
55 #
56 #  - we generate a different .depend file for each build.  They need to be
57 #    different, because each stage might include different files: stage1
58 #    might not include GHCi, for example.  For each stage, a normal .depend
59 #    file is generated, and then post-processed to add the correct stageN/
60 #    prefix to each object and .hi filename.  The resulting .depend file
61 #    is named .depend-$(stage).  See the end of this Makefile for details.
62 #
63 #  - normal implicit rules don't work any more, because they're of the form
64 #
65 #        %.o : %.hs 
66 #
67 #    whereas we really need 
68 #
69 #        stageN/%.o : %.hs
70 #
71 #    so suffix.mk now defines the appropriate suffix rules when
72 #    $(odir) is set to a non-empty value.  Here we set $(odir) to
73 #    stage1, stage2, or stage3.
74 #
75 #  There are other plausible designs that might work, but each has different
76 #  problems:
77 #
78 #  - using -odir and -hidir: GHC <= 4.08 doesn't support -hidir, and
79 #    anyway -odir puts all the objects in one directory (strips off the
80 #    subdirectory part), which eventually forces us to use VPATH to find
81 #    the sources.  I have a really bad feeling about VPATH.
82 #
83 #  - invoke make in the stageN subdirectory.  This probably requires VPATH
84 #    too.
85 #
86 #  - create a link tree.  The problem with requiring link trees is that 
87 #    Windows doesn't support symbolic links.
88
89 ifeq "$(stage)" ""
90 stage=1
91 endif
92
93 .DUMMY: stage_dir
94 stage_dirs :
95         $(MKDIRHIER) stage$(stage)
96         for i in $(ALL_DIRS); do \
97             $(MKDIRHIER) stage$(stage)/$$i; \
98         done
99
100 boot :: stage_dirs
101
102 # On Windows, we can't use symbolic links for the -hi-boot files
103 # because GHC itself is a Mingw program and does not understand
104 # symbolic links.  So we have to copy the files instead of link them.
105 # That means that if you modify a .hi-boot file in Windows, you
106 # have to to say 'make boot' again.
107 #
108 # PS: 'ln -s foo baz' takes 'foo' relative to the path to 'baz'
109 #     whereas 'cp foo baz' treats the two paths independently.
110 #     Hence the "../.." in the ln command line
111 ifeq "$(stage)" "1"
112 ifeq "$(ghc_ge_603)" "NO"
113 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
114         for i in */*hi-boot*; do \
115             cp -u -f $$i stage$(stage)/$$i; \
116         done
117 else
118         for i in */*hi-boot*; do \
119             $(LN_S) -f ../../$$i stage$(stage)/$$i || true ; \
120         done
121 endif
122 endif
123 endif
124
125 ifeq "$(stage)" "1"
126 HC=$(GHC)
127 endif
128
129 ifeq "$(stage)" "2"
130 HC=$(GHC_STAGE1)
131 endif
132
133 ifeq "$(stage)" "3"
134 HC=$(GHC_STAGE2)
135 endif
136
137 stage1 ::
138         $(MAKE) stage=1
139
140 stage2 ::
141         $(MAKE) stage=2
142
143 stage3 ::
144         $(MAKE) stage=3
145
146 odir=stage$(stage)
147
148 SRC_HC_OPTS += $(patsubst %, -i$(odir)/%, $(ALL_DIRS))
149
150 HS_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(HS_SRCS))))
151 C_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(C_SRCS))))
152
153 CLEAN_FILES += $(odir)/*/*.hi
154
155 ifeq "$(stage)" "1"
156 mostlyclean clean distclean maintainer-clean ::
157         $(MAKE) $@ stage=2
158         $(MAKE) $@ stage=3
159 endif
160
161 # -----------------------------------------------------------------------------
162 #               Set HS_PROG
163
164 # Note: there have been reports of people running up against the ARG_MAX limit
165 # when linking ghc with all its constituent object files. The likely source of 
166 # the problem is that the environment is a bit too big, so a workaround could
167 # be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
168 # equivalent of `env' if it doesn't exist locally).
169 #
170 ifneq "$(BuildPackageGHC)" "YES"
171 ifneq "$(way)" "dll"
172 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
173 HS_PROG=$(odir)/ghc$(_way)-$(ProjectVersion)
174 else
175 HS_PROG=$(odir)/ghc$(_way)
176 endif
177 else
178 HS_PROG=$(odir)/ghc-$(ProjectVersion)
179 endif
180 endif
181
182 # -----------------------------------------------------------------------------
183 # Create compiler configuration
184 #
185 # The 'echo' commands simply spit the values of various make variables
186 # into Config.hs, whence they can be compiled and used by GHC itself
187
188 CONFIG_HS       = main/Config.hs
189 boot :: $(CONFIG_HS)
190
191 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
192         @$(RM) -f $(CONFIG_HS)
193         @echo "Creating $(CONFIG_HS) ... "
194         @echo "module Config where" >>$(CONFIG_HS)
195         @echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
196         @echo "cProjectVersion       = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
197         @echo "cProjectVersionInt    = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
198         @echo "cProjectPatchLevel    = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
199         @echo "cBooterVersion        = \"$(GhcVersion)\"" >> $(CONFIG_HS)
200         @echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
201         @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
202         @echo "cGhcUnregisterised    = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
203         @echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
204         @echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
205         @echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
206         @echo "cMKDLL                = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
207         @echo "cPROJECT_DIR          = \"$(PROJECT_DIR)\"" >> $(CONFIG_HS)
208         @echo "cGHC_DRIVER_DIR_REL   = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
209         @echo "cGHC_TOUCHY_PGM       = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
210         @echo "cGHC_TOUCHY_DIR_REL   = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
211         @echo "cGHC_UNLIT_PGM        = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
212         @echo "cGHC_UNLIT_DIR_REL    = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
213         @echo "cGHC_MANGLER_PGM      = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
214         @echo "cGHC_MANGLER_DIR_REL  = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
215         @echo "cGHC_SPLIT_PGM        = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
216         @echo "cGHC_SPLIT_DIR_REL    = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
217         @echo "cGHC_SYSMAN_PGM       = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
218         @echo "cGHC_SYSMAN_DIR_REL   = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
219         @echo "cGHC_CP               = \"$(GHC_CP)\"" >> $(CONFIG_HS)
220         @echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
221 ifeq ($(GhcWithIlx),YES)
222         @echo "cILX2IL               = \"$(ILX2IL)\"" >> $(CONFIG_HS)
223         @echo "cILASM                = \"$(ILASM)\"" >> $(CONFIG_HS)
224 endif
225         @echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
226         @echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
227         @echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
228         @echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
229         @echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
230         @echo done.
231
232 CLEAN_FILES += $(CONFIG_HS)
233
234 # -----------------------------------------------------------------------------
235 # Create platform includes
236
237 # Here we generate a little header file containing CPP symbols that GHC
238 # uses to determine which platform it is building on/for.  The platforms
239 # can differ between stage1 and stage2 if we're cross-compiling, so we
240 # need one of these header files per stage.
241
242 PLATFORM_H = ghc_boot_platform.h
243
244 stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk Makefile
245         @echo "Creating $@..."
246         @$(RM) $@
247         @echo "#ifndef __PLATFORM_H__"  >$@
248         @echo "#define __PLATFORM_H__" >>$@
249         @echo >> $@
250         @echo "#define BuildPlatform_TYPE  $(BuildPlatform_CPP)" >> $@
251         @echo "#define HostPlatform_TYPE   $(HostPlatform_CPP)" >> $@
252         @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
253         @echo >> $@
254         @echo "#define $(BuildPlatform_CPP)_BUILD       1" >> $@
255         @echo "#define $(HostPlatform_CPP)_HOST         1" >> $@
256         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
257         @echo >> $@
258         @echo "#define $(BuildArch_CPP)_BUILD_ARCH      1" >> $@
259         @echo "#define $(HostArch_CPP)_HOST_ARCH        1" >> $@
260         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
261         @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
262         @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
263         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
264         @echo >> $@
265         @echo "#define $(BuildOS_CPP)_BUILD_OS          1" >> $@
266         @echo "#define $(HostOS_CPP)_HOST_OS            1" >> $@
267         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
268         @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
269         @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
270         @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
271 ifeq "$(HostOS_CPP)" "irix"
272         @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS           " >> $@  
273         @echo "#define $(IRIX_MAJOR)_TARGET_OS          1" >> $@  
274         @echo "#endif                                    " >> $@  
275 endif
276         @echo >> $@
277         @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR  1" >> $@
278         @echo "#define $(HostVendor_CPP)_HOST_VENDOR    1" >> $@
279         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
280         @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
281         @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
282         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
283         @echo >> $@
284         @echo "#endif /* __PLATFORM_H__ */"          >> $@
285         @echo "Done."
286
287 # For stage2 and above, the BUILD platform is the HOST of stage1, and
288 # the HOST platform is the TARGET of stage1.  The TARGET remains the same
289 # (stage1 is the cross-compiler, not stage2).
290 stage2/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk Makefile
291         @echo "Creating $@..."
292         @$(RM) $@
293         @echo "#ifndef __PLATFORM_H__"  >$@
294         @echo "#define __PLATFORM_H__" >>$@
295         @echo >> $@
296         @echo "#define BuildPlatform_TYPE  $(HostPlatform_CPP)" >> $@
297         @echo "#define HostPlatform_TYPE   $(TargetPlatform_CPP)" >> $@
298         @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
299         @echo >> $@
300         @echo "#define $(HostPlatform_CPP)_BUILD        1" >> $@
301         @echo "#define $(TargetPlatform_CPP)_HOST               1" >> $@
302         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
303         @echo >> $@
304         @echo "#define $(HostArch_CPP)_BUILD_ARCH       1" >> $@
305         @echo "#define $(TargetArch_CPP)_HOST_ARCH      1" >> $@
306         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
307         @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
308         @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
309         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
310         @echo >> $@
311         @echo "#define $(HostOS_CPP)_BUILD_OS           1" >> $@
312         @echo "#define $(TargetOS_CPP)_HOST_OS          1" >> $@
313         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
314         @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
315         @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
316         @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
317 ifeq "$(HostOS_CPP)" "irix"
318         @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS           " >> $@  
319         @echo "#define $(IRIX_MAJOR)_TARGET_OS          1" >> $@  
320         @echo "#endif                                    " >> $@  
321 endif
322         @echo >> $@
323         @echo "#define $(HostVendor_CPP)_BUILD_VENDOR   1" >> $@
324         @echo "#define $(TargetVendor_CPP)_HOST_VENDOR  1" >> $@
325         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
326         @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
327         @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
328         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
329         @echo >> $@
330         @echo "#endif /* __PLATFORM_H__ */"          >> $@
331         @echo "Done."
332
333 stage3/$(PLATFORM_H) : stage_dirs stage2/$(PLATFORM_H)
334         $(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)
335
336 STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)
337
338 boot :: $(STAGE_PLATFORM_H)
339
340 SRC_HC_OPTS += -Istage$(stage)
341
342 # -----------------------------------------------------------------------------
343 # Set SRCS etc.
344 #
345 # First figure out ALL_DIRS, the source sub-directories
346
347 ALL_DIRS = \
348   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
349   specialise simplCore stranal stgSyn simplStg codeGen main \
350   profiling parser cprAnalysis compMan ndpFlatten iface cmm
351
352 # Make sure we include Config.hs even if it doesn't exist yet...
353 ALL_SRCS += $(CONFIG_HS)
354
355 # HsGeneric.hs is not used just now
356 EXCLUDED_SRCS += hsSyn/HsGeneric.hs
357
358 ifeq ($(GhcWithNativeCodeGen),YES)
359 ALL_DIRS += nativeGen
360 else
361 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
362 endif
363
364 ifeq ($(GhcWithIlx),YES)
365 ALL_DIRS += ilxGen
366 SRC_HC_OPTS += -DILX
367 endif
368
369 ifeq ($(GhcWithJavaGen),YES)
370 ALL_DIRS += javaGen
371 SRC_HC_OPTS += -DJAVA
372 endif
373
374 ifeq "$(BootingFromHc)" "YES"
375 # HC files are always from a self-booted compiler
376 bootstrapped = YES
377 else
378 ifneq "$(findstring $(stage), 2 3)" ""
379 bootstrapped = YES
380 else
381 bootstrapped = $(shell if (test $(GhcCanonVersion) -ge $(ProjectVersionInt) -a $(GhcPatchLevel) -ge $(ProjectPatchLevel)); then echo YES; else echo NO; fi)
382 endif
383 endif
384
385 # -----------------------------------------------------------------------------
386 # Building a compiler with interpreter support
387 #
388 # The interpreter, GHCi interface, and Template Haskell are only
389 # enabled when we are bootstrapping with the same version of GHC, and
390 # the interpreter is supported on this platform.
391
392 ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
393
394 # Yes, include the interepreter, readline, and Template Haskell extensions
395 SRC_HC_OPTS += -DGHCI -package template-haskell
396
397 ALL_DIRS += ghci
398
399 # Enable readline if either:
400 #   - we're building stage 1 and $(GhcHasReadline)="YES"
401 #   - we're building stage 2/3, and we have built the readline package
402 #
403 # But we don't enable readline on Windows, because readline is fairly
404 # broken there.
405 #
406 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
407 ifeq "$(stage)" "1"
408 ifeq "$(GhcHasReadline)" "YES"
409 SRC_HC_OPTS += -package readline -DUSE_READLINE
410 endif
411 else
412 ifeq "$(GhcLibsWithReadline)" "YES"
413 SRC_HC_OPTS += -package readline -DUSE_READLINE
414 endif
415 endif # stage=1
416 endif # not windows
417
418 else
419
420 # No interpreter, so exclude Template Haskell modules
421 EXCLUDED_SRCS += deSugar/DsMeta.hs typecheck/TcSplice.lhs hsSyn/Convert.lhs
422
423 endif # bootstrapped with interpreter
424
425 # -----------------------------------------------
426 # mkdependC stuff
427 #
428 # Big Fudge to get around inherent problem that Makefile setup
429 # has got with 'mkdependC'.
430
431 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
432
433 # XXX not really correct, hschooks.c actually gets include files like
434 # RtsFlags.c from the installed GHC, but we can't tell mkdependC about that.
435 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
436
437 # -----------------------------------------------------------------------------
438 #               Haskell compilations
439
440 SRC_HC_OPTS += \
441   -cpp -fglasgow-exts -fno-generics -Rghc-timing \
442   -I. -IcodeGen -InativeGen -Iparser
443
444 # Omitted:      -I$(GHC_INCLUDE_DIR)
445 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS, 
446 # to avoid the use of an explicit path in GHC source files
447 #       (include "../includes/config.h"
448 # But alas GHC 4.08 (and others for all I know) uses this very
449 # same include path when compiling the .hc files it generates.
450 # Disaster!  Then the hc file sees the GHC 5.02 (or whatever)
451 # include files.   For the moment we've reverted to using
452 # an explicit path in the .hs sources
453 #
454 # For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
455 # when generating dependencies. (=> it gets passed onto mkdependHS,
456 # which needs it).
457 SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
458
459 # We need System.Posix (or Posix when ghc < 6.2)
460 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
461 ifeq "$(bootstrapped) $(ghc_ge_601)" "NO NO"
462 SRC_HC_OPTS += -package posix
463 else
464 SRC_HC_OPTS += -package unix
465 endif
466 endif
467
468 ifneq "$(findstring YES, $(bootstrapped) $(ghc_ge_603))" ""
469 SRC_HC_OPTS += -package Cabal
470 endif
471
472 SRC_CC_OPTS += -Iparser -I. -O
473 SRC_HC_OPTS += -recomp $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
474 SRC_HC_OPTS += -H16M
475
476 ifeq "$(BootingFromHc)" "YES"
477 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
478 endif
479
480 #       Special flags for particular modules
481 #       The standard suffix rule for compiling a Haskell file
482 #       adds these flags to the command line
483
484 # There used to be a -no-recomp flag on PrimOp, but why?
485 # It's an expensive module to recompile!
486 prelude/PrimOp_HC_OPTS          = -H80m
487
488 # because the NCG can't handle the 64-bit math in here
489 prelude/PrelRules_HC_OPTS       = -fvia-C
490
491 main/ParsePkgConf_HC_OPTS       += -fno-warn-incomplete-patterns
492 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
493 # primops on all platforms.
494 parser/Parser_HC_OPTS           += -fno-warn-incomplete-patterns -fvia-C
495
496 # Careful optimisation of the parser: we don't want to throw everything
497 # at it, because that takes too long and doesn't buy much, but we do want
498 # to inline certain key external functions, so we instruct GHC not to
499 # throw away inlinings as it would normally do in -Onot mode:
500 parser/Parser_HC_OPTS           += -Onot -fno-ignore-interface-pragmas
501
502 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
503 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
504 endif
505
506 utils/Digraph_HC_OPTS           = -fglasgow-exts 
507
508 basicTypes/SrcLoc_HC_OPTS       = -funbox-strict-fields
509
510 ifeq "$(bootstrapped)" "YES"
511 utils/Binary_HC_OPTS            = -funbox-strict-fields
512 endif
513
514 # ByteCodeItbls uses primops that the NCG doesn't support yet.
515 ghci/ByteCodeItbls_HC_OPTS      += -fvia-C
516 ghci/ByteCodeLink_HC_OPTS       += -fvia-C -monly-3-regs
517
518 # BinIface and Binary take ages to both compile and run if you don's use -O
519 main/BinIface_HC_OPTS           += -O
520 utils/Binary_HC_OPTS            += -O
521 utils/FastMutInt_HC_OPTS        += -O
522
523
524 # ---- Profiling ----
525 #simplCore/Simplify_HC_OPTS = -auto-all
526 #simplCore/SimplEnv_HC_OPTS = -auto-all
527 #simplCore/SimplUtils_HC_OPTS = -auto-all
528
529 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
530 # DriverMkDepend), causing some of them to be commoned up.  We have a fix for
531 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
532 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
533 compMan/CompManager_HC_OPTS     = -fno-cse
534 ghci/InteractiveUI_HC_OPTS      = -fno-cse
535 main/CmdLineOpts_HC_OPTS        = -fno-cse
536 main/DriverFlags_HC_OPTS        = -fno-cse
537 main/DriverMkDepend_HC_OPTS     = -fno-cse
538 main/DriverPipeline_HC_OPTS     = -fno-cse
539 main/DriverState_HC_OPTS        = -fno-cse
540 main/DriverUtil_HC_OPTS         = -fno-cse
541 main/Finder_HC_OPTS             = -fno-cse
542 main/SysTools_HC_OPTS           = -fno-cse
543
544 # The #include is vital for the via-C route, else the C
545 # compiler doesn't realise that the stcall foreign imports are indeed
546 # stdcall, and doesn't generate the Foo@8 name for them
547 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
548 main/SysTools_HC_OPTS           += '-\#include <windows.h>' '-\#include <process.h>'
549 endif
550
551 parser/Lexer_HC_OPTS += -funbox-strict-fields
552
553 # ghc_strlen percolates through so many modules that it is easier to get its
554 # prototype via a global option instead of a myriad of per-file OPTIONS
555 SRC_HC_OPTS += '-\#include "hschooks.h"'
556
557 # ----------------------------------------------------------------------------
558 #               Generate supporting stuff for prelude/PrimOp.lhs 
559 #               from prelude/primops.txt
560
561 GENPOC=$(TOP)/utils/genprimopcode/genprimopcode
562
563 PRIMOP_BITS=primop-data-decl.hs-incl \
564             primop-tag.hs-incl  \
565             primop-list.hs-incl  \
566             primop-has-side-effects.hs-incl  \
567             primop-out-of-line.hs-incl  \
568             primop-commutable.hs-incl  \
569             primop-needs-wrapper.hs-incl  \
570             primop-can-fail.hs-incl  \
571             primop-strictness.hs-incl  \
572             primop-primop-info.hs-incl
573
574 CLEAN_FILES += prelude/primops.txt
575 CLEAN_FILES += $(PRIMOP_BITS)
576
577 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
578 SRC_CPP_OPTS += ${GhcCppOpts}
579
580 ifneq "$(BootingFromHc)" "YES"
581 prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
582 endif
583
584 ifneq "$(BootingFromHc)" "YES"
585 depend :: $(PRIMOP_BITS)
586 endif
587
588 primop-data-decl.hs-incl: prelude/primops.txt
589         $(GENPOC) --data-decl          < $< > $@
590 primop-tag.hs-incl: prelude/primops.txt
591         $(GENPOC) --primop-tag         < $< > $@
592 primop-list.hs-incl: prelude/primops.txt
593         $(GENPOC) --primop-list        < $< > $@
594 primop-has-side-effects.hs-incl: prelude/primops.txt
595         $(GENPOC) --has-side-effects   < $< > $@
596 primop-out-of-line.hs-incl: prelude/primops.txt
597         $(GENPOC) --out-of-line        < $< > $@
598 primop-commutable.hs-incl: prelude/primops.txt
599         $(GENPOC) --commutable         < $< > $@
600 primop-needs-wrapper.hs-incl: prelude/primops.txt
601         $(GENPOC) --needs-wrapper      < $< > $@
602 primop-can-fail.hs-incl: prelude/primops.txt
603         $(GENPOC) --can-fail           < $< > $@
604 primop-strictness.hs-incl: prelude/primops.txt
605         $(GENPOC) --strictness         < $< > $@
606 primop-primop-info.hs-incl: prelude/primops.txt
607         $(GENPOC) --primop-primop-info < $< > $@
608
609 # Usages aren't used any more; but the generator 
610 # can still generate them if we want them back
611 primop-usage.hs-incl: prelude/primops.txt
612         $(GENPOC) --usage              < $< > $@
613
614
615 #-----------------------------------------------------------------------------
616 #               Linking
617
618 # Include libghccompat in stage1 only.  In stage2 onwards, all these
619 # libraries will be available from the main libraries.
620 ifeq "$(stage)" "1"
621 SRC_HC_OPTS += -i$(GHC_LIB_COMPAT_DIR)
622 SRC_LD_OPTS += -L$(GHC_LIB_COMPAT_DIR) -lghccompat
623
624 ifeq "$(Windows)" "YES"
625 # not very nice, but required for -lghccompat on Windows
626 SRC_LD_OPTS += -lshell32
627 endif
628
629 # This is horrible.  We ought to be able to omit the entire directory
630 # from mkDependHS.
631 SRC_MKDEPENDHS_OPTS += \
632         -optdep--exclude-module=Compat.RawSystem \
633         -optdep--exclude-module=Compat.Directory \
634         -optdep--exclude-module=Distribution.Compat.ReadP \
635         -optdep--exclude-module=Distribution.Extension \
636         -optdep--exclude-module=Distribution.GetOpt \
637         -optdep--exclude-module=Distribution.InstalledPackageInfo \
638         -optdep--exclude-module=Distribution.License \
639         -optdep--exclude-module=Distribution.Package \
640         -optdep--exclude-module=Distribution.ParseUtils \
641         -optdep--exclude-module=Distribution.Setup \
642         -optdep--exclude-module=Distribution.Version \
643         -optdep--exclude-module=System.Directory.Internals
644 endif
645
646 SRC_LD_OPTS += -no-link-chk
647
648 # -----------------------------------------------------------------------------
649 # create ghc-inplace, a convenient way to run ghc from the build tree...
650
651 all :: $(odir)/ghc-inplace ghc-inplace
652
653 $(odir)/ghc-inplace : $(HS_PROG)
654         @$(RM) $@
655         echo '#!/bin/sh' >>$@
656         echo exec $(FPTOOLS_TOP_ABS)/ghc/compiler/$(HS_PROG) '-B$(subst \,\\,$(FPTOOLS_TOP_ABS_PLATFORM))' '"$$@"' >>$@
657         chmod 755 $@
658
659 ghc-inplace : stage1/ghc-inplace
660         $(LN_S) -f $< $@
661
662 CLEAN_FILES += $(odir)/ghc-inplace ghc-inplace
663
664 #-----------------------------------------------------------------------------
665 #               install
666
667 # We don't want ghc treated as an ordinary executable,
668 # but put it together with the libraries.
669 # Also don't want any interface files installed
670
671 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
672
673 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
674 INSTALL_LIBEXECS += $(HS_PROG)
675 else
676 INSTALL_PROGS += $(HS_PROG)
677 endif
678
679 # ----------------------------------------------------------------------------
680 # profiling.
681
682 # rename/RnBinds_HC_OPTS += -auto-all
683 # rename/RnEnv_HC_OPTS += -auto-all
684 # rename/RnExpr_HC_OPTS += -auto-all
685 # rename/RnHiFiles_HC_OPTS += -auto-all
686 # rename/RnHsSyn_HC_OPTS += -auto-all
687 # rename/Rename_HC_OPTS += -auto-all
688 # rename/RnIfaces_HC_OPTS += -auto-all
689 # rename/RnNames_HC_OPTS += -auto-all
690 # rename/RnSource_HC_OPTS += -auto-all
691 # rename/RnTypes_HC_OPTS += -auto-all
692
693 # typecheck/Inst_HC_OPTS += -auto-all
694 # typecheck/TcBinds_HC_OPTS += -auto-all
695 # typecheck/TcClassDcl_HC_OPTS += -auto-all
696 # typecheck/TcDefaults_HC_OPTS += -auto-all
697 # typecheck/TcDeriv_HC_OPTS += -auto-all
698 # typecheck/TcEnv_HC_OPTS += -auto-all
699 # typecheck/TcExpr_HC_OPTS += -auto-all
700 # typecheck/TcForeign_HC_OPTS += -auto-all
701 # typecheck/TcGenDeriv_HC_OPTS += -auto-all
702 # typecheck/TcHsSyn_HC_OPTS += -auto-all
703 # typecheck/TcIfaceSig_HC_OPTS += -auto-all
704 # typecheck/TcInstDcls_HC_OPTS += -auto-all
705 # typecheck/TcMatches_HC_OPTS += -auto-all
706 # typecheck/TcMonoType_HC_OPTS += -auto-all
707 # typecheck/TcMType_HC_OPTS += -auto-all
708 # typecheck/TcPat_HC_OPTS += -auto-all
709 # typecheck/TcRnDriver_HC_OPTS += -auto-all
710 # #typecheck/TcRnMonad_HC_OPTS += -auto-all
711 # #typecheck/TcRnTypes_HC_OPTS += -auto-all
712 # typecheck/TcRules_HC_OPTS += -auto-all
713 # typecheck/TcSimplify_HC_OPTS += -auto-all
714 # typecheck/TcSplice_HC_OPTS += -auto-all
715 # typecheck/TcTyClsDecls_HC_OPTS += -auto-all
716 # typecheck/TcTyDecls_HC_OPTS += -auto-all
717 # typecheck/TcType_HC_OPTS += -auto-all
718 # typecheck/TcUnify_HC_OPTS += -auto-all
719
720 coreSyn/CorePrep_HC_OPTS += -auto-all
721
722 #-----------------------------------------------------------------------------
723 # Building GHC package
724
725 ifeq "$(BuildPackageGHC)" "YES"
726
727 PACKAGE = ghc
728 STANDALONE_PACKAGE = YES
729 PACKAGE_DEPS =
730
731 endif
732
733 #-----------------------------------------------------------------------------
734 #               clean
735
736 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
737
738 #-----------------------------------------------------------------------------
739 #               Include target-rule boilerplate
740
741 # Don't use the default MKDEPENDHS stuff... we'll do our own, below
742 MKDEPENDHS_SRCS =
743 MKDEPENDC_SRCS =
744
745 # Make doesn't work this out for itself, it seems
746 parser/Parser.y : parser/Parser.y.pp
747 EXTRA_SRCS += parser/Parser.y
748
749
750 #-----------------------------------------------------------------------------
751 #               Source files for tags file generation
752 #
753 # We want to excluded derived sources, because they won't be in the source
754 # tree, which is where we are going to move the TAGS file to.a
755
756 TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
757
758
759 include $(TOP)/mk/target.mk
760
761 # -----------------------------------------------------------------------------
762 # Dependencies
763
764 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
765
766 MKDEPENDHS=$(HC)
767
768 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
769 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
770         touch .depend-BASE
771 ifneq "$(BootingFromHc)" "YES"
772         $(MKDEPENDHS) -M -optdep-f -optdep.depend-BASE $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) $(HS_SRCS)
773 endif
774         $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS) 
775         $(PERL) -pe 'binmode(stdin); binmode(stdout); s@^(\S*\.o)@stage$(stage)/$$1@g; s@(\S*\.hi)@stage$(stage)/$$1@g' <.depend-BASE >.depend-$(stage)
776 # The binmode stuff tells perl not to add stupid ^M's to the output
777
778 -include .depend-$(stage)