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