1 # -----------------------------------------------------------------------------
4 include $(TOP)/mk/boilerplate.mk
6 #-----------------------------------------------------------------------------
7 # Building hsc different ways (default is just `normal' sequential)
8 override 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 ($(GhcWithDeforester),YES)
51 ifeq ($(GhcWithNativeCodeGen),YES)
54 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
58 HS_SRCS = $(SRCS_UGNHS) \
59 $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
60 rename/ParseIface.hs rename/ParseType.hs rename/ParseUnfolding.hs \
63 # NB: it's no good to include *.hs in the top-line wildcard, because the .hs files
64 # in parser/ may not have been created at that point.
67 HCS = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
70 # When booting using a ghc-2.xx compiler, the loop breakers are actually written in
71 # Haskell, source stubs just re-exporting info from the various .hi-boot files.
72 # (Reason: we don't want to fiddle with the imports in the sources). We give them
73 # the suffix .hs, since they're special and don't fall under the umbrella of $(HS_SRCS)
74 # always (only when $(Ghc2_0) is equal to YES)
75 ifeq "$(Ghc2_0)" "YES"
76 #OLD:LOOPS_HS = $(wildcard */*Loop*.hs)
77 MKDEPENDHS_SRCS = $(HS_SRCS)
78 #HS_SRCS += $(LOOPS_HS)
80 LOOPS = $(patsubst %.lhi, %.hi, $(wildcard */*.lhi))
84 $(patsubst %.hc, %.o, $(HCS)) \
85 parser/hsclink.o parser/hschooks.o libhsp.a
88 DESTDIR = $(INSTALL_LIBRARY_DIR_GHC)
90 SRCS_UGN = $(wildcard parser/*.ugn)
91 SRCS_UGNC = $(patsubst %.ugn, %.c, $(SRCS_UGN))
92 SRCS_UGNH = $(patsubst %.ugn, %.h, $(SRCS_UGN))
93 SRCS_UGNHS = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
94 SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))
97 # Add the generated C files to the C_SRCS, so as to let `depend'
98 # generate correct dependencies for them.
100 C_SRCS += $(SRCS_UGNC)
103 $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
104 parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
108 # stuff you get for free in a source distribution
110 SRC_DIST_FILES += rename/ParseIface.hs \
111 rename/ParseType.hs rename/ParseUnfolding.hs \
112 parser/U_tree.c parser/tree.h parser/tree.c \
113 parser/hsparser.tab.c parser/hsparser.tab.h \
116 # -----------------------------------------------------------------------------
117 # Haskell compilations
119 # Compiler to use for building hsc
125 -fglasgow-exts -DCOMPILING_GHC -Rghc-timing -I. -IcodeGen \
126 -InativeGen -Iparser $(foreach dir,$(DIRS),-i$(dir))
128 # -syslib ghc just needed for use of PackedString.hPutPS
130 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
132 ifeq "$(Ghc2_0)" "NO"
133 SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
135 # Recompilation checking - unconditionally so (ToDo: move to mk/config.mk.in)
136 SRC_HC_OPTS += -recomp
139 ifeq ($(GhcWithDeforester),NO)
140 ifeq "$(Ghc2_0)" "NO"
141 SRC_MKDEPENDHS_OPTS += -DOMIT_DEFORESTER
143 SRC_HC_OPTS += -DOMIT_DEFORESTER
146 SRC_HC_OPTS += $(GhcHcOpts)
148 # Special flags for particular modules
149 # The standard suffix rule for compiling a Haskell file
150 # adds these flags to the command line
152 absCSyn/AbsCSyn_HC_OPTS = -fno-omit-reexported-instances
153 basicTypes/IdInfo_HC_OPTS = -K2m
154 coreSyn/AnnCoreSyn_HC_OPTS = -fno-omit-reexported-instances
155 hsSyn/HsExpr_HC_OPTS = -K2m
156 hsSyn/HsSyn_HC_OPTS = -fno-omit-reexported-instances
157 main/Main_HC_OPTS = -fvia-C
158 main/CmdLineOpts_HC_OPTS = -fvia-C
159 nativeGen/PprMach_HC_OPTS = -K2m
160 nativeGen/MachMisc_HC_OPTS = -K2m -fvia-C
161 parser/UgenAll_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
162 parser/UgenUtil_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
163 parser/U_constr_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
164 parser/U_binding_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
165 parser/U_pbinding_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
166 parser/U_entidt_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
167 parser/U_list_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
168 parser/U_literal_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
169 parser/U_maybe_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
170 parser/U_either_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
171 parser/U_qid_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
172 parser/U_tree_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
173 parser/U_ttype_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
174 prelude/PrimOp_HC_OPTS = -K3m
175 reader/Lex_HC_OPTS = -K2m -H16m -fvia-C
176 ifeq "$(Ghc2_0)" "NO"
177 reader/Lex_HC_OPTS += -fomit-derived-read
179 reader/ReadPrefix_HC_OPTS = -fvia-C '-\#include"hspincl.h"'
180 rename/ParseIface_HC_OPTS = -Onot -H16m
181 rename/ParseType_HC_OPTS = -Onot -H16m
182 rename/ParseUnfolding_HC_OPTS = -Onot -H16m
183 ifeq "$(Ghc2_0)" "YES"
184 rename/ParseIface_HC_OPTS += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
185 rename/ParseType_HC_OPTS += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
186 rename/ParseUnfolding_HC_OPTS += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
189 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
190 rename/RnMonad_HC_OPTS = -fvia-C -O2 -O2-for-C
192 ifeq "$(Ghc2_0)" "NO"
193 rename/RnMonad_HC_OPTS = -fvia-C
196 rename/RnEnv_HC_OPTS = -fvia-C
197 rename/RnSource_HC_OPTS = -H12m
198 rename/RnIfaces_HC_OPTS = -H8m -fvia-C
199 rename/RnNames_HC_OPTS = -H12m
200 rename/RnMonad_HC_OPTS = -fvia-C
201 specialise/Specialise_HC_OPTS = -Onot -H12m
202 stgSyn/StgSyn_HC_OPTS = -fno-omit-reexported-instances
203 typecheck/TcGenDeriv_HC_OPTS = -H10m
204 typecheck/TcExpr_HC_OPTS = -H10m
205 typecheck/TcEnv_HC_OPTS = -H10m
206 ifeq "$(Ghc2_0)" "NO"
207 typecheck/TcMonad_HC_OPTS = -fvia-C
209 utils/Argv_HC_OPTS = -fvia-C
210 utils/SST_HC_OPTS = -fvia-C
211 utils/PrimPacked_HC_OPTS = -fvia-C -monly-3-regs
212 utils/FastString_HC_OPTS = -fvia-C
213 utils/StringBuffer_HC_OPTS = -fvia-C
214 utils/Digraph_HC_OPTS = -fglasgow-exts -fvia-C
217 # ----------------------------------------------------------------------------
220 SRC_C_OPTS += -O -Iparser -I. -IcodeGen
223 # ----------------------------------------------------------------------------
226 # Main parser uses Yacc/Bison
227 SRC_YACC_OPTS += -d -v
230 # Want to keep the intermediate (included in src distribs).
232 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
234 parser/hschooks.o : parser/hschooks.c
236 $(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c
239 # Interface-file parser uses Happy
240 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
242 rename/ParseIface.hs : rename/ParseIface.y
243 @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
244 $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
245 @chmod 444 rename/ParseIface.hs
247 rename/ParseType.hs : rename/ParseType.y
248 @$(RM) rename/ParseType.hs rename/ParseType.hinfo
249 $(HAPPY) $(HAPPY_OPTS) -g rename/ParseType.y
250 @chmod 444 rename/ParseType.hs
252 rename/ParseUnfolding.hs : rename/ParseUnfolding.y
253 @$(RM) rename/ParseUnfolding.hs rename/ParseUnfolding.hinfo
254 $(HAPPY) $(HAPPY_OPTS) -g rename/ParseUnfolding.y
255 @chmod 444 rename/ParseUnfolding.hs
257 #----------------------------------------------------------------------
259 # Building the stand-alone parser
263 hsp: parser/printtree.o parser/main.o libhsp.a
264 $(CC) -o $@ $(CC_OPTS) $^
267 #-----------------------------------------------------------------------------
270 # LoopHack.lhc is an SLPJ addition to fix a profiling problem. See comments
271 # inside it. (compilation is handled by the suffix rules).
274 # Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
278 BOOT_HI_STEMS = $(basename $(wildcard */*.hi-boot))
281 @for n in $(BOOT_HI_STEMS); \
283 echo Creating $$n.hi ; \
285 $(CP) $$n.hi-boot $$n.hi || ( $(RM) $$n.hi && exit 1 ) ; \
288 # Have the collector *Loop.hs interface files be generated just after having
289 # created the .hi's from the .hi-boot's.
297 $(UNLIT) $< $@ || ( $(RM) $@ && exit 1 )
303 #-----------------------------------------------------------------------------
306 SRC_LD_OPTS += -no-link-chk
309 #SRC_LD_OPTS += "-pgml time gcc -B/projects/unsupported/gnu/sparc-sunos5/bin/g"
312 #-----------------------------------------------------------------------------
315 # We don't want hsc treated as an ordinary executable,
316 # but put it together with the libraries.
317 # Also don't want any interface files intstalled
319 INSTALL_LIBEXECS += hsc hsp
321 #-----------------------------------------------------------------------------
324 # If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
326 # ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
327 # in a build.mk file.
330 MKDEPENDHS = $(MKDEPENDHS_1_2)
334 # Before doing `make depend', need to build all derived Haskell source files
336 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs rename/ParseUnfolding.hs rename/ParseType.hs
339 ifeq "$(GhcWithHscBuiltViaC)" "YES"
340 ifeq "$(Ghc2_0)" "NO"
341 SRC_MKDEPENDHS_OPTS += -o hc
343 SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
345 # When booting from .hc, (hackily) remove the suffix rule for
346 # .l?hs -> .o, so that the .hc -> .o is used instead.
350 SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
354 #-----------------------------------------------------------------------------
357 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
358 $(SRCS_UGNC) $(SRCS_UGNH) \
360 parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
362 # Extra tidy, remove the .hc files (if you've got them).
363 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
366 #-----------------------------------------------------------------------------
369 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
372 #-----------------------------------------------------------------------------
373 # Include target-rule boilerplate
375 include $(TOP)/mk/target.mk
379 # Special extra dependencies for yukky ugen stuff
382 parser/%.o : parser/%.c $(SRCS_UGNH)
383 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
385 parser/hspincl.h : $(SRCS_UGNH)
386 parser/UgenAll.o : parser/hspincl.h
387 parser/UgenUtil.o : parser/hspincl.h
388 parser/U_constr.o : parser/hspincl.h
389 parser/U_binding.o : parser/hspincl.h
390 parser/U_pbinding.o : parser/hspincl.h
391 parser/U_entidt.o : parser/hspincl.h
392 parser/U_list.o : parser/hspincl.h
393 parser/U_literal.o : parser/hspincl.h
394 parser/U_maybe.o : parser/hspincl.h
395 parser/U_either.o : parser/hspincl.h
396 parser/U_qid.o : parser/hspincl.h
397 parser/U_tree.o : parser/hspincl.h
398 parser/U_ttype.o : parser/hspincl.h
399 parser/printtree.o : parser/hspincl.h
400 reader/ReadPrefix.o : parser/hspincl.h