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