Makefile 14.4 KB
Newer Older
1
# -----------------------------------------------------------------------------
rrt's avatar
rrt committed
2
# $Id: Makefile,v 1.184 2001/08/15 09:33:41 rrt 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
#		Set HS_PROG
13

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
# -----------------------------------------------------------------------------
# Create compiler configuration
28 29 30
#
# The 'echo' commands simply spit the values of various make variables
# into Config.hs, whence they can be compiled and used by GHC itself
31

32
CONFIG_HS 	= main/Config.hs
33 34 35 36 37 38 39 40 41
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)
42
	@echo "cBooterVersion        = \"$(GhcVersion)\"" >> $(CONFIG_HS)
43 44 45 46
	@echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
	@echo "cHOSTPLATFORM         = \"$(HOSTPLATFORM)\"" >> $(CONFIG_HS)
	@echo "cTARGETPLATFORM       = \"$(TARGETPLATFORM)\"" >> $(CONFIG_HS)
	@echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
47
	@echo "cGhcUnregisterised    = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
48
	@echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
49
	@echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
50
	@echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
51
	@echo "cMKDLL                = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
52 53
	@echo "cGHC_DRIVER_DIR       = \"$(GHC_DRIVER_DIR)\"" >> $(CONFIG_HS)
	@echo "cGHC_TOUCHY           = \"$(GHC_TOUCHY)\"" >> $(CONFIG_HS)
54
	@echo "cGHC_TOUCHY_DIR       = \"$(GHC_TOUCHY_DIR)\"" >> $(CONFIG_HS)
55
	@echo "cGHC_UNLIT            = \"$(GHC_UNLIT)\"" >> $(CONFIG_HS)
56
	@echo "cGHC_UNLIT_DIR        = \"$(GHC_UNLIT_DIR)\"" >> $(CONFIG_HS)
57
	@echo "cGHC_MANGLER          = \"$(GHC_MANGLER)\"" >> $(CONFIG_HS)
58
	@echo "cGHC_MANGLER_DIR      = \"$(GHC_MANGLER_DIR)\"" >> $(CONFIG_HS)
59
	@echo "cGHC_SPLIT            = \"$(GHC_SPLIT)\"" >> $(CONFIG_HS)
60
	@echo "cGHC_SPLIT_DIR        = \"$(GHC_SPLIT_DIR)\"" >> $(CONFIG_HS)
61
	@echo "cGHC_SYSMAN           = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
62 63 64
	@echo "cGHC_SYSMAN_DIR       = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
	@echo "cGHC_CP               = \"$(GHC_CP)\"" >> $(CONFIG_HS)
	@echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
rrt's avatar
rrt committed
65 66 67 68
ifeq ($(GhcWithIlx),YES)
	@echo "cILX2IL               = \"$(ILX2IL)\"" >> $(CONFIG_HS)
	@echo "cILASM                = \"$(ILASM)\"" >> $(CONFIG_HS)
