config.mk.in 30.3 KB
Newer Older
1
#								 -*-makefile-*-
2 3
# @configure_input@
#
4
################################################################################
5
#
6
# config.mk.in
7
#
8 9 10
# This file supplies defaults for many tweakable build configuration
# options.  Some of the defaults are filled in by the autoconf-generated
# configure script.
11
#
12
# DO NOT EDIT THIS FILE!
13
#
14
# 	- config.mk is auto-generated from config.mk.in by configure.
15
#	  If you edit config.mk your changes will be spammed.
16
#
17
#	- Settings in this file may be overridden by giving replacement
18 19 20 21 22
#	  definitions in build.mk.  See build.mk.sample for a good
#	  starting point for a build.mk file.
#
#	  If you don't have a build.mk file then you get defaults for everything.
#	  The defaults should provide a reasonable vanilla build.
23

Ian Lynagh's avatar
Ian Lynagh committed
24 25 26
# TOP: the top of the fptools hierarchy, absolute path.
# On Windows this is a c:/foo/bar style path.
TOP		= @hardtop@
sof's avatar
sof committed
27

Ian Lynagh's avatar
Ian Lynagh committed
28
include $(TOP)/mk/project.mk
sof's avatar
sof committed
29

30 31 32
# By default, be verbose
V = 1

33 34 35 36 37 38
################################################################################
#
#		Global configuration options
#
################################################################################

Ian Lynagh's avatar
Ian Lynagh committed
39 40 41
NO_INCLUDE_DEPS = NO
NO_INCLUDE_PKGDATA = NO

42
################################################################################
43 44
#
# Variables that control how the compiler itself is built
sof's avatar
sof committed
45
#
46
################################################################################
47

48 49
# The compiler used to build GHC is $(GHC).  To change the actual compiler
# used, re-configure with --with-ghc=<path-to-ghc>.
sof's avatar
sof committed
50

51
# Extra option flags to pass to the compiler that compiles the compiler
52
# (Ones that are essential are wired into compiler/Makefile)
53
# Typical options to use here:
sof's avatar
sof committed
54
#
55 56 57
#	-DDEBUG		include debugging code and assertions (will make the
#			compiler slower and produce debugging output, but useful
#			for development)
sof's avatar
sof committed
58 59
#
#	-dcore-lint	check the types after every pass of the compiler;
60 61 62 63
#			a pretty strong internal check of the compiler being
#			used to compile GHC.  Useful when bootstrapping.
GhcHcOpts=-Rghc-timing

64 65 66
# Extra options added to specific stages of the compiler bootstrap.
# These are placed later on the command line, and may therefore
# override options from $(GhcHcOpts).
67 68
#
# See Note [Stage number in build variables].
69 70 71
#
# -haddock is needed so the GHCi :doc command can find docs
#   in the .hi-files for the ghc library
72
GhcStage1HcOpts=
73 74
GhcStage2HcOpts=-O2 -haddock
GhcStage3HcOpts=-O2 -haddock
75

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

# Note [Stage number in build variables].
#
# There are (unfortunately) two different naming schemes for build variables
# specific to a certain stage.
#
# * GhcStage1HcOpts/GhcStage2HcOpts/GhcStage3HcOpts:
#
#   The stage number refers to the compiler stage being built (ghc library
#   and executable).
#
# * SRC_HC_OPTS_STAGE$4 and SRC_HC_WARNING_OPTS_STAGE$4:
#
#   The stage number refers to the compiler stage the options are passed to.

91
GhcDebugged=NO
92 93 94

# GhcProfiled=YES means compile a profiled stage-2 compiler
GhcProfiled=NO
95

96 97 98
# WITH_TERMINFO can be used to disable terminfo support throughout the compiler
# and its tools. This is handy in the case of cross-compilation, where we may
# not have an ncurses build for the target.
99 100 101 102
ifeq "$(TargetOS_CPP)" "ios"
# iOS has no terminfo support
WITH_TERMINFO=NO
else ifeq "$(Windows_Target)" "YES"
103
WITH_TERMINFO=NO
104 105
else
WITH_TERMINFO=YES
106 107
endif

108 109 110 111 112 113 114
ifeq "$(findstring $(TargetOS_CPP),linux freebsd dragonfly openbsd netbsd solaris2 kfreebsdgnu haiku linux-android)" ""
TargetElf = NO
else
TargetElf = YES
endif

# Some platforms don't support shared libraries
115
NoSharedLibsPlatformList = \
116
	powerpc-ibm-aix \
117
	x86_64-unknown-mingw32 \
118
	i386-unknown-mingw32
119 120 121

ifeq "$(SOLARIS_BROKEN_SHLD)" "YES"
NoSharedLibsPlatformList += i386-unknown-solaris2
122 123 124
endif

PlatformSupportsSharedLibs = $(if $(filter $(TARGETPLATFORM),\
125
    $(NoSharedLibsPlatformList)),NO,YES)
126

127
# DYNAMIC_BY_DEFAULT says whether this compiler will default to
128
# building dynamic executables, i.e. -dynamic is on.  We do this for
129
# most platforms because it lets us use the system dynamic linker
130 131
# instead of our own linker for GHCi.
#
132 133
# Currently this isn't possible on Windows, and we have not yet enabled
# it on i386 while we consider the performance implications.
134
#
135 136 137 138 139 140 141
ifeq "$(TargetOS_CPP)" "mingw32"
DYNAMIC_BY_DEFAULT = NO
else ifeq "$(TargetArch_CPP)" "i386"
DYNAMIC_BY_DEFAULT = NO
else
DYNAMIC_BY_DEFAULT = YES
endif
142

