Makefile 11.7 KB
Newer Older
1 2
# -----------------------------------------------------------------------------

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

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

#-----------------------------------------------------------------------------
11
#		Set SUBDIRS
12 13 14 15 16

ifeq ($(IncludeTestDirsInBuild),YES)
  SUBDIRS = tests
endif

17 18 19 20 21 22
# -----------------------------------------------------------------------------
#		Set HS_PROG, LIBRARY
# Setting HS_PROG and LIBRARY causes all targets in target.mk
# (included below) to kick in.

LIBRARY=libhsp.a
sof's avatar
sof committed
23 24 25 26 27 28 29 30

#
# Note: there have been reports of people running up against the ARG_MAX limit
# when linking hsc with all its constituent object files. The likely source of 
# the problem is that the environment is a bit too big, so a workaround could
# be to do ` env PATH=$(PATH) make hsc 'to minimise the environment. (or the
# equivalent of `env' if it doesn't exist locally).
#
31 32 33
HS_PROG=hsc


34 35 36 37 38 39 40
# -----------------------------------------------------------------------------
#		Compilation history for Patrick

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


41 42 43 44 45 46
# -----------------------------------------------------------------------------
# 		Set SRCS, LOOPS, HCS, OBJS
#
# First figure out DIRS, the source sub-directories
# Then derive SRCS by looking in them
#
47 48 49 50 51 52 53 54

DIRS = \
  utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
  specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
  reader profiling parser


ifeq ($(GhcWithNativeCodeGen),YES)
sof's avatar
sof committed
55
DIRS += nativeGen
56 57
else
SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
58 59 60
endif


61 62
HS_SRCS = $(SRCS_UGNHS) \
          $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
63
	  rename/ParseIface.hs
sof's avatar
sof committed
64 65 66 67

ifneq "$(Ghc2_0)" "YES"
HS_SRCS += main/LoopHack.hc 
endif
68

69 70
# NB: it's no good to include *.hs in the top-line wildcard, because the .hs files
#     in parser/ may not have been created at that point.
71 72


sof's avatar
sof committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86
HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))

