Makefile 38.5 KB
Newer Older
1
# -----------------------------------------------------------------------------
2
# Main compiler Makefile
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# Targets:
#
#	all	builds stage1 compiler
#
#	boot stage=N   generate build dirs and dependencies for stage N.
#		       NB. Must be done before 'make stageN'.
#		       NB. Cannot 'make boot stage=2' until stage1 has
#		           been built (similarly for stage3).
#
#	stage1  (or stage=1) builds stage1 compiler
#	stage2  (or stage=2) builds stage2 compiler
#	stage3  (or stage=3) builds stage3 compiler
#
17

18
TOP = ..
19
20
21
22
23

# Use GHC for compiling C bits (NB. must be before boilerplate include)
#
UseGhcForCc = YES

24
25
26
27
28
# We don't want to compile stage1 in multiple ways
ifeq "$(findstring $(stage), 2 3)" ""
WAYS=
endif

29
include $(TOP)/mk/boilerplate.mk
30

31
32
33
34
ifeq "$(GhcThreaded)$(GhcProfiled)" "YESYES"
$(error Cannot make GHC both threaded and profiled)
endif

35

36
37
38
#-----------------------------------------------------------------------------
# Counting source code lines

39
40
41
42
USER_SRCS = $(filter-out $(DERIVED_SRCS),$(SRCS))
count :
	./count_lines $(USER_SRCS)

43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -----------------------------------------------------------------------------
# Bootstrapping

# The stage1/stage2/stage3 business is quite delicate.  Here's how it works:
# 
#  - the variable $(stage) holds the current stage number.  To build a 
#    particular stage, you say 'make stage=N' where N is 1, 2, or 3.
#    N defaults to 1.
#
#  - for stage N, object files and .hi files are placed inside 
#    the directory stageN, in subdirectories as per the sources.
#
#  - we use explicit -o and -ohi options to direct the output from C & 
#    Haskell compilations.
#
#  - we generate a different .depend file for each build.  They need to be
#    different, because each stage might include different files: stage1
#    might not include GHCi, for example.  For each stage, a normal .depend
#    file is generated, and then post-processed to add the correct stageN/
#    prefix to each object and .hi filename.  The resulting .depend file
#    is named .depend-$(stage).  See the end of this Makefile for details.
#
#  - normal implicit rules don't work any more, because they're of the form
#
#        %.o : %.hs 
#
#    whereas we really need 
#
#	 stageN/%.o : %.hs
#
#    so suffix.mk now defines the appropriate suffix rules when
#    $(odir) is set to a non-empty value.  Here we set $(odir) to
#    stage1, stage2, or stage3.
#
#  There are other plausible designs that might work, but each has different
#  problems:
#
Ian Lynagh's avatar
Ian Lynagh committed
80
81
#  - using -odir and -hidir:
#    -odir puts all the objects in one directory (strips off the
82
83
84
85
86
87
88
89
90
#    subdirectory part), which eventually forces us to use VPATH to find
#    the sources.  I have a really bad feeling about VPATH.
#
#  - invoke make in the stageN subdirectory.  This probably requires VPATH
#    too.
#
#  - create a link tree.  The problem with requiring link trees is that 
#    Windows doesn't support symbolic links.

91
92
93
94
ifeq "$(stage)" ""
stage=1
endif

95
96
.DUMMY: stage_dir
stage_dirs :
97
98
99
100
	$(MKDIRHIER) stage$(stage)
	for i in $(ALL_DIRS); do \
	    $(MKDIRHIER) stage$(stage)/$$i; \
	done
101

102
ifeq "$(stage)" "1"
103
104
105
106
107
108
109
110
UsingHsBoot = YES
else
ifneq "$(findstring $(stage), 2 3)" ""
UsingHsBoot = YES
else
UsingHsBoot = NO
endif
endif
111

112
boot :: stage_dirs
113
114
115
116
117
118
119
120
121
# On Windows, we can't use symbolic links for the -hi-boot files
# because GHC itself is a Mingw program and does not understand
# symbolic links.  So we have to copy the files instead of link them.
# That means that if you modify a .hi-boot file in Windows, you
# have to to say 'make boot' again.
#
# PS: 'ln -s foo baz' takes 'foo' relative to the path to 'baz'
#     whereas 'cp foo baz' treats the two paths independently.
#     Hence the "../.." in the ln command line
122
123
124
125
126
127
128
129
130
131
132
133
134

ifeq "$(stage)" "1"
HC=$(GHC)
endif

ifeq "$(stage)" "2"
HC=$(GHC_STAGE1)
endif

ifeq "$(stage)" "3"
HC=$(GHC_STAGE2)
endif

135
stage1 ::
136
137
	$(MAKE) stage=1

138
stage2 ::
139
140
	$(MAKE) stage=2

141
stage3 ::
142
143
144
145
146
147
	$(MAKE) stage=3

odir=stage$(stage)

SRC_HC_OPTS += $(patsubst %, -i$(odir)/%, $(ALL_DIRS))

148
SRC_HC_OPTS += -Wall -fno-warn-name-shadowing -fno-warn-orphans
149

150
151
152
HS_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(HS_SRCS))))
C_OBJS = $(patsubst %, $(odir)/%, $(addsuffix .$(way_)o,$(basename $(C_SRCS))))

153
154
# Our standard cleaning rules don't know that we're doing our output
# into $(odir), so we have to augment CLEAN_FILES appropriateliy.
155