143 144 145 146
# For now, we unconditionally disable dynamic-by-default, as the
# cabal-install's that are in the wild don't handle it properly.
DYNAMIC_BY_DEFAULT = NO

147 148
# If building both v and dyn ways, then use -dynamic-too to build them.
# This makes the build faster.
149
DYNAMIC_TOO = YES
150

151 152 153
# Use the dynamic way when building programs in the GHC tree. In
# particular, this means that GHCi will use DLLs rather than loading
# object files directly.
154 155 156
ifeq "$(TargetOS_CPP)" "mingw32"
# This doesn't work on Windows yet
DYNAMIC_GHC_PROGRAMS = NO
157
DYNAMIC_TOO=NO
158 159
else ifeq "$(PlatformSupportsSharedLibs)" "NO"
DYNAMIC_GHC_PROGRAMS = NO
160
else
161
DYNAMIC_GHC_PROGRAMS = YES
162
endif
163

164 165 166 167 168 169
# Build a compiler that will build *unregisterised* libraries and
# binaries by default.  Unregisterised code is supposed to compile and
# run without any support for architecture-specific assembly mangling,
# register assignment or tail-calls, and is therefore a good way to get
# started when porting GHC to new architectures.
#
170 171 172
# NOTE: the stage1 compiler will be a registerised binary (assuming
# the compiler you build with is generating registerised binaries), but
# the stage2 compiler will be an unregisterised binary.
173
#
174
GhcUnregisterised=@Unregisterised@
175

176
# ArchSupportsSMP should be set iff there is support for that arch in
Simon Marlow's avatar
Simon Marlow committed
177
# includes/stg/SMP.h
178 179
ifeq "$(TargetArch_CPP)" "arm"
# We don't support load/store barriers pre-ARMv7. See #10433.
180
ArchSupportsSMP=$(if $(filter $(ARM_ISA),ARMv5 ARMv6),NO,YES)
181
else
182
ArchSupportsSMP=$(strip $(patsubst $(TargetArch_CPP), YES, $(findstring $(TargetArch_CPP), i386 x86_64 sparc powerpc powerpc64 powerpc64le s390x aarch64)))
183
endif
184

185
# The THREADED_RTS requires `BaseReg` to be in a register and the
Erik de Castro Lopo's avatar
Erik de Castro Lopo committed
186
# `GhcUnregisterised` mode doesn't allow that.
187
GhcWithSMP := $(strip $(if $(filter YESNO, $(ArchSupportsSMP)$(GhcUnregisterised)),YES,NO))
188

189 190 191
# Whether or not the bootstrapping GHC supplies a threaded RTS.
GhcThreadedRts = @GhcThreadedRts@

192 193
# Whether to include GHCi in the compiler.  Depends on whether the RTS linker
# has support for this OS/ARCH combination.
194

195
OsSupportsGHCi=$(strip $(patsubst $(TargetOS_CPP), YES, $(findstring $(TargetOS_CPP), mingw32 linux solaris2 freebsd dragonfly netbsd openbsd darwin kfreebsdgnu)))
196
ArchSupportsGHCi=$(strip $(patsubst $(TargetArch_CPP), YES, $(findstring $(TargetArch_CPP), i386 x86_64 powerpc powerpc64 powerpc64le sparc sparc64 arm aarch64)))
197 198

ifeq "$(OsSupportsGHCi)$(ArchSupportsGHCi)" "YESYES"
199
GhcWithInterpreter=YES
200
else
201
GhcWithInterpreter=$(if $(findstring YES,$(DYNAMIC_GHC_PROGRAMS)),YES,NO)
202
endif
203

204 205 206
# Whether to use libffi for adjustors (foreign import "wrapper") or
# not.  If we have built-in support (rts/Adjustor.c) then we use that,
# otherwise we fall back on libffi, which is slightly slower.
207
ArchHasAdjustorSupport = $(if $(findstring $(TargetArch_CPP),i386 x86_64),YES,NO)
208 209 210 211 212 213
ifeq "$(ArchHasAdjustorSupport)" "YES"
UseLibFFIForAdjustors=NO
else
UseLibFFIForAdjustors=YES
endif

214 215
# On Windows we normally want to make a relocatable bindist, to we
# ignore flags like libdir
216
ifeq "$(Windows_Host)" "YES"
217 218 219 220 221
RelocatableBuild = YES
else
RelocatableBuild = NO
endif

Simon Marlow's avatar
Simon Marlow committed
222 223 224
# needs to be after $(RelocatableBuild) is set above
include $(TOP)/mk/install.mk

225 226 227 228
# When building bindists we set this to yes so that the binaries are as
# portable as possible.
BeConservative = NO

229 230
ExtraMakefileSanityChecks = NO

231
#------------------------------------------------------------------------------
232
# Options for Libraries
233

234 235
# Backend to use in ghc-bignum (gmp, native, etc.)
BIGNUM_BACKEND=gmp
236

Ian Lynagh's avatar
Ian Lynagh committed
237
# We build the libraries at least the "vanilla" way (way "v")
238 239
# Technically we don't need the v way if DYNAMIC_GHC_PROGRAMS is YES,
# but with -dynamic-too it's cheap, and makes life easier.
Ian Lynagh's avatar
Ian Lynagh committed
240 241
GhcLibWays = v

242
# In addition to the normal sequential way, the default is to also build
243
# profiled prelude libraries
244 245 246 247 248 249 250 251
# $(if $(filter ...)) allows controlling this expression from build.mk.
GhcLibWays += $(if $(filter $(BUILD_PROF_LIBS),NO),,p)

