c037578537eba59d30f84e13550e0eb5c7713228
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.45 1998/08/21 11:03:30 sof Exp $
3
4 TOP = ..
5 include $(TOP)/mk/boilerplate.mk
6
7 #-----------------------------------------------------------------------------
8 # Building hsc different ways (default is just `normal' sequential)
9 WAYS=$(GhcCompilerWays)
10
11 #-----------------------------------------------------------------------------
12 #               Set SUBDIRS
13
14 ifeq ($(IncludeTestDirsInBuild),YES)
15   SUBDIRS = tests
16 endif
17
18 # -----------------------------------------------------------------------------
19 #               Set HS_PROG, LIBRARY
20 # Setting HS_PROG and LIBRARY causes all targets in target.mk
21 # (included below) to kick in.
22
23 LIBRARY=libhsp.a
24
25 #
26 # Note: there have been reports of people running up against the ARG_MAX limit
27 # when linking hsc with all its constituent object files. The likely source of 
28 # the problem is that the environment is a bit too big, so a workaround could
29 # be to do ` env PATH=$(PATH) make hsc 'to minimise the environment. (or the
30 # equivalent of `env' if it doesn't exist locally).
31 #
32 HS_PROG=hsc$(_way)
33
34
35 # -----------------------------------------------------------------------------
36 #               Compilation history for Patrick
37
38 # Make the sources first, because that's what the compilation history needs
39 $(HS_PROG) :: $(HS_SRCS)
40
41
42 # -----------------------------------------------------------------------------
43 #               Set SRCS, LOOPS, HCS, OBJS
44 #
45 # First figure out DIRS, the source sub-directories
46 # Then derive SRCS by looking in them
47 #
48
49 DIRS = \
50   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
51   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
52   reader profiling parser
53
54
55 ifeq ($(GhcWithNativeCodeGen),YES)
56 DIRS += nativeGen
57 else
58 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
59 endif
60
61
62 HS_SRCS = $(SRCS_UGNHS) \
63           $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
64           rename/ParseIface.hs
65
66 # NB: it's no good to include *.hs in the top-line wildcard, because the .hs files
67 #     in parser/ may not have been created at that point.
68
69 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
70
71
72 HS_OBJS  = \
73   $(patsubst %.hc, %.o, $(HCS)) \
74   parser/hsclink.o parser/hschooks.o libhsp.a
75
76
77 DESTDIR       = $(INSTALL_LIBRARY_DIR_GHC)
78
79 SRCS_UGN      = $(wildcard parser/*.ugn)
80 SRCS_UGNC     = $(patsubst %.ugn, %.c, $(SRCS_UGN))
81 SRCS_UGNH     = $(patsubst %.ugn, %.h, $(SRCS_UGN))
82 SRCS_UGNHS    = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
83 SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))
84
85 #
86 # Add the generated C files to the C_SRCS, so as to let `depend'
87 # generate correct dependencies for them.
88 #
89 C_SRCS += $(SRCS_UGNC)
90
91 LIBOBJS = \
92   $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
93   parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
94   parser/util.o
95
96 #
97 # stuff you get for free in a source distribution
98
99 SRC_DIST_FILES += rename/ParseIface.hs \
100  parser/U_tree.c parser/tree.h parser/tree.c \
101  parser/hsparser.tab.c parser/hsparser.tab.h \
102  parser/hslexer.c
103
104 # -----------------------------------------------------------------------------
105 #               Haskell compilations
106
107 #
108 # Compiler to use for building hsc, use the build tree
109 # driver when booting.
110 #
111 ifneq "$(GhcWithHscBuiltViaC)" "YES"
112 HC=$(WithGhcHc)
113 else
114 HC=$(GHC_DRIVER_DIR)/ghc
115 endif
116
117 # magic from GNU make manual to convert a list of values
118 # into a colon-separated list
119 empty:=
120 space:= $(empty) $(empty)
121
122 SRC_HC_OPTS += \
123   -cpp -fglasgow-exts -Rghc-timing \
124   -I. -IcodeGen -InativeGen -Iparser \
125   -i$(subst $(space),:,$(DIRS))
126
127 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
128
129 SRC_HC_OPTS += -recomp $(GhcHcOpts)
130
131 #       Special flags for particular modules
132 #       The standard suffix rule for compiling a Haskell file
133 #       adds these flags to the command line
134
135 # Was 6m with 2.10
136 absCSyn/PprAbsC_HC_OPTS         = -H10m
137
138 basicTypes/IdInfo_HC_OPTS       = -K2m
139 hsSyn/HsExpr_HC_OPTS            = -K2m
140 main/Main_HC_OPTS               = -fvia-C
141 ifeq "$(GhcReportCompiles)" "YES"
142 main/Main_HC_OPTS               += -syslib misc -DREPORT_TO_MOTHERLODE
143 endif
144
145 main/CmdLineOpts_HC_OPTS        = -fvia-C
146 nativeGen/PprMach_HC_OPTS       = -K2m
147 nativeGen/MachMisc_HC_OPTS      = -K2m -fvia-C
148 nativeGen/MachCode_HC_OPTS      = -H10m
149 parser/UgenAll_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
150 parser/UgenUtil_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
151 parser/U_constr_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
152 parser/U_binding_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
153 parser/U_pbinding_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
154 parser/U_entidt_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
155 parser/U_list_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
156 parser/U_literal_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
157 parser/U_maybe_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
158 parser/U_either_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
159 parser/U_qid_HC_OPTS            = -fvia-C '-\#include"hspincl.h"'
160 parser/U_tree_HC_OPTS           = -H12m -fvia-C '-\#include"hspincl.h"'
161 parser/U_ttype_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
162 prelude/PrimOp_HC_OPTS          = -H12m -K3m
163 reader/Lex_HC_OPTS              = -K2m -H16m -fvia-C
164
165 # Heap was 6m with 2.10
166 reader/ReadPrefix_HC_OPTS       = -fvia-C '-\#include"hspincl.h"' -H10m
167
168 rename/ParseIface_HC_OPTS       += -Onot -H30m -fno-warn-incomplete-patterns
169 rename/ParseIface_HAPPY_OPTS    += -g
170
171 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
172 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
173 endif
174
175 rename/RnEnv_HC_OPTS            = -fvia-C
176 rename/RnSource_HC_OPTS         = -H12m
177 rename/RnIfaces_HC_OPTS         = -H8m -fvia-C
178 rename/RnExpr_HC_OPTS           = -H10m
179 rename/RnNames_HC_OPTS          = -H12m
180 rename/RnMonad_HC_OPTS          = -fvia-C
181 specialise/Specialise_HC_OPTS   = -Onot -H12m
182 typecheck/TcGenDeriv_HC_OPTS    = -H10m
183
184 # Was 10m for 2.10
185 typecheck/TcHsSyn_HC_OPTS       = -H15m 
186
187 # Was 10m for 2.10
188 typecheck/TcExpr_HC_OPTS        = -H15m
189
190 typecheck/TcEnv_HC_OPTS         = -H10m
191 utils/Argv_HC_OPTS              = -fvia-C
192 utils/SST_HC_OPTS               = -fvia-C
193 utils/FastString_HC_OPTS        = -fvia-C
194 utils/StringBuffer_HC_OPTS      = -fvia-C -fno-prune-tydecls
195 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
196 utils/DirUtils_HC_OPTS          = -fvia-C
197
198 ifeq "$(alpha_HOST_ARCH)" "1"
199 # "stbu" bug in alpha native code generator...
200 basicTypes/Unique_HC_OPTS       = -fvia-C
201 endif
202
203 # flags for PrimPacked:
204 #
205 # -monly-3-regs 
206 #       because it contains a 'ccall strlen', which gets inlined by
207 #       gcc, causing a lack of registers.
208 #
209 # -optC-funfolding-interface-threshold10
210 #       To stop the definition of 'strLength', which calls strlen, getting
211 #       into the interface file and spreading the -monly-3-regs virus.
212 #       We need -optC here because the driver before 3.02 didn't understand
213 #       the -funfolding flags.
214
215 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs -optC-funfolding-interface-threshold10
216
217 # Strictness analyser misbehaving in 2.10, fails to terminate on
218 # UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
219 # separate bugfix to the fixpoint finder.
220 simplStg/UpdAnal_HC_OPTS        = -fno-strictness
221
222 # ----------------------------------------------------------------------------
223 #               C compilations
224
225 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
226
227
228 # ----------------------------------------------------------------------------
229 #               Parsers/lexers
230
231 # Main parser uses Yacc/Bison
232 SRC_YACC_OPTS  += -d -v
233 # Suppress the generation of a default rule
234 SRC_FLEX_OPTS += -s
235
236 #
237 # Want to keep the intermediate (included in src distribs).
238 #
239 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
240
241 parser/hschooks.o : parser/hschooks.c
242         @$(RM) $@
243         $(HC) -c -o $@ $(HC_OPTS) parser/hschooks.c
244
245
246 # Interface-file parser uses Happy
247 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
248
249 rename/ParseIface.hs : rename/ParseIface.y
250         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
251         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
252         @chmod 444 rename/ParseIface.hs
253
254 #----------------------------------------------------------------------
255 #
256 # Building the stand-alone parser
257 #
258 all :: hsp
259
260 hsp: parser/printtree.o parser/main.o libhsp.a 
261         $(CC) -o $@ $(CC_OPTS) $^
262
263 CLEAN_FILES += hsp
264
265 #-----------------------------------------------------------------------------
266 #               Linking
267
268 SRC_LD_OPTS += -no-link-chk
269 ifeq "$(GhcReportCompiles)" "YES"
270 SRC_LD_OPTS += -syslib misc -syslib exts
271 endif
272
273 #-----------------------------------------------------------------------------
274 #               install
275
276 # We don't want hsc treated as an ordinary executable,
277 # but put it together with the libraries.
278 # Also don't want any interface files intstalled
279
280 INSTALL_LIBEXECS += hsc hsp
281
282 #-----------------------------------------------------------------------------
283 #               depend
284
285 #
286 # Before doing `make depend', need to build all derived Haskell source files
287 #
288 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs
289
290 #-----------------------------------------------------------------------------
291 #               clean
292
293 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
294                $(SRCS_UGNC) $(SRCS_UGNH) \
295                $(SRCS_UGNHS)\
296                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
297
298 # Extra tidy, remove the .hc files (if you've got them).
299 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
300
301
302 #-----------------------------------------------------------------------------
303 #               TAGS setup
304
305 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
306 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
307 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
308
309 #-----------------------------------------------------------------------------
310 #               Include target-rule boilerplate
311
312 include $(TOP)/mk/target.mk
313
314
315 #
316 # Special extra dependencies for yukky ugen stuff
317 #
318
319 parser/%.o : parser/%.c $(SRCS_UGNH)
320 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
321
322 parser/hspincl.h : $(SRCS_UGNH)
323 parser/UgenAll.o : parser/hspincl.h
324 parser/UgenUtil.o : parser/hspincl.h
325 parser/U_constr.o : parser/hspincl.h
326 parser/U_binding.o : parser/hspincl.h
327 parser/U_pbinding.o : parser/hspincl.h
328 parser/U_entidt.o : parser/hspincl.h
329 parser/U_list.o : parser/hspincl.h
330 parser/U_literal.o : parser/hspincl.h
331 parser/U_maybe.o : parser/hspincl.h
332 parser/U_either.o : parser/hspincl.h
333 parser/U_qid.o : parser/hspincl.h
334 parser/U_tree.o : parser/hspincl.h
335 parser/U_ttype.o : parser/hspincl.h
336 parser/printtree.o : parser/hspincl.h
337 reader/ReadPrefix.o : parser/hspincl.h