156
CLEAN_FILES += $(odir)/*/*.$(way_)hi $(odir)/*/*.$(way_)hi-boot $(odir)/*/*.$(way_)o-boot
157

158
159
160
161
ifeq "$(UsingHsBoot)" "YES"
CLEAN_FILES += $(odir)/*/*.hi-boot $(odir)/*/*.o-boot
endif

162
163
164
165
166
167
ifeq "$(stage)" "1"
mostlyclean clean distclean maintainer-clean ::
	$(MAKE) $@ stage=2
	$(MAKE) $@ stage=3
endif

168
# -----------------------------------------------------------------------------
169
#		Set HS_PROG
170

sof's avatar
sof committed
171
# Note: there have been reports of people running up against the ARG_MAX limit
172
# when linking ghc with all its constituent object files. The likely source of 
sof's avatar
sof committed
173
# the problem is that the environment is a bit too big, so a workaround could
rrt's avatar
rrt committed
174
# be to do `env PATH=$(PATH) make ghc' to minimise the environment. (or the
sof's avatar
sof committed
175
176
# equivalent of `env' if it doesn't exist locally).
#
sof's avatar
sof committed
177
ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
Simon Marlow's avatar
Simon Marlow committed
178
GHC_PROG=$(odir)/ghc$(_way)-$(ProjectVersion)
rrt's avatar
rrt committed
179
else
Simon Marlow's avatar
Simon Marlow committed
180
GHC_PROG=$(odir)/ghc$(_way)
rrt's avatar
rrt committed
181
endif
Simon Marlow's avatar
Simon Marlow committed
182

183
ifeq "$(stage)" "1"
Simon Marlow's avatar
Simon Marlow committed
184
HS_PROG = $(GHC_PROG)
rrt's avatar
rrt committed
185
endif
186

187
188
# -----------------------------------------------------------------------------
# Create compiler configuration
189
190
191
#
# The 'echo' commands simply spit the values of various make variables
# into Config.hs, whence they can be compiled and used by GHC itself
192

193
CONFIG_HS 	= main/Config.hs
194
195
boot :: $(CONFIG_HS)

196
$(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
197
	@$(RM) -f $(CONFIG_HS)
198
	@echo "Creating $(CONFIG_HS) ... "
199
	@echo "module Config where" >>$(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
200
	@echo "cProjectName          :: String" >> $(CONFIG_HS)
201
	@echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
202
	@echo "cProjectVersion       :: String" >> $(CONFIG_HS)
203
	@echo "cProjectVersion       = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
204
	@echo "cProjectVersionInt    :: String" >> $(CONFIG_HS)
205
	@echo "cProjectVersionInt    = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
206
	@echo "cProjectPatchLevel    :: String" >> $(CONFIG_HS)
207
	@echo "cProjectPatchLevel    = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
208
	@echo "cBooterVersion        :: String" >> $(CONFIG_HS)
209
	@echo "cBooterVersion        = \"$(GhcVersion)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
210
	@echo "cStage                :: String" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
211
	@echo "cStage                = STAGE" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
212
	@echo "cHscIfaceFileVersion  :: String" >> $(CONFIG_HS)
213
	@echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
214
	@echo "cSplitObjs            :: String" >> $(CONFIG_HS)
215
	@echo "cSplitObjs            = \"$(SplitObjs)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
216
	@echo "cGhcWithInterpreter   :: String" >> $(CONFIG_HS)
217
	@echo "cGhcWithInterpreter   = \"$(GhcWithInterpreter)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
218
	@echo "cGhcWithNativeCodeGen :: String" >> $(CONFIG_HS)
219
	@echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
220
	@echo "cGhcWithSMP           :: String" >> $(CONFIG_HS)
221
	@echo "cGhcWithSMP           = \"$(GhcWithSMP)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
222
	@echo "cGhcRTSWays           :: String" >> $(CONFIG_HS)
223
	@echo "cGhcRTSWays           = \"$(GhcRTSWays)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
224
	@echo "cGhcUnregisterised    :: String" >> $(CONFIG_HS)
225
	@echo "cGhcUnregisterised    = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
226
	@echo "cGhcEnableTablesNextToCode :: String" >> $(CONFIG_HS)
227
	@echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
228
	@echo "cLeadingUnderscore    :: String" >> $(CONFIG_HS)
229
	@echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
230
	@echo "cRAWCPP_FLAGS         :: String" >> $(CONFIG_HS)
231
	@echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
232
	@echo "cGCC                  :: String" >> $(CONFIG_HS)
233
	@echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
234
	@echo "cMKDLL                :: String" >> $(CONFIG_HS)
235
	@echo "cMKDLL                = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
236
	@echo "cLdIsGNULd            :: String" >> $(CONFIG_HS)
237
	@echo "cLdIsGNULd            = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
238
	@echo "cLD_X		     :: String" >> $(CONFIG_HS)
239
	@echo "cLD_X		     = \"$(LD_X)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
240
	@echo "cGHC_DRIVER_DIR_REL   :: String" >> $(CONFIG_HS)
241
	@echo "cGHC_DRIVER_DIR_REL   = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
242
	@echo "cGHC_TOUCHY_PGM       :: String" >> $(CONFIG_HS)
243
	@echo "cGHC_TOUCHY_PGM       = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
244
	@echo "cGHC_TOUCHY_DIR_REL   :: String" >> $(CONFIG_HS)
245
	@echo "cGHC_TOUCHY_DIR_REL   = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
246
	@echo "cGHC_UNLIT_PGM        :: String" >> $(CONFIG_HS)
247
	@echo "cGHC_UNLIT_PGM        = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
248
	@echo "cGHC_UNLIT_DIR_REL    :: String" >> $(CONFIG_HS)
249
	@echo "cGHC_UNLIT_DIR_REL    = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
250
	@echo "cGHC_MANGLER_PGM      :: String" >> $(CONFIG_HS)
251
	@echo "cGHC_MANGLER_PGM      = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
252
	@echo "cGHC_MANGLER_DIR_REL  :: String" >> $(CONFIG_HS)
253
	@echo "cGHC_MANGLER_DIR_REL  = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
254
	@echo "cGHC_SPLIT_PGM        :: String" >> $(CONFIG_HS)
255
	@echo "cGHC_SPLIT_PGM        = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
256
	@echo "cGHC_SPLIT_DIR_REL    :: String" >> $(CONFIG_HS)
257
	@echo "cGHC_SPLIT_DIR_REL    = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
258
	@echo "cGHC_SYSMAN_PGM       :: String" >> $(CONFIG_HS)
259
	@echo "cGHC_SYSMAN_PGM       = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
260
	@echo "cGHC_SYSMAN_DIR_REL   :: String" >> $(CONFIG_HS)
261
	@echo "cGHC_SYSMAN_DIR_REL   = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
262
	@echo "cGHC_CP               :: String" >> $(CONFIG_HS)
263
	@echo "cGHC_CP               = \"$(GHC_CP)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
264
	@echo "cGHC_PERL             :: String" >> $(CONFIG_HS)
265
	@echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
266
	@echo "cEnableWin32DLLs      :: String" >> $(CONFIG_HS)
267
	@echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
268
	@echo "cCONTEXT_DIFF         :: String" >> $(CONFIG_HS)
269
	@echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
270
	@echo "cUSER_WAY_NAMES       :: String" >> $(CONFIG_HS)
271
	@echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
272
	@echo "cUSER_WAY_OPTS        :: String" >> $(CONFIG_HS)
273
	@echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
274
	@echo "cDEFAULT_TMPDIR       :: String" >> $(CONFIG_HS)
275
	@echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
Ian Lynagh's avatar
Ian Lynagh committed
276
	@echo "cRelocatableBuild     :: Bool"                 >> $(CONFIG_HS)
277
278
279
280
ifeq "$(RelocatableBuild)" "YES"
	@echo "cRelocatableBuild     = True"                  >> $(CONFIG_HS)
else
	@echo "cRelocatableBuild     = False"                 >> $(CONFIG_HS)
281
endif
Ian Lynagh's avatar
Ian Lynagh committed
282
	@echo "cLibFFI               :: Bool"                 >> $(CONFIG_HS)
283
ifeq "$(UseLibFFIForAdjustors)" "YES"
284
285
286
	@echo "cLibFFI               = True"                  >> $(CONFIG_HS)
else
	@echo "cLibFFI               = False"                 >> $(CONFIG_HS)
287
endif
288
289
290
	@echo done.

CLEAN_FILES += $(CONFIG_HS)
291

292
293
294
295
296
297
298
299
300
301
# -----------------------------------------------------------------------------
# Create platform includes

# Here we generate a little header file containing CPP symbols that GHC
# uses to determine which platform it is building on/for.  The platforms
# can differ between stage1 and stage2 if we're cross-compiling, so we
# need one of these header files per stage.

PLATFORM_H = ghc_boot_platform.h

302
stage1/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
303
304
305
306
307
	@echo "Creating $@..."
	@$(RM) $@
	@echo "#ifndef __PLATFORM_H__"  >$@
	@echo "#define __PLATFORM_H__" >>$@
	@echo >> $@
308
309
310
	@echo "#define BuildPlatform_NAME  \"$(BUILDPLATFORM)\"" >> $@
	@echo "#define HostPlatform_NAME   \"$(HOSTPLATFORM)\"" >> $@
	@echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
	@echo >> $@
	@echo "#define $(BuildPlatform_CPP)_BUILD  	1" >> $@
	@echo "#define $(HostPlatform_CPP)_HOST		1" >> $@
	@echo "#define $(TargetPlatform_CPP)_TARGET	1" >> $@
	@echo >> $@
	@echo "#define $(BuildArch_CPP)_BUILD_ARCH  	1" >> $@
	@echo "#define $(HostArch_CPP)_HOST_ARCH	1" >> $@
	@echo "#define $(TargetArch_CPP)_TARGET_ARCH	1" >> $@
	@echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
	@echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
	@echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
	@echo >> $@
	@echo "#define $(BuildOS_CPP)_BUILD_OS 		1" >> $@
	@echo "#define $(HostOS_CPP)_HOST_OS		1" >> $@
	@echo "#define $(TargetOS_CPP)_TARGET_OS	1" >> $@  
	@echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
	@echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
	@echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
ifeq "$(HostOS_CPP)" "irix"
	@echo "#ifndef $(IRIX_MAJOR)_TARGET_OS		 " >> $@  
	@echo "#define $(IRIX_MAJOR)_TARGET_OS		1" >> $@  
	@echo "#endif					 " >> $@  
endif
	@echo >> $@
	@echo "#define $(BuildVendor_CPP)_BUILD_VENDOR 	1" >> $@
	@echo "#define $(HostVendor_CPP)_HOST_VENDOR	1" >> $@
	@echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
	@echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
	@echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
	@echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
	@echo >> $@
	@echo "#endif /* __PLATFORM_H__ */"          >> $@
	@echo "Done."