# Backward compatibility: although it would be cleaner to test for
# PlatformSupportsSharedLibs, or perhaps a new variable BUILD_SHARED_LIBS,
# some users currently expect that DYNAMIC_GHC_PROGRAMS=NO in build.mk implies
# that dyn is not added to GhcLibWays.
GhcLibWays += $(if $(filter $(DYNAMIC_GHC_PROGRAMS),NO),,dyn)
252

253 254 255
# Handy way to test whether we're building shared libs or not.
BuildSharedLibs=$(strip $(if $(findstring dyn,$(GhcLibWays)),YES,NO))

256 257
# In addition, the RTS is built in some further variations.  Ways that
# make sense here:
258
#
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
#   thr           : threaded
#   thr_p         : threaded + profiled + eventlog
#   debug         : debugging + eventlog
#   thr_debug     : debugging + threaded, + eventlog
#   l             : eventlog
#   p             : profiled + eventlog
#   thr_l         : threaded + eventlog
#
# Note how there are a few cases which are handled specially (in packageHsLibs)
# to reduce the number of distinct ways,
#
#   debug     implies  eventlog
#   profiled  implies  eventlog
#
# This means, for instance, that there is no debug_l way.
274
#
Simon Marlow's avatar
Simon Marlow committed
275
GhcRTSWays=l
276 277

# Usually want the debug version
278
GhcRTSWays += debug
279

280 281 282 283
# We always have the threaded versions, but note that SMP support may be disabled
# (see GhcWithSMP).
GhcRTSWays += thr thr_debug thr_l
GhcRTSWays += $(if $(findstring p, $(GhcLibWays)),thr_p,)
284
GhcRTSWays += $(if $(findstring dyn, $(GhcLibWays)),dyn debug_dyn thr_dyn thr_debug_dyn l_dyn thr_l_dyn,)
285
GhcRTSWays += $(if $(findstring p, $(GhcLibWays)),thr_debug_p debug_p,)
286

287
# We can only build GHCi threaded if we have a threaded RTS:
288
GhcThreaded = $(if $(findstring thr,$(GhcRTSWays)),YES,NO)
289

290 291 292 293
# Option flags to pass to GHC when it's compiling modules in
# fptools/libraries.  Typically these are things like -O or
# -dcore-lint or -H32m.  The ones that are *essential* are wired into
# the build system.
sof's avatar
sof committed
294
#
295
# 	-O(2) is pretty desirable, otherwise no inlining of prelude
sof's avatar
sof committed
296
#		things (incl "+") happens when compiling with this compiler
297 298 299
#
#       -haddock is needed so the GHCi :doc command can find the boot
#               library docs in the respective .hi-files
sof's avatar
sof committed
300

301
GhcLibHcOpts=-O2 -haddock
rrt's avatar
rrt committed
302

303 304 305 306 307
# Strip local symbols from libraries?  This can make the libraries smaller,
# but makes debugging somewhat more difficult.  Doesn't work with all ld's.
#
StripLibraries=NO

308 309 310
# ----------------------------------------------------------------------------
# Section splitting
#
Ben Gamari's avatar
Ben Gamari committed
311
# Similar to -ffunction-sections -fdata-sections in GCC.
312
#
313 314 315
# Set SplitSections=YES or NO in your build.mk to override the default.
#
# This is not supported on Darwin (where you can use subsections-via-symbols
316 317
# instead) and Windows is disabled until we figure the linking performance
# issues related to BFD out. (See #11445, #12913 and related tickets.)
318
OsSupportsSplitSections=$(if $(filter $(TargetOS_CPP),darwin),NO,YES)
319
SupportsSplitSections=$(if $(and $(filter YES,$(OsSupportsSplitSections)),\
dobenour's avatar
dobenour committed
320
                                   $(filter YES,$(LdIsGNULd))),YES,NO)
321
SplitSections ?= $(SupportsSplitSections)
322

323 324
# ----------------------------------------------------------------------------

325 326
# There are a number of things which technically depend on GHC (e.g. if
# ghc changes then Haskell files may be compiled differently, or Cabal
327 328 329 330 331 332 333 334 335
# packages may be configured differently). By default we therefore
# have dependencies on the compiler executable.

# However, in practice, having a dependency on GHC is just a pain: We
# normally don't want to spend time recompiling other things while
# we're working on the compiler, and even if we did, GHC will normally
# decide compilation isn't needed anyway. So by setting LAX_DEPENDENCIES
# to YES you can turn these dependencies into order-only dependencies,
# i.e. GHC must exist, but if it's newer than other targets then
336
# rebuilding is not necessary.
337 338

LAX_DEPENDENCIES = NO
339

340 341
# ----------------------------------------------------------------------------
# Options for GHC's RTS
342

343 344 345 346
# Build an optimised RTS.  Remember that we need to turn on
# optimisation both for C code (-optc-O2) and .cmm code (-O2).  For
# the debugging RTS flavour, rts/ghc.mk overrides these to turn off
# optimisation.
347
GhcRtsHcOpts=-O2
348
GhcRtsCcOpts=-O2 -fomit-frame-pointer -g
349

350 351 352 353 354 355
# Configuration for libffi
UseSystemLibFFI=@UseSystemLibFFI@
# Flags to go into package.conf for rts
FFILibDir=@FFILibDir@
FFIIncludeDir=@FFIIncludeDir@

356
UseLibdw=@UseLibdw@
357 358 359
LibdwLibDir=@LibdwLibDir@
LibdwIncludeDir=@LibdwIncludeDir@

360 361
# GHC needs arch-specific tweak at least in
#     rts/Libdw.c:set_initial_registers()
362
GhcRtsWithLibdw=$(strip $(if $(filter $(TargetArch_CPP),i386 x86_64 s390x),@UseLibdw@,NO))
363

