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