Makefile 11.5 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)
sof's avatar
sof committed
8
override 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
34
35
36
37
38
39
HS_PROG=hsc


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

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


ifeq ($(GhcWithDeforester),YES)
  DIRS += deforest
endif

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


58
59
HS_SRCS = $(SRCS_UGNHS) \
          $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
sof's avatar
sof committed
60
61
62
63
64
	  rename/ParseIface.hs rename/ParseType.hs rename/ParseUnfolding.hs

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

66
67
# 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.
68
69


sof's avatar
sof committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
 
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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
107

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

# -----------------------------------------------------------------------------
118
# 		Haskell compilations
119

120
121
122
# Compiler to use for building hsc
#
HC=$(WithGhcHc)
123

124
SRC_HC_OPTS += \
sof's avatar
sof committed
125
  -cpp -fhaskell-1.3 \
126
  -fglasgow-exts -DCOMPILING_GHC -Rghc-timing -I. -IcodeGen \
127
  -InativeGen -Iparser $(foreach dir,$(DIRS),-i$(dir))
128

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

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

sof's avatar
sof committed
133
134
ifeq "$(Ghc2_0)" "NO"
SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
sof's avatar
sof committed
135
136
else
SRC_HC_OPTS += -recomp
137
138
139
endif

ifeq ($(GhcWithDeforester),NO)
sof's avatar
sof committed
140
 ifeq "$(Ghc2_0)" "NO"
sof's avatar
sof committed
141
  SRC_MKDEPENDHS_OPTS += -DOMIT_DEFORESTER
sof's avatar
sof committed
142
 endif
sof's avatar
sof committed
143
SRC_HC_OPTS += -DOMIT_DEFORESTER
144
145
146
147
148
149
150
151
152
153
154
155
156
endif

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
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
157
main/Main_HC_OPTS 		= -fvia-C -DPROJECTVERSION=$(GhcProjectVersion)
158
159
main/CmdLineOpts_HC_OPTS 	= -fvia-C
nativeGen/PprMach_HC_OPTS 	= -K2m
160
nativeGen/MachMisc_HC_OPTS 	= -K2m -fvia-C
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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"'
parser/U_tree_HC_OPTS 		= -fvia-C '-\#include"hspincl.h"'
parser/U_ttype_HC_OPTS 		= -fvia-C '-\#include"hspincl.h"'
prelude/PrimOp_HC_OPTS 		= -K3m
sof's avatar
sof committed
175
176
177
178
reader/Lex_HC_OPTS		= -K2m -H16m -fvia-C
ifeq "$(Ghc2_0)" "NO"
reader/Lex_HC_OPTS		+= -fomit-derived-read
endif
179
reader/ReadPrefix_HC_OPTS 	= -fvia-C '-\#include"hspincl.h"'
sof's avatar
sof committed
180
181
182
rename/ParseIface_HC_OPTS 	+= -Onot -H16m
rename/ParseType_HC_OPTS 	+= -Onot -H16m
rename/ParseUnfolding_HC_OPTS 	+= -Onot -H16m
sof's avatar
sof committed
183
184
185
186
187
188
ifeq "$(Ghc2_0)" "YES"
rename/ParseIface_HC_OPTS       += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
rename/ParseType_HC_OPTS        += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
rename/ParseUnfolding_HC_OPTS   += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
endif

189
190
191
ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
rename/RnMonad_HC_OPTS 		= -fvia-C -O2 -O2-for-C
else
sof's avatar
sof committed
192
ifeq "$(Ghc2_0)" "NO"
193
rename/RnMonad_HC_OPTS 		= -fvia-C
194
endif
sof's avatar
sof committed
195
endif
196
197
198
199
rename/RnEnv_HC_OPTS 		= -fvia-C
rename/RnSource_HC_OPTS		= -H12m
rename/RnIfaces_HC_OPTS		= -H8m -fvia-C
rename/RnNames_HC_OPTS		= -H12m
sof's avatar
sof committed
200
rename/RnMonad_HC_OPTS		= -fvia-C
sof's avatar
sof committed
201
# Urk!  Really big heap for ParseUnfolding
sof's avatar
sof committed
202
#rename/ParseUnfolding_HC_OPTS	= -H45m		
203
204
205
206
specialise/Specialise_HC_OPTS 	= -Onot -H12m
stgSyn/StgSyn_HC_OPTS 		= -fno-omit-reexported-instances
typecheck/TcGenDeriv_HC_OPTS	= -H10m
typecheck/TcExpr_HC_OPTS	= -H10m
sof's avatar
sof committed
207
typecheck/TcEnv_HC_OPTS		= -H10m
sof's avatar
sof committed
208
209
210
ifeq "$(Ghc2_0)" "NO"
typecheck/TcMonad_HC_OPTS	= -fvia-C	
endif
211
212
213
214
215
utils/Argv_HC_OPTS 		= -fvia-C
utils/SST_HC_OPTS 		= -fvia-C
utils/PrimPacked_HC_OPTS	= -fvia-C -monly-3-regs
utils/FastString_HC_OPTS	= -fvia-C
utils/StringBuffer_HC_OPTS	= -fvia-C
sof's avatar
sof committed
216
utils/Digraph_HC_OPTS		= -fglasgow-exts -fvia-C
217
218
219
220
221
222
223