# For stage2 and above, the BUILD platform is the HOST of stage1, and
# the HOST platform is the TARGET of stage1.  The TARGET remains the same
# (stage1 is the cross-compiler, not stage2).
348
stage2/$(PLATFORM_H) : stage_dirs $(FPTOOLS_TOP)/mk/config.mk
349
350
351
352
353
	@echo "Creating $@..."
	@$(RM) $@
	@echo "#ifndef __PLATFORM_H__"  >$@
	@echo "#define __PLATFORM_H__" >>$@
	@echo >> $@
354
355
356
	@echo "#define BuildPlatform_NAME  \"$(HOSTPLATFORM)\"" >> $@
	@echo "#define HostPlatform_NAME   \"$(TARGETPLATFORM)\"" >> $@
	@echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
	@echo >> $@
	@echo "#define $(HostPlatform_CPP)_BUILD  	1" >> $@
	@echo "#define $(TargetPlatform_CPP)_HOST		1" >> $@
	@echo "#define $(TargetPlatform_CPP)_TARGET	1" >> $@
	@echo >> $@
	@echo "#define $(HostArch_CPP)_BUILD_ARCH  	1" >> $@
	@echo "#define $(TargetArch_CPP)_HOST_ARCH	1" >> $@
	@echo "#define $(TargetArch_CPP)_TARGET_ARCH	1" >> $@
	@echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
	@echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
	@echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
	@echo >> $@
	@echo "#define $(HostOS_CPP)_BUILD_OS 		1" >> $@
	@echo "#define $(TargetOS_CPP)_HOST_OS		1" >> $@
	@echo "#define $(TargetOS_CPP)_TARGET_OS	1" >> $@  
	@echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
	@echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
	@echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
ifeq "$(HostOS_CPP)" "irix"
	@echo "#ifndef $(IRIX_MAJOR)_TARGET_OS		 " >> $@  
	@echo "#define $(IRIX_MAJOR)_TARGET_OS		1" >> $@  
	@echo "#endif					 " >> $@  
endif
	@echo >> $@
	@echo "#define $(HostVendor_CPP)_BUILD_VENDOR 	1" >> $@
	@echo "#define $(TargetVendor_CPP)_HOST_VENDOR	1" >> $@
	@echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
	@echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
	@echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
	@echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
	@echo >> $@
	@echo "#endif /* __PLATFORM_H__ */"          >> $@
	@echo "Done."

391
stage3/$(PLATFORM_H) : stage_dirs stage2/$(PLATFORM_H)
392
393
	$(CP) stage2/$(PLATFORM_H) stage3/$(PLATFORM_H)

394
395
396
STAGE_PLATFORM_H = stage$(stage)/$(PLATFORM_H)

boot :: $(STAGE_PLATFORM_H)
397
398
399

SRC_HC_OPTS += -Istage$(stage)

400
# -----------------------------------------------------------------------------
401
# Set SRCS etc.
402
#
403
# First figure out ALL_DIRS, the source sub-directories
404

405
ALL_DIRS = \
406
  utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
407
  vectorise specialise simplCore stranal stgSyn simplStg codeGen main \
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
408
  profiling parser cprAnalysis iface cmm
409

410
411
412
# Make sure we include Config.hs even if it doesn't exist yet...
ALL_SRCS += $(CONFIG_HS)

413
414
415
# HsGeneric.hs is not used just now
EXCLUDED_SRCS += hsSyn/HsGeneric.hs