endif
69 70 71 72 73 74 75 76 77
	@echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(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 "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
	@echo done.

CLEAN_FILES += $(CONFIG_HS)
78 79

# -----------------------------------------------------------------------------
80
# 		Set SRCS, HCS, OBJS
81 82 83 84
#
# First figure out DIRS, the source sub-directories
# Then derive SRCS by looking in them
#
85 86 87 88

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

ifeq ($(GhcWithNativeCodeGen),YES)
sof's avatar
sof committed
92
DIRS += nativeGen
93 94
else
SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
rrt's avatar
rrt committed
95 96
endif

97 98 99 100
ifeq ($(GhcWithIlx),YES)
DIRS += ilxGen
SRC_HC_OPTS += -DILX
endif
101

sof's avatar
sof committed
102
#
sof's avatar
sof committed
103 104
# Canonicalize the GHC version number - assume it is has the form x.yy.[z] or 
# x.yy[.date] where date = yyyymmdd
sof's avatar
sof committed
105
#
sof's avatar
sof committed
106 107
# [First sed substitution gets rid of the '.', second gets rid of the date portion,
#  third appends a '0' if the z portion is missing]
sof's avatar
sof committed
108
#
sof's avatar
sof committed
109 110 111
CANON_HC_VERSION=$(shell echo "$(GhcVersion)" | sed -e 's/\.//g;s/^\(...\)........$$/\1/g;s/^\(...\)$$/\10/g')

# 20010625
sof's avatar
sof committed
112

113 114
ifeq "$(BootingFromHc)" "YES"
# HC files are always from a self-booted compiler
115
bootstrapped = YES
sof's avatar
sof committed
116
compiling_with_4xx=NO
117
else
118
bootstrapped = $(shell if (test $(CANON_HC_VERSION) -ge $(ProjectVersionInt)0); then echo YES; else echo NO; fi)
sof's avatar
sof committed
119
compiling_with_4xx = $(shell if (test $(CANON_HC_VERSION) -lt 5000); then echo YES; else echo NO; fi)
rrt's avatar
rrt committed
120
ghc_502_at_least = $(shell if (test $(CANON_HC_VERSION) -ge 5020); then echo YES; else echo NO; fi)
121
endif
122

123
# Only include GHCi if we're bootstrapping with at least version 411
124
ifeq "$(GhcWithInterpreter)" "YES"
125
ifeq "$(bootstrapped)" "YES"
126
SRC_HC_OPTS += -DGHCI
127 128 129
DIRS += ghci
endif
endif
130

sof's avatar
sof committed
131 132
# Enable code that assumes a MSDOSish subshell. See mk/config.mk.in
# for explanatory comment as to what this does.
rrt's avatar
rrt committed
133
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
rrt's avatar
rrt committed
134
ghc_501_at_least = $(shell if (test $(CANON_HC_VERSION) -ge 5010); then echo YES; else echo NO; fi)
sof's avatar
sof committed
135

136
# -----------------------------------------------
rrt's avatar
rrt committed
137 138 139
# GHCi calls the C procedure 'rawSystem'; but alas GHC 4.08 
# does not have this.  Everything is fine if you are compiling
# GHC with GHC 5.02 or better, but lacking that we have the following
140
# hack: 
rrt's avatar
rrt committed
141 142 143
#	copy rawSystem.c from hslibs/lang/cbits
#       and SystemExts.lhs from hslibs/lang
#	into main/ (where they'll be compiled and linked with the compiler)
144

rrt's avatar
rrt committed
145 146 147
ifneq "$(ghc_502_at_least)" "YES"
C_SRCS += main/rawSystem.c
HS_SRCS += main/SystemExts.lhs
rrt's avatar
rrt committed
148 149
SRC_CC_OPTS += -I$(GHC_LIB_DIR)/std/cbits
SRC_MKDEPENDC_OPTS += -I$(GHC_LIB_DIR)/std/cbits
rrt's avatar
rrt committed
150 151 152 153 154
HS_OBJS += main/rawSystem.o
main/rawSystem.c : $(FPTOOLS_TOP)/hslibs/lang/cbits/rawSystem.c
	$(CP) $< main
main/SystemExts.lhs: $(FPTOOLS_TOP)/hslibs/lang/SystemExts.lhs
	$(CP) $< main
rrt's avatar
rrt committed
155
endif
sof's avatar
sof committed
156
endif
157 158
#		End of system hack
# -----------------------------------------------
sof's avatar
sof committed
159

160
HS_SRCS := $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs) $(wildcard $(dir)/*.hs))
161
HS_SRCS := $(filter-out rename/ParseIface.hs parser/Parser.hs main/ParsePkgConf.hs $(CONFIG_HS), $(HS_SRCS))
162
HS_SRCS += $(CONFIG_HS)
163

164 165
ifneq "$(BootingFromHc)" "YES"
HS_SRCS += rename/ParseIface.hs parser/Parser.hs main/ParsePkgConf.hs
166
endif
167

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

170
ifeq "$(BootingFromHc)" "YES"
171
HCS	+= rename/ParseIface.hc parser/Parser.hc main/ParsePkgConf.hc
172
endif
sof's avatar
sof committed
173

sof's avatar
sof committed
174 175 176
#
# Add misc .c helper code (used by the frontend.)
#
177
C_SRCS += parser/hschooks.c
sof's avatar
sof committed
178

rrt's avatar
rrt committed
179 180 181 182 183 184
HS_OBJS = \
  $(patsubst %.hc, %.o, $(HCS)) \
  $(patsubst %.c, %.o, $(C_SRCS))

DESTDIR       = $(INSTALL_LIBRARY_DIR_GHC)

sof's avatar
sof committed
185 186 187 188
#
# Big Fudge to get around inherent problem that Makefile setup
# has got with 'mkdependC'.
# 
sof's avatar
sof committed
189
SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt) -I$(GHC_INCLUDE_DIR)
190

191
# -----------------------------------------------------------------------------
192
# 		Haskell compilations
193

194
#
195
# Compiler to use for building ghc, use the build tree
sof's avatar
sof committed
196 197
# driver when booting.
#
198
HC=$(GHC)
199

200 201 202
#
# Use GHC for compiling C bits
#
203 204 205
ifeq "$(BootingFromHc)" "YES"
SRC_CC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
else
206
CC = $(HC)
sebc's avatar
sebc committed
207
CC_OPTS := $(addprefix -optc, $(CC_OPTS))
208
endif
209

sof's avatar
sof committed
210 211 212 213 214
# magic from GNU make manual to convert a list of values
# into a colon-separated list
empty:=
space:= $(empty) $(empty)

215
SRC_HC_OPTS += \
216
  -cpp -fglasgow-exts -Rghc-timing \
217
  -I. -IcodeGen -InativeGen -Iparser \
218
  -i$(subst $(space),:,$(DIRS)) 
sof's avatar
sof committed
219

220 221 222 223
# 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"
224 225 226 227 228 229
# 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

230
ifneq "$(mingw32_TARGET_OS)" "1"
231
SRC_HC_OPTS += -package concurrent -package posix -package text -package util
232
else
sof's avatar
sof committed
233
SRC_HC_OPTS += -package concurrent -package text -package util
234 235
endif

sof's avatar
sof committed
236
SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
237
SRC_HC_OPTS += -recomp $(GhcHcOpts)
238
SRC_HC_OPTS += -H16M
239 240 241 242 243

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

244
# not sure if this is required --SDM
245
main/Main_HC_OPTS 		= -fvia-C
246

247
prelude/PrimOp_HC_OPTS 		= -no-recomp -H80m
248 249 250

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

252 253
rename/ParseIface_HC_OPTS 	+= -Onot -H45m -fno-warn-incomplete-patterns
parser/Parser_HC_OPTS 		+= -Onot -fno-warn-incomplete-patterns
254
main/ParsePkgConf_HC_OPTS	+= -fno-warn-incomplete-patterns
255 256 257

# The latest GHC version doesn't have a -K option yet, and it doesn't
# seem to be necessary anymore for the modules below.
sof's avatar
sof committed
258
ifeq "$(compiling_with_4xx)" "YES"
259 260 261
rename/ParseIface_HC_OPTS 	+= -K2m
parser/Parser_HC_OPTS 		+= -K2m
endif
262

263
ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
264
rename/RnMonad_HC_OPTS 		=  -O2 -O2-for-C
sof's avatar
sof committed
265
endif
266

sof's avatar
sof committed
267
utils/StringBuffer_HC_OPTS	= -fvia-C -fno-prune-tydecls
268
utils/Digraph_HC_OPTS		= -fglasgow-exts 
sof's avatar
sof committed
269

270 271 272 273 274 275
# flags for PrimPacked:
#
# -monly-3-regs 
#	because it contains a 'ccall strlen', which gets inlined by
# 	gcc, causing a lack of registers.
#
276
utils/PrimPacked_HC_OPTS	= -fvia-C -monly-3-regs
277

278 279
# ByteCodeItbls uses primops that the NCG doesn't support yet.
ghci/ByteCodeItbls_HC_OPTS	= -fvia-C
280
ghci/ByteCodeLink_HC_OPTS	= -fvia-C
281

282 283 284 285 286 287 288 289 290 291
# 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.
compMan/CompManager_HC_OPTS	= -fno-cse
ghci/InteractiveUI_HC_OPTS	= -fno-cse
main/CmdLineOpts_HC_OPTS	= -fno-cse
main/DriverFlags_HC_OPTS	= -fno-cse
main/DriverMkDepend_HC_OPTS	= -fno-cse
main/DriverPipeline_HC_OPTS	= -fno-cse
292
main/DriverState_HC_OPTS	= -fno-cse
293 294
main/DriverUtil_HC_OPTS		= -fno-cse
main/Finder_HC_OPTS		= -fno-cse
295
main/SysTools_HC_OPTS		= -fno-cse
296

297 298 299 300 301 302 303
# 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
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
main/SysTools_HC_OPTS		+= '-\#include <windows.h>'
endif

304 305 306
# ----------------------------------------------------------------------------
#		C compilations

307
SRC_C_OPTS     += -O -I. -IcodeGen
308

309

310 311 312 313
# ----------------------------------------------------------------------------
#		Generate supporting stuff for prelude/PrimOp.lhs 
#		from prelude/primops.txt

ken's avatar
ken committed
314
CLEAN_FILES += prelude/primops.txt
ken's avatar
ken committed
315

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

318 319 320 321 322 323 324 325 326 327 328 329
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

330
ifneq "$(BootingFromHc)" "YES"
331
prelude/PrimOp.lhs prelude/PrimOp.o: $(PRIMOP_BITS)
332
endif
333

334
ifneq "$(BootingFromHc)" "YES"
335
depend :: $(PRIMOP_BITS)
336
endif
337

ken's avatar
ken committed
338
primop-data-decl.hs-incl: prelude/primops.txt
339
	$(GENPOC) --data-decl          < $< > $@
ken's avatar
ken committed
340
primop-tag.hs-incl: prelude/primops.txt
341
	$(GENPOC) --primop-tag         < $< > $@
ken's avatar
ken committed
342
primop-list.hs-incl: prelude/primops.txt
343
	$(GENPOC) --primop-list        < $< > $@
ken's avatar
ken committed
344
primop-has-side-effects.hs-incl: prelude/primops.txt
345
	$(GENPOC) --has-side-effects   < $< > $@
ken's avatar
ken committed
346
primop-out-of-line.hs-incl: prelude/primops.txt
347
	$(GENPOC) --out-of-line        < $< > $@
ken's avatar
ken committed
348
primop-commutable.hs-incl: prelude/primops.txt
349
	$(GENPOC) --commutable         < $< > $@
ken's avatar
ken committed
350
primop-needs-wrapper.hs-incl: prelude/primops.txt
351
	$(GENPOC) --needs-wrapper      < $< > $@
ken's avatar
ken committed
352
primop-can-fail.hs-incl: prelude/primops.txt
353
	$(GENPOC) --can-fail           < $< > $@
ken's avatar
ken committed
354
primop-strictness.hs-incl: prelude/primops.txt
355
	$(GENPOC) --strictness         < $< > $@
ken's avatar
ken committed
356
primop-usage.hs-incl: prelude/primops.txt
357
	$(GENPOC) --usage              < $< > $@
ken's avatar
ken committed
358
primop-primop-info.hs-incl: prelude/primops.txt
359
	$(GENPOC) --primop-primop-info < $< > $@
360 361


362

363
# ----------------------------------------------------------------------------
sof's avatar
sof committed
364
#		Parsers/lexers
365

366
SRC_HAPPY_OPTS += +RTS -K2m -H16m -RTS  $(GHC_HAPPY_OPTS)
367 368 369 370

#-----------------------------------------------------------------------------
# 		Linking

371
SRC_LD_OPTS += -no-link-chk 
372

373 374 375 376 377
# -----------------------------------------------------------------------------
# create ghc-inplace, a convenient way to run ghc from the build tree...

all :: ghc-inplace

378
ghc-inplace : $(HS_PROG)
379 380
	@$(RM) $@
	echo '#!/bin/sh' >>$@
381
	echo exec $(FPTOOLS_TOP_ABS_UNIX)/ghc/compiler/$(HS_PROG) -B$(FPTOOLS_TOP_ABS) '"$$@"' >>$@
382
	chmod 755 $@
rrt's avatar
rrt committed
383
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
sof's avatar
sof committed
384
	@$(RM) $@.bat
sof's avatar
sof committed
385
	echo "@"$(subst /,\\,$(FPTOOLS_TOP_ABS)/ghc/compiler/$(HS_PROG)) "-B$(FPTOOLS_TOP_ABS) %1 %2 %3 %4 %5 %6 %7 %8 %9" >$@.bat
sof's avatar
sof committed
386 387
	chmod 755 $@.bat
endif
388 389 390

CLEAN_FILES += ghc-inplace

391 392 393
#-----------------------------------------------------------------------------
# 		install

394
# We don't want ghc treated as an ordinary executable,
395 396 397
# but put it together with the libraries.
# Also don't want any interface files intstalled

398
INSTALL_LIBEXECS += $(HS_PROG)
399

400 401 402
#-----------------------------------------------------------------------------
# 		clean

403
CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi)
404
CLEAN_FILES += $(PRIMOP_BITS)
405 406

# Extra tidy, remove the .hc files (if you've got them).
407
MAINTAINER_CLEAN_FILES += $(wildcard */*.hc) \
408 409
	parser/Parser.info rename/ParseIface.info main/ParsePkgConf.info \
	parser/Parser.hs rename/ParseIface.hs main/ParsePkgConf.hs
410 411 412 413 414

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

include $(TOP)/mk/target.mk