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