364
################################################################################
365 366 367
#
#		Paths (see paths.mk)
#
368
################################################################################
369

370 371 372 373 374 375
BINDIST                 = NO
BIN_DIST_NAME           = ghc-$(ProjectVersion)
BIN_DIST_PREP_DIR       = bindistprep/$(BIN_DIST_NAME)
BIN_DIST_PREP_TAR       = bindistprep/$(BIN_DIST_NAME)-$(TARGETPLATFORM).tar
BIN_DIST_PREP_TAR_COMP ?= $(BIN_DIST_PREP_TAR).$(TAR_COMP_EXT)
BIN_DIST_TAR_COMP       = $(BIN_DIST_NAME)-$(TARGETPLATFORM).tar.$(TAR_COMP_EXT)
376

377
# -----------------------------------------------------------------------------
378
# Utilities programs: flags
379 380 381 382 383 384 385

# If you want to give any standard flags to pretty much any utility
# (see utils.mk for a complete list), by adding a line here
#
# 	SRC_P_OPTS += ...
#
# where P is the utility. For example, to add -O to all Haskell
386
# compilations,
387 388 389
#
#	SRC_HC_OPTS += -O

390 391 392 393

# SRC_HC_OPTS includes flags to be added to *every* Haskell
# compilation.  Setting SRC_HC_OPTS is a good way to set the default
# optimisation level (-O) and heap size (-H<size>).
394
#
395 396 397 398 399 400 401 402 403 404 405 406
# SRC_HC_OPTS is *not* for adding flags that are required to make your
# build work.  Examples:
#
#  - instead of using -pgmc/-pgma-/-pgml, use the --with-gcc option to configure
#
#  - if you need -optc, -opta, or -optl flags, the CONF_CC_* and CONF_LD_*
#    variables are more appropriate (set via configure)
#
# Note that SRC_HC_OPTS are added to every Haskell compilation,
# including when using the bootstrapping compiler (stage 0), So don't
# put options here that are only supported by very recent GHCs.
#
407
SRC_HC_OPTS += -H32m -O
408

409 410 411 412 413 414

# See Note [Stage number in build variables].
SRC_HC_OPTS_STAGE0 =
SRC_HC_OPTS_STAGE1 =
SRC_HC_OPTS_STAGE2 =

Gabor Greif's avatar
Gabor Greif committed
415
# Warning suppression flags. See mk/warnings.mk.
416 417 418 419 420 421 422
SRC_CC_WARNING_OPTS =
SRC_HC_WARNING_OPTS =

# See Note [Stage number in build variables].
SRC_HC_WARNING_OPTS_STAGE0 =
SRC_HC_WARNING_OPTS_STAGE1 =
SRC_HC_WARNING_OPTS_STAGE2 =
423

424 425
# -----------------------------------------------------------------------------
# Names of programs in the GHC tree
Ian Lynagh's avatar
Ian Lynagh committed
426

427
MKDIRHIER           = $(INPLACE_BIN)/mkdirhier
Ian Lynagh's avatar
Ian Lynagh committed
428

429
GENERATED_FILE  = chmod a-w
Ian Lynagh's avatar
Ian Lynagh committed
430
EXECUTABLE_FILE = chmod +x
431

432
#-----------------------------------------------------------------------------
433
# Installed GHC
434

435
# $(GHC) points to installed version of the compiler.
436
#
437 438
# NOTE: Don't override $(GHC) in build.mk, use
# `./configure GHC=...` instead
439
# (because the version numbers have to be calculated).
440

Ian Lynagh's avatar
Ian Lynagh committed
441 442 443 444 445 446 447 448 449
GHC := @WithGhc@
# If we have a make dependency on c:/ghc/ghc, and the file is actually
# called c:/ghc/ghc.exe, then make will think that ghc doesn't exist
# and that it doesn't know how to create it.
ifneq "$(wildcard $(GHC).exe)" ""
GHC := $(GHC).exe
endif

GHC_STAGE0  = $(GHC)
450 451 452
GHC_STAGE1  = $(ghc-stage1_INPLACE)
GHC_STAGE2  = $(ghc-stage2_INPLACE)
GHC_STAGE3  = $(ghc-stage3_INPLACE)
453

Ian Lynagh's avatar
Ian Lynagh committed
454
BOOTSTRAPPING_CONF = libraries/bootstrapping.conf
455

456
INPLACE_PACKAGE_CONF = $(INPLACE_LIB)/package.conf.d
457 458 459 460 461 462 463 464 465 466 467 468 469

GhcVersion	= @GhcVersion@
GhcPatchLevel	= @GhcPatchLevel@
GhcMajVersion	= @GhcMajVersion@
GhcMinVersion	= @GhcMinVersion@

# Canonicalised ghc version number, used for easy (integer) version
# comparisons.  We must expand $(GhcMinVersion) to two digits by
# adding a leading zero if necessary:
ifneq "$(findstring $(GhcMinVersion), 0 1 2 3 4 5 6 7 8 9)" ""
GhcCanonVersion = $(GhcMajVersion)0$(GhcMinVersion)
else
GhcCanonVersion = $(GhcMajVersion)$(GhcMinVersion)
470
endif
471

472 473 474 475 476 477 478 479 480 481
#-----------------------------------------------------------------------------
# Settings

# We are in the process of moving the settings file from being entirely
# generated by configure, to generated being by the build system. Many of these
# might become redundant.

