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