416
ifeq ($(GhcWithNativeCodeGen),YES)
417
ALL_DIRS += nativeGen
418
419
else
SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
rrt's avatar
rrt committed
420
421
endif

422
423
ifeq "$(BootingFromHc)" "YES"
# HC files are always from a self-booted compiler
424
bootstrapped = YES
425
else
426
427
428
ifneq "$(findstring $(stage), 2 3)" ""
bootstrapped = YES
else
429
bootstrapped = NO
430
endif
431
endif
432

433
434
435
436
437
438
439
440
441
# Beyond stage 1, honour any Mac OS X depolyment target options.  If we use 
# these options in stage 1 we get a linker error if the bootstrap compiler is
#  for a more recent OS version
ifneq "$(findstring $(stage), 2 3)" ""
SRC_CC_OPTS += $(MACOSX_DEPLOYMENT_CC_OPTS)
SRC_HC_OPTS += $(addprefix -optc, $(MACOSX_DEPLOYMENT_CC_OPTS))
SRC_LD_OPTS += $(addprefix -optl, $(MACOSX_DEPLOYMENT_LD_OPTS))
endif

442
443
444
# -----------------------------------------------------------------------------
# Building a compiler with interpreter support
#
445
# The interpreter, GHCi interface, Template Haskell and Hpc are only
446
447
448
# enabled when we are bootstrapping with the same version of GHC, and
# the interpreter is supported on this platform.

449
ifeq "$(bootstrapped)" "YES"
Ian Lynagh's avatar
Ian Lynagh committed
450
451
SRC_HC_OPTS += -package bytestring
PKG_DEPENDS += bytestring
452
453
endif

Ian Lynagh's avatar
Ian Lynagh committed
454
455
456
SRC_HC_OPTS += -package hpc
PKG_DEPENDS += hpc

457
ifeq "$(GhcWithInterpreter) $(bootstrapped)" "YES YES"
458

Ian Lynagh's avatar
Ian Lynagh committed
459
# Yes, include the interepreter and Template Haskell extensions
460
461
SRC_HC_OPTS += -DGHCI -package template-haskell
PKG_DEPENDS += template-haskell
462

463
464
465
466
467
468
# Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
# or not?
ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
SRC_HC_OPTS += -DGHCI_TABLES_NEXT_TO_CODE
endif

469
ifeq "$(GhcThreaded)" "YES"
470
# Use threaded RTS with GHCi, so threads don't get blocked at the prompt.
471
472
473
474
SRC_LD_OPTS += -threaded
endif
ifeq "$(GhcProfiled)" "YES"
SRC_LD_OPTS += -prof
475
endif
476
477
478
ifeq "$(GhcDebugged)" "YES"
SRC_LD_OPTS += -debug
endif
479

480
481
482
SRC_HC_OPTS     += -I$(FPTOOLS_TOP)/libffi/build/include
SRC_HSC2HS_OPTS += -I$(FPTOOLS_TOP)/libffi/build/include

483
ALL_DIRS += ghci
484

485
486
487
488
489
490
491
492
493
494
# If we are going to use dynamic libraries instead of .o files for ghci,
# we will need to always retain CAFs in the compiler.
# ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
# function which sets the keepCAFs flag for the RTS before any Haskell
# code is run.
ifeq "$(GhcBuildDylibs)" "YES"
else
EXCLUDED_SRCS += ghci/keepCAFsForGHCi.c
endif

Ian Lynagh's avatar
Ian Lynagh committed
495
496
497
# Enable editline if either:
#   - we're building stage 1 and $(GhcHasEditline)="YES"
#   - we're building stage 2/3, and we have built the editline package
498
#
Ian Lynagh's avatar
Ian Lynagh committed
499
500
# But we don't enable editline on Windows, as Windows terminals have
# editline-like support builtin.
501
502
503
#
ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
ifeq "$(stage)" "1"
Ian Lynagh's avatar
Ian Lynagh committed
504
505
506
ifeq "$(GhcHasEditline)" "YES"
SRC_HC_OPTS += -package editline -DUSE_EDITLINE
PKG_DEPENDS += editline
507
508
endif
else
Ian Lynagh's avatar
Ian Lynagh committed
509
510
511
ifeq "$(wildcard $(FPTOOLS_TOP_ABS)/libraries/editline/unbuildable)" ""
SRC_HC_OPTS += -package editline -DUSE_EDITLINE
PKG_DEPENDS += editline
512
513
514
515
endif
endif # stage=1
endif # not windows

516
else
517

518
519
# No interpreter, so exclude Template Haskell modules
EXCLUDED_SRCS += deSugar/DsMeta.hs typecheck/TcSplice.lhs hsSyn/Convert.lhs
520
521

endif # bootstrapped with interpreter
522

523
524
# -----------------------------------------------
# mkdependC stuff
sof's avatar
sof committed
525
526
527
528
#
# Big Fudge to get around inherent problem that Makefile setup
# has got with 'mkdependC'.
# 
529
530
531
532
533
SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)

# XXX not really correct, hschooks.c actually gets include files like
# RtsFlags.c from the installed GHC, but we can't tell mkdependC about that.
SRC_MKDEPENDC_OPTS += -I$(GHC_INCLUDE_DIR)
534

535
# -----------------------------------------------------------------------------
536
# 		Haskell compilations
537

538
539
540
541
542
543
544
SRC_HC_OPTS += -cpp -fglasgow-exts -Rghc-timing -I. -Iparser -Iutil

ifeq "$(ghc_ge_609)" "NO"
SRC_HC_OPTS += -fno-generics
else
SRC_HC_OPTS += -XNoGenerics
endif
sof's avatar
sof committed
545

546
547
548
549
# Omitted: 	-I$(GHC_INCLUDE_DIR)
# We should have -I$(GHC_INCLUDE_DIR) in SRC_HC_OPTS, 
# to avoid the use of an explicit path in GHC source files
#	(include "../includes/config.h"
550
551
552
553
554
555
# But alas GHC 4.08 (and others for all I know) uses this very
# same include path when compiling the .hc files it generates.
# Disaster!  Then the hc file sees the GHC 5.02 (or whatever)
# include files.   For the moment we've reverted to using
# an explicit path in the .hs sources

556
# We need System.Posix (or Posix when ghc < 6.2)
557
558
559
560
561
562
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
ifeq "$(bootstrapped)" "YES"
SRC_HC_OPTS += -package Win32
PKG_DEPENDS += Win32
endif
else
563
SRC_HC_OPTS += -package unix
564
PKG_DEPENDS += unix
565
566
endif

567
SRC_HC_OPTS += -package Cabal
568
PKG_DEPENDS += Cabal
569