GccExtraViaCOpts = @GccExtraViaCOpts@
LdHasFilelist = @LdHasFilelist@
ArArgs = @ArArgs@
482 483
HaskellHostOs = @HaskellHostOs@
HaskellHostArch = @HaskellHostArch@
484 485 486
HaskellTargetOs = @HaskellTargetOs@
HaskellTargetArch = @HaskellTargetArch@
TargetWordSize = @TargetWordSize@
487
TargetWordBigEndian = @TargetWordBigEndian@
488 489 490 491
TargetHasGnuNonexecStack = @TargetHasGnuNonexecStack@
TargetHasIdentDirective = @TargetHasIdentDirective@
TargetHasSubsectionsViaSymbols = @TargetHasSubsectionsViaSymbols@
TargetHasRTSLinker = @TargetHasRTSLinker@
492
TablesNextToCode = @TablesNextToCode@
493 494 495 496 497

SettingsCCompilerCommand = @SettingsCCompilerCommand@
SettingsHaskellCPPCommand = @SettingsHaskellCPPCommand@
SettingsHaskellCPPFlags = @SettingsHaskellCPPFlags@
SettingsCCompilerFlags = @SettingsCCompilerFlags@
498
SettingsCxxCompilerFlags = @SettingsCxxCompilerFlags@
499 500 501 502
SettingsCCompilerLinkFlags = @SettingsCCompilerLinkFlags@
SettingsCCompilerSupportsNoPie = @SettingsCCompilerSupportsNoPie@
SettingsLdCommand = @SettingsLdCommand@
SettingsLdFlags = @SettingsLdFlags@
503 504
SettingsMergeObjectsCommand = @SettingsMergeObjectsCommand@
SettingsMergeObjectsFlags = @SettingsMergeObjectsFlags@
505 506 507 508 509 510 511 512 513 514
SettingsArCommand = @SettingsArCommand@
SettingsRanlibCommand = @SettingsRanlibCommand@
SettingsDllWrapCommand = @SettingsDllWrapCommand@
SettingsWindresCommand = @SettingsWindresCommand@
SettingsLibtoolCommand = @SettingsLibtoolCommand@
SettingsTouchCommand = @SettingsTouchCommand@
SettingsClangCommand = @SettingsClangCommand@
SettingsLlcCommand = @SettingsLlcCommand@
SettingsOptCommand = @SettingsOptCommand@

515 516 517
#-----------------------------------------------------------------------------
# C compiler
#
518 519
# NB. Don't override $(CC) using build.mk,  re-configure using
# the flag CC=<blah> instead.  The reason is that the configure script
520 521
# needs to know which gcc you're using in order to perform its tests.

522 523 524
# TargetPlatformFull retains the string passed to configure so we have it in
# the necessary format to pass to libffi's configure.
TargetPlatformFull    = @TargetPlatformFull@
525 526 527

# Do we have a C compiler using an LLVM back end?
CcLlvmBackend   = @CcLlvmBackend@
Simon Marlow's avatar
Simon Marlow committed
528

529
CC              = @CC@
530
CC_STAGE0       = @CC_STAGE0@
531 532 533
CC_STAGE1       = $(CC)
CC_STAGE2       = $(CC)
CC_STAGE3       = $(CC)
Simon Marlow's avatar
Simon Marlow committed
534

535
AS              = @CC@
536 537 538 539
AS_STAGE0       = @CC_STAGE0@
AS_STAGE1       = $(AS)
AS_STAGE2       = $(AS)
AS_STAGE3       = $(AS)
540

541
# why no LD=@LD@ ?
542
LD_STAGE0       = @LD_STAGE0@
Simon Marlow's avatar
Simon Marlow committed
543 544 545 546
LD_STAGE1       = $(LD)
LD_STAGE2       = $(LD)
LD_STAGE3       = $(LD)

547
# Cross-compiling options
548
# See Note [CrossCompiling vs Stage1Only]
549 550
CrossCompiling        = @CrossCompiling@

Simon Marlow's avatar
Simon Marlow committed
551 552
# Change this to YES if you're building a cross-compiler and don't
# want to build stage 2.
553 554
# See Note [CrossCompiling vs Stage1Only]
# See Note [Stage1Only vs stage=1]
Simon Marlow's avatar
Simon Marlow committed
555 556
Stage1Only = NO

557 558 559 560 561
# Installed tools prefix:
#    we add prefix to crosscompiler GHC only (ghc-stage1),
#    not cross-built GHC (not ghc-stage2).
CrossCompilePrefix    = $(if $(filter YES,$(Stage1Only)),@CrossCompilePrefix@,)

Simon Marlow's avatar
Simon Marlow committed
562 563 564
# Install stage 2 by default, or stage 1 in the cross compiler
# case. Can be changed to 3
INSTALL_GHC_STAGE= $(if $(filter YES,$(Stage1Only)),1,2)
565

566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
# Note [CrossCompiling vs Stage1Only]
#
# There are 4 possible settings:
#
# 1 CrossCompiling=NO Stage1Only=NO
#   The default.
#
# 2 CrossCompiling=NO Stage1Only=YES
#   Don't build ghc-stage2. See Note [Stage1Only vs stage=1].
#
# 3 CrossCompiling=YES Stage1Only=YES
#   Building a cross-compiler (ghc-stage1). See [1] and
#   Note [Stage1Only vs stage=1].
#
# 4 CrossCompiling=YES Stage1Only=NO
#   Cross-compiling GHC itself. See [1].
#
583
# [1] https://gitlab.haskell.org/ghc/ghc/wikis/building/cross-compiling
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615