#
# When booting using a ghc-2.xx compiler, the loop breakers are actually written in
# Haskell, source stubs just re-exporting info from the various .hi-boot files.
# (Reason: we don't want to fiddle with the imports in the sources). We give them
# the suffix .hs, since they're special and don't fall under the umbrella of $(HS_SRCS)
# always (only when $(Ghc2_0) is equal to YES)
ifeq "$(Ghc2_0)" "YES"
MKDEPENDHS_SRCS = $(HS_SRCS)
else
LOOPS   = $(patsubst %.lhi, %.hi, $(wildcard */*.lhi))
endif
 
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
HS_OBJS  = \
  $(patsubst %.hc, %.o, $(HCS)) \
  parser/hsclink.o parser/hschooks.o libhsp.a


DESTDIR         = $(INSTALL_LIBRARY_DIR_GHC)

SRCS_UGN      = $(wildcard parser/*.ugn)
SRCS_UGNC     = $(patsubst %.ugn, %.c, $(SRCS_UGN))
SRCS_UGNH     = $(patsubst %.ugn, %.h, $(SRCS_UGN))
SRCS_UGNHS    = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))

#
# Add the generated C files to the C_SRCS, so as to let `depend'
# generate correct dependencies for them.
#
C_SRCS += $(SRCS_UGNC)

LIBOBJS = \
  $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
  parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
  parser/util.o
110

111 112 113
#
# stuff you get for free in a source distribution
# 
114
SRC_DIST_FILES += rename/ParseIface.hs \
115 116 117
 parser/U_tree.c parser/tree.h parser/tree.c \
 parser/hsparser.tab.c parser/hsparser.tab.h \
 parser/hslexer.c
118 119

# -----------------------------------------------------------------------------
120
# 		Haskell compilations
121

122 123 124
# Compiler to use for building hsc
#
HC=$(WithGhcHc)
125

sof's avatar
sof committed
126 127 128 129 130
# magic from GNU make manual to convert a list of values
# into a colon-separated list
empty:=
space:= $(empty) $(empty)

131
SRC_HC_OPTS += \
sof's avatar
sof committed
132 133 134 135 136 137 138
  -cpp -fglasgow-exts -Rghc-timing \
  -I. -IcodeGen -InativeGen -Iparser \
  -i$(subst $(space),:,$(DIRS))

ifeq "$(Ghc2_0)" "NO"
SRC_HC_OPTS += -fhaskell-1.3
endif
139

sof's avatar
sof committed
140
# -syslib ghc just needed for use of PackedString.hPutPS
141

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

sof's avatar
sof committed
144 145
ifeq "$(Ghc2_0)" "NO"
SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
sof's avatar
sof committed
146 147
else
SRC_HC_OPTS += -recomp
148 149
endif

150 151 152 153 154 155 156
SRC_HC_OPTS += $(GhcHcOpts)

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

absCSyn/AbsCSyn_HC_OPTS 	= -fno-omit-reexported-instances
sof's avatar
sof committed
157
absCSyn/CStrings_HC_OPTS 	= -monly-3-regs
158 159 160 161

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

162 163 164 165
basicTypes/IdInfo_HC_OPTS 	= -K2m
coreSyn/AnnCoreSyn_HC_OPTS 	= -fno-omit-reexported-instances
hsSyn/HsExpr_HC_OPTS 		= -K2m
hsSyn/HsSyn_HC_OPTS 		= -fno-omit-reexported-instances
sof's avatar
sof committed
166
main/Main_HC_OPTS 		= -fvia-C -DPROJECTVERSION=$(GhcProjectVersion)
167 168
main/CmdLineOpts_HC_OPTS 	= -fvia-C
nativeGen/PprMach_HC_OPTS 	= -K2m
169
nativeGen/MachMisc_HC_OPTS 	= -K2m -fvia-C
170
nativeGen/MachCode_HC_OPTS 	= -H10m
171 172 173 174 175 176 177 178 179 180 181
parser/UgenAll_HC_OPTS 		= -fvia-C '-\#include"hspincl.h"'
parser/UgenUtil_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
parser/U_constr_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
parser/U_binding_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
parser/U_pbinding_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
parser/U_entidt_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
parser/U_list_HC_OPTS 		= -fvia-C '-\#include"hspincl.h"'
parser/U_literal_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
parser/U_maybe_HC_OPTS 		= -fvia-C '-\#include"hspincl.h"'
parser/U_either_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
parser/U_qid_HC_OPTS 		= -fvia-C '-\#include"hspincl.h"'
182
parser/U_tree_HC_OPTS 		= -H12m -fvia-C '-\#include"hspincl.h"'
183
parser/U_ttype_HC_OPTS 		= -fvia-C '-\#include"hspincl.h"'
184
prelude/PrimOp_HC_OPTS 		= -H12m -K3m
sof's avatar
sof committed
185
reader/Lex_HC_OPTS		= -K2m -H16m -fvia-C
186 187 188 189 190

# Heap was 6m with 2.10
reader/ReadPrefix_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"' -H10m

rename/ParseIface_HC_OPTS 	+= -Onot -H30m
sof's avatar
sof committed
191
ifeq "$(Ghc2_0)" "YES"
192
rename/ParseIface_HC_OPTS       += -fno-warn-incomplete-patterns
sof's avatar
sof committed
193 194
endif

195 196 197
ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
rename/RnMonad_HC_OPTS 		= -fvia-C -O2 -O2-for-C
else
sof's avatar
sof committed
198
ifeq "$(Ghc2_0)" "NO"
199
rename/RnMonad_HC_OPTS 		= -fvia-C
200
endif
sof's avatar
sof committed
201
endif
202 203 204
rename/RnEnv_HC_OPTS 		= -fvia-C
rename/RnSource_HC_OPTS		= -H12m
rename/RnIfaces_HC_OPTS		= -H8m -fvia-C
205
rename/RnExpr_HC_OPTS		= -H10m
206
rename/RnNames_HC_OPTS		= -H12m
sof's avatar
sof committed
207
rename/RnMonad_HC_OPTS		= -fvia-C
sof's avatar
sof committed
208
# Urk!  Really big heap for ParseUnfolding
sof's avatar
sof committed
209
#rename/ParseUnfolding_HC_OPTS	= -H45m		
210 211 212
specialise/Specialise_HC_OPTS 	= -Onot -H12m
stgSyn/StgSyn_HC_OPTS 		= -fno-omit-reexported-instances
typecheck/TcGenDeriv_HC_OPTS	= -H10m
213 214 215 216 217 218 219

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

# Was 10m for 2.10
typecheck/TcExpr_HC_OPTS	= -H15m

sof's avatar
sof committed
220
typecheck/TcEnv_HC_OPTS		= -H10m
sof's avatar
sof committed
221 222 223
ifeq "$(Ghc2_0)" "NO"
typecheck/TcMonad_HC_OPTS	= -fvia-C	
endif
sof's avatar
sof committed
224
utils/Argv_HC_OPTS 		= -fvia-C -monly-3-regs
225 226
utils/SST_HC_OPTS 		= -fvia-C
utils/PrimPacked_HC_OPTS	= -fvia-C -monly-3-regs
sof's avatar
sof committed
227
utils/FastString_HC_OPTS	= -fvia-C -monly-3-regs
228
utils/StringBuffer_HC_OPTS	= -fvia-C
sof's avatar
sof committed
229
utils/Digraph_HC_OPTS		= -fglasgow-exts -fvia-C
sof's avatar
sof committed
230
utils/Outputable_HC_OPTS	= -monly-3-regs
231

232 233 234 235 236
# optimiser misbehaving in 0.29, occurrence analyser fails to terminate when
# compiling lib/required/Time.lhs
ifeq "$(Ghc2_0)" "NO"
simplCore/OccurAnal_HC_OPTS	= -Onot
endif
237

238 239 240 241 242
# 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

243 244 245 246 247
# ----------------------------------------------------------------------------
#		C compilations

SRC_C_OPTS     += -O -Iparser -I. -IcodeGen

248 249

# ----------------------------------------------------------------------------
250
#		Parsers
251

252 253
# Main parser uses Yacc/Bison
SRC_YACC_OPTS  += -d -v
254

255 256 257
#
# Want to keep the intermediate (included in src distribs).
#
sof's avatar
sof committed
258
.PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
259 260 261 262 263

parser/hschooks.o : parser/hschooks.c
	@$(RM) $@
	$(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c

264 265 266 267

# Interface-file parser uses Happy
SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS

sof's avatar
sof committed
268 269 270 271
ifeq ($(Ghc2_0),NO)
SRC_HAPPY_OPTS+= -1.2
endif

272 273
rename/ParseIface.hs : rename/ParseIface.y
	@$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
274
	$(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
275 276
	@chmod 444 rename/ParseIface.hs

277 278 279 280 281 282 283 284 285
#----------------------------------------------------------------------
#
# Building the stand-alone parser
#
all :: hsp

hsp: parser/printtree.o parser/main.o libhsp.a 
	$(CC) -o $@ $(CC_OPTS) $^

286
CLEAN_FILES += hsp
287 288 289 290 291 292 293
#-----------------------------------------------------------------------------
# 		Interface files

# LoopHack.lhc is an SLPJ addition to fix a profiling problem.  See comments
# inside it. (compilation is handled by the suffix rules).

#
sof's avatar
sof committed
294
# Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
295
#
sof's avatar
sof committed
296
ifeq "$(Ghc2_0)" "NO"
sof's avatar
sof committed
297 298
hi-boot :: $(LOOPS)

sof's avatar
sof committed
299
%.hi : %.lhi
300 301 302 303
	$(RM) $@
	$(UNLIT) $<  $@ || ( $(RM) $@ && exit 1 )
	@chmod 444 $@

sof's avatar
sof committed
304
boot :: hi-boot
sof's avatar
sof committed
305 306 307 308 309 310
else
# hi-boot not needed when using 2.04+ as HC, defining it here
# to be consistent across setting of Ghc2_0
hi-boot :
	@echo "Done."
endif
sof's avatar
sof committed
311

312 313 314 315 316 317 318 319 320 321 322 323 324
#-----------------------------------------------------------------------------
# 		Linking

SRC_LD_OPTS += -no-link-chk

#-----------------------------------------------------------------------------
# 		install

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

INSTALL_LIBEXECS += hsc hsp
325 326

#-----------------------------------------------------------------------------
327 328 329 330 331 332 333 334 335 336
# 		depend

# If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
#
# ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
# in a build.mk file.
#
ifeq ($(Ghc2_0),NO)
MKDEPENDHS      = $(MKDEPENDHS_1_2)
endif
337

338 339 340
#
# Before doing `make depend', need to build all derived Haskell source files
#
341
depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs
342

343

sof's avatar
sof committed
344
ifeq "$(GhcWithHscBuiltViaC)" "YES"
sof's avatar
sof committed
345 346 347 348 349
ifeq "$(Ghc2_0)" "NO"
SRC_MKDEPENDHS_OPTS += -o hc
else
SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
endif
sof's avatar
sof committed
350 351 352 353
# When booting from .hc, (hackily) remove the suffix rule for 
# .l?hs -> .o, so that the .hc -> .o is used instead.
%.$(way_)o : %.lhs
%.$(way_)o : %.hs
354
else
355
  SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
356 357 358
endif


359 360 361 362 363 364 365 366 367 368 369 370 371
#-----------------------------------------------------------------------------
# 		clean

CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
               $(SRCS_UGNC) $(SRCS_UGNH) \
               $(SRCS_UGNHS)\
	       parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c

# Extra tidy, remove the .hc files (if you've got them).
MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)


#-----------------------------------------------------------------------------
sof's avatar
sof committed
372
# 		TAGS setup
373 374

SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
sof's avatar
sof committed
375 376
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)))
377 378 379 380 381 382

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

include $(TOP)/mk/target.mk

sof's avatar
sof committed
383

384 385 386
#
# Special extra dependencies for yukky ugen stuff
#
387

388 389
parser/%.o : parser/%.c $(SRCS_UGNH)
parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
390

391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
parser/hspincl.h : $(SRCS_UGNH)
parser/UgenAll.o : parser/hspincl.h
parser/UgenUtil.o : parser/hspincl.h
parser/U_constr.o : parser/hspincl.h
parser/U_binding.o : parser/hspincl.h
parser/U_pbinding.o : parser/hspincl.h
parser/U_entidt.o : parser/hspincl.h
parser/U_list.o : parser/hspincl.h
parser/U_literal.o : parser/hspincl.h
parser/U_maybe.o : parser/hspincl.h
parser/U_either.o : parser/hspincl.h
parser/U_qid.o : parser/hspincl.h
parser/U_tree.o : parser/hspincl.h
parser/U_ttype.o : parser/hspincl.h
parser/printtree.o : parser/hspincl.h
reader/ReadPrefix.o : parser/hspincl.h