1 # -----------------------------------------------------------------------------
4 include $(TOP)/mk/boilerplate.mk
6 #-----------------------------------------------------------------------------
7 # Building hsc different ways (default is just `normal' sequential)
8 WAYS=$(GhcCompilerWays)
10 #-----------------------------------------------------------------------------
13 ifeq ($(IncludeTestDirsInBuild),YES)
17 # -----------------------------------------------------------------------------
18 # Set HS_PROG, LIBRARY
19 # Setting HS_PROG and LIBRARY causes all targets in target.mk
20 # (included below) to kick in.
25 # Note: there have been reports of people running up against the ARG_MAX limit
26 # when linking hsc with all its constituent object files. The likely source of
27 # the problem is that the environment is a bit too big, so a workaround could
28 # be to do ` env PATH=$(PATH) make hsc 'to minimise the environment. (or the
29 # equivalent of `env' if it doesn't exist locally).
34 # -----------------------------------------------------------------------------
35 # Set SRCS, LOOPS, HCS, OBJS
37 # First figure out DIRS, the source sub-directories
38 # Then derive SRCS by looking in them
42 utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
43 specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
44 reader profiling parser
47 ifeq ($(GhcWithNativeCodeGen),YES)
50 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
54 HS_SRCS = $(SRCS_UGNHS) \
55 $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
56 rename/ParseIface.hs rename/ParseType.hs rename/ParseUnfolding.hs
58 ifneq "$(Ghc2_0)" "YES"
59 HS_SRCS += main/LoopHack.hc
62 # NB: it's no good to include *.hs in the top-line wildcard, because the .hs files
63 # in parser/ may not have been created at that point.
66 HCS = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
69 # When booting using a ghc-2.xx compiler, the loop breakers are actually written in
70 # Haskell, source stubs just re-exporting info from the various .hi-boot files.
71 # (Reason: we don't want to fiddle with the imports in the sources). We give them
72 # the suffix .hs, since they're special and don't fall under the umbrella of $(HS_SRCS)
73 # always (only when $(Ghc2_0) is equal to YES)
74 ifeq "$(Ghc2_0)" "YES"
75 MKDEPENDHS_SRCS = $(HS_SRCS)
77 LOOPS = $(patsubst %.lhi, %.hi, $(wildcard */*.lhi))
81 $(patsubst %.hc, %.o, $(HCS)) \
82 parser/hsclink.o parser/hschooks.o libhsp.a
85 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
87 SRCS_UGN = $(wildcard parser/*.ugn)
88 SRCS_UGNC = $(patsubst %.ugn, %.c, $(SRCS_UGN))
89 SRCS_UGNH = $(patsubst %.ugn, %.h, $(SRCS_UGN))
90 SRCS_UGNHS = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
91 SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))
94 # Add the generated C files to the C_SRCS, so as to let `depend'
95 # generate correct dependencies for them.
97 C_SRCS += $(SRCS_UGNC)
100 $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
101 parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
105 # stuff you get for free in a source distribution
108 parser/U_tree.c parser/tree.h parser/tree.c \
109 parser/hsparser.tab.c parser/hsparser.tab.h \
112 # -----------------------------------------------------------------------------
113 # Haskell compilations
115 # Compiler to use for building hsc
119 # magic from GNU make manual to convert a list of values
120 # into a colon-separated list
122 space:= $(empty) $(empty)
125 -cpp -fglasgow-exts -Rghc-timing \
126 -I. -IcodeGen -InativeGen -Iparser \
127 -i$(subst $(space),:,$(DIRS))
129 ifeq "$(Ghc2_0)" "NO"
130 SRC_HC_OPTS += -fhaskell-1.3
133 # -syslib ghc just needed for use of PackedString.hPutPS
135 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
137 ifeq "$(Ghc2_0)" "NO"
138 SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
140 SRC_HC_OPTS += -recomp
143 SRC_HC_OPTS += $(GhcHcOpts)
145 # Special flags for particular modules
146 # The standard suffix rule for compiling a Haskell file
147 # adds these flags to the command line
149 absCSyn/AbsCSyn_HC_OPTS = -fno-omit-reexported-instances
150 absCSyn/CStrings_HC_OPTS = -monly-3-regs
151 basicTypes/IdInfo_HC_OPTS = -K2m
152 coreSyn/AnnCoreSyn_HC_OPTS = -fno-omit-reexported-instances
153 hsSyn/HsExpr_HC_OPTS = -K2m
154 hsSyn/HsSyn_HC_OPTS = -fno-omit-reexported-instances
155 main/Main_HC_OPTS = -fvia-C -DPROJECTVERSION=$(GhcProjectVersion)
156 main/CmdLineOpts_HC_OPTS = -fvia-C
157 nativeGen/PprMach_HC_OPTS = -K2m
158 nativeGen/MachMisc_HC_OPTS = -K2m -fvia-C
159 nativeGen/MachCode_HC_OPTS = -H10m
160 parser/UgenAll_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
161 parser/UgenUtil_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
162 parser/U_constr_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
163 parser/U_binding_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
164 parser/U_pbinding_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
165 parser/U_entidt_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
166 parser/U_list_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
167 parser/U_literal_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
168 parser/U_maybe_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
169 parser/U_either_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
170 parser/U_qid_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
171 parser/U_tree_HC_OPTS = -H12m -fvia-C '-\#include"hspincl.h"'
172 parser/U_ttype_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
173 prelude/PrimOp_HC_OPTS = -H12m -K3m
174 reader/Lex_HC_OPTS = -K2m -H16m -fvia-C
175 reader/ReadPrefix_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
176 rename/ParseIface_HC_OPTS += -Onot -H16m
177 rename/ParseType_HC_OPTS += -Onot -H16m
178 rename/ParseUnfolding_HC_OPTS += -Onot -H30m
179 ifeq "$(Ghc2_0)" "YES"
180 rename/ParseIface_HC_OPTS += -fno-warn-incomplete-patterns
181 rename/ParseType_HC_OPTS += -fno-warn-incomplete-patterns
182 rename/ParseUnfolding_HC_OPTS += -fno-warn-incomplete-patterns
185 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
186 rename/RnMonad_HC_OPTS = -fvia-C -O2 -O2-for-C
188 ifeq "$(Ghc2_0)" "NO"
189 rename/RnMonad_HC_OPTS = -fvia-C
192 rename/RnEnv_HC_OPTS = -fvia-C
193 rename/RnSource_HC_OPTS = -H12m
194 rename/RnIfaces_HC_OPTS = -H8m -fvia-C
195 rename/RnNames_HC_OPTS = -H12m
196 rename/RnMonad_HC_OPTS = -fvia-C
197 # Urk! Really big heap for ParseUnfolding
198 #rename/ParseUnfolding_HC_OPTS = -H45m
199 specialise/Specialise_HC_OPTS = -Onot -H12m
200 stgSyn/StgSyn_HC_OPTS = -fno-omit-reexported-instances
201 typecheck/TcGenDeriv_HC_OPTS = -H10m
202 typecheck/TcHsSyn_HC_OPTS = -H10m
203 typecheck/TcExpr_HC_OPTS = -H10m
204 typecheck/TcEnv_HC_OPTS = -H10m
205 ifeq "$(Ghc2_0)" "NO"
206 typecheck/TcMonad_HC_OPTS = -fvia-C
208 utils/Argv_HC_OPTS = -fvia-C -monly-3-regs
209 utils/SST_HC_OPTS = -fvia-C
210 utils/PrimPacked_HC_OPTS = -fvia-C -monly-3-regs
211 utils/FastString_HC_OPTS = -fvia-C -monly-3-regs
212 utils/StringBuffer_HC_OPTS = -fvia-C
213 utils/Digraph_HC_OPTS = -fglasgow-exts -fvia-C
214 utils/Outputable_HC_OPTS = -monly-3-regs
216 # optimiser misbehaving in 0.29, occurrence analyser fails to terminate when
217 # compiling lib/required/Time.lhs
218 ifeq "$(Ghc2_0)" "NO"
219 simplCore/OccurAnal_HC_OPTS = -Onot
222 # ----------------------------------------------------------------------------
225 SRC_C_OPTS += -O -Iparser -I. -IcodeGen
228 # ----------------------------------------------------------------------------
231 # Main parser uses Yacc/Bison
232 SRC_YACC_OPTS += -d -v
235 # Want to keep the intermediate (included in src distribs).
237 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
239 parser/hschooks.o : parser/hschooks.c
241 $(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c
244 # Interface-file parser uses Happy
245 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
248 SRC_HAPPY_OPTS+= -1.2
251 rename/ParseIface.hs : rename/ParseIface.y
252 @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
253 $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
254 @chmod 444 rename/ParseIface.hs
256 rename/ParseType.hs : rename/ParseType.y
257 @$(RM) rename/ParseType.hs rename/ParseType.hinfo
258 $(HAPPY) $(HAPPY_OPTS) -g rename/ParseType.y
259 @chmod 444 rename/ParseType.hs
261 rename/ParseUnfolding.hs : rename/ParseUnfolding.y
262 @$(RM) rename/ParseUnfolding.hs rename/ParseUnfolding.hinfo
263 $(HAPPY) $(HAPPY_OPTS) -g rename/ParseUnfolding.y
264 @chmod 444 rename/ParseUnfolding.hs
266 #----------------------------------------------------------------------
268 # Building the stand-alone parser
272 hsp: parser/printtree.o parser/main.o libhsp.a
273 $(CC) -o $@ $(CC_OPTS) $^
276 #-----------------------------------------------------------------------------
279 # LoopHack.lhc is an SLPJ addition to fix a profiling problem. See comments
280 # inside it. (compilation is handled by the suffix rules).
283 # Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
285 ifeq "$(Ghc2_0)" "NO"
290 $(UNLIT) $< $@ || ( $(RM) $@ && exit 1 )
295 # hi-boot not needed when using 2.04+ as HC, defining it here
296 # to be consistent across setting of Ghc2_0
301 #-----------------------------------------------------------------------------
304 SRC_LD_OPTS += -no-link-chk
306 #-----------------------------------------------------------------------------
309 # We don't want hsc treated as an ordinary executable,
310 # but put it together with the libraries.
311 # Also don't want any interface files intstalled
313 INSTALL_LIBEXECS += hsc hsp
315 #-----------------------------------------------------------------------------
318 # If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
320 # ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
321 # in a build.mk file.
324 MKDEPENDHS = $(MKDEPENDHS_1_2)
328 # Before doing `make depend', need to build all derived Haskell source files
330 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs rename/ParseUnfolding.hs rename/ParseType.hs
333 ifeq "$(GhcWithHscBuiltViaC)" "YES"
334 ifeq "$(Ghc2_0)" "NO"
335 SRC_MKDEPENDHS_OPTS += -o hc
337 SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
339 # When booting from .hc, (hackily) remove the suffix rule for
340 # .l?hs -> .o, so that the .hc -> .o is used instead.
344 SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
348 #-----------------------------------------------------------------------------
351 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
352 $(SRCS_UGNC) $(SRCS_UGNH) \
354 parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
356 # Extra tidy, remove the .hc files (if you've got them).
357 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
360 #-----------------------------------------------------------------------------
363 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
364 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
365 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
367 #-----------------------------------------------------------------------------
368 # Include target-rule boilerplate
370 include $(TOP)/mk/target.mk
374 # Special extra dependencies for yukky ugen stuff
377 parser/%.o : parser/%.c $(SRCS_UGNH)
378 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
380 parser/hspincl.h : $(SRCS_UGNH)
381 parser/UgenAll.o : parser/hspincl.h
382 parser/UgenUtil.o : parser/hspincl.h
383 parser/U_constr.o : parser/hspincl.h
384 parser/U_binding.o : parser/hspincl.h
385 parser/U_pbinding.o : parser/hspincl.h
386 parser/U_entidt.o : parser/hspincl.h
387 parser/U_list.o : parser/hspincl.h
388 parser/U_literal.o : parser/hspincl.h
389 parser/U_maybe.o : parser/hspincl.h
390 parser/U_either.o : parser/hspincl.h
391 parser/U_qid.o : parser/hspincl.h
392 parser/U_tree.o : parser/hspincl.h
393 parser/U_ttype.o : parser/hspincl.h
394 parser/printtree.o : parser/hspincl.h
395 reader/ReadPrefix.o : parser/hspincl.h