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