Makefile 15 KB
Newer Older
1
# -----------------------------------------------------------------------------
2
# $Id: Makefile,v 1.107 2000/11/03 11:30:23 sewardj Exp $
3

4
5
TOP = ..
include $(TOP)/mk/boilerplate.mk
6
7

#-----------------------------------------------------------------------------
8
# Building ghc different ways (default is just `normal' sequential)
9
WAYS=$(GhcCompilerWays)
10

11
12
13
# -----------------------------------------------------------------------------
#		Set HS_PROG, LIBRARY

sof's avatar
sof committed
14
# Note: there have been reports of people running up against the ARG_MAX limit
15
# when linking ghc with all its constituent object files. The likely source of 
sof's avatar
sof committed
16
# the problem is that the environment is a bit too big, so a workaround could
17
# be to do ` env PATH=$(PATH) make ghc 'to minimise the environment. (or the
sof's avatar
sof committed
18
19
# equivalent of `env' if it doesn't exist locally).
#
rrt's avatar
rrt committed
20
ifneq "$(way)" "dll"
21
HS_PROG=ghc$(_way)-$(ProjectVersion)
rrt's avatar
rrt committed
22
else
23
HS_PROG=ghc-$(ProjectVersion)
rrt's avatar
rrt committed
24
endif
25

26
27
LINK = ghc

28
29
30
# -----------------------------------------------------------------------------
# Create compiler configuration

31
CURRENT_DIR=ghc/compiler
32
33
34
35
36
37
38
39
40
41
42
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
CONFIG_HS = main/Config.hs
boot :: $(CONFIG_HS)