# Note [Stage1Only vs stage=1]
#
# Stage1Only=YES means:
#   - don't build ghc-stage2 (the executable)
#   - don't build utils that rely on ghc-stage2
#     See Note [No stage2 packages when CrossCompiling or Stage1Only] in
#     ./ghc.mk.
#   - install ghc-stage1 instead of ghc-stage2
#   - install the ghc-pkg that was built with the stage0 compiler
#   - (*do* still build compiler/stage2 (i.e. the ghc library))
#   - (*do* still build all other libraries)
#
# stage=1 means:
#   - don't build compiler/stage2 (i.e. the ghc library)
#   - don't build ghc-stage2 (the executable)
#   Note: these are the only two things it does. If you want to exclude more
#   stuff, combine it with Stage1Only=YES, or run make in the ghc or compiler
#   directory.
#
# running make in the ghc or compiler directory means:
#   - don't build any packages in the libraries/ directory, except the ones
#     listed in PACKAGES_STAGE0 (i.e. the boot libraries)
#
# You may wonder why Stage1Only=YES still builds compiler/stage2. Quoting
# simonmar in #7639:
#
#     "strictly speaking building compiler/stage2 is correct, because it is
#     the ghc package that can be used with [ghc-stage1]. If you don't
#     want to build it, then setting stage=1 in your mk/build.mk should
#     disable it."

616
# C compiler and linker flags from configure (e.g. -m<blah> to select
617 618
# correct C compiler backend). The stage number is the stage of GHC
# that is being used to compile with.
619 620 621
CONF_CC_OPTS_STAGE0 = @CONF_CC_OPTS_STAGE0@
CONF_CC_OPTS_STAGE1 = @CONF_CC_OPTS_STAGE1@
CONF_CC_OPTS_STAGE2 = @CONF_CC_OPTS_STAGE2@
622 623 624 625 626 627
CONF_GCC_LINKER_OPTS_STAGE0 = @CONF_GCC_LINKER_OPTS_STAGE0@
CONF_GCC_LINKER_OPTS_STAGE1 = @CONF_GCC_LINKER_OPTS_STAGE1@
CONF_GCC_LINKER_OPTS_STAGE2 = @CONF_GCC_LINKER_OPTS_STAGE2@
CONF_LD_LINKER_OPTS_STAGE0 = @CONF_LD_LINKER_OPTS_STAGE0@
CONF_LD_LINKER_OPTS_STAGE1 = @CONF_LD_LINKER_OPTS_STAGE1@
CONF_LD_LINKER_OPTS_STAGE2 = @CONF_LD_LINKER_OPTS_STAGE2@
628 629 630
CONF_CPP_OPTS_STAGE0 = @CONF_CPP_OPTS_STAGE0@
CONF_CPP_OPTS_STAGE1 = @CONF_CPP_OPTS_STAGE1@
CONF_CPP_OPTS_STAGE2 = @CONF_CPP_OPTS_STAGE2@
631 632 633
CONF_HC_OPTS_STAGE0 = @CONF_HC_OPTS_STAGE0@
CONF_HC_OPTS_STAGE1 = @CONF_HC_OPTS_STAGE1@
CONF_HC_OPTS_STAGE2 = @CONF_HC_OPTS_STAGE2@
634

635 636 637
# The .hsc files aren't currently safe for cross-compilation on Windows:
#     libraries\haskeline\.\System\Console\Haskeline\Backend\Win32.hsc:160
#     directive "let" is not safe for cross-compilation
638
ifneq "$(Windows_Host)" "YES"
639
SRC_HSC2HS_OPTS += --cross-safe
640
endif
641
SRC_HSC2HS_OPTS += $(foreach d,$(GMP_INCLUDE_DIRS),-I$(d))
642 643 644 645 646

define set_stage_HSC2HS_OPTS
# $1 = stage
SRC_HSC2HS_OPTS_STAGE$1 += $$(addprefix --cflag=,$$(filter-out -O,$$(SRC_CC_OPTS) $$(CONF_CC_OPTS_STAGE$1)))
SRC_HSC2HS_OPTS_STAGE$1 += $$(addprefix --cflag=,$$(CONF_CPP_OPTS_STAGE$1))
647
SRC_HSC2HS_OPTS_STAGE$1 += $$(addprefix --lflag=,$$(CONF_GCC_LINKER_OPTS_STAGE$1))
648 649 650 651
endef
$(eval $(call set_stage_HSC2HS_OPTS,0))
$(eval $(call set_stage_HSC2HS_OPTS,1))
$(eval $(call set_stage_HSC2HS_OPTS,2))
652
ifeq "$(CrossCompiling)" "YES"
653 654 655
SRC_HSC2HS_OPTS_STAGE1 += --cross-compile
SRC_HSC2HS_OPTS_STAGE2 += --cross-compile
ifeq "$(Windows_Target)" "YES"
656 657 658 659
# We'll assume we compile with gcc or clang, and both support `-S` and can as such use the
# --via-asm pass, which should be faster and is required for cross compiling to windows, as
# the c compiler complains about non-constant expressions even though they are constant and
# end up as constants in the assembly.
660 661 662
SRC_HSC2HS_OPTS_STAGE1 += --via-asm
SRC_HSC2HS_OPTS_STAGE2 += --via-asm
endif
663
endif
664 665 666
SRC_HSC2HS_OPTS_STAGE0 += --cflag=-D$(HostArch_CPP)_HOST_ARCH --cflag=-D$(HostOS_CPP)_HOST_OS
SRC_HSC2HS_OPTS_STAGE1 += --cflag=-D$(TargetArch_CPP)_HOST_ARCH --cflag=-D$(TargetOS_CPP)_HOST_OS
SRC_HSC2HS_OPTS_STAGE2 += --cflag=-D$(TargetArch_CPP)_HOST_ARCH --cflag=-D$(TargetOS_CPP)_HOST_OS
Ian Lynagh's avatar
Ian Lynagh committed
667