# ----------------------------------------------------------------------------
#		C compilations

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

224
225

# ----------------------------------------------------------------------------
226
#		Parsers
227

228
229
# Main parser uses Yacc/Bison
SRC_YACC_OPTS  += -d -v
230

231
232
233
#
# Want to keep the intermediate (included in src distribs).
#
sof's avatar
sof committed
234
.PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
235
236
237
238
239

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

240
241
242
243

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

244
245
rename/ParseIface.hs : rename/ParseIface.y
	@$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
246
	$(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
247
248
	@chmod 444 rename/ParseIface.hs

249
250
251
252
rename/ParseType.hs : rename/ParseType.y
	@$(RM) rename/ParseType.hs rename/ParseType.hinfo
	$(HAPPY) $(HAPPY_OPTS) -g rename/ParseType.y
	@chmod 444 rename/ParseType.hs
dnt's avatar
dnt committed
253

254
255
256
257
rename/ParseUnfolding.hs : rename/ParseUnfolding.y
	@$(RM) rename/ParseUnfolding.hs rename/ParseUnfolding.hinfo
	$(HAPPY) $(HAPPY_OPTS) -g rename/ParseUnfolding.y
	@chmod 444 rename/ParseUnfolding.hs
dnt's avatar
dnt committed
258

259
260
261
262
263
264
265
266
267
#----------------------------------------------------------------------
#
# Building the stand-alone parser
#
all :: hsp

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

268
CLEAN_FILES += hsp
269
270
271
272
273
274
275
#-----------------------------------------------------------------------------
# 		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
276
# Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
277
#
sof's avatar
sof committed
278
ifeq "$(Ghc2_0)" "NO"
sof's avatar
sof committed
279
280
hi-boot :: $(LOOPS)

sof's avatar
sof committed
281
%.hi : %.lhi
282
283
284
285
	$(RM) $@
	$(UNLIT) $<  $@ || ( $(RM) $@ && exit 1 )
	@chmod 444 $@

sof's avatar
sof committed
286
boot :: hi-boot
sof's avatar
sof committed
287
288
289
290
291
292
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
293

294
295
296
297
298
299
300
301
302
303
304
305
306
#-----------------------------------------------------------------------------
# 		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
307
308

#-----------------------------------------------------------------------------
309
310
311
312
313
314
315
316
317
318
# 		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
319

320
321
322
323
#
# Before doing `make depend', need to build all derived Haskell source files
#
depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs rename/ParseUnfolding.hs rename/ParseType.hs
324

325

sof's avatar
sof committed
326
ifeq "$(GhcWithHscBuiltViaC)" "YES"
sof's avatar
sof committed
327
328
329
330
331
ifeq "$(Ghc2_0)" "NO"
SRC_MKDEPENDHS_OPTS += -o hc
else
SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
endif
sof's avatar
sof committed
332
333
334
335
# 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
336
else
337
  SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
338
339
340
endif


341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#-----------------------------------------------------------------------------
# 		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)


#-----------------------------------------------------------------------------
# 		TAGS

SRC_HSTAGS_OPTS += -fglasgow-exts -cpp


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

include $(TOP)/mk/target.mk

sof's avatar
sof committed
364

365
366
367
#
# Special extra dependencies for yukky ugen stuff
#
368

369
370
parser/%.o : parser/%.c $(SRCS_UGNH)
parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
371

372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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