$(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk Makefile
	@$(RM) -f $(CONFIG_HS)
	@echo -n "Creating $(CONFIG_HS) ... "
	@echo "module Config where" >>$(CONFIG_HS)
	@echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
	@echo "cProjectVersion       = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
	@echo "cProjectVersionInt    = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
	@echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
	@echo "cHOSTPLATFORM         = \"$(HOSTPLATFORM)\"" >> $(CONFIG_HS)
	@echo "cTARGETPLATFORM       = \"$(TARGETPLATFORM)\"" >> $(CONFIG_HS)
	@echo "cCURRENT_DIR          = \"$(CURRENT_DIR)\"" >> $(CONFIG_HS)
	@echo "cGHC_LIB_DIR          = \"$(GHC_LIB_DIR)\"" >> $(CONFIG_HS)
	@echo "cGHC_RUNTIME_DIR      = \"$(GHC_RUNTIME_DIR)\"" >> $(CONFIG_HS)
	@echo "cGHC_UTILS_DIR        = \"$(GHC_UTILS_DIR)\"" >> $(CONFIG_HS)
	@echo "cGHC_INCLUDE_DIR      = \"$(GHC_INCLUDE_DIR)\"" >> $(CONFIG_HS)
	@echo "cGHC_DRIVER_DIR       = \"$(GHC_DRIVER_DIR)\"" >> $(CONFIG_HS)
	@echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
	@echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
	@echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
	@echo "cGHC_UNLIT            = \"$(GHC_UNLIT)\"" >> $(CONFIG_HS)
	@echo "cGHC_MANGLER          = \"$(GHC_MANGLER)\"" >> $(CONFIG_HS)
	@echo "cGHC_SPLIT            = \"$(GHC_SPLIT)\"" >> $(CONFIG_HS)
	@echo "cGHC_STATS            = \"$(GHC_STATS)\"" >> $(CONFIG_HS)
	@echo "cGHC_SYSMAN           = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
	@echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
	@echo "cCP                   = \"$(CP)\"" >> $(CONFIG_HS)
	@echo "cRM                   = \"$(RM)\"" >> $(CONFIG_HS)
	@echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
	@echo "cHaveLibGmp           = \"$(HaveLibGmp)\"" >> $(CONFIG_HS)
	@echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
	@echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
	@echo "clibdir               = \"$(libdir)\"" >> $(CONFIG_HS)
	@echo "clibexecdir           = \"$(libexecdir)\"" >> $(CONFIG_HS)
	@echo "cdatadir              = \"$(datadir)\"" >> $(CONFIG_HS)
	@echo "cbindir               = \"$(bindir)\"" >> $(CONFIG_HS)
	@echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
	@echo "cFPTOOLS_TOP_ABS      = \"$(FPTOOLS_TOP_ABS)\"" >> $(CONFIG_HS)
	@echo "cRAWCPP               = \"$(RAWCPP)\"" >> $(CONFIG_HS)
	@echo done.

CLEAN_FILES += $(CONFIG_HS)
76

77
78
79
80
81
82
83
# -----------------------------------------------------------------------------
#		Compilation history for Patrick

# Make the sources first, because that's what the compilation history needs
$(HS_PROG) :: $(HS_SRCS)


84
85
86
87
88
89
# -----------------------------------------------------------------------------
# 		Set SRCS, LOOPS, HCS, OBJS
#
# First figure out DIRS, the source sub-directories
# Then derive SRCS by looking in them
#
90
91
92
93

DIRS = \
  utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
  specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
94
  profiling parser usageSP cprAnalysis javaGen compMan
95
96

ifeq ($(GhcWithNativeCodeGen),YES)
sof's avatar
sof committed
97
DIRS += nativeGen
98
99
else
SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
100
101
102
103
ifeq ($(GhcWithIlx),YES)
DIRS += ilxGen
SRC_HC_OPTS += -DILX
endif
104
105
endif

106
107
108
109
110
111
112
113
# Only include GHCi if we're bootstrapping with at least version 409
ifeq "$(GhcWithInterpreter)" "YES"
ghc_409_at_least = $(shell expr "$(GhcMinVersion)" \>= 9)
ifeq "$(ghc_409_at_least)" "1"
SRC_HC_OPTS += -DGHCI
DIRS += ghci
endif
endif
114

115
HS_SRCS = $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs) $(wildcard $(dir)/*.hs))
116

117
118
119
120
# ToDo: not clear why this is here -- messes up linking
#ifneq "$(GhcWithHscBuiltViaC)" "YES"
#HS_SRCS += rename/ParseIface.hs parser/Parser.hs
#endif
sof's avatar
sof committed
121

sof's avatar
sof committed
122
123
HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))

124
125
# ParseIface.hs ain't part of HS_SRCS when this is on..
ifeq "$(GhcWithHscBuiltViaC)" "YES"
126
HCS      += rename/ParseIface.hc parser/Parser.hc
127
endif
sof's avatar
sof committed
128

129
130
HS_OBJS  = \
  $(patsubst %.hc, %.o, $(HCS)) \
131
  parser/hschooks.o
132
133


sof's avatar
sof committed
134
DESTDIR       = $(INSTALL_LIBRARY_DIR_GHC)
135

sof's avatar
sof committed
136
137
138
#
# Add misc .c helper code (used by the frontend.)
#
139
C_SRCS += parser/hschooks.c
sof's avatar
sof committed
140
141
142
143
144
145

#
# Big Fudge to get around inherent problem that Makefile setup
# has got with 'mkdependC'.
# 
SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
146
147
148

# stuff you get for free in a source distribution
# 
149
# SRC_DIST_FILES += rename/ParseIface.hs rename/Parser.hs
150
151

# -----------------------------------------------------------------------------
152
# 		Haskell compilations
153

154
#
155
# Compiler to use for building ghc, use the build tree
sof's avatar
sof committed
156
157
158
# driver when booting.
#
ifneq "$(GhcWithHscBuiltViaC)" "YES"
159
HC=$(GHC)
sof's avatar
sof committed
160
else
161
HC=$(GHC_INPLACE)
sof's avatar
sof committed
162
endif
163

sof's avatar
sof committed
164
165
166
167
168
# magic from GNU make manual to convert a list of values
# into a colon-separated list
empty:=
space:= $(empty) $(empty)

169
SRC_HC_OPTS += \
170
171
  -cpp -fglasgow-exts \
  -Rghc-timing -I. -IcodeGen -InativeGen -Iparser \
172
  -i$(subst $(space),:,$(DIRS)) 
sof's avatar
sof committed
173

174
175
176
177
178
179
180
181
182
183
184
ghc_407_at_least = $(shell expr "$(GhcMinVersion)" \>= 7)
ifeq "$(ghc_407_at_least)" "1"
ifneq "$(mingw32_TARGET_OS)" "1"
SRC_HC_OPTS += -package concurrent -package posix -package text
else
SRC_HC_OPTS += -package concurrent -package text
endif
else
SRC_HC_OPTS += -syslib concurrent -syslib posix -syslib misc
endif

sof's avatar
sof committed
185
SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
186

187
SRC_HC_OPTS += -recomp $(GhcHcOpts)
188
189
190
191
192

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

193
194
195
# Was 6m with 2.10
absCSyn/PprAbsC_HC_OPTS 	= -H10m

196
basicTypes/IdInfo_HC_OPTS 	= -K2m
sof's avatar
sof committed
197
codeGen/CgCase_HC_OPTS		= -fno-prune-tydecls
198
hsSyn/HsExpr_HC_OPTS 		= -K2m
199
main/Main_HC_OPTS 		= 
200
201

ifneq "$(GhcWithHscBuiltViaC)" "YES"
sof's avatar
sof committed
202
203
204
ifeq "$(GhcReportCompiles)" "YES"
main/Main_HC_OPTS 		+= -syslib misc -DREPORT_TO_MOTHERLODE
endif
205
endif
sof's avatar
sof committed
206

207
main/CmdLineOpts_HC_OPTS 	= -K6m
208
nativeGen/PprMach_HC_OPTS 	= -K2m
209
nativeGen/MachMisc_HC_OPTS 	= -K2m 
210
nativeGen/MachCode_HC_OPTS 	= -H10m
211

212
213
214
# Avoids Bug in 3.02, it seems
usageSP/UsageSPInf_HC_OPTS	= -Onot

215
prelude/PrimOp_HC_OPTS 		= -H12m -K3m
216
217
218

# because the NCG can't handle the 64-bit math in here
prelude/PrelRules_HC_OPTS	= -fvia-C
219

220
221
parser/Lex_HC_OPTS		= -K2m -H16m 
parser/Ctype_HC_OPTS		= -K2m
222

223
rename/ParseIface_HC_OPTS 	+= -Onot -H45m -K2m -fno-warn-incomplete-patterns
sof's avatar
sof committed
224

225
parser/Parser_HC_OPTS 		+= -Onot -H80m -optCrts-M80m -K2m -fno-warn-incomplete-patterns
226

227
ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
228
rename/RnMonad_HC_OPTS 		=  -O2 -O2-for-C
sof's avatar
sof committed
229
endif
230

231
rename/RnEnv_HC_OPTS 		= 
232
rename/RnSource_HC_OPTS		= -H12m
233
rename/RnIfaces_HC_OPTS		= -H8m 
234
rename/RnExpr_HC_OPTS		= -H10m
235
rename/RnNames_HC_OPTS		= -H12m
236
rename/RnMonad_HC_OPTS		= 
237
specialise/Specialise_HC_OPTS 	= -Onot -H12m
238
simplCore/Simplify_HC_OPTS	= -H15m	
239
simplCore/OccurAnal_HC_OPTS	= -H10m
240
typecheck/TcGenDeriv_HC_OPTS	= -H10m
241

242
243
# tmp, -- SDM
specialise/Specialise_HC_OPTS 	+= -fno-prune-tydecls
244
hsSyn/HsBasic_HC_OPTS		+= -fno-prune-tydecls
245
246
247
248
249
250
251
simplCore/SimplMonad_HC_OPTS	+= -fno-prune-tydecls
absCSyn/AbsCSyn_HC_OPTS		+= -fno-prune-tydecls
absCSyn/AbsCUtils_HC_OPTS	+= -fno-prune-tydecls
codeGen/CgBindery_HC_OPTS	+= -fno-prune-tydecls
codeGen/CgLetNoEscape_HC_OPTS	+= -fno-prune-tydecls
codeGen/CgExpr_HC_OPTS		+= -fno-prune-tydecls
nativeGen/AbsCStixGen_HC_OPTS	+= -fno-prune-tydecls
252

253
254
255
# Was 10m for 2.10
typecheck/TcHsSyn_HC_OPTS	= -H15m	

256

257
258
# Was 10m for 2.10
typecheck/TcExpr_HC_OPTS	= -H15m
259
typecheck/TcBinds_HC_OPTS       = -H10m
260

sof's avatar
sof committed
261
typecheck/TcEnv_HC_OPTS		= -H10m
262
utils/SST_HC_OPTS 		= 
sof's avatar
sof committed
263
utils/StringBuffer_HC_OPTS	= -fvia-C -fno-prune-tydecls
264
265
utils/Digraph_HC_OPTS		= -fglasgow-exts 
utils/DirUtils_HC_OPTS 		= 
sof's avatar
sof committed
266

267
268
269
# temporary, due to bug in NCG (x86 spiller fails because a basic block
# contains both multiply and divide insns, probably soaking up all spill
# regs) (SDM, 1/6/2000), augmented by JRS 27 Oct 00.
270
271
utils/FastString_HC_OPTS	= -fvia-C

272
273
ifeq "$(alpha_HOST_ARCH)" "1"
# "stbu" bug in alpha native code generator...
274
basicTypes/Unique_HC_OPTS	= 
275
276
endif

277
278
279
280
281
282
# flags for PrimPacked:
#
# -monly-3-regs 
#	because it contains a 'ccall strlen', which gets inlined by
# 	gcc, causing a lack of registers.
#
283
# -optC-funfolding-interface-threshold7
284
285
286
287
288
#	To stop the definition of 'strLength', which calls strlen, getting
#	into the interface file and spreading the -monly-3-regs virus.
#	We need -optC here because the driver before 3.02 didn't understand
#	the -funfolding flags.

289
utils/PrimPacked_HC_OPTS	= -fvia-C -monly-3-regs -optC-funfolding-interface-threshold7
290

291
292
293
294
295
# Strictness analyser misbehaving in 2.10, fails to terminate on
# UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
# separate bugfix to the fixpoint finder.
simplStg/UpdAnal_HC_OPTS	= -fno-strictness

296
ghci/StgInterp_HC_OPTS		= -fvia-C
297

298
299
300
# ----------------------------------------------------------------------------
#		C compilations

301
SRC_C_OPTS     += -O -I. -IcodeGen
302

303

304
305
306
307
308
309
# ----------------------------------------------------------------------------
#		Generate supporting stuff for prelude/PrimOp.lhs 
#		from prelude/primops.txt

GENPOC=$(TOP)/utils/genprimopcode/genprimopcode

310
311
312
313
314
315
316
317
318
319
320
321
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-usage.hs-incl  \
            primop-primop-info.hs-incl

322
323
324
prelude/PrimOp.o: $(PRIMOP_BITS)

depend :: $(PRIMOP_BITS)
325
326

primop-data-decl.hs-incl: prelude/primops.txt
327
	$(GENPOC) --data-decl          < $< > $@
328
primop-tag.hs-incl: prelude/primops.txt
329
	$(GENPOC) --primop-tag         < $< > $@
330
primop-list.hs-incl: prelude/primops.txt
331
	$(GENPOC) --primop-list        < $< > $@
332
primop-has-side-effects.hs-incl: prelude/primops.txt
333
	$(GENPOC) --has-side-effects   < $< > $@
334
primop-out-of-line.hs-incl: prelude/primops.txt
335
	$(GENPOC) --out-of-line        < $< > $@
336
primop-commutable.hs-incl: prelude/primops.txt
337
	$(GENPOC) --commutable         < $< > $@
338
primop-needs-wrapper.hs-incl: prelude/primops.txt
339
	$(GENPOC) --needs-wrapper      < $< > $@
340
primop-can-fail.hs-incl: prelude/primops.txt
341
	$(GENPOC) --can-fail           < $< > $@
342
primop-strictness.hs-incl: prelude/primops.txt
343
	$(GENPOC) --strictness         < $< > $@
344
primop-usage.hs-incl: prelude/primops.txt
345
	$(GENPOC) --usage              < $< > $@
346
primop-primop-info.hs-incl: prelude/primops.txt
347
	$(GENPOC) --primop-primop-info < $< > $@
348
349


350

351
# ----------------------------------------------------------------------------
sof's avatar
sof committed
352
#		Parsers/lexers
353
354
355

parser/hschooks.o : parser/hschooks.c
	@$(RM) $@
356
	$(HC) -c -o $@ $(HC_OPTS) parser/hschooks.c
357

358
359

# Interface-file parser uses Happy
360
SRC_HAPPY_OPTS += +RTS -K2m -H16m -RTS  $(GHC_HAPPY_OPTS)
361

362
363
rename/ParseIface.hs : rename/ParseIface.y
	@$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
364
	$(HAPPY) $(HAPPY_OPTS) rename/ParseIface.y
365
366
	@chmod 444 rename/ParseIface.hs

367
368
parser/Parser.hs : parser/Parser.y
	@$(RM) parser/Parser.hs parser/ParseIface.hinfo
369
	$(HAPPY) $(HAPPY_OPTS) parser/Parser.y
370
	@chmod 444 parser/Parser.hs
sof's avatar
sof committed
371

372
373
374
#-----------------------------------------------------------------------------
# 		Linking

375
376
377
SRC_LD_OPTS += -no-link-chk 
# REMOVED SLPJ
# -ldl
378
379

ifneq "$(GhcWithHscBuiltViaC)" "YES"
sof's avatar
sof committed
380
ifeq "$(GhcReportCompiles)" "YES"
sof's avatar
sof committed
381
SRC_LD_OPTS += -syslib misc -syslib exts
sof's avatar
sof committed
382
endif
383
endif
384

385
386
387
388
389
# -----------------------------------------------------------------------------
# create ghc-inplace, a convenient way to run ghc from the build tree...

all :: ghc-inplace

390
ghc-inplace : ghc
391
392
	@$(RM) $@
	echo '#!/bin/sh' >>$@
393
	echo exec $(FPTOOLS_TOP_ABS)/ghc/compiler/ghc -B$(FPTOOLS_TOP_ABS) '"$$@"' >>$@
394
395
396
397
	chmod 755 $@

CLEAN_FILES += ghc-inplace

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
# -----------------------------------------------------------------------------
# Create link to from ghc-x.xx to ghc...

all :: $(LINK)

$(LINK) : $(HS_PROG)
	@if ( $(PERL) -e '$$fn="$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
	   echo "Creating a symbolic link from $(HS_PROG) to $(LINK)"; \
	   $(RM) $(LINK); \
	   $(LN_S) $(HS_PROG) $(LINK); \
	 else \
	   echo "Creating a symbolic link from $(HS_PROG) to $(LINK) failed: \`$(LINK)' already exists"; \
	   echo "Perhaps remove \`$(LINK)' manually?"; \
	   exit 1; \
	 fi;

CLEAN_FILES += $(LINK)

install ::
	@if ( $(PERL) -e '$$fn="$(bindir)/$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
	   echo "Creating a symbol link from $(HS_PROG) to $(LINK) in $(bindir)"; \
	   $(RM) $(bindir)/$(LINK); \
	   $(LN_S) $(HS_PROG) $(bindir)/$(LINK); \
	 else \
	   echo "Creating a symbol link from $(HS_PROG) to $(LINK) in $(bindir) failed: \`$(bindir)/$(LINK)' already exists"; \
	   echo "Perhaps remove \`$(bindir)/$(LINK)' manually?"; \
	   exit 1; \
	 fi;

427
428
429
#-----------------------------------------------------------------------------
# 		install

430
# We don't want ghc treated as an ordinary executable,
431
432
433
# but put it together with the libraries.
# Also don't want any interface files intstalled

434
INSTALL_PROGS += $(HS_PROG)
435
436

#-----------------------------------------------------------------------------
437
438
439
440
441
# 		depend

#
# Before doing `make depend', need to build all derived Haskell source files
#
442
depend :: $(LOOPS)
443
444
445
446

ifneq "$(GhcWithHscBuiltViaC)" "YES"
depend :: rename/ParseIface.hs
endif
447

448
449
450
#-----------------------------------------------------------------------------
# 		clean

451
CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi)
452
CLEAN_FILES += $(PRIMOP_BITS)
453
454

# Extra tidy, remove the .hc files (if you've got them).
455
456
MAINTAINER_CLEAN_FILES += $(wildcard */*.hc) \
	parser/Parser.hs rename/ParseIface.hs
457
458
459


#-----------------------------------------------------------------------------
sof's avatar
sof committed
460
# 		TAGS setup
461
462

SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
sof's avatar
sof committed
463
464
TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
465
466
467
468
469
470

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

include $(TOP)/mk/target.mk

471
parser/%.o : parser/%.c
sof's avatar
sof committed
472