Fix ghc-inplace.c on Windows; new code based on ghci.c
[ghc-hetmet.git] / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # Main 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 ifeq "$(GhcThreaded)$(GhcProfiled)" "YESYES"
27 $(error Cannot make GHC both threaded and profiled)
28 endif
29
30 #-----------------------------------------------------------------------------
31 # Counting source code lines
32
33 USER_SRCS = $(filter-out $(DERIVED_SRCS),$(SRCS))
34 count :
35         ./count_lines $(USER_SRCS)
36
37 # -----------------------------------------------------------------------------
38 # Bootstrapping
39
40 # The stage1/stage2/stage3 business is quite delicate.  Here's how it works:
41
42 #  - the variable $(stage) holds the current stage number.  To build a 
43 #    particular stage, you say 'make stage=N' where N is 1, 2, or 3.
44 #    N defaults to 1.
45 #
46 #  - for stage N, object files and .hi files are placed inside 
47 #    the directory stageN, in subdirectories as per the sources.
48 #
49 #  - .hi-boot files are *linked* into the stageN tree, because in GHC 5.05+
50 #    the .hi-boot file must reside in the same place as the .hi file.
51 #
52 #  - we use explicit -o and -ohi options to direct the output from C & 
53 #    Haskell compilations.
54 #
55 #  - we generate a different .depend file for each build.  They need to be
56 #    different, because each stage might include different files: stage1
57 #    might not include GHCi, for example.  For each stage, a normal .depend
58 #    file is generated, and then post-processed to add the correct stageN/
59 #    prefix to each object and .hi filename.  The resulting .depend file
60 #    is named .depend-$(stage).  See the end of this Makefile for details.
61 #
62 #  - normal implicit rules don't work any more, because they're of the form
63 #
64 #        %.o : %.hs 
65 #
66 #    whereas we really need 
67 #
68 #        stageN/%.o : %.hs
69 #
70 #    so suffix.mk now defines the appropriate suffix rules when
71 #    $(odir) is set to a non-empty value.  Here we set $(odir) to
72 #    stage1, stage2, or stage3.
73 #
74 #  There are other plausible designs that might work, but each has different
75 #  problems:
76 #
77 #  - using -odir and -hidir: GHC <= 4.08 doesn't support -hidir, and
78 #    anyway -odir puts all the objects in one directory (strips off the
79 #    subdirectory part), which eventually forces us to use VPATH to find
80 #    the sources.  I have a really bad feeling about VPATH.
81 #
82 #  - invoke make in the stageN subdirectory.  This probably requires VPATH
83 #    too.
84 #
85 #  - create a link tree.  The problem with requiring link trees is that 
86 #    Windows doesn't support symbolic links.
87
88 ifeq "$(stage)" ""
89 stage=1
90 endif
91
92 .DUMMY: stage_dir
93 stage_dirs :
94         $(MKDIRHIER) stage$(stage)
95         for i in $(ALL_DIRS); do \
96             $(MKDIRHIER) stage$(stage)/$$i; \
97         done
98
99 ifeq "$(stage) $(ghc_ge_603)" "1 YES"
100 UsingHsBoot = YES
101 else
102 ifneq "$(findstring $(stage), 2 3)" ""
103 UsingHsBoot = YES
104 else
105 UsingHsBoot = NO
106 endif
107 endif
108
109 boot :: stage_dirs
110 # On Windows, we can't use symbolic links for the -hi-boot files
111 # because GHC itself is a Mingw program and does not understand
112 # symbolic links.  So we have to copy the files instead of link them.
113 # That means that if you modify a .hi-boot file in Windows, you
114 # have to to say 'make boot' again.
115 #
116 # PS: 'ln -s foo baz' takes 'foo' relative to the path to 'baz'
117 #     whereas 'cp foo baz' treats the two paths independently.
118 #     Hence the "../.." in the ln command line
119 ifeq "$(UsingHsBoot)" "NO"
120 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
121         for i in */*hi-boot*; do \
122             cp -u -f $$i stage$(stage)/$$i; \
123         done
124 else
125         for i in */*hi-boot*; do \
126             ($(RM) -f stage$(stage)/$$i \
127                && $(LN_S) ../../$$i stage$(stage)/$$i) || true ; \
128         done
129 endif
130 endif
131
132 ifeq "$(stage)" "1"
133 HC=$(GHC)
134 endif
135
136 ifeq "$(stage)" "2"
137 HC=$(GHC_STAGE1)
138 endif
139
140 ifeq "$(stage)" "3"
141 HC=$(GHC_STAGE2)
142 endif
143
144 stage1 ::
145         $(MAKE) stage=1
146
147 stage2 ::
148         $(MAKE) stage=2
149
150 stage3 ::
151         $(MAKE) stage=3
152
153 odir=stage$(stage)
154
155 SRC_HC_OPTS += $(patsubst %, -i$(odir)/%, $(ALL_DIRS))
156
157 HS_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(HS_SRCS))))
158 C_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(C_SRCS))))
159
160 # Our standard cleaning rules don't know that we're doing our output
161 # into $(odir), so we have to augment CLEAN_FILES appropriateliy.
162
163 CLEAN_FILES += $(odir)/*/*.hi $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
164
165 ifeq "$(UsingHsBoot)" "YES"
166 CLEAN_FILES += $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
167 endif
168
169 ifeq "$(stage)" "1"
170 mostlyclean clean distclean maintainer-clean ::
171         $(MAKE) $@ stage=2
172         $(MAKE) $@ stage=3
173 endif
174
175 # -----------------------------------------------------------------------------
176 #               Set HS_PROG
177
178 # Note: there have been reports of people running up against the ARG_MAX limit
179 # when linking ghc with all its constituent object files. The likely source of 
180 # the problem is that the environment is a bit too big, so a workaround could
181 # be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
182 # equivalent of `env' if it doesn't exist locally).
183 #
184 ifneq "$(way)" "dll"
185 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
186 GHC_PROG=$(odir)/ghc$(_way)-$(ProjectVersion)
187 else
188 GHC_PROG=$(odir)/ghc$(_way)
189 endif
190 else
191 GHC_PROG=$(odir)/ghc-$(ProjectVersion)
192 endif
193
194 ifeq "$(stage)" "1"
195 HS_PROG = $(GHC_PROG)
196 endif
197
198 # -----------------------------------------------------------------------------
199 # Create compiler configuration
200 #
201 # The 'echo' commands simply spit the values of various make variables
202 # into Config.hs, whence they can be compiled and used by GHC itself
203
204 CONFIG_HS       = main/Config.hs
205 boot :: $(CONFIG_HS)
206
207 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
208         @$(RM) -f $(CONFIG_HS)
209         @echo "Creating $(CONFIG_HS) ... "
210         @echo "module Config where" >>$(CONFIG_HS)
211         @echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
212         @echo "cProjectVersion       = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
213         @echo "cProjectVersionInt    = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
214         @echo "cProjectPatchLevel    = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
215         @echo "cBooterVersion        = \"$(GhcVersion)\"" >> $(CONFIG_HS)
216         @echo "cStage                = STAGE" >> $(CONFIG_HS)
217         @echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
218         @echo "cSplitObjs            = \"$(SplitObjs)\"" >> $(CONFIG_HS)
219         @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
220         @echo "cGhcUnregisterised    = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
221         @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
222         @echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
223         @echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
224         @echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
225         @echo "cMKDLL                = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
226         @echo "cLdIsGNULd            = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
227         @echo "cLD_X                 = \"$(LD_X)\"" >> $(CONFIG_HS)
228         @echo "cPROJECT_DIR          = \"$(PROJECT_DIR)\"" >> $(CONFIG_HS)
229         @echo "cGHC_DRIVER_DIR_REL   = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
230         @echo "cGHC_TOUCHY_PGM       = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
231         @echo "cGHC_TOUCHY_DIR_REL   = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
232         @echo "cGHC_UNLIT_PGM        = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
233         @echo "cGHC_UNLIT_DIR_REL    = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
234         @echo "cGHC_MANGLER_PGM      = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
235         @echo "cGHC_MANGLER_DIR_REL  = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
236         @echo "cGHC_SPLIT_PGM        = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
237         @echo "cGHC_SPLIT_DIR_REL    = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
238         @echo "cGHC_SYSMAN_PGM       = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
239         @echo "cGHC_SYSMAN_DIR_REL   = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
240         @echo "cGHC_CP               = \"$(GHC_CP)\"" >> $(CONFIG_HS)
241         @echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
242 ifeq ($(GhcWithIlx),YES)
243         @echo "cILX2IL               = \"$(ILX2IL)\"" >> $(CONFIG_HS)
244         @echo "cILASM                = \"$(ILASM)\"" >> $(CONFIG_HS)
245 endif
246         @echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
247         @echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
248         @echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
249         @echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
250         @echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
251         @echo done.
252
253 CLEAN_FILES += $(CONFIG_HS)
254
255 # -----------------------------------------------------------------------------
256 # Create platform includes
257
258 # Here we generate a little header file containing CPP symbols that GHC
259 # uses to determine which platform it is building on/for.  The platforms
260 # can differ between stage1 and stage2 if we're cross-compiling, so we
261 # need one of these header files per stage.
262
263 PLATFORM_H = ghc_boot_platform.h
264
265 stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
266         @echo "Creating $@..."
267         @$(RM) $@
268         @echo "#ifndef __PLATFORM_H__"  >$@
269         @echo "#define __PLATFORM_H__" >>$@
270         @echo >> $@
271         @echo "#define BuildPlatform_NAME  \"$(BUILDPLATFORM)\"" >> $@
272         @echo "#define HostPlatform_NAME   \"$(HOSTPLATFORM)\"" >> $@
273         @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
274         @echo >> $@
275         @echo "#define $(BuildPlatform_CPP)_BUILD       1" >> $@
276         @echo "#define $(HostPlatform_CPP)_HOST         1" >> $@
277         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
278         @echo >> $@
279         @echo "#define $(BuildArch_CPP)_BUILD_ARCH      1" >> $@
280         @echo "#define $(HostArch_CPP)_HOST_ARCH        1" >> $@
281         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
282         @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
283         @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
284         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
285         @echo >> $@
286         @echo "#define $(BuildOS_CPP)_BUILD_OS          1" >> $@
287         @echo "#define $(HostOS_CPP)_HOST_OS            1" >> $@
288         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
289         @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
290         @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
291         @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
292 ifeq "$(HostOS_CPP)" "irix"
293         @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS           " >> $@  
294         @echo "#define $(IRIX_MAJOR)_TARGET_OS          1" >> $@  
295         @echo "#endif                                    " >> $@  
296 endif
297         @echo >> $@
298         @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR  1" >> $@
299         @echo "#define $(HostVendor_CPP)_HOST_VENDOR    1" >> $@
300         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
301         @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
302         @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
303         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
304         @echo >> $@
305         @echo "#endif /* __PLATFORM_H__ */"          >> $@
306         @echo "Done."
307
308 # For stage2 and above, the BUILD platform is the HOST of stage1, and
309 # the HOST platform is the TARGET of stage1.  The TARGET remains the same
310 # (stage1 is the cross-compiler, not stage2).
311 stage2/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
312         @echo "Creating $@..."
313         @$(RM) $@
314         @echo "#ifndef __PLATFORM_H__"  >$@
315         @echo "#define __PLATFORM_H__" >>$@
316         @echo >> $@
317         @echo "#define BuildPlatform_NAME  \"$(HOSTPLATFORM)\"" >> $@
318         @echo "#define HostPlatform_NAME   \"$(TARGETPLATFORM)\"" >> $@
319         @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
320         @echo >> $@
321         @echo "#define $(HostPlatform_CPP)_BUILD        1" >> $@
322         @echo "#define $(TargetPlatform_CPP)_HOST               1" >> $@
323         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
324         @echo >> $@
325         @echo "#define $(HostArch_CPP)_BUILD_ARCH       1" >> $@
326         @echo "#define $(TargetArch_CPP)_HOST_ARCH      1" >> $@
327         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
328         @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
329         @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
330         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
331         @echo >> $@
332         @echo "#define $(HostOS_CPP)_BUILD_OS           1" >> $@
333         @echo "#define $(TargetOS_CPP)_HOST_OS          1" >> $@
334         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
335         @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
336         @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
337         @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
338 ifeq "$(HostOS_CPP)" "irix"
339         @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS           " >> $@  
340         @echo "#define $(IRIX_MAJOR)_TARGET_OS          1" >> $@  
341         @echo "#endif                                    " >> $@  
342 endif
343         @echo >> $@
344         @echo "#define $(HostVendor_CPP)_BUILD_VENDOR   1" >> $@
345         @echo "#define $(TargetVendor_CPP)_HOST_VENDOR  1" >> $@
346         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
347         @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
348         @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
349         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
350         @echo >> $@
351         @echo "#endif /* __PLATFORM_H__ */"          >> $@
352         @echo "Done."
353
354 stage3/$(PLATFORM_H) : stage_dirs stage2/$(PLATFORM_H)
355         $(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)
356
357 STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)
358
359 boot :: $(STAGE_PLATFORM_H)
360
361 SRC_HC_OPTS += -Istage$(stage)
362
363 # -----------------------------------------------------------------------------
364 # Set SRCS etc.
365 #
366 # First figure out ALL_DIRS, the source sub-directories
367
368 ALL_DIRS = \
369   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
370   vectorise specialise simplCore stranal stgSyn simplStg codeGen main \
371   profiling parser cprAnalysis ndpFlatten iface cmm
372
373 # Make sure we include Config.hs even if it doesn't exist yet...
374 ALL_SRCS += $(CONFIG_HS)
375
376 # HsGeneric.hs is not used just now
377 EXCLUDED_SRCS += hsSyn/HsGeneric.hs
378
379 ifeq ($(GhcWithNativeCodeGen),YES)
380 ALL_DIRS += nativeGen
381 else
382 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
383 endif
384
385 ifeq ($(GhcWithIlx),YES)
386 ALL_DIRS += ilxGen
387 SRC_HC_OPTS += -DILX
388 endif
389
390 ifeq ($(GhcWithJavaGen),YES)
391 ALL_DIRS += javaGen
392 SRC_HC_OPTS += -DJAVA
393 endif
394
395 ifeq "$(BootingFromHc)" "YES"
396 # HC files are always from a self-booted compiler
397 bootstrapped = YES
398 else
399 ifneq "$(findstring $(stage), 2 3)" ""
400 bootstrapped = YES
401 else
402 bootstrapped = NO
403 endif
404 endif
405
406 # -----------------------------------------------------------------------------
407 # Building a compiler with interpreter support
408 #
409 # The interpreter, GHCi interface, Template Haskell and Hpc are only
410 # enabled when we are bootstrapping with the same version of GHC, and
411 # the interpreter is supported on this platform.
412
413 ifeq "$(bootstrapped)" "YES"
414 SRC_HC_OPTS += -package hpc -package bytestring
415 PKG_DEPENDS += hpc bytestring
416 endif
417
418 ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
419
420 # Yes, include the interepreter, readline, and Template Haskell extensions
421 SRC_HC_OPTS += -DGHCI -package template-haskell
422 PKG_DEPENDS += template-haskell
423
424 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
425 # or not?
426 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
427 SRC_HC_OPTS += -DGHCI_TABLES_NEXT_TO_CODE
428 endif
429
430 ifeq "$(GhcThreaded)" "YES"
431 # Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
432 SRC_LD_OPTS += -threaded
433 endif
434 ifeq "$(GhcProfiled)" "YES"
435 SRC_LD_OPTS += -prof
436 endif
437 ifeq "$(GhcDebugged)" "YES"
438 SRC_LD_OPTS += -debug
439 endif
440
441 ALL_DIRS += ghci
442
443 # If we are going to use dynamic libraries instead of .o files for ghci,
444 # we will need to always retain CAFs in the compiler.
445 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
446 # function which sets the keepCAFs flag for the RTS before any Haskell
447 # code is run.
448 ifeq "$(GhcBuildDylibs)" "YES"
449 else
450 EXCLUDED_SRCS += ghci/keepCAFsForGHCi.c
451 endif
452
453 # Enable readline if either:
454 #   - we're building stage 1 and $(GhcHasReadline)="YES"
455 #   - we're building stage 2/3, and we have built the readline package
456 #
457 # But we don't enable readline on Windows, because readline is fairly
458 # broken there.
459 #
460 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
461 ifeq "$(stage)" "1"
462 ifeq "$(GhcHasReadline)" "YES"
463 SRC_HC_OPTS += -package readline -DUSE_READLINE
464 PKG_DEPENDS += readline
465 endif
466 else
467 -include $(FPTOOLS_TOP)/libraries/readline/config.mk
468 # readline's config.mk sets PACKAGE, which we don't want here
469 PACKAGE=
470 ifeq "$(READLINE_BUILD_PACKAGE)" "yes"
471 SRC_HC_OPTS += -package readline -DUSE_READLINE
472 PKG_DEPENDS += readline
473 endif
474 endif # stage=1
475 endif # not windows
476
477 else
478
479 # No interpreter, so exclude Template Haskell modules
480 EXCLUDED_SRCS += deSugar/DsMeta.hs typecheck/TcSplice.lhs hsSyn/Convert.lhs
481
482 endif # bootstrapped with interpreter
483
484 # -----------------------------------------------
485 # mkdependC stuff
486 #
487 # Big Fudge to get around inherent problem that Makefile setup
488 # has got with 'mkdependC'.
489
490 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
491
492 # XXX not really correct, hschooks.c actually gets include files like
493 # RtsFlags.c from the installed GHC, but we can't tell mkdependC about that.
494 SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
495
496 # -----------------------------------------------------------------------------
497 #               Haskell compilations
498
499 SRC_HC_OPTS += \
500   -cpp -fglasgow-exts -fno-generics -Rghc-timing \
501   -I. -Iparser
502
503 # Omitted:      -I$(GHC_INCLUDE_DIR)
504 # We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS, 
505 # to avoid the use of an explicit path in GHC source files
506 #       (include "../includes/config.h"
507 # But alas GHC 4.08 (and others for all I know) uses this very
508 # same include path when compiling the .hc files it generates.
509 # Disaster!  Then the hc file sees the GHC 5.02 (or whatever)
510 # include files.   For the moment we've reverted to using
511 # an explicit path in the .hs sources
512 #
513 # For the benefit of <5.00 compilers, do include GHC_INCLUDE_DIR
514 # when generating dependencies. (=> it gets passed onto mkdependHS,
515 # which needs it).
516 SRC_MKDEPENDHS_OPTS += -I$(GHC_INCLUDE_DIR)
517
518 # We need System.Posix (or Posix when ghc < 6.2)
519 ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
520 ifeq "$(bootstrapped)" "YES"
521 SRC_HC_OPTS += -package Win32
522 PKG_DEPENDS += Win32
523 endif
524 else
525 ifeq "$(bootstrapped) $(ghc_ge_601)" "NO NO"
526 SRC_HC_OPTS += -package posix
527 else
528 SRC_HC_OPTS += -package unix
529 PKG_DEPENDS += unix
530 endif
531 endif
532
533 # We use the Cabal package in stages 2/3 only; in stage 1 we're using
534 # the libcompat library which provides the Cabal modules.
535 ifneq "$(stage)" "1"
536 SRC_HC_OPTS += -package Cabal
537 PKG_DEPENDS += Cabal
538 endif
539
540 ifeq "$(ghc_ge_603)" "YES"
541 # Ignore lang, to avoid potential clash with the Generics module if
542 # lang happens to be a dependency of some exposed package in the local
543 # GHC installation (eg. wxHaskell did this around 6.4).
544 SRC_HC_OPTS += -ignore-package lang
545 endif
546
547 SRC_CC_OPTS += -Iparser -I. -O
548 SRC_HC_OPTS += -recomp $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
549 SRC_HC_OPTS += -H16M
550
551 ifeq "$(BootingFromHc)" "YES"
552 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
553 endif
554
555 #       Special flags for particular modules
556 #       The standard suffix rule for compiling a Haskell file
557 #       adds these flags to the command line
558
559 # There used to be a -no-recomp flag on PrimOp, but why?
560 # It's an expensive module to recompile!
561 prelude/PrimOp_HC_OPTS          = -H80m
562
563
564 main/ParsePkgConf_HC_OPTS       += -fno-warn-incomplete-patterns
565 parser/Parser_HC_OPTS           += -fno-warn-incomplete-patterns
566
567 ifeq "$(ghc_ge_603)" "NO"
568 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
569 # primops on all platforms.
570 parser/Parser_HC_OPTS           += -fvia-C
571 # because the NCG can't handle the 64-bit math in here
572 prelude/PrelRules_HC_OPTS       += -fvia-C
573 # ByteCodeItbls uses primops that the NCG doesn't support.
574 ghci/ByteCodeItbls_HC_OPTS      += -fvia-C
575 ghci/ByteCodeLink_HC_OPTS       += -fvia-C -monly-3-regs
576 endif
577
578 # Careful optimisation of the parser: we don't want to throw everything
579 # at it, because that takes too long and doesn't buy much, but we do want
580 # to inline certain key external functions, so we instruct GHC not to
581 # throw away inlinings as it would normally do in -Onot mode:
582 parser/Parser_HC_OPTS           += -Onot -fno-ignore-interface-pragmas
583
584 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
585 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
586 endif
587
588 utils/Digraph_HC_OPTS           = -fglasgow-exts 
589
590 basicTypes/SrcLoc_HC_OPTS       = -funbox-strict-fields
591
592 # We always optimise some low-level modules, otherwise performance of
593 # a non-optimised compiler is severely affected.
594 main/BinIface_HC_OPTS           += -O
595 utils/Binary_HC_OPTS            += -O -funbox-strict-fields
596 utils/FastMutInt_HC_OPTS        += -O
597 utils/Encoding_HC_OPTS          += -O
598 utils/StringBuffer_HC_OPTS      += -O -funbox-strict-fields
599 utils/FastString_HC_OPTS        += -O -funbox-strict-fields
600
601 # ---- Profiling ----
602 #simplCore/Simplify_HC_OPTS = -auto-all
603 #simplCore/SimplEnv_HC_OPTS = -auto-all
604 #simplCore/SimplUtils_HC_OPTS = -auto-all
605
606 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
607 # DriverMkDepend), causing some of them to be commoned up.  We have a fix for
608 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
609 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
610 ghci/InteractiveUI_HC_OPTS      = -fno-cse
611 main/CmdLineOpts_HC_OPTS        = -fno-cse
612 main/DriverMkDepend_HC_OPTS     = -fno-cse
613 main/DriverPipeline_HC_OPTS     = -fno-cse
614 main/Finder_HC_OPTS             = -fno-cse
615 main/SysTools_HC_OPTS           = -fno-cse
616 main/StaticFlags_HC_OPTS        = -fno-cse
617
618 # The #include is vital for the via-C route, else the C
619 # compiler doesn't realise that the stcall foreign imports are indeed
620 # stdcall, and doesn't generate the Foo@8 name for them
621 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
622 main/SysTools_HC_OPTS           += '-\#include <windows.h>' '-\#include <process.h>'
623 endif
624
625 parser/Lexer_HC_OPTS += -funbox-strict-fields
626
627 # ghc_strlen percolates through so many modules that it is easier to get its
628 # prototype via a global option instead of a myriad of per-file OPTIONS
629 SRC_HC_OPTS += '-\#include "cutils.h"'
630
631 # ----------------------------------------------------------------------------
632 #               Generate supporting stuff for prelude/PrimOp.lhs 
633 #               from prelude/primops.txt
634
635 PRIMOP_BITS=primop-data-decl.hs-incl \
636             primop-tag.hs-incl  \
637             primop-list.hs-incl  \
638             primop-has-side-effects.hs-incl  \
639             primop-out-of-line.hs-incl  \
640             primop-commutable.hs-incl  \
641             primop-needs-wrapper.hs-incl  \
642             primop-can-fail.hs-incl  \
643             primop-strictness.hs-incl  \
644             primop-primop-info.hs-incl
645
646 CLEAN_FILES += prelude/primops.txt
647 CLEAN_FILES += $(PRIMOP_BITS)
648
649 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
650 SRC_CPP_OPTS += ${GhcCppOpts}
651
652 ifneq "$(BootingFromHc)" "YES"
653 prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
654 endif
655
656 ifneq "$(BootingFromHc)" "YES"
657 depend :: $(PRIMOP_BITS)
658 endif
659
660 # This is an ugly hack: we need stage1/$(PLATFORM_H) built before we
661 # preprocess primops.txt.pp, but we don't want to just add that
662 # dependency because we don't want $(PLATFORM_H) built during normal
663 # operations, because we don't have have dependencies from the .hs
664 # sources on it, and we don't want those dependencies because that
665 # would cause everything to be rebuilt every time the Makefile
666 # changed.  So here we add the required dependency only when making
667 # boot or depend:
668 ifneq "$(findstring boot, $(MAKECMDGOALS))$(findstring depend, $(MAKECMDGOALS))" ""
669 prelude/primops.txt.pp : stage1/$(PLATFORM_H)
670 endif
671
672 primop-data-decl.hs-incl: prelude/primops.txt
673         $(GENPRIMOP) --data-decl          < $< > $@
674 primop-tag.hs-incl: prelude/primops.txt
675         $(GENPRIMOP) --primop-tag         < $< > $@
676 primop-list.hs-incl: prelude/primops.txt
677         $(GENPRIMOP) --primop-list        < $< > $@
678 primop-has-side-effects.hs-incl: prelude/primops.txt
679         $(GENPRIMOP) --has-side-effects   < $< > $@
680 primop-out-of-line.hs-incl: prelude/primops.txt
681         $(GENPRIMOP) --out-of-line        < $< > $@
682 primop-commutable.hs-incl: prelude/primops.txt
683         $(GENPRIMOP) --commutable         < $< > $@
684 primop-needs-wrapper.hs-incl: prelude/primops.txt
685         $(GENPRIMOP) --needs-wrapper      < $< > $@
686 primop-can-fail.hs-incl: prelude/primops.txt
687         $(GENPRIMOP) --can-fail           < $< > $@
688 primop-strictness.hs-incl: prelude/primops.txt
689         $(GENPRIMOP) --strictness         < $< > $@
690 primop-primop-info.hs-incl: prelude/primops.txt
691         $(GENPRIMOP) --primop-primop-info < $< > $@
692
693 # Usages aren't used any more; but the generator 
694 # can still generate them if we want them back
695 primop-usage.hs-incl: prelude/primops.txt
696         $(GENPRIMOP) --usage              < $< > $@
697
698
699 #-----------------------------------------------------------------------------
700 #               Linking
701
702 # Include libghccompat in stage1 only.  In stage2 onwards, all these
703 # libraries will be available from the main libraries.
704
705 ifeq "$(stage)" "1"
706 include $(GHC_COMPAT_DIR)/compat.mk
707 endif
708
709 SRC_LD_OPTS += -no-link-chk
710
711 # -----------------------------------------------------------------------------
712 # create ghc-inplace, a convenient way to run ghc from the build tree...
713 # See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
714 # a real binary here rather than a shell script.
715
716 INPLACE_PROG = $(odir)/ghc-inplace$(exeext)
717 EXCLUDED_C_SRCS += ghc-inplace.c
718
719 # FPTOOLS_TOP_ABS platform uses backslashes, at least on Cygwin, but that
720 # will go wrong when we use it in a Haskell string below.
721 TOP_ABS=$(subst \\,/,$(FPTOOLS_TOP_ABS_PLATFORM))
722
723 GHC_PATH=$(TOP_ABS)/$(GHC_COMPILER_DIR_REL)/$(GHC_PROG)$(exeext)
724
725 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
726 INPLACE_EXTRA_FLAGS = -optc-DWINDOWS
727 endif
728
729 $(INPLACE_PROG): ghc-inplace.c
730         $(HC) -cpp -optc-DGHC_PATH=\"$(GHC_PATH)\" -optc-DTOP_ABS=\"$(TOP_ABS)\" $(INPLACE_EXTRA_FLAGS) $< -o $@
731
732 all :: $(INPLACE_PROG)
733
734 CLEAN_FILES += $(INPLACE_PROG)
735
736 ifeq "$(stage)" "1"
737 ghc-inplace : $(INPLACE_PROG)
738         $(RM) -f $@ && $(LN_S) $< $@
739
740 all :: ghc-inplace
741
742 CLEAN_FILES += ghc-inplace
743 endif
744
745 #-----------------------------------------------------------------------------
746 #               install
747
748 # We don't want ghc treated as an ordinary executable,
749 # but put it together with the libraries.
750 # Also don't want any interface files installed
751
752 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
753
754 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
755 INSTALL_LIBEXECS += $(GHC_PROG)
756 else
757 INSTALL_PROGS += $(GHC_PROG)
758 endif
759
760 # ----------------------------------------------------------------------------
761 # profiling.
762
763 # rename/RnBinds_HC_OPTS += -auto-all
764 # rename/RnEnv_HC_OPTS += -auto-all
765 # rename/RnExpr_HC_OPTS += -auto-all
766 # rename/RnHiFiles_HC_OPTS += -auto-all
767 # rename/RnHsSyn_HC_OPTS += -auto-all
768 # rename/Rename_HC_OPTS += -auto-all
769 # rename/RnIfaces_HC_OPTS += -auto-all
770 # rename/RnNames_HC_OPTS += -auto-all
771 # rename/RnSource_HC_OPTS += -auto-all
772 # rename/RnTypes_HC_OPTS += -auto-all
773
774 # typecheck/Inst_HC_OPTS += -auto-all
775 # typecheck/TcBinds_HC_OPTS += -auto-all
776 # typecheck/TcClassDcl_HC_OPTS += -auto-all
777 # typecheck/TcDefaults_HC_OPTS += -auto-all
778 # typecheck/TcDeriv_HC_OPTS += -auto-all
779 # typecheck/TcEnv_HC_OPTS += -auto-all
780 # typecheck/TcExpr_HC_OPTS += -auto-all
781 # typecheck/TcForeign_HC_OPTS += -auto-all
782 # typecheck/TcGenDeriv_HC_OPTS += -auto-all
783 # typecheck/TcHsSyn_HC_OPTS += -auto-all
784 # typecheck/TcIfaceSig_HC_OPTS += -auto-all
785 # typecheck/TcInstDcls_HC_OPTS += -auto-all
786 # typecheck/TcMatches_HC_OPTS += -auto-all
787 # typecheck/TcMonoType_HC_OPTS += -auto-all
788 # typecheck/TcMType_HC_OPTS += -auto-all
789 # typecheck/TcPat_HC_OPTS += -auto-all
790 # typecheck/TcRnDriver_HC_OPTS += -auto-all
791 # #typecheck/TcRnMonad_HC_OPTS += -auto-all
792 # #typecheck/TcRnTypes_HC_OPTS += -auto-all
793 # typecheck/TcRules_HC_OPTS += -auto-all
794 # typecheck/TcSimplify_HC_OPTS += -auto-all
795 # typecheck/TcSplice_HC_OPTS += -auto-all
796 # typecheck/TcTyClsDecls_HC_OPTS += -auto-all
797 # typecheck/TcTyDecls_HC_OPTS += -auto-all
798 # typecheck/TcType_HC_OPTS += -auto-all
799 # typecheck/TcUnify_HC_OPTS += -auto-all
800
801 coreSyn/CorePrep_HC_OPTS += -auto-all
802 # parser/Parser_HC_OPTS += -fasm
803
804 #-----------------------------------------------------------------------------
805 # Building the GHC package
806
807 # The GHC package is made from the stage 2 build and later.
808 # Fortunately the package build system framework more or less does the
809 # right thing for us here.
810
811 ifneq "$(findstring $(stage), 2 3)" ""
812 BUILD_GHC_PACKAGE=YES
813 endif
814
815 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
816 PACKAGE = ghc
817 HIERARCHICAL_LIB = NO
818 VERSION = $(ProjectVersion)
819 PKG_DEPENDS += base haskell98
820 PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(PKG_DEPENDS)'
821 PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
822
823 # Omit Main from the library, the client will want to plug their own Main in
824 LIBOBJS = $(filter-out $(odir)/main/Main.o   $(odir)/parser/hschooks.o     \
825                        $(odir)/main/Main.p_o $(odir)/parser/hschooks.p_o,  \
826                        $(OBJS))
827
828 # disable splitting: it won't really help with GHC, and the specialised
829 # build system for compiler/ isn't set up to handle it.
830 SplitObjs = NO
831
832 # the package build system likes to set WAYS=$(GhcLibWays), but we don't 
833 # really want to build the whole of GHC multiple ways... if you do,
834 # set GhcCompilerWays instead.
835 GhcLibWays = $(GhcCompilerWays)
836
837 # override $(GhcLibHcOpts): we want GhcStage2HcOpts to take precedence
838 GhcLibHcOpts =
839
840 # override default definition of HS_IFACES so we can add $(odir)
841 HS_IFACES   = $(addsuffix .$(way_)hi,$(basename $(HS_OBJS)))
842
843 # Haddock can't handle recursive modules currently, so we disable it for now.
844 HADDOCK_DOCS = NO
845
846 # Tell package.mk not to set $(HC)
847 NO_SET_HC = YES
848
849 # The stage 2 GHC binary itself is built by  compiling main/Main.hs 
850 # (the same as used in stage 1) against the GHC package.
851 #
852 # This is done by compiling Main.hs separately and linking it with 
853 # -package ghc.  This is done using a separate Makefile, Makefile.ghcbin
854 # Why? See comments in Makefile.ghcbin
855
856 # The stage 2 and stage 3 package.conf.in files are different, because they
857 # point to either the stage2/ or stage3/ dirs in import-dirs.  Hence before
858 # linking the ghc binary we must install the correct version of the package
859 # configuration.  Yeuch... maybe one day this will all be done more cleanly.
860 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
861
862 ifeq "$(GhcBuildDylibs)" "YES"
863 ifeq "$(darwin_TARGET_OS)" "1"
864 GhcLibraryName=libHS$(PACKAGE)$(_way)_dyn.dylib
865 else
866 GhcLibraryName=libHS$(PACKAGE)$(_way)_dyn.so
867 endif
868 else
869 GhcLibraryName=libHS$(PACKAGE)$(_way).a
870 endif
871
872 ifneq "$(DOING_BIN_DIST)" "YES"
873 $(GHC_PROG) : $(GhcLibraryName) main/Main.hs
874         $(RM) package.conf.inplace
875         $(RM) $(STAMP_PKG_CONF)
876         $(MAKE) $(STAMP_PKG_CONF)
877         $(MAKE) -f Makefile.ghcbin $(MFLAGS) HS_PROG=$(GHC_PROG) $@
878 endif
879
880 # Propagate standard targets to Makefile.ghcbin
881 docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
882         $(MAKE) -f Makefile.ghcbin $(MFLAGS) $@
883 endif
884
885 #-----------------------------------------------------------------------------
886 #               clean
887
888 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
889
890 #-----------------------------------------------------------------------------
891 #               Include target-rule boilerplate
892
893 # Don't use the default MKDEPENDHS stuff... we'll do our own, below
894 MKDEPENDHS_SRCS =
895 MKDEPENDC_SRCS =
896
897 # Make doesn't work this out for itself, it seems
898 parser/Parser.y : parser/Parser.y.pp
899 EXTRA_SRCS += parser/Parser.y
900
901
902 #-----------------------------------------------------------------------------
903 #               Source files for tags file generation
904 #
905 # We want to excluded derived sources, because they won't be in the source
906 # tree, which is where we are going to move the TAGS file to.a
907
908 TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
909
910 include $(TOP)/mk/target.mk
911
912 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
913 ifeq "$(way)" ""
914 all :: $(GHC_PROG)
915 endif
916 endif
917
918 $(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE='"$(stage)"'
919
920 #-----------------------------------------------------------------------------
921 # binary-dist
922
923 ifeq "$(DOING_BIN_DIST)" "YES"
924 # This is derived from the sources when we are in a source tree, but we
925 # don't have any sources in a bindist, so we have to shortcut it
926 HS_IFACES := $(wildcard stage$(stage)/*/*.hi)
927 endif
928
929 binary-dist:
930         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler
931         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler/stage$(stage)
932         echo "stage=$(stage)"                > $(BIN_DIST_DIR)/compiler/Makefile
933         cat Makefile                        >> $(BIN_DIST_DIR)/compiler/Makefile
934         $(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/compiler/
935         set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
936         set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
937 ifneq "$(INSTALL_LIBS)" ""
938         set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
939 endif
940 ifneq "$(INSTALL_PROGS)" ""
941         set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
942 endif
943 ifneq "$(INSTALL_LIBEXECS)" ""
944         set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
945 endif
946
947 # -----------------------------------------------------------------------------
948 # Explicit dependencies
949
950 # Some .hs files #include other source files, but since ghc -M doesn't spit out
951 # these dependencies we have to include them manually.
952
953 # We don't add dependencies on HsVersions.h, ghcautoconf.h, or ghc_boot_platform.h,
954 # because then modifying one of these files would force recompilation of everything,
955 # which is probably not what you want.  However, it does mean you have to be
956 # careful to recompile stuff you need if you reconfigure or change HsVersions.h.
957
958 # Aargh, these don't work properly anyway, because GHC's recompilation checker
959 # just reports "compilation NOT required".  Do we have to add -no-recomp for each
960 # of these .hs files?  I haven't done anything about this yet.
961
962 $(odir)/codeGen/Bitmap.$(way_)o         :  ../includes/MachDeps.h
963 $(odir)/codeGen/CgCallConv.$(way_)o     :  ../includes/StgFun.h
964 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/MachDeps.h
965 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/Constants.h
966 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/DerivedConstants.h
967 $(odir)/codeGen/CgTicky.$(way_)o        :  ../includes/DerivedConstants.h
968 $(odir)/codeGen/ClosureInfo.$(way_)o    :  ../includes/MachDeps.h
969 $(odir)/codeGen/SMRep.$(way_)o          :  ../includes/MachDeps.h
970 $(odir)/codeGen/SMRep.$(way_)o          :  ../includes/ClosureTypes.h
971 $(odir)/ghci/ByteCodeAsm.$(way_)o       :  ../includes/Bytecodes.h
972 $(odir)/ghci/ByteCodeFFI.$(way_)o       :  nativeGen/NCG.h
973 $(odir)/ghci/ByteCodeInstr.$(way_)o     :  ../includes/MachDeps.h
974 $(odir)/ghci/ByteCodeItbls.$(way_)o     :  ../includes/ClosureTypes.h
975 $(odir)/ghci/ByteCodeItbls.$(way_)o     :  nativeGen/NCG.h
976 $(odir)/main/Constants.$(way_)o         :  ../includes/MachRegs.h
977 $(odir)/main/Constants.$(way_)o         :  ../includes/Constants.h
978 $(odir)/main/Constants.$(way_)o         :  ../includes/MachDeps.h
979 $(odir)/main/Constants.$(way_)o         :  ../includes/DerivedConstants.h
980 $(odir)/main/Constants.$(way_)o         :  ../includes/GHCConstants.h
981 $(odir)/nativeGen/AsmCodeGen.$(way_)o   :  nativeGen/NCG.h
982 $(odir)/nativeGen/MachCodeGen.$(way_)o  :  nativeGen/NCG.h
983 $(odir)/nativeGen/MachCodeGen.$(way_)o  : ../includes/MachDeps.h
984 $(odir)/nativeGen/MachInstrs.$(way_)o   :  nativeGen/NCG.h
985 $(odir)/nativeGen/MachRegs.$(way_)o     :  nativeGen/NCG.h
986 $(odir)/nativeGen/MachRegs.$(way_)o     :  ../includes/MachRegs.h
987 $(odir)/nativeGen/PositionIndependentCode.$(way_)o :  nativeGen/NCG.h
988 $(odir)/nativeGen/PprMach.$(way_)o      :  nativeGen/NCG.h
989 $(odir)/nativeGen/RegAllocInfo.$(way_)o :  nativeGen/NCG.h
990 $(odir)/typecheck/TcForeign.$(way_)o    :  nativeGen/NCG.h
991 $(odir)/utils/Binary.$(way_)o           :  ../includes/MachDeps.h
992 $(odir)/utils/FastMutInt.$(way_)o       :  ../includes/MachDeps.h
993
994 # -----------------------------------------------------------------------------
995 # Dependencies
996
997 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
998
999 MKDEPENDHS=$(HC)
1000
1001 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
1002 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
1003         touch .depend-BASE
1004 ifneq "$(BootingFromHc)" "YES"
1005         $(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)
1006 endif
1007         $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS) 
1008         $(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g; s@^.*/compat.*$$@@g;' <.depend-BASE >.depend-$(stage)
1009 # The binmode stuff tells perl not to add stupid ^M's to the output
1010 #
1011 # The /lib/compat replacement is to workaround a bug in the
1012 # -optdep--exclude-module flag in GHC 6.4.  It is not required for any
1013 # other version of GHC, but doesn't do any harm.
1014
1015 ifeq "$(MakefileDeps)" "YES"
1016 $(CONFIG_HS) : Makefile
1017 stage1/$(PLATFORM_H) : Makefile
1018 stage2/$(PLATFORM_H) : Makefile
1019 endif
1020
1021 -include .depend-$(stage)