[project @ 1999-01-07 12:48:13 by simonpj]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.48 1999/01/07 12:48:13 simonpj 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
65 ifneq "$(GhcWithHscBuiltViaC)" "YES"
66 HS_SRCS += rename/ParseIface.hs
67 endif
68
69 # NB: it's no good to include *.hs in the top-line wildcard, because the .hs files
70 #     in parser/ may not have been created at that point.
71
72 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
73
74 # ParseIface.hs ain't part of HS_SRCS when this is on..
75 ifeq "$(GhcWithHscBuiltViaC)" "YES"
76 HCS      += rename/ParseIface.hc
77 endif
78
79 HS_OBJS  = \
80   $(patsubst %.hc, %.o, $(HCS)) \
81   parser/hsclink.o parser/hschooks.o libhsp.a
82
83
84 DESTDIR       = $(INSTALL_LIBRARY_DIR_GHC)
85
86 SRCS_UGN      = $(wildcard parser/*.ugn)
87 SRCS_UGNC     = $(patsubst %.ugn, %.c, $(SRCS_UGN))
88 SRCS_UGNH     = $(patsubst %.ugn, %.h, $(SRCS_UGN))
89 SRCS_UGNHS    = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
90 SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))
91
92 #
93 # Add the generated C files to the C_SRCS, so as to let `depend'
94 # generate correct dependencies for them.
95 #
96 C_SRCS += $(SRCS_UGNC)
97
98 LIBOBJS = \
99   $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
100   parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
101   parser/util.o parser/ctypes.o
102
103 # stuff you get for free in a source distribution
104
105 # SRC_DIST_FILES += rename/ParseIface.hs \
106 #  parser/U_tree.c parser/tree.h parser/tree.c \
107 #  parser/hsparser.tab.c parser/hsparser.tab.h \
108 #  parser/hslexer.c
109
110 # -----------------------------------------------------------------------------
111 #               Haskell compilations
112
113 #
114 # Compiler to use for building hsc, use the build tree
115 # driver when booting.
116 #
117 ifneq "$(GhcWithHscBuiltViaC)" "YES"
118 HC=$(WithGhcHc)
119 else
120 HC=$(GHC_DRIVER_DIR)/ghc
121 endif
122
123 # magic from GNU make manual to convert a list of values
124 # into a colon-separated list
125 empty:=
126 space:= $(empty) $(empty)
127
128 SRC_HC_OPTS += \
129   -cpp -fglasgow-exts -Rghc-timing \
130   -I. -IcodeGen -InativeGen -Iparser \
131   -i$(subst $(space),:,$(DIRS))
132
133 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
134
135 SRC_HC_OPTS += -recomp $(GhcHcOpts)
136
137 #       Special flags for particular modules
138 #       The standard suffix rule for compiling a Haskell file
139 #       adds these flags to the command line
140
141 # Was 6m with 2.10
142 absCSyn/PprAbsC_HC_OPTS         = -H10m
143
144 basicTypes/IdInfo_HC_OPTS       = -K2m
145 hsSyn/HsExpr_HC_OPTS            = -K2m
146 main/Main_HC_OPTS               = -fvia-C
147 main/Constants_HC_OPTS          = -DHscIfaceFileVersion=$(HscIfaceFileVersion)
148
149 ifneq "$(GhcWithHscBuiltViaC)" "YES"
150 ifeq "$(GhcReportCompiles)" "YES"
151 main/Main_HC_OPTS               += -syslib misc -DREPORT_TO_MOTHERLODE
152 endif
153 endif
154
155 main/CmdLineOpts_HC_OPTS        = -fvia-C
156 nativeGen/PprMach_HC_OPTS       = -K2m
157 nativeGen/MachMisc_HC_OPTS      = -K2m -fvia-C
158 nativeGen/MachCode_HC_OPTS      = -H10m
159 parser/UgenAll_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
160 parser/UgenUtil_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
161 parser/U_binding_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
162 parser/U_constr_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
163 parser/U_either_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
164 parser/U_entidt_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
165 parser/U_gdexp_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
166 parser/U_grhsb_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_match_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
170 parser/U_maybe_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
171 parser/U_qid_HC_OPTS            = -fvia-C '-\#include"hspincl.h"'
172 parser/U_tree_HC_OPTS           = -H12m -fvia-C '-\#include"hspincl.h"'
173 parser/U_ttype_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
174
175 prelude/PrimOp_HC_OPTS          = -H12m -K3m
176 reader/Lex_HC_OPTS              = -K2m -H16m -fvia-C
177
178 # Heap was 6m with 2.10
179 reader/ReadPrefix_HC_OPTS       = -fvia-C '-\#include"hspincl.h"' -H10m
180
181 rename/ParseIface_HC_OPTS       += -Onot -H45m -fno-warn-incomplete-patterns
182 rename/ParseIface_HAPPY_OPTS    += -g
183
184 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
185 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
186 endif
187
188 rename/RnEnv_HC_OPTS            = -fvia-C
189 rename/RnSource_HC_OPTS         = -H12m
190 rename/RnIfaces_HC_OPTS         = -H8m -fvia-C
191 rename/RnExpr_HC_OPTS           = -H10m
192 rename/RnNames_HC_OPTS          = -H12m
193 rename/RnMonad_HC_OPTS          = -fvia-C
194 specialise/Specialise_HC_OPTS   = -Onot -H12m
195 simplCore/Simplify_HC_OPTS      = -H15m 
196 typecheck/TcGenDeriv_HC_OPTS    = -H10m
197
198 # tmp, -- SDM
199 specialise/Specialise_HC_OPTS   += -fno-prune-tydecls
200
201 # Was 10m for 2.10
202 typecheck/TcHsSyn_HC_OPTS       = -H15m 
203
204
205 # Was 10m for 2.10
206 typecheck/TcExpr_HC_OPTS        = -H15m
207 typecheck/TcBinds_HC_OPTS       = -H10m
208
209 typecheck/TcEnv_HC_OPTS         = -H10m
210 utils/Argv_HC_OPTS              = -fvia-C
211 utils/SST_HC_OPTS               = -fvia-C
212 utils/FastString_HC_OPTS        = -fvia-C
213 utils/StringBuffer_HC_OPTS      = -fvia-C -fno-prune-tydecls
214 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
215 utils/DirUtils_HC_OPTS          = -fvia-C
216
217 ifeq "$(alpha_HOST_ARCH)" "1"
218 # "stbu" bug in alpha native code generator...
219 basicTypes/Unique_HC_OPTS       = -fvia-C
220 endif
221
222 # flags for PrimPacked:
223 #
224 # -monly-3-regs 
225 #       because it contains a 'ccall strlen', which gets inlined by
226 #       gcc, causing a lack of registers.
227 #
228 # -optC-funfolding-interface-threshold10
229 #       To stop the definition of 'strLength', which calls strlen, getting
230 #       into the interface file and spreading the -monly-3-regs virus.
231 #       We need -optC here because the driver before 3.02 didn't understand
232 #       the -funfolding flags.
233
234 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs -optC-funfolding-interface-threshold10
235
236 # Strictness analyser misbehaving in 2.10, fails to terminate on
237 # UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
238 # separate bugfix to the fixpoint finder.
239 simplStg/UpdAnal_HC_OPTS        = -fno-strictness
240
241 # ----------------------------------------------------------------------------
242 #               C compilations
243
244 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
245
246
247 # ----------------------------------------------------------------------------
248 #               Parsers/lexers
249
250 # Main parser uses Yacc/Bison
251 SRC_YACC_OPTS  += -d -v
252 # Suppress the generation of a default rule
253 SRC_FLEX_OPTS += -s
254
255 #
256 # Want to keep the intermediate (included in src distribs).
257 #
258 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
259
260 parser/hschooks.o : parser/hschooks.c
261         @$(RM) $@
262         $(HC) -c -o $@ -I$(GHC_INCLUDE_DIR) $(HC_OPTS) parser/hschooks.c
263
264
265 # Interface-file parser uses Happy
266 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
267
268 rename/ParseIface.hs : rename/ParseIface.y
269         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
270         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
271         @chmod 444 rename/ParseIface.hs
272
273 #----------------------------------------------------------------------
274 #
275 # Building the stand-alone parser
276 #
277 all :: hsp
278
279 hsp: parser/printtree.o parser/main.o libhsp.a 
280         $(CC) -o $@ $(CC_OPTS) $^
281
282 CLEAN_FILES += hsp
283
284 #-----------------------------------------------------------------------------
285 #               Linking
286
287 SRC_LD_OPTS += -no-link-chk
288
289 ifneq "$(GhcWithHscBuiltViaC)" "YES"
290 ifeq "$(GhcReportCompiles)" "YES"
291 SRC_LD_OPTS += -syslib misc -syslib exts
292 endif
293 endif
294
295 #-----------------------------------------------------------------------------
296 #               install
297
298 # We don't want hsc treated as an ordinary executable,
299 # but put it together with the libraries.
300 # Also don't want any interface files intstalled
301
302 INSTALL_LIBEXECS += hsc hsp
303
304 #-----------------------------------------------------------------------------
305 #               depend
306
307 #
308 # Before doing `make depend', need to build all derived Haskell source files
309 #
310 depend :: $(LOOPS) $(SRCS_UGNHS)
311
312 ifneq "$(GhcWithHscBuiltViaC)" "YES"
313 depend :: rename/ParseIface.hs
314 endif
315
316 #-----------------------------------------------------------------------------
317 #               clean
318
319 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
320                $(SRCS_UGNC) $(SRCS_UGNH) \
321                $(SRCS_UGNHS)\
322                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
323
324 # Extra tidy, remove the .hc files (if you've got them).
325 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
326
327
328 #-----------------------------------------------------------------------------
329 #               TAGS setup
330
331 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
332 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
333 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
334
335 #-----------------------------------------------------------------------------
336 #               Include target-rule boilerplate
337
338 include $(TOP)/mk/target.mk
339
340
341 #
342 # Special extra dependencies for yukky ugen stuff
343 #
344
345 parser/%.o : parser/%.c $(SRCS_UGNH)
346 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
347
348 parser/hspincl.h : $(SRCS_UGNH)
349 parser/UgenAll.o : parser/hspincl.h
350 parser/UgenUtil.o : parser/hspincl.h
351 parser/U_constr.o : parser/hspincl.h
352 parser/U_binding.o : parser/hspincl.h
353 parser/U_pbinding.o : parser/hspincl.h
354 parser/U_entidt.o : parser/hspincl.h
355 parser/U_list.o : parser/hspincl.h
356 parser/U_literal.o : parser/hspincl.h
357 parser/U_maybe.o : parser/hspincl.h
358 parser/U_either.o : parser/hspincl.h
359 parser/U_qid.o : parser/hspincl.h
360 parser/U_tree.o : parser/hspincl.h
361 parser/U_ttype.o : parser/hspincl.h
362 parser/printtree.o : parser/hspincl.h
363 reader/ReadPrefix.o : parser/hspincl.h