Ian Lynagh's avatar
Ian Lynagh committed
668 669 670
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
WINDRES = $(INPLACE_MINGW)/bin/windres
else ifeq "$(TARGETPLATFORM)" "x86_64-unknown-mingw32"
671
WINDRES = $(INPLACE_MINGW)/bin/windres
Ian Lynagh's avatar
Ian Lynagh committed
672 673
endif

674
#-----------------------------------------------------------------------------
675
# Mingwex Library
676
#
677
HaveLibMingwEx	= @HaveLibMingwEx@
678
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
679
DLLTOOL			= inplace/mingw/bin/dlltool.exe
680
else ifeq "$(TARGETPLATFORM)" "x86_64-unknown-mingw32"
681
DLLTOOL			= inplace/mingw/bin/dlltool.exe
682
endif
683

684 685 686 687
#-----------------------------------------------------------------------------
# Other standard (ha!) Unix utilities

AR			= @ArCmd@
688
AR_OPTS			= @ArArgs@
689
ArSupportsAtFile = @ArSupportsAtFile@
690

691
AR_STAGE0 = @AR_STAGE0@
692 693 694
AR_STAGE1 = $(AR)
AR_STAGE2 = $(AR)
AR_STAGE3 = $(AR)
695
AR_OPTS_STAGE0 = @AR_OPTS_STAGE0@
696 697 698 699 700 701 702
AR_OPTS_STAGE1 = $(AR_OPTS)
AR_OPTS_STAGE2 = $(AR_OPTS)
AR_OPTS_STAGE3 = $(AR_OPTS)
EXTRA_AR_ARGS_STAGE0 = $(EXTRA_AR_ARGS)
EXTRA_AR_ARGS_STAGE1 = $(EXTRA_AR_ARGS)
EXTRA_AR_ARGS_STAGE2 = $(EXTRA_AR_ARGS)
EXTRA_AR_ARGS_STAGE3 = $(EXTRA_AR_ARGS)
703
ArSupportsAtFile_STAGE0 = @ArSupportsAtFile_STAGE0@
704 705 706
ArSupportsAtFile_STAGE1 = $(ArSupportsAtFile)
ArSupportsAtFile_STAGE2 = $(ArSupportsAtFile)
ArSupportsAtFile_STAGE3 = $(ArSupportsAtFile)
707

708 709
CONTEXT_DIFF		= @ContextDiffCmd@
CP			= cp
thomie's avatar
thomie committed
710

711 712
# It's not easy to separate the CPP program from its flags, as
# AC_PROG_CPP defines CPP as "/usr/bin/gcc -E"
sof's avatar
sof committed
713
CPP			= @CPP@ @CPPFLAGS@
thomie's avatar
thomie committed
714
HS_CPP			= @HaskellCPPCmd@ @HaskellCPPArgs@
715

rrt's avatar
rrt committed
716
FIND			= @FindCmd@
717

sof's avatar
sof committed
718 719 720 721
#
# Sigh - the autoconf macro for INSTALL will subst a relative path to the fallback
# install-sh script (if chosen). This not terribly useful to us, so we convert
# it into an abs. path.
722
#
723
INSTALL			= @INSTALL@
Ian Lynagh's avatar
Ian Lynagh committed
724
INSTALL			:= $(subst .././install-sh,$(TOP)/install-sh,$(INSTALL))
725

726 727 728
LN_S			= @LN_S@
MV			= mv
PIC			= pic
729 730
RANLIB_CMD = @RANLIB_CMD@
REAL_RANLIB_CMD = @REAL_RANLIB_CMD@
731
SED			= @SedCmd@
732
SHELL			= @SHELL@
733

734
HaveDtrace		= @HaveDtrace@
735
USE_DTRACE = $(HaveDtrace)
736 737
DTRACE			= @DtraceCmd@

738 739
LD = @LdCmd@
NM = @NmCmd@
740
AR = @ArCmd@
741
OBJDUMP = @ObjdumpCmd@
742

Moritz Angermann's avatar
Moritz Angermann committed
743
CLANG = @ClangCmd@
744 745 746
LLC = @LlcCmd@
OPT = @OptCmd@

747 748 749 750
# GNU ld supports input via a linker script, which is useful to avoid
# overflowing command-line length limits.
LdIsGNULd		= @LdIsGNULd@

751 752 753 754
# Set to YES if ld has the --build-id flag.  Sometimes we need to
# disable it with --build-id=none.
LdHasBuildId	        = @LdHasBuildId@

755
# Set to YES if ld has the --no_compact_unwind flag. See #5019
Sylvain Henry's avatar
Sylvain Henry committed
756
# and GHC.Driver.Pipeline.
757 758
LdHasNoCompactUnwind	= @LdHasNoCompactUnwind@

759
# On MSYS, building with SplitObjs=YES fails with
760 761
#   ar: Bad file number
# see #3201.  We need to specify a smaller max command-line size
762 763 764
# to work around it.  32767 doesn't work; 30000 does, but says
#     xargs: value for -s option should be < 28153
# so we now use 20000 to be comfortably below this bound
765
XARGS = xargs
766
ifeq "$(Windows_Host)" "YES"
767
XARGS_OPTS = -s 20000
768 769
endif

