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