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