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