Remove a redundant comment
[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 #       Special flags for particular modules
575 #       The standard suffix rule for compiling a Haskell file
576 #       adds these flags to the command line
577
578 # There used to be a -fforce-recomp flag on PrimOp, but why?
579 # It's an expensive module to recompile!
580 prelude/PrimOp_HC_OPTS          = -H80m
581
582
583 main/ParsePkgConf_HC_OPTS       += -fno-warn-incomplete-patterns
584 parser/Parser_HC_OPTS           += -fno-warn-incomplete-patterns
585
586 # Careful optimisation of the parser: we don't want to throw everything
587 # at it, because that takes too long and doesn't buy much, but we do want
588 # to inline certain key external functions, so we instruct GHC not to
589 # throw away inlinings as it would normally do in -O0 mode:
590 parser/Parser_HC_OPTS           += -O0 -fno-ignore-interface-pragmas
591
592 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
593 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
594 endif
595
596 # basicTypes/SrcLoc_HC_OPTS     = -funbox-strict-fields
597
598 # ---- Profiling ----
599 #simplCore/Simplify_HC_OPTS = -auto-all
600 #simplCore/SimplEnv_HC_OPTS = -auto-all
601 #simplCore/SimplUtils_HC_OPTS = -auto-all
602
603 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
604 # DriverMkDepend), causing some of them to be commoned up.  We have a fix for
605 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
606 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
607 ghci/InteractiveUI_HC_OPTS      = -fno-cse
608 main/CmdLineOpts_HC_OPTS        = -fno-cse
609 main/DriverMkDepend_HC_OPTS     = -fno-cse
610 main/DriverPipeline_HC_OPTS     = -fno-cse
611 main/Finder_HC_OPTS             = -fno-cse
612 main/SysTools_HC_OPTS           = -fno-cse
613 main/StaticFlags_HC_OPTS        = -fno-cse
614
615 # The #include is vital for the via-C route, else the C
616 # compiler doesn't realise that the stcall foreign imports are indeed
617 # stdcall, and doesn't generate the Foo@8 name for them
618 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
619 main/SysTools_HC_OPTS           += '-\#include <windows.h>' '-\#include <process.h>'
620 endif
621
622 # ghc_strlen percolates through so many modules that it is easier to get its
623 # prototype via a global option instead of a myriad of per-file OPTIONS
624 SRC_HC_OPTS += '-\#include "cutils.h"'
625
626 ifeq "$(ghc_ge_605)" "NO"
627 utils/LazyUniqFM_HC_OPTS += -fallow-undecidable-instances
628 endif
629
630 # ----------------------------------------------------------------------------
631 #               Generate supporting stuff for prelude/PrimOp.lhs 
632 #               from prelude/primops.txt
633
634 PRIMOP_BITS=primop-data-decl.hs-incl \
635             primop-tag.hs-incl  \
636             primop-list.hs-incl  \
637             primop-has-side-effects.hs-incl  \
638             primop-out-of-line.hs-incl  \
639             primop-commutable.hs-incl  \
640             primop-needs-wrapper.hs-incl  \
641             primop-can-fail.hs-incl  \
642             primop-strictness.hs-incl  \
643             primop-primop-info.hs-incl
644
645 CLEAN_FILES += prelude/primops.txt
646 CLEAN_FILES += $(PRIMOP_BITS)
647
648 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
649 SRC_CPP_OPTS += ${GhcCppOpts}
650
651 ifneq "$(BootingFromHc)" "YES"
652 prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
653 endif
654
655 ifneq "$(BootingFromHc)" "YES"
656 depend :: $(PRIMOP_BITS)
657 endif
658
659 # This is an ugly hack: we need stage1/$(PLATFORM_H) built before we
660 # preprocess primops.txt.pp, but we don't want to just add that
661 # dependency because we don't want $(PLATFORM_H) built during normal
662 # operations, because we don't have have dependencies from the .hs
663 # sources on it, and we don't want those dependencies because that
664 # would cause everything to be rebuilt every time the Makefile
665 # changed.  So here we add the required dependency only when making
666 # boot or depend:
667 ifneq "$(findstring boot, $(MAKECMDGOALS))$(findstring depend, $(MAKECMDGOALS))" ""
668 prelude/primops.txt.pp : stage1/$(PLATFORM_H)
669 endif
670
671 primop-data-decl.hs-incl: prelude/primops.txt
672         $(GENPRIMOP) --data-decl          < $< > $@
673 primop-tag.hs-incl: prelude/primops.txt
674         $(GENPRIMOP) --primop-tag         < $< > $@
675 primop-list.hs-incl: prelude/primops.txt
676         $(GENPRIMOP) --primop-list        < $< > $@
677 primop-has-side-effects.hs-incl: prelude/primops.txt
678         $(GENPRIMOP) --has-side-effects   < $< > $@
679 primop-out-of-line.hs-incl: prelude/primops.txt
680         $(GENPRIMOP) --out-of-line        < $< > $@
681 primop-commutable.hs-incl: prelude/primops.txt
682         $(GENPRIMOP) --commutable         < $< > $@
683 primop-needs-wrapper.hs-incl: prelude/primops.txt
684         $(GENPRIMOP) --needs-wrapper      < $< > $@
685 primop-can-fail.hs-incl: prelude/primops.txt
686         $(GENPRIMOP) --can-fail           < $< > $@
687 primop-strictness.hs-incl: prelude/primops.txt
688         $(GENPRIMOP) --strictness         < $< > $@
689 primop-primop-info.hs-incl: prelude/primops.txt
690         $(GENPRIMOP) --primop-primop-info < $< > $@
691
692 # Usages aren't used any more; but the generator 
693 # can still generate them if we want them back
694 primop-usage.hs-incl: prelude/primops.txt
695         $(GENPRIMOP) --usage              < $< > $@
696
697
698 #-----------------------------------------------------------------------------
699 #               Linking
700
701 ifeq "$(GhcUnregisterised)" "NO"
702 ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
703 # needed for generating proper relocation in large binaries: trac #856
704 SRC_LD_OPTS += -optl-Wl,--relax
705 endif
706 endif
707
708 # -----------------------------------------------------------------------------
709 # create ghc-inplace, a convenient way to run ghc from the build tree...
710 # See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
711 # a real binary here rather than a shell script.
712
713 INPLACE_SRC  = $(odir)/ghc-inplace.c
714 INPLACE_PROG = $(odir)/ghc-inplace$(_way)$(exeext)
715 INPLACE_EXTRA_FLAGS = -I$(TOP)/includes
716 EXCLUDED_C_SRCS += ghc-inplace.c
717
718 CLEAN_FILES += $(INPLACE_SRC)
719
720 GHC_PATH=$(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)/$(GHC_PROG)$(exeext)
721
722 $(INPLACE_PROG): ghc-inplace.c
723         $(SED) -e "s@GHC_PATH@$(GHC_PATH)@g" -e "s@TOP_ABS@$(FPTOOLS_TOP_ABS)@g" < $< > $(INPLACE_SRC)
724         $(HC) -cpp $(INPLACE_EXTRA_FLAGS) $(INPLACE_SRC) -o $@
725
726 all :: $(INPLACE_PROG)
727
728 CLEAN_FILES += $(INPLACE_PROG)
729
730 ifeq "$(stage)" "1"
731 ghc-inplace : $(INPLACE_PROG)
732         $(RM) -f $@ && $(LN_S) $< $@
733
734 all :: ghc-inplace
735
736 CLEAN_FILES += ghc-inplace
737 endif
738
739 #-----------------------------------------------------------------------------
740 #               install
741
742 # We don't want ghc treated as an ordinary executable,
743 # but put it together with the libraries.
744 # Also don't want any interface files installed
745
746 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
747
748 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
749 INSTALL_LIBEXECS += $(GHC_PROG)
750 else
751 INSTALL_PROGS += $(GHC_PROG)
752 endif
753
754 # ----------------------------------------------------------------------------
755 # profiling.
756
757 # rename/RnBinds_HC_OPTS += -auto-all
758 # rename/RnEnv_HC_OPTS += -auto-all
759 # rename/RnExpr_HC_OPTS += -auto-all
760 # rename/RnHiFiles_HC_OPTS += -auto-all
761 # rename/RnHsSyn_HC_OPTS += -auto-all
762 # rename/Rename_HC_OPTS += -auto-all
763 # rename/RnIfaces_HC_OPTS += -auto-all
764 # rename/RnNames_HC_OPTS += -auto-all
765 # rename/RnSource_HC_OPTS += -auto-all
766 # rename/RnTypes_HC_OPTS += -auto-all
767
768 # typecheck/Inst_HC_OPTS += -auto-all
769 # typecheck/TcBinds_HC_OPTS += -auto-all
770 # typecheck/TcClassDcl_HC_OPTS += -auto-all
771 # typecheck/TcDefaults_HC_OPTS += -auto-all
772 # typecheck/TcDeriv_HC_OPTS += -auto-all
773 # typecheck/TcEnv_HC_OPTS += -auto-all
774 # typecheck/TcExpr_HC_OPTS += -auto-all
775 # typecheck/TcForeign_HC_OPTS += -auto-all
776 # typecheck/TcGenDeriv_HC_OPTS += -auto-all
777 # typecheck/TcHsSyn_HC_OPTS += -auto-all
778 # typecheck/TcIfaceSig_HC_OPTS += -auto-all
779 # typecheck/TcInstDcls_HC_OPTS += -auto-all
780 # typecheck/TcMatches_HC_OPTS += -auto-all
781 # typecheck/TcMonoType_HC_OPTS += -auto-all
782 # typecheck/TcMType_HC_OPTS += -auto-all
783 # typecheck/TcPat_HC_OPTS += -auto-all
784 # typecheck/TcRnDriver_HC_OPTS += -auto-all
785 # #typecheck/TcRnMonad_HC_OPTS += -auto-all
786 # #typecheck/TcRnTypes_HC_OPTS += -auto-all
787 # typecheck/TcRules_HC_OPTS += -auto-all
788 # typecheck/TcSimplify_HC_OPTS += -auto-all
789 # typecheck/TcSplice_HC_OPTS += -auto-all
790 # typecheck/TcTyClsDecls_HC_OPTS += -auto-all
791 # typecheck/TcTyDecls_HC_OPTS += -auto-all
792 # typecheck/TcType_HC_OPTS += -auto-all
793 # typecheck/TcUnify_HC_OPTS += -auto-all
794
795 # coreSyn/CorePrep_HC_OPTS += -auto-all
796
797 #-----------------------------------------------------------------------------
798 # Building the GHC package
799
800 # The GHC package is made from the stage 2 build and later.
801 # Fortunately the package build system framework more or less does the
802 # right thing for us here.
803
804 ifneq "$(findstring $(stage), 2 3)" ""
805 BUILD_GHC_PACKAGE=YES
806 endif
807
808 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
809 PACKAGE = ghc
810 HIERARCHICAL_LIB = NO
811 VERSION = $(ProjectVersion)
812 PKG_DEPENDS += base haskell98
813 LIB_LD_OPTS += $(foreach pkg,$(PKG_DEPENDS),-package $(pkg))
814 # We have to expand each package dependency with its version, which we
815 # can do by calling "ghc-pkg list $pkg --simple-output".
816 PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(foreach pkg,$(PKG_DEPENDS),$(shell $(GHC_PKG_INPLACE) latest --global $(pkg)))'
817 # We want to define STAGE to be like "2" in the Haskell code, so we need
818 # to quote the "s so that they don't get interpreted by the shell.
819 PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
820
821 # Omit Main from the library, the client will want to plug their own Main in
822 LIBOBJS = $(filter-out $(odir)/main/Main.$(way_)o $(odir)/parser/hschooks.$(way_)o, $(OBJS))
823
824 # disable splitting: it won't really help with GHC, and the specialised
825 # build system for compiler/ isn't set up to handle it.
826 SplitObjs = NO
827
828 # the package build system likes to set WAYS=$(GhcLibWays), but we don't 
829 # really want to build the whole of GHC multiple ways... if you do,
830 # set GhcCompilerWays instead.
831 GhcLibWays = $(GhcCompilerWays)
832
833 # override $(GhcLibHcOpts): we want GhcStage2HcOpts to take precedence
834 GhcLibHcOpts =
835
836 ifeq "$(DOING_BIN_DIST)" "YES"
837 # This is derived from the sources when we are in a source tree, but we
838 # don't have any sources in a bindist, so we have to shortcut it
839 HS_IFACES := $(wildcard stage$(stage)/*/*.hi)
840 else
841 # override default definition of HS_IFACES so we can add $(odir)
842 HS_IFACES   = $(addsuffix .$(way_)hi,$(basename $(HS_OBJS)))
843 endif
844
845 # Haddock can't handle recursive modules currently, so we disable it for now.
846 override HADDOCK_DOCS = NO
847
848 # Tell package.mk not to set $(HC)
849 NO_SET_HC = YES
850
851 # The stage 2 GHC binary itself is built by  compiling main/Main.hs 
852 # (the same as used in stage 1) against the GHC package.
853 #
854 # This is done by compiling Main.hs separately and linking it with 
855 # -package ghc.  This is done using a separate Makefile, Makefile.ghcbin
856 # Why? See comments in Makefile.ghcbin
857
858 # The stage 2 and stage 3 package.conf.in files are different, because they
859 # point to either the stage2/ or stage3/ dirs in import-dirs.  Hence before
860 # linking the ghc binary we must install the correct version of the package
861 # configuration.  Yeuch... maybe one day this will all be done more cleanly.
862 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
863
864 # Propagate standard targets to Makefile.ghcbin
865 docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
866         $(MAKE) -f Makefile.ghcbin $(MFLAGS) $@
867 endif
868
869 #-----------------------------------------------------------------------------
870 #               clean
871
872 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
873
874 #-----------------------------------------------------------------------------
875 #               Include target-rule boilerplate
876
877 # Don't use the default MKDEPENDHS stuff... we'll do our own, below
878 MKDEPENDHS_SRCS =
879 MKDEPENDC_SRCS =
880
881 # Make doesn't work this out for itself, it seems
882 parser/Parser.y : parser/Parser.y.pp
883 EXTRA_SRCS += parser/Parser.y
884
885
886 #-----------------------------------------------------------------------------
887 #               Source files for tags file generation
888 #
889 # We want to excluded derived sources, because they won't be in the source
890 # tree, which is where we are going to move the TAGS file to.a
891
892 TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
893
894 WRONG_GHCTAGS_HS_SRCS = $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
895 # above is wrong because of the following problem:
896 #      module `main:DataCon' is defined in multiple files: basicTypes/DataCon.lhs
897 #                                                        basicTypes/DataCon.lhs-boot
898
899 GHCTAGS_HS_SRCS = $(HS_SRCS)
900 GHCTAGS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
901 GHCTAGS_HC_OPTS += -DSTAGE='"$(stage)"'
902
903 #------------------------------------------------------------
904 #                       Tags
905
906 .PHONY: ghctags
907
908 ghctags :: $(GHCTAGS_HS_SRCS) $(TAGS_C_SRCS)
909         @if [ "$(stage)" != 2 ]; then echo "Must use 'make stage=2 ghctags'"; exit 1; fi
910         @$(RM) TAGS
911         @touch TAGS
912         @echo SOURCES ARE "$(GHCTAGS_HS_SRCS)"
913         : ifneq "$(GHCTAGS_HS_SRCS)" ""
914         @echo TIME TO ROCK AND ROLL
915         # $(GHCTAGS_INPLACE) -- $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) -- $(GHCTAGS_HS_SRCS)
916         $(GHCTAGS_INPLACE) -- $(GHCTAGS_HC_OPTS) -- $(GHCTAGS_HS_SRCS)
917         : endif
918 ifneq "$(TAGS_C_SRCS)" ""
919         etags -a $(TAGS_C_SRCS)
920 endif
921         @( 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?
922
923 include $(TOP)/mk/target.mk
924
925 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
926 all :: $(GHC_PROG)
927 endif
928
929 $(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE='"$(stage)"'
930
931 ifneq "$(findstring $(stage), 2 3)" ""
932 $(warning LIBRARY is $(LIBRARY))
933
934 ifneq "$(DOING_BIN_DIST)" "YES"
935 $(GHC_PROG) : $(LIBRARY) main/Main.hs
936         $(RM) package.conf.inplace
937         $(RM) $(STAMP_PKG_CONF)
938         $(MAKE) way="" $(STAMP_PKG_CONF)
939         $(MAKE) -f Makefile.ghcbin $(MFLAGS) HS_PROG=$(GHC_PROG) $@
940 endif
941 endif
942
943
944 #-----------------------------------------------------------------------------
945 # binary-dist
946
947 binary-dist:
948         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler
949         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler/stage$(stage)
950         echo "stage=$(stage)"                > $(BIN_DIST_DIR)/compiler/Makefile
951         cat Makefile                        >> $(BIN_DIST_DIR)/compiler/Makefile
952         $(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/compiler/
953         set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
954         set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
955 ifneq "$(INSTALL_LIBS)" ""
956         set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
957 endif
958 ifneq "$(INSTALL_PROGS)" ""
959         set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
960 endif
961 ifneq "$(INSTALL_LIBEXECS)" ""
962         set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
963 endif
964
965 # -----------------------------------------------------------------------------
966 # Explicit dependencies
967
968 # Some .hs files #include other source files, but since ghc -M doesn't spit out
969 # these dependencies we have to include them manually.
970
971 # We don't add dependencies on HsVersions.h, ghcautoconf.h, or ghc_boot_platform.h,
972 # because then modifying one of these files would force recompilation of everything,
973 # which is probably not what you want.  However, it does mean you have to be
974 # careful to recompile stuff you need if you reconfigure or change HsVersions.h.
975
976 # Aargh, these don't work properly anyway, because GHC's recompilation checker
977 # just reports "compilation NOT required".  Do we have to add -fforce-recomp for each
978 # of these .hs files?  I haven't done anything about this yet.
979
980 $(odir)/codeGen/Bitmap.$(way_)o         :  ../includes/MachDeps.h
981 $(odir)/codeGen/CgCallConv.$(way_)o     :  ../includes/StgFun.h
982 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/MachDeps.h
983 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/Constants.h
984 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/DerivedConstants.h
985 $(odir)/codeGen/CgTicky.$(way_)o        :  ../includes/DerivedConstants.h
986 $(odir)/codeGen/ClosureInfo.$(way_)o    :  ../includes/MachDeps.h
987 $(odir)/codeGen/SMRep.$(way_)o          :  ../includes/MachDeps.h
988 $(odir)/codeGen/SMRep.$(way_)o          :  ../includes/ClosureTypes.h
989 $(odir)/ghci/ByteCodeAsm.$(way_)o       :  ../includes/Bytecodes.h
990 $(odir)/ghci/ByteCodeFFI.$(way_)o       :  nativeGen/NCG.h
991 $(odir)/ghci/ByteCodeInstr.$(way_)o     :  ../includes/MachDeps.h
992 $(odir)/ghci/ByteCodeItbls.$(way_)o     :  ../includes/ClosureTypes.h
993 $(odir)/ghci/ByteCodeItbls.$(way_)o     :  nativeGen/NCG.h
994 $(odir)/main/Constants.$(way_)o         :  ../includes/MachRegs.h
995 $(odir)/main/Constants.$(way_)o         :  ../includes/Constants.h
996 $(odir)/main/Constants.$(way_)o         :  ../includes/MachDeps.h
997 $(odir)/main/Constants.$(way_)o         :  ../includes/DerivedConstants.h
998 $(odir)/main/Constants.$(way_)o         :  ../includes/GHCConstants.h
999 $(odir)/nativeGen/AsmCodeGen.$(way_)o   :  nativeGen/NCG.h
1000 $(odir)/nativeGen/MachCodeGen.$(way_)o  :  nativeGen/NCG.h
1001 $(odir)/nativeGen/MachCodeGen.$(way_)o  : ../includes/MachDeps.h
1002 $(odir)/nativeGen/MachInstrs.$(way_)o   :  nativeGen/NCG.h
1003 $(odir)/nativeGen/MachRegs.$(way_)o     :  nativeGen/NCG.h
1004 $(odir)/nativeGen/MachRegs.$(way_)o     :  ../includes/MachRegs.h
1005 $(odir)/nativeGen/PositionIndependentCode.$(way_)o :  nativeGen/NCG.h
1006 $(odir)/nativeGen/PprMach.$(way_)o      :  nativeGen/NCG.h
1007 $(odir)/nativeGen/RegAllocInfo.$(way_)o :  nativeGen/NCG.h
1008 $(odir)/typecheck/TcForeign.$(way_)o    :  nativeGen/NCG.h
1009 $(odir)/utils/Binary.$(way_)o           :  ../includes/MachDeps.h
1010 $(odir)/utils/FastMutInt.$(way_)o       :  ../includes/MachDeps.h
1011
1012 # -----------------------------------------------------------------------------
1013 # Dependencies
1014
1015 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
1016
1017 MKDEPENDHS=$(HC)
1018
1019 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
1020 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
1021         touch .depend-BASE
1022 ifneq "$(BootingFromHc)" "YES"
1023         $(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)
1024 endif
1025         $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS) 
1026         $(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g;' <.depend-BASE >.depend-$(stage)
1027 # The binmode stuff tells perl not to add stupid ^M's to the output
1028
1029 ifeq "$(MakefileDeps)" "YES"
1030 $(CONFIG_HS) : Makefile
1031 stage1/$(PLATFORM_H) : Makefile
1032 stage2/$(PLATFORM_H) : Makefile
1033 endif
1034
1035 -include .depend-$(stage)