770
ifeq "$(TARGETPLATFORM)" "x86_64-unknown-mingw32"
771
STRIP_CMD      = $(TOP)/inplace/mingw/bin/strip.exe
772 773 774 775 776 777 778 779 780 781 782
else ifeq "$(TARGETPLATFORM)" "arm-unknown-linux"
# The Cortex A8 hardware apparently has a bug which ld.gold will check for;
# however in order to do so it must have unstripped executables lest we
# see warnings of the form (see #10376, #10464),
#
#     /usr/bin/ld.gold: warning: cannot scan executable section 1 of ... for
#     Cortex-A8 erratum because it has no mapping symbols.
#
# Consequently we disabling stripping by default on this architecture.
# The hack of using `:` to disable stripping is implemented by ghc-cabal.
STRIP_CMD      = :
783
else
784
STRIP_CMD      = @StripCmd@
785
endif
786 787
PATCH_CMD      = @PatchCmd@
TAR_CMD        = @TarCmd@
788 789 790
BZIP2_CMD      = @Bzip2Cmd@
GZIP_CMD       = @GzipCmd@
XZ_CMD         = @XzCmd@
791

Ben Gamari's avatar
Ben Gamari committed
792
# xz is default compression
793
TAR_COMP      ?= xz
794 795 796

# select compression command and .tar extension based on TAR_COMP value
ifeq "$(TAR_COMP)" "bzip2"
797
TAR_COMP_CMD  = $(BZIP2_CMD) $(TAR_COMP_OPTS)
798 799
TAR_COMP_EXT  = bz2
else ifeq "$(TAR_COMP)" "gzip"
800
TAR_COMP_CMD  = $(GZIP_CMD) $(TAR_COMP_OPTS)
801 802
TAR_COMP_EXT  = gz
else ifeq "$(TAR_COMP)" "xz"
803
TAR_COMP_CMD  = $(XZ_CMD) $(TAR_COMP_OPTS)
804 805 806 807
TAR_COMP_EXT  = xz
else
$(error $$(TAR_COMP) set to unknown value "$(TAR_COMP)" (supported: "bzip2", "gzip", "xz"))
endif
sof's avatar
sof committed
808

809
ifeq "$(Windows_Host)" "YES"
810 811 812 813 814 815 816
TOUCH_CMD      = $(utils/touchy_dist_INPLACE)
TOUCH_DEP      = $(TOUCH_CMD)
else
TOUCH_CMD      = touch
TOUCH_DEP      =
endif

817
HSCOLOUR_CMD   = @HSCOLOUR@
818

819
TIME_CMD       = @TimeCmd@
820

821
#-----------------------------------------------------------------------------
822 823 824 825 826 827 828 829
# Sphinx stuff

SPHINXBUILD              = @SPHINXBUILD@
BUILD_MAN                = @BUILD_MAN@
BUILD_SPHINX_HTML        = @BUILD_SPHINX_HTML@
BUILD_SPHINX_PDF         = @BUILD_SPHINX_PDF@
SPHINXOPTS               = -D latex_paper_size=letter
XELATEX                  = @XELATEX@
Ben Gamari's avatar
Ben Gamari committed
830
MAKEINDEX                = @MAKEINDEX@
831

832 833 834
#-----------------------------------------------------------------------------
# 		FPtools support software

835 836 837 838 839
#
# ghc-pkg
#
GHC_PKG		        = @GhcPkgCmd@

840 841 842 843
#
# Happy
#
HAPPY			= @HappyCmd@
844
HAPPY_VERSION		= @HappyVersion@
845 846 847
#
# Options to pass to Happy when we're going to compile the output with GHC
#
848
SRC_HAPPY_OPTS		= -agc --strict
849

850 851 852 853
#
# Alex
#
ALEX			= @AlexCmd@
854
ALEX_VERSION		= @AlexVersion@
855
#
856
# Options to pass to Alex when we're going to compile the output with GHC
857
#
858 859
SRC_ALEX_OPTS = -g
# The compiler isn't using the Unicode support in Alex 3.0 yet, in fact we do our own
860
# Unicode handling, so diable Alex's.
861
compiler_ALEX_OPTS = --latin1
862

863
# Should we build haddock docs?
Ian Lynagh's avatar
Ian Lynagh committed
864
HADDOCK_DOCS = YES
865
# And HsColour the sources?
866
ifeq "$(HSCOLOUR_CMD)" ""
867 868 869 870 871
HSCOLOUR_SRCS = NO
else
HSCOLOUR_SRCS = YES
endif

872
# Build and install the "extra" packages (see ./packages)?
873
BUILD_EXTRA_PKGS = NO
874

875
################################################################################
876 877 878 879 880 881 882 883
#
#    To be passed to sub-builds
#
################################################################################

ICONV_INCLUDE_DIRS = @ICONV_INCLUDE_DIRS@
ICONV_LIB_DIRS = @ICONV_LIB_DIRS@

884 885
GMP_INCLUDE_DIRS = @GMP_INCLUDE_DIRS@
GMP_LIB_DIRS = @GMP_LIB_DIRS@
886 887
GMP_PREFER_FRAMEWORK = @GMP_PREFER_FRAMEWORK@
GMP_FORCE_INTREE = @GMP_FORCE_INTREE@
888 889

CURSES_LIB_DIRS = @CURSES_LIB_DIRS@
890

891
# See Note [Disable -O2 in unregisterised mode]
892 893 894 895 896 897 898 899 900
# Be careful: 'GhcUnregisterised' should be defined earlier in this file.
ifeq "$(GhcUnregisterised)" "YES"
GhcStage1HcOpts=
GhcStage2HcOpts=
GhcStage3HcOpts=

GhcLibHcOpts=
endif

901 902
# Note [Disable -O2 in unregisterised mode]
# Disable -O2 optimization in unregisterised mode. Otherwise amount
903
# of generated C code # makes things very slow to compile (~5 minutes
904 905 906
# on core-i7 for 'compiler/GHC/Hs/Expr.hs') and sometimes not compile
# at all: powerpc64 overflows TOC section on 'compiler/GHC/Hs/Expr.hs'
#         ia64 overflows short data section on 'compiler/GHC/Driver/Session.hs'