570
571
572
573
574
# Ignore lang, to avoid potential clash with the Generics module if
# lang happens to be a dependency of some exposed package in the local
# GHC installation (eg. wxHaskell did this around 6.4).
SRC_HC_OPTS += -ignore-package lang

575
SRC_CC_OPTS += -Iparser -I. -O
576
SRC_HC_OPTS += $(GhcHcOpts) $(GhcStage$(stage)HcOpts)
577
SRC_HC_OPTS += -H16M
578

579
580
581
582
ifeq "$(BootingFromHc)" "YES"
SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
endif

583
584
585
586
# 	Special flags for particular modules
#	The standard suffix rule for compiling a Haskell file
#	adds these flags to the command line

587
# There used to be a -fforce-recomp flag on PrimOp, but why?
588
589
# It's an expensive module to recompile!
prelude/PrimOp_HC_OPTS 		= -H80m
590

591

592
main/ParsePkgConf_HC_OPTS	+= -fno-warn-incomplete-patterns
593
594
parser/Parser_HC_OPTS 		+= -fno-warn-incomplete-patterns

595
596
597
# Careful optimisation of the parser: we don't want to throw everything
# at it, because that takes too long and doesn't buy much, but we do want
# to inline certain key external functions, so we instruct GHC not to
598
599
# throw away inlinings as it would normally do in -O0 mode:
parser/Parser_HC_OPTS		+= -O0 -fno-ignore-interface-pragmas
600

sof's avatar
sof committed
601
ifeq "$(HOSTPLATFORM)" "hppa1.1-hp-hpux9"
602
rename/RnMonad_HC_OPTS 		=  -O2 -O2-for-C
sof's avatar
sof committed
603
endif
604

Ian Lynagh's avatar
Ian Lynagh committed
605
# basicTypes/SrcLoc_HC_OPTS	= -funbox-strict-fields
606

607
608
609
610
611
# ---- Profiling ----
#simplCore/Simplify_HC_OPTS = -auto-all
#simplCore/SimplEnv_HC_OPTS = -auto-all
#simplCore/SimplUtils_HC_OPTS = -auto-all

612
613
614
615
616
617
618
619
620
# CSE interacts badly with top-level IORefs (reportedly in DriverState and
# DriverMkDepend), causing some of them to be commoned up.  We have a fix for
# this in 5.00+, but earlier versions of the compiler will need CSE turned off.
# To be on the safe side, we disable CSE in *all* modules with top-level IORefs.
ghci/InteractiveUI_HC_OPTS	= -fno-cse
main/CmdLineOpts_HC_OPTS	= -fno-cse
main/DriverMkDepend_HC_OPTS	= -fno-cse
main/DriverPipeline_HC_OPTS	= -fno-cse
main/Finder_HC_OPTS		= -fno-cse
621
main/SysTools_HC_OPTS		= -fno-cse
622
main/StaticFlags_HC_OPTS	= -fno-cse
623

624
625
626
# The #include is vital for the via-C route, else the C
# compiler doesn't realise that the stcall foreign imports are indeed
# stdcall, and doesn't generate the Foo@8 name for them
sof's avatar
sof committed
627
ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
sof's avatar
sof committed
628
main/SysTools_HC_OPTS		+= '-\#include <windows.h>' '-\#include <process.h>'
629
630
endif

631
632
# ghc_strlen percolates through so many modules that it is easier to get its
# prototype via a global option instead of a myriad of per-file OPTIONS
633
SRC_HC_OPTS += '-\#include "cutils.h"'
634

Ian Lynagh's avatar
Ian Lynagh committed
635
636
637
638
ifeq "$(ghc_ge_605)" "NO"
utils/LazyUniqFM_HC_OPTS += -fallow-undecidable-instances
endif

639
640
641
642
# ----------------------------------------------------------------------------
#		Generate supporting stuff for prelude/PrimOp.lhs 
#		from prelude/primops.txt

643
644
645
646
647
648
649
650
651
652
653
PRIMOP_BITS=primop-data-decl.hs-incl \
            primop-tag.hs-incl  \
            primop-list.hs-incl  \
            primop-has-side-effects.hs-incl  \
            primop-out-of-line.hs-incl  \
            primop-commutable.hs-incl  \
            primop-needs-wrapper.hs-incl  \
            primop-can-fail.hs-incl  \
            primop-strictness.hs-incl  \
            primop-primop-info.hs-incl

654
655
656
CLEAN_FILES += prelude/primops.txt
CLEAN_FILES += $(PRIMOP_BITS)

657
SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
apt's avatar
apt committed
658
SRC_CPP_OPTS += ${GhcCppOpts}
sof's avatar
sof committed
659

660
ifneq "$(BootingFromHc)" "YES"
sof's avatar
sof committed
661
prelude/PrimOp.lhs $(odir)/prelude/PrimOp.o: $(PRIMOP_BITS)
662
endif
663

664
ifneq "$(BootingFromHc)" "YES"
665
depend :: $(PRIMOP_BITS)
666
endif
667

668
669
670
671
672
673
674
675
676
677
678
679
# This is an ugly hack: we need stage1/$(PLATFORM_H) built before we
# preprocess primops.txt.pp, but we don't want to just add that
# dependency because we don't want $(PLATFORM_H) built during normal
# operations, because we don't have have dependencies from the .hs
# sources on it, and we don't want those dependencies because that
# would cause everything to be rebuilt every time the Makefile
# changed.  So here we add the required dependency only when making
# boot or depend:
ifneq "$(findstring boot, $(MAKECMDGOALS))$(findstring depend, $(MAKECMDGOALS))" ""
prelude/primops.txt.pp : stage1/$(PLATFORM_H)
endif

ken's avatar
ken committed
680
primop-data-decl.hs-incl: prelude/primops.txt
681
	$(GENPRIMOP) --data-decl          < $< > $@
ken's avatar
ken committed
682
primop-tag.hs-incl: prelude/primops.txt
683
	$(GENPRIMOP) --primop-tag         < $< > $@
ken's avatar
ken committed
684
primop-list.hs-incl: prelude/primops.txt
685
	$(GENPRIMOP) --primop-list        < $< > $@
ken's avatar
ken committed
686
primop-has-side-effects.hs-incl: prelude/primops.txt
687
	$(GENPRIMOP) --has-side-effects   < $< > $@
ken's avatar
ken committed
688
primop-out-of-line.hs-incl: prelude/primops.txt
689
	$(GENPRIMOP) --out-of-line        < $< > $@
ken's avatar
ken committed
690
primop-commutable.hs-incl: prelude/primops.txt
691
	$(GENPRIMOP) --commutable         < $< > $@
