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