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