ken's avatar
ken committed
692
primop-needs-wrapper.hs-incl: prelude/primops.txt
693
	$(GENPRIMOP) --needs-wrapper      < $< > $@
ken's avatar
ken committed
694
primop-can-fail.hs-incl: prelude/primops.txt
695
	$(GENPRIMOP) --can-fail           < $< > $@
ken's avatar
ken committed
696
primop-strictness.hs-incl: prelude/primops.txt
697
	$(GENPRIMOP) --strictness         < $< > $@
ken's avatar
ken committed
698
primop-primop-info.hs-incl: prelude/primops.txt
699
	$(GENPRIMOP) --primop-primop-info < $< > $@
700

701
702
703
# Usages aren't used any more; but the generator 
# can still generate them if we want them back
primop-usage.hs-incl: prelude/primops.txt
704
	$(GENPRIMOP) --usage              < $< > $@
705

706

707
708
709
#-----------------------------------------------------------------------------
# 		Linking

710
711
712
713
714
715
716
ifeq "$(GhcUnregisterised)" "NO"
ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
# needed for generating proper relocation in large binaries: trac #856
SRC_LD_OPTS += -optl-Wl,--relax
endif
endif

717
718
# -----------------------------------------------------------------------------
# create ghc-inplace, a convenient way to run ghc from the build tree...
719
720
# See comments in $(FPTOOLS_TOP)/utils/ghc-pkg/Makefile for why we use
# a real binary here rather than a shell script.
721

722
INPLACE_SRC  = $(odir)/ghc-inplace.c
723
INPLACE_PROG = $(odir)/ghc-inplace$(_way)$(exeext)
724
INPLACE_EXTRA_FLAGS = -I$(TOP)/includes
725
EXCLUDED_C_SRCS += ghc-inplace.c
726

Ian Lynagh's avatar
Ian Lynagh committed
727
728
CLEAN_FILES += $(INPLACE_SRC)

729
GHC_PATH=$(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)/$(GHC_PROG)$(exeext)
730

731
732
733
$(INPLACE_PROG): ghc-inplace.c
	$(SED) -e "s@GHC_PATH@$(GHC_PATH)@g" -e "s@TOP_ABS@$(FPTOOLS_TOP_ABS)@g" < $< > $(INPLACE_SRC)
	$(HC) -cpp $(INPLACE_EXTRA_FLAGS) $(INPLACE_SRC) -o $@
734

735
all :: $(INPLACE_PROG)
736

Ian Lynagh's avatar
Ian Lynagh committed
737
CLEAN_FILES += $(INPLACE_PROG)
738

739
ifeq "$(stage)" "1"
740
741
742
ghc-inplace : $(INPLACE_PROG)
	$(RM) -f $@ && $(LN_S) $< $@

743
744
all :: ghc-inplace

745
746
747
CLEAN_FILES += ghc-inplace
endif

748
749
750
#-----------------------------------------------------------------------------
# 		install

751
# We don't want ghc treated as an ordinary executable,
752
# but put it together with the libraries.
rrt's avatar
rrt committed
753
# Also don't want any interface files installed
754

755
756
DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)

sof's avatar
sof committed
757
ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
Simon Marlow's avatar
Simon Marlow committed
758
INSTALL_LIBEXECS += $(GHC_PROG)
rrt's avatar
rrt committed
759
else
Simon Marlow's avatar
Simon Marlow committed
760
INSTALL_PROGS += $(GHC_PROG)
rrt's avatar
rrt committed
761
endif
762

763
764
765
# ----------------------------------------------------------------------------
# profiling.

766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# rename/RnBinds_HC_OPTS += -auto-all
# rename/RnEnv_HC_OPTS += -auto-all
# rename/RnExpr_HC_OPTS += -auto-all
# rename/RnHiFiles_HC_OPTS += -auto-all
# rename/RnHsSyn_HC_OPTS += -auto-all
# rename/Rename_HC_OPTS += -auto-all
# rename/RnIfaces_HC_OPTS += -auto-all
# rename/RnNames_HC_OPTS += -auto-all
# rename/RnSource_HC_OPTS += -auto-all
# rename/RnTypes_HC_OPTS += -auto-all
# 
# typecheck/Inst_HC_OPTS += -auto-all
# typecheck/TcBinds_HC_OPTS += -auto-all
# typecheck/TcClassDcl_HC_OPTS += -auto-all
# typecheck/TcDefaults_HC_OPTS += -auto-all
# typecheck/TcDeriv_HC_OPTS += -auto-all
# typecheck/TcEnv_HC_OPTS += -auto-all
# typecheck/TcExpr_HC_OPTS += -auto-all
# typecheck/TcForeign_HC_OPTS += -auto-all
# typecheck/TcGenDeriv_HC_OPTS += -auto-all
# typecheck/TcHsSyn_HC_OPTS += -auto-all
# typecheck/TcIfaceSig_HC_OPTS += -auto-all
# typecheck/TcInstDcls_HC_OPTS += -auto-all
# typecheck/TcMatches_HC_OPTS += -auto-all
# typecheck/TcMonoType_HC_OPTS += -auto-all
# typecheck/TcMType_HC_OPTS += -auto-all
# typecheck/TcPat_HC_OPTS += -auto-all
# typecheck/TcRnDriver_HC_OPTS += -auto-all
# #typecheck/TcRnMonad_HC_OPTS += -auto-all
# #typecheck/TcRnTypes_HC_OPTS += -auto-all
# typecheck/TcRules_HC_OPTS += -auto-all
# typecheck/TcSimplify_HC_OPTS += -auto-all
# typecheck/TcSplice_HC_OPTS += -auto-all
# typecheck/TcTyClsDecls_HC_OPTS += -auto-all
# typecheck/TcTyDecls_HC_OPTS += -auto-all
# typecheck/TcType_HC_OPTS += -auto-all
# typecheck/TcUnify_HC_OPTS += -auto-all

Simon Marlow's avatar
Simon Marlow committed
804
# coreSyn/CorePrep_HC_OPTS += -auto-all
805

806
#-----------------------------------------------------------------------------
807
# Building the GHC package
808

809
810
811
# The GHC package is made from the stage 2 build and later.
# Fortunately the package build system framework more or less does the
# right thing for us here.
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
812

813
ifneq "$(findstring $(stage), 2 3)" ""
814
815
816
817
BUILD_GHC_PACKAGE=YES
endif

