Optionally use libffi to implement 'foreign import "wrapper"' (#793)
[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 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 ifeq "$(ghc_ge_603)" "YES"
571 # Ignore lang, to avoid potential clash with the Generics module if
572 # lang happens to be a dependency of some exposed package in the local
573 # GHC installation (eg. wxHaskell did this around 6.4).
574 SRC_HC_OPTS += -ignore-package lang
575 endif
576
577 SRC_CC_OPTS += -Iparser -I. -O
578 SRC_HC_OPTS += -recomp $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
579 SRC_HC_OPTS += -H16M
580
581 ifeq "$(BootingFromHc)" "YES"
582 SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
583 endif
584
585 #       Special flags for particular modules
586 #       The standard suffix rule for compiling a Haskell file
587 #       adds these flags to the command line
588
589 # There used to be a -no-recomp flag on PrimOp, but why?
590 # It's an expensive module to recompile!
591 prelude/PrimOp_HC_OPTS          = -H80m
592
593
594 main/ParsePkgConf_HC_OPTS       += -fno-warn-incomplete-patterns
595 parser/Parser_HC_OPTS           += -fno-warn-incomplete-patterns
596
597 ifeq "$(ghc_ge_603)" "NO"
598 # Use -fvia-C since the NCG can't handle the narrow16Int# (and intToInt16#?)
599 # primops on all platforms.
600 parser/Parser_HC_OPTS           += -fvia-C
601 # because the NCG can't handle the 64-bit math in here
602 prelude/PrelRules_HC_OPTS       += -fvia-C
603 # ByteCodeItbls uses primops that the NCG doesn't support.
604 ghci/ByteCodeItbls_HC_OPTS      += -fvia-C
605 ghci/ByteCodeLink_HC_OPTS       += -fvia-C -monly-3-regs
606 endif
607
608 # Careful optimisation of the parser: we don't want to throw everything
609 # at it, because that takes too long and doesn't buy much, but we do want
610 # to inline certain key external functions, so we instruct GHC not to
611 # throw away inlinings as it would normally do in -Onot mode:
612 parser/Parser_HC_OPTS           += -Onot -fno-ignore-interface-pragmas
613
614 ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
615 rename/RnMonad_HC_OPTS          =  -O2 -O2-for-C
616 endif
617
618 utils/Digraph_HC_OPTS           = -fglasgow-exts 
619
620 basicTypes/SrcLoc_HC_OPTS       = -funbox-strict-fields
621
622 # We always optimise some low-level modules, otherwise performance of
623 # a non-optimised compiler is severely affected.
624 main/BinIface_HC_OPTS           += -O
625 utils/Binary_HC_OPTS            += -O -funbox-strict-fields
626 utils/FastMutInt_HC_OPTS        += -O
627 utils/Encoding_HC_OPTS          += -O
628 utils/StringBuffer_HC_OPTS      += -O -funbox-strict-fields
629 utils/FastString_HC_OPTS        += -O -funbox-strict-fields
630
631 # ---- Profiling ----
632 #simplCore/Simplify_HC_OPTS = -auto-all
633 #simplCore/SimplEnv_HC_OPTS = -auto-all
634 #simplCore/SimplUtils_HC_OPTS = -auto-all
635
636 # CSE interacts badly with top-level IORefs (reportedly in DriverState and
637 # DriverMkDepend), causing some of them to be commoned up.  We have a fix for
638 # this in 5.00+, but earlier versions of the compiler will need CSE turned off.
639 # To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
640 ghci/InteractiveUI_HC_OPTS      = -fno-cse
641 main/CmdLineOpts_HC_OPTS        = -fno-cse
642 main/DriverMkDepend_HC_OPTS     = -fno-cse
643 main/DriverPipeline_HC_OPTS     = -fno-cse
644 main/Finder_HC_OPTS             = -fno-cse
645 main/SysTools_HC_OPTS           = -fno-cse
646 main/StaticFlags_HC_OPTS        = -fno-cse
647
648 # The #include is vital for the via-C route, else the C
649 # compiler doesn't realise that the stcall foreign imports are indeed
650 # stdcall, and doesn't generate the Foo@8 name for them
651 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
652 main/SysTools_HC_OPTS           += '-\#include <windows.h>' '-\#include <process.h>'
653 endif
654
655 parser/Lexer_HC_OPTS += -funbox-strict-fields
656
657 # ghc_strlen percolates through so many modules that it is easier to get its
658 # prototype via a global option instead of a myriad of per-file OPTIONS
659 SRC_HC_OPTS += '-\#include "cutils.h"'
660
661 # ----------------------------------------------------------------------------
662 #               Generate supporting stuff for prelude/PrimOp.lhs 
663 #               from prelude/primops.txt
664
665 PRIMOP_BITS=primop-data-decl.hs-incl \
666             primop-tag.hs-incl  \
667             primop-list.hs-incl  \
668             primop-has-side-effects.hs-incl  \
669             primop-out-of-line.hs-incl  \
670             primop-commutable.hs-incl  \
671             primop-needs-wrapper.hs-incl  \
672             primop-can-fail.hs-incl  \
673             primop-strictness.hs-incl  \
674             primop-primop-info.hs-incl
675
676 CLEAN_FILES += prelude/primops.txt
677 CLEAN_FILES += $(PRIMOP_BITS)
678
679 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
680 SRC_CPP_OPTS += ${GhcCppOpts}
681
682 ifneq "$(BootingFromHc)" "YES"
683 prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
684 endif
685
686 ifneq "$(BootingFromHc)" "YES"
687 depend :: $(PRIMOP_BITS)
688 endif
689
690 # This is an ugly hack: we need stage1/$(PLATFORM_H) built before we
691 # preprocess primops.txt.pp, but we don't want to just add that
692 # dependency because we don't want $(PLATFORM_H) built during normal
693 # operations, because we don't have have dependencies from the .hs
694 # sources on it, and we don't want those dependencies because that
695 # would cause everything to be rebuilt every time the Makefile
696 # changed.  So here we add the required dependency only when making
697 # boot or depend:
698 ifneq "$(findstring boot, $(MAKECMDGOALS))$(findstring depend, $(MAKECMDGOALS))" ""
699 prelude/primops.txt.pp : stage1/$(PLATFORM_H)
700 endif
701
702 primop-data-decl.hs-incl: prelude/primops.txt
703         $(GENPRIMOP) --data-decl          < $< > $@
704 primop-tag.hs-incl: prelude/primops.txt
705         $(GENPRIMOP) --primop-tag         < $< > $@
706 primop-list.hs-incl: prelude/primops.txt
707         $(GENPRIMOP) --primop-list        < $< > $@
708 primop-has-side-effects.hs-incl: prelude/primops.txt
709         $(GENPRIMOP) --has-side-effects   < $< > $@
710 primop-out-of-line.hs-incl: prelude/primops.txt
711         $(GENPRIMOP) --out-of-line        < $< > $@
712 primop-commutable.hs-incl: prelude/primops.txt
713         $(GENPRIMOP) --commutable         < $< > $@
714 primop-needs-wrapper.hs-incl: prelude/primops.txt
715         $(GENPRIMOP) --needs-wrapper      < $< > $@
716 primop-can-fail.hs-incl: prelude/primops.txt
717         $(GENPRIMOP) --can-fail           < $< > $@
718 primop-strictness.hs-incl: prelude/primops.txt
719         $(GENPRIMOP) --strictness         < $< > $@
720 primop-primop-info.hs-incl: prelude/primops.txt
721         $(GENPRIMOP) --primop-primop-info < $< > $@
722
723 # Usages aren't used any more; but the generator 
724 # can still generate them if we want them back
725 primop-usage.hs-incl: prelude/primops.txt
726         $(GENPRIMOP) --usage              < $< > $@
727
728
729 #-----------------------------------------------------------------------------
730 #               Linking
731
732 # Include libghccompat in stage1 only.  In stage2 onwards, all these
733 # libraries will be available from the main libraries.
734
735 ifeq "$(stage)" "1"
736 include $(GHC_COMPAT_DIR)/compat.mk
737 endif
738
739 SRC_LD_OPTS += -no-link-chk
740
741 # -----------------------------------------------------------------------------
742 # create ghc-inplace, a convenient way to run ghc from the build tree...
743 # See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
744 # a real binary here rather than a shell script.
745
746 INPLACE_SRC  = $(odir)/ghc-inplace.c
747 INPLACE_PROG = $(odir)/ghc-inplace$(_way)$(exeext)
748 EXCLUDED_C_SRCS += ghc-inplace.c
749
750 CLEAN_FILES += $(INPLACE_SRC)
751
752 GHC_PATH=$(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)/$(GHC_PROG)$(exeext)
753
754 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
755 INPLACE_EXTRA_FLAGS = -optc-DWINDOWS
756 endif
757
758 $(INPLACE_PROG): ghc-inplace.c
759         $(SED) -e "s@GHC_PATH@$(GHC_PATH)@g" -e "s@TOP_ABS@$(FPTOOLS_TOP_ABS)@g" < $< > $(INPLACE_SRC)
760         $(HC) -cpp $(INPLACE_EXTRA_FLAGS) $(INPLACE_SRC) -o $@
761
762 all :: $(INPLACE_PROG)
763
764 CLEAN_FILES += $(INPLACE_PROG)
765
766 ifeq "$(stage)" "1"
767 ghc-inplace : $(INPLACE_PROG)
768         $(RM) -f $@ && $(LN_S) $< $@
769
770 all :: ghc-inplace
771
772 CLEAN_FILES += ghc-inplace
773 endif
774
775 #-----------------------------------------------------------------------------
776 #               install
777
778 # We don't want ghc treated as an ordinary executable,
779 # but put it together with the libraries.
780 # Also don't want any interface files installed
781
782 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
783
784 ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
785 INSTALL_LIBEXECS += $(GHC_PROG)
786 else
787 INSTALL_PROGS += $(GHC_PROG)
788 endif
789
790 # ----------------------------------------------------------------------------
791 # profiling.
792
793 # rename/RnBinds_HC_OPTS += -auto-all
794 # rename/RnEnv_HC_OPTS += -auto-all
795 # rename/RnExpr_HC_OPTS += -auto-all
796 # rename/RnHiFiles_HC_OPTS += -auto-all
797 # rename/RnHsSyn_HC_OPTS += -auto-all
798 # rename/Rename_HC_OPTS += -auto-all
799 # rename/RnIfaces_HC_OPTS += -auto-all
800 # rename/RnNames_HC_OPTS += -auto-all
801 # rename/RnSource_HC_OPTS += -auto-all
802 # rename/RnTypes_HC_OPTS += -auto-all
803
804 # typecheck/Inst_HC_OPTS += -auto-all
805 # typecheck/TcBinds_HC_OPTS += -auto-all
806 # typecheck/TcClassDcl_HC_OPTS += -auto-all
807 # typecheck/TcDefaults_HC_OPTS += -auto-all
808 # typecheck/TcDeriv_HC_OPTS += -auto-all
809 # typecheck/TcEnv_HC_OPTS += -auto-all
810 # typecheck/TcExpr_HC_OPTS += -auto-all
811 # typecheck/TcForeign_HC_OPTS += -auto-all
812 # typecheck/TcGenDeriv_HC_OPTS += -auto-all
813 # typecheck/TcHsSyn_HC_OPTS += -auto-all
814 # typecheck/TcIfaceSig_HC_OPTS += -auto-all
815 # typecheck/TcInstDcls_HC_OPTS += -auto-all
816 # typecheck/TcMatches_HC_OPTS += -auto-all
817 # typecheck/TcMonoType_HC_OPTS += -auto-all
818 # typecheck/TcMType_HC_OPTS += -auto-all
819 # typecheck/TcPat_HC_OPTS += -auto-all
820 # typecheck/TcRnDriver_HC_OPTS += -auto-all
821 # #typecheck/TcRnMonad_HC_OPTS += -auto-all
822 # #typecheck/TcRnTypes_HC_OPTS += -auto-all
823 # typecheck/TcRules_HC_OPTS += -auto-all
824 # typecheck/TcSimplify_HC_OPTS += -auto-all
825 # typecheck/TcSplice_HC_OPTS += -auto-all
826 # typecheck/TcTyClsDecls_HC_OPTS += -auto-all
827 # typecheck/TcTyDecls_HC_OPTS += -auto-all
828 # typecheck/TcType_HC_OPTS += -auto-all
829 # typecheck/TcUnify_HC_OPTS += -auto-all
830
831 # coreSyn/CorePrep_HC_OPTS += -auto-all
832 # parser/Parser_HC_OPTS += -fasm
833
834 #-----------------------------------------------------------------------------
835 # Building the GHC package
836
837 # The GHC package is made from the stage 2 build and later.
838 # Fortunately the package build system framework more or less does the
839 # right thing for us here.
840
841 ifneq "$(findstring $(stage), 2 3)" ""
842 BUILD_GHC_PACKAGE=YES
843 endif
844
845 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
846 PACKAGE = ghc
847 HIERARCHICAL_LIB = NO
848 VERSION = $(ProjectVersion)
849 PKG_DEPENDS += base haskell98
850 LIB_LD_OPTS += $(foreach pkg,$(PKG_DEPENDS),-package $(pkg))
851 # We have to expand each package dependency with its version, which we
852 # can do by calling "ghc-pkg list $pkg --simple-output".
853 PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(foreach pkg,$(PKG_DEPENDS),$(shell $(GHC_PKG_INPLACE) latest --global $(pkg)))'
854 PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
855
856 # Omit Main from the library, the client will want to plug their own Main in
857 LIBOBJS = $(filter-out $(odir)/main/Main.$(way_)o $(odir)/parser/hschooks.$(way_)o, $(OBJS))
858
859 # disable splitting: it won't really help with GHC, and the specialised
860 # build system for compiler/ isn't set up to handle it.
861 SplitObjs = NO
862
863 # the package build system likes to set WAYS=$(GhcLibWays), but we don't 
864 # really want to build the whole of GHC multiple ways... if you do,
865 # set GhcCompilerWays instead.
866 GhcLibWays = $(GhcCompilerWays)
867
868 # override $(GhcLibHcOpts): we want GhcStage2HcOpts to take precedence
869 GhcLibHcOpts =
870
871 ifeq "$(DOING_BIN_DIST)" "YES"
872 # This is derived from the sources when we are in a source tree, but we
873 # don't have any sources in a bindist, so we have to shortcut it
874 HS_IFACES := $(wildcard stage$(stage)/*/*.hi)
875 else
876 # override default definition of HS_IFACES so we can add $(odir)
877 HS_IFACES   = $(addsuffix .$(way_)hi,$(basename $(HS_OBJS)))
878 endif
879
880 # Haddock can't handle recursive modules currently, so we disable it for now.
881 override HADDOCK_DOCS = NO
882
883 # Tell package.mk not to set $(HC)
884 NO_SET_HC = YES
885
886 # The stage 2 GHC binary itself is built by  compiling main/Main.hs 
887 # (the same as used in stage 1) against the GHC package.
888 #
889 # This is done by compiling Main.hs separately and linking it with 
890 # -package ghc.  This is done using a separate Makefile, Makefile.ghcbin
891 # Why? See comments in Makefile.ghcbin
892
893 # The stage 2 and stage 3 package.conf.in files are different, because they
894 # point to either the stage2/ or stage3/ dirs in import-dirs.  Hence before
895 # linking the ghc binary we must install the correct version of the package
896 # configuration.  Yeuch... maybe one day this will all be done more cleanly.
897 STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)
898
899 # Propagate standard targets to Makefile.ghcbin
900 docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
901         $(MAKE) -f Makefile.ghcbin $(MFLAGS) $@
902 endif
903
904 #-----------------------------------------------------------------------------
905 #               clean
906
907 MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
908
909 #-----------------------------------------------------------------------------
910 #               Include target-rule boilerplate
911
912 # Don't use the default MKDEPENDHS stuff... we'll do our own, below
913 MKDEPENDHS_SRCS =
914 MKDEPENDC_SRCS =
915
916 # Make doesn't work this out for itself, it seems
917 parser/Parser.y : parser/Parser.y.pp
918 EXTRA_SRCS += parser/Parser.y
919
920
921 #-----------------------------------------------------------------------------
922 #               Source files for tags file generation
923 #
924 # We want to excluded derived sources, because they won't be in the source
925 # tree, which is where we are going to move the TAGS file to.a
926
927 TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
928
929 WRONG_GHCTAGS_HS_SRCS = $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
930 # above is wrong because of the following problem:
931 #      module `main:DataCon' is defined in multiple files: basicTypes/DataCon.lhs
932 #                                                        basicTypes/DataCon.lhs-boot
933
934 GHCTAGS_HS_SRCS = $(HS_SRCS)
935 GHCTAGS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
936 GHCTAGS_HC_OPTS += -DSTAGE='"$(stage)"'
937
938 #------------------------------------------------------------
939 #                       Tags
940
941 .PHONY: ghctags
942
943 ghctags :: $(GHCTAGS_HS_SRCS) $(TAGS_C_SRCS)
944         @if [ "$(stage)" != 2 ]; then echo "Must use 'make stage=2 ghctags'"; exit 1; fi
945         @$(RM) TAGS
946         @touch TAGS
947         @echo SOURCES ARE "$(GHCTAGS_HS_SRCS)"
948         : ifneq "$(GHCTAGS_HS_SRCS)" ""
949         @echo TIME TO ROCK AND ROLL
950         # $(GHCTAGS_INPLACE) -- $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) -- $(GHCTAGS_HS_SRCS)
951         $(GHCTAGS_INPLACE) -- $(GHCTAGS_HC_OPTS) -- $(GHCTAGS_HS_SRCS)
952         : endif
953 ifneq "$(TAGS_C_SRCS)" ""
954         etags -a $(TAGS_C_SRCS)
955 endif
956         @( 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?
957
958 include $(TOP)/mk/target.mk
959
960 ifeq "$(BUILD_GHC_PACKAGE)" "YES"
961 all :: $(GHC_PROG)
962 endif
963
964 $(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE=$(DQ)$(stage)$(DQ)
965
966 ifneq "$(findstring $(stage), 2 3)" ""
967 $(warning LIBRARY is $(LIBRARY))
968
969 ifneq "$(DOING_BIN_DIST)" "YES"
970 $(GHC_PROG) : $(LIBRARY) main/Main.hs
971         $(RM) package.conf.inplace
972         $(RM) $(STAMP_PKG_CONF)
973         $(MAKE) way="" $(STAMP_PKG_CONF)
974         $(MAKE) -f Makefile.ghcbin $(MFLAGS) HS_PROG=$(GHC_PROG) $@
975 endif
976 endif
977
978
979 #-----------------------------------------------------------------------------
980 # binary-dist
981
982 binary-dist:
983         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler
984         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler/stage$(stage)
985         echo "stage=$(stage)"                > $(BIN_DIST_DIR)/compiler/Makefile
986         cat Makefile                        >> $(BIN_DIST_DIR)/compiler/Makefile
987         $(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/compiler/
988         set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
989         set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
990 ifneq "$(INSTALL_LIBS)" ""
991         set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
992 endif
993 ifneq "$(INSTALL_PROGS)" ""
994         set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
995 endif
996 ifneq "$(INSTALL_LIBEXECS)" ""
997         set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
998 endif
999
1000 # -----------------------------------------------------------------------------
1001 # Explicit dependencies
1002
1003 # Some .hs files #include other source files, but since ghc -M doesn't spit out
1004 # these dependencies we have to include them manually.
1005
1006 # We don't add dependencies on HsVersions.h, ghcautoconf.h, or ghc_boot_platform.h,
1007 # because then modifying one of these files would force recompilation of everything,
1008 # which is probably not what you want.  However, it does mean you have to be
1009 # careful to recompile stuff you need if you reconfigure or change HsVersions.h.
1010
1011 # Aargh, these don't work properly anyway, because GHC's recompilation checker
1012 # just reports "compilation NOT required".  Do we have to add -no-recomp for each
1013 # of these .hs files?  I haven't done anything about this yet.
1014
1015 $(odir)/codeGen/Bitmap.$(way_)o         :  ../includes/MachDeps.h
1016 $(odir)/codeGen/CgCallConv.$(way_)o     :  ../includes/StgFun.h
1017 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/MachDeps.h
1018 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/Constants.h
1019 $(odir)/codeGen/CgProf.$(way_)o         :  ../includes/DerivedConstants.h
1020 $(odir)/codeGen/CgTicky.$(way_)o        :  ../includes/DerivedConstants.h
1021 $(odir)/codeGen/ClosureInfo.$(way_)o    :  ../includes/MachDeps.h
1022 $(odir)/codeGen/SMRep.$(way_)o          :  ../includes/MachDeps.h
1023 $(odir)/codeGen/SMRep.$(way_)o          :  ../includes/ClosureTypes.h
1024 $(odir)/ghci/ByteCodeAsm.$(way_)o       :  ../includes/Bytecodes.h
1025 $(odir)/ghci/ByteCodeFFI.$(way_)o       :  nativeGen/NCG.h
1026 $(odir)/ghci/ByteCodeInstr.$(way_)o     :  ../includes/MachDeps.h
1027 $(odir)/ghci/ByteCodeItbls.$(way_)o     :  ../includes/ClosureTypes.h
1028 $(odir)/ghci/ByteCodeItbls.$(way_)o     :  nativeGen/NCG.h
1029 $(odir)/main/Constants.$(way_)o         :  ../includes/MachRegs.h
1030 $(odir)/main/Constants.$(way_)o         :  ../includes/Constants.h
1031 $(odir)/main/Constants.$(way_)o         :  ../includes/MachDeps.h
1032 $(odir)/main/Constants.$(way_)o         :  ../includes/DerivedConstants.h
1033 $(odir)/main/Constants.$(way_)o         :  ../includes/GHCConstants.h
1034 $(odir)/nativeGen/AsmCodeGen.$(way_)o   :  nativeGen/NCG.h
1035 $(odir)/nativeGen/MachCodeGen.$(way_)o  :  nativeGen/NCG.h
1036 $(odir)/nativeGen/MachCodeGen.$(way_)o  : ../includes/MachDeps.h
1037 $(odir)/nativeGen/MachInstrs.$(way_)o   :  nativeGen/NCG.h
1038 $(odir)/nativeGen/MachRegs.$(way_)o     :  nativeGen/NCG.h
1039 $(odir)/nativeGen/MachRegs.$(way_)o     :  ../includes/MachRegs.h
1040 $(odir)/nativeGen/PositionIndependentCode.$(way_)o :  nativeGen/NCG.h
1041 $(odir)/nativeGen/PprMach.$(way_)o      :  nativeGen/NCG.h
1042 $(odir)/nativeGen/RegAllocInfo.$(way_)o :  nativeGen/NCG.h
1043 $(odir)/typecheck/TcForeign.$(way_)o    :  nativeGen/NCG.h
1044 $(odir)/utils/Binary.$(way_)o           :  ../includes/MachDeps.h
1045 $(odir)/utils/FastMutInt.$(way_)o       :  ../includes/MachDeps.h
1046
1047 # -----------------------------------------------------------------------------
1048 # Dependencies
1049
1050 MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
1051
1052 MKDEPENDHS=$(HC)
1053
1054 # Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
1055 depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
1056         touch .depend-BASE
1057 ifneq "$(BootingFromHc)" "YES"
1058         $(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)
1059 endif
1060         $(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS) 
1061         $(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)
1062 # The binmode stuff tells perl not to add stupid ^M's to the output
1063 #
1064 # The /lib/compat replacement is to workaround a bug in the
1065 # -optdep--exclude-module flag in GHC 6.4.  It is not required for any
1066 # other version of GHC, but doesn't do any harm.
1067
1068 ifeq "$(MakefileDeps)" "YES"
1069 $(CONFIG_HS) : Makefile
1070 stage1/$(PLATFORM_H) : Makefile
1071 stage2/$(PLATFORM_H) : Makefile
1072 endif
1073
1074 -include .depend-$(stage)