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