ifeq "$(BUILD_GHC_PACKAGE)" "YES"
818
PACKAGE = ghc
819
820
821
HIERARCHICAL_LIB = NO
VERSION = $(ProjectVersion)
PKG_DEPENDS += base haskell98
822
LIB_LD_OPTS += $(foreach pkg,$(PKG_DEPENDS),-package $(pkg))
823
824
# We have to expand each package dependency with its version, which we
# can do by calling "ghc-pkg list $pkg --simple-output".
825
PACKAGE_CPP_OPTS += -DPKG_DEPENDS='$(foreach pkg,$(PKG_DEPENDS),$(shell $(GHC_PKG_INPLACE) latest --global $(pkg)))'
Ian Lynagh's avatar
Ian Lynagh committed
826
827
# We want to define STAGE to be like "2" in the Haskell code, so we need
# to quote the "s so that they don't get interpreted by the shell.
828
PACKAGE_CPP_OPTS += -DSTAGE='"$(stage)"'
829

830
# Omit Main from the library, the client will want to plug their own Main in
831
LIBOBJS = $(filter-out $(odir)/main/Main.$(way_)o $(odir)/parser/hschooks.$(way_)o, $(OBJS))
832

833
# disable splitting: it won't really help with GHC, and the specialised
834
# build system for compiler/ isn't set up to handle it.
835
836
SplitObjs = NO

837
838
839
840
841
# the package build system likes to set WAYS=$(GhcLibWays), but we don't 
# really want to build the whole of GHC multiple ways... if you do,
# set GhcCompilerWays instead.
GhcLibWays = $(GhcCompilerWays)

842
843
844
# override $(GhcLibHcOpts): we want GhcStage2HcOpts to take precedence
GhcLibHcOpts =

