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