845
846
847
848
849
ifeq "$(DOING_BIN_DIST)" "YES"
# This is derived from the sources when we are in a source tree, but we
# don't have any sources in a bindist, so we have to shortcut it
HS_IFACES := $(wildcard stage$(stage)/*/*.hi)
else
850
851
# override default definition of HS_IFACES so we can add $(odir)
HS_IFACES   = $(addsuffix .$(way_)hi,$(basename $(HS_OBJS)))
852
endif
853
854

# Haddock can't handle recursive modules currently, so we disable it for now.
855
override HADDOCK_DOCS = NO
Simon Marlow's avatar
Simon Marlow committed
856

Simon Marlow's avatar
Simon Marlow committed
857
858
859
# Tell package.mk not to set $(HC)
NO_SET_HC = YES

simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
860
861
862
863
864
865
# The stage 2 GHC binary itself is built by  compiling main/Main.hs 
# (the same as used in stage 1) against the GHC package.
#
# This is done by compiling Main.hs separately and linking it with 
# -package ghc.  This is done using a separate Makefile, Makefile.ghcbin
# Why? See comments in Makefile.ghcbin
Simon Marlow's avatar
Simon Marlow committed
866

867
868
869
870
871
872
# The stage 2 and stage 3 package.conf.in files are different, because they
# point to either the stage2/ or stage3/ dirs in import-dirs.  Hence before
# linking the ghc binary we must install the correct version of the package
# configuration.  Yeuch... maybe one day this will all be done more cleanly.
STAMP_PKG_CONF = $(GHC_DRIVER_DIR)/stamp-pkg-conf-$(PACKAGE)

simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
873
# Propagate standard targets to Makefile.ghcbin
Simon Marlow's avatar
Simon Marlow committed
874
875
docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) $(INSTALL_DOCS_TARGET) html chm HxS ps dvi txt::
	$(MAKE) -f Makefile.ghcbin $(MFLAGS) $@
876
877
endif

878
879
880
#-----------------------------------------------------------------------------
# 		clean

881
MAINTAINER_CLEAN_FILES += parser/Parser.info main/ParsePkgConf.info
882
883
884
885

#-----------------------------------------------------------------------------
# 		Include target-rule boilerplate

886
887
888
889
# Don't use the default MKDEPENDHS stuff... we'll do our own, below
MKDEPENDHS_SRCS =
MKDEPENDC_SRCS =

890
891
# Make doesn't work this out for itself, it seems
parser/Parser.y : parser/Parser.y.pp
892
EXTRA_SRCS += parser/Parser.y
893

894
895
896
897
898
899
900
901
902

#-----------------------------------------------------------------------------
# 		Source files for tags file generation
#
# We want to excluded derived sources, because they won't be in the source
# tree, which is where we are going to move the TAGS file to.a

TAGS_HS_SRCS = parser/Parser.y.pp $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))

903
904
905
906
907
908
909
WRONG_GHCTAGS_HS_SRCS = $(filter-out $(DERIVED_SRCS) main/Config.hs parser/Parser.y, $(sort $(SRCS)))
# above is wrong because of the following problem:
#      module `main:DataCon' is defined in multiple files: basicTypes/DataCon.lhs
#                                                        basicTypes/DataCon.lhs-boot

GHCTAGS_HS_SRCS = $(HS_SRCS)
GHCTAGS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
Simon Marlow's avatar
Simon Marlow committed
910
GHCTAGS_HC_OPTS += -DSTAGE='"$(stage)"'
911
912
913
914
915
916
917
918
919
920
921
922
923

#------------------------------------------------------------
# 			Tags

.PHONY: ghctags

ghctags :: $(GHCTAGS_HS_SRCS) $(TAGS_C_SRCS)
	@if [ "$(stage)" != 2 ]; then echo "Must use 'make stage=2 ghctags'"; exit 1; fi
	@$(RM) TAGS
	@touch TAGS
	@echo SOURCES ARE "$(GHCTAGS_HS_SRCS)"
	: ifneq "$(GHCTAGS_HS_SRCS)" ""
	@echo TIME TO ROCK AND ROLL
Simon Marlow's avatar
Simon Marlow committed
924
925
	# $(GHCTAGS_INPLACE) -- $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(MKDEPENDHS_HC_OPTS)) -- $(GHCTAGS_HS_SRCS)
	$(GHCTAGS_INPLACE) -- $(GHCTAGS_HC_OPTS) -- $(GHCTAGS_HS_SRCS)
926
927
928
929
930
931
	: endif
ifneq "$(TAGS_C_SRCS)" ""
	etags -a $(TAGS_C_SRCS)
endif
	@( 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?

932
include $(TOP)/mk/target.mk
933

934
935
936
937
ifeq "$(BUILD_GHC_PACKAGE)" "YES"
all :: $(GHC_PROG)
endif

938
$(odir)/main/Config.$(way_)o: SRC_HC_OPTS+=-DSTAGE='"$(stage)"'
Ian Lynagh's avatar
Ian Lynagh committed
939

940
941
942
943
944
945
946
947
948
949
950
951
952
ifneq "$(findstring $(stage), 2 3)" ""
$(warning LIBRARY is $(LIBRARY))

ifneq "$(DOING_BIN_DIST)" "YES"
$(GHC_PROG) : $(LIBRARY) main/Main.hs
	$(RM) package.conf.inplace
	$(RM) $(STAMP_PKG_CONF)
	$(MAKE) way="" $(STAMP_PKG_CONF)
	$(MAKE) -f Makefile.ghcbin $(MFLAGS) HS_PROG=$(GHC_PROG) $@
endif
endif


953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
#-----------------------------------------------------------------------------
# binary-dist

binary-dist:
	$(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler
	$(INSTALL_DIR)                         $(BIN_DIST_DIR)/compiler/stage$(stage)
	echo "stage=$(stage)"                > $(BIN_DIST_DIR)/compiler/Makefile
	cat Makefile                        >> $(BIN_DIST_DIR)/compiler/Makefile
	$(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/compiler/
	set -e; for d in stage$(stage)/*/; do $(INSTALL_DIR) $(BIN_DIST_DIR)/compiler/$$d; done
	set -e; for f in $(HS_IFACES); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
ifneq "$(INSTALL_LIBS)" ""
	set -e; for f in $(INSTALL_LIBS); do $(INSTALL_DATA) $$f $(BIN_DIST_DIR)/compiler/$$f; done
endif
ifneq "$(INSTALL_PROGS)" ""
	set -e; for f in $(INSTALL_PROGS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
endif
ifneq "$(INSTALL_LIBEXECS)" ""
	set -e; for f in $(INSTALL_LIBEXECS); do $(INSTALL_PROGRAM) $$f $(BIN_DIST_DIR)/compiler/$$f; done
endif

974
975
976
977
978
979
980
981
982
983
984
# -----------------------------------------------------------------------------
# Explicit dependencies

# Some .hs files #include other source files, but since ghc -M doesn't spit out
# these dependencies we have to include them manually.

# We don't add dependencies on HsVersions.h, ghcautoconf.h, or ghc_boot_platform.h,
# because then modifying one of these files would force recompilation of everything,
# which is probably not what you want.  However, it does mean you have to be
# careful to recompile stuff you need if you reconfigure or change HsVersions.h.

985
# Aargh, these don't work properly anyway, because GHC's recompilation checker
986
# just reports "compilation NOT required".  Do we have to add -fforce-recomp for each
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
# of these .hs files?  I haven't done anything about this yet.

$(odir)/codeGen/Bitmap.$(way_)o		:  ../includes/MachDeps.h
$(odir)/codeGen/CgCallConv.$(way_)o	:  ../includes/StgFun.h
$(odir)/codeGen/CgProf.$(way_)o		:  ../includes/MachDeps.h
$(odir)/codeGen/CgProf.$(way_)o		:  ../includes/Constants.h
$(odir)/codeGen/CgProf.$(way_)o		:  ../includes/DerivedConstants.h
$(odir)/codeGen/CgTicky.$(way_)o	:  ../includes/DerivedConstants.h
$(odir)/codeGen/ClosureInfo.$(way_)o	:  ../includes/MachDeps.h
$(odir)/codeGen/SMRep.$(way_)o		:  ../includes/MachDeps.h
$(odir)/codeGen/SMRep.$(way_)o		:  ../includes/ClosureTypes.h
$(odir)/ghci/ByteCodeAsm.$(way_)o	:  ../includes/Bytecodes.h
$(odir)/ghci/ByteCodeFFI.$(way_)o	:  nativeGen/NCG.h
$(odir)/ghci/ByteCodeInstr.$(way_)o	:  ../includes/MachDeps.h
$(odir)/ghci/ByteCodeItbls.$(way_)o	:  ../includes/ClosureTypes.h
$(odir)/ghci/ByteCodeItbls.$(way_)o	:  nativeGen/NCG.h
$(odir)/main/Constants.$(way_)o		:  ../includes/MachRegs.h
$(odir)/main/Constants.$(way_)o		:  ../includes/Constants.h
$(odir)/main/Constants.$(way_)o		:  ../includes/MachDeps.h
$(odir)/main/Constants.$(way_)o		:  ../includes/DerivedConstants.h
$(odir)/main/Constants.$(way_)o		:  ../includes/GHCConstants.h
$(odir)/nativeGen/AsmCodeGen.$(way_)o 	:  nativeGen/NCG.h
$(odir)/nativeGen/MachCodeGen.$(way_)o 	:  nativeGen/NCG.h
$(odir)/nativeGen/MachCodeGen.$(way_)o 	: ../includes/MachDeps.h
$(odir)/nativeGen/MachInstrs.$(way_)o	:  nativeGen/NCG.h
$(odir)/nativeGen/MachRegs.$(way_)o	:  nativeGen/NCG.h
$(odir)/nativeGen/MachRegs.$(way_)o	:  ../includes/MachRegs.h
$(odir)/nativeGen/PositionIndependentCode.$(way_)o :  nativeGen/NCG.h
$(odir)/nativeGen/PprMach.$(way_)o	:  nativeGen/NCG.h
$(odir)/nativeGen/RegAllocInfo.$(way_)o :  nativeGen/NCG.h
$(odir)/typecheck/TcForeign.$(way_)o	:  nativeGen/NCG.h
$(odir)/utils/Binary.$(way_)o		:  ../includes/MachDeps.h
$(odir)/utils/FastMutInt.$(way_)o	:  ../includes/MachDeps.h
1020

1021
1022
1023
# -----------------------------------------------------------------------------
# Dependencies

1024
MKDEPENDHS_HC_OPTS = $(patsubst -i$(odir)/%, -i%, $(HC_OPTS))
1025
1026
1027
1028

MKDEPENDHS=$(HC)

# Must do this *after* including target.mk, because $(HS_SRCS) isn't set yet.
1029
depend :: $(STAGE_PLATFORM_H) $(HS_SRCS) $(C_SRCS)
1030
1031
	touch .depend-BASE
ifneq "$(BootingFromHc)" "YES"
1032
	$(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)
1033
endif
1034
	$(MKDEPENDC) -f .depend-BASE $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(C_SRCS) 
Ian Lynagh's avatar
Ian Lynagh committed
1035
	$(PERL) -pe 'binmode(stdin); binmode(stdout); s@(\S*[._]o)@stage$(stage)/$$1@g; s@(\S*[._]hi)@stage$(stage)/$$1@g;' <.depend-BASE >.depend-$(stage)
1036
# The binmode stuff tells perl not to add stupid ^M's to the output
1037

1038
1039
1040
1041
1042
1043
ifeq "$(MakefileDeps)" "YES"
$(CONFIG_HS) : Makefile
stage1/$(PLATFORM_H) : Makefile
stage2/$(PLATFORM_H) : Makefile
endif

1044
-include .depend-$(stage)