[project @ 1998-01-08 18:03:08 by simonm]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2
3 TOP = ..
4 include $(TOP)/mk/boilerplate.mk
5
6 #-----------------------------------------------------------------------------
7 # Building hsc different ways (default is just `normal' sequential)
8 WAYS=$(GhcCompilerWays)
9
10 #-----------------------------------------------------------------------------
11 #               Set SUBDIRS
12
13 ifeq ($(IncludeTestDirsInBuild),YES)
14   SUBDIRS = tests
15 endif
16
17 # -----------------------------------------------------------------------------
18 #               Set HS_PROG, LIBRARY
19 # Setting HS_PROG and LIBRARY causes all targets in target.mk
20 # (included below) to kick in.
21
22 LIBRARY=libhsp.a
23
24 #
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).
30 #
31 HS_PROG=hsc
32
33
34 # -----------------------------------------------------------------------------
35 #               Compilation history for Patrick
36
37 # Make the sources first, because that's what the compilation history needs
38 $(HS_PROG) :: $(HS_SRCS)
39
40
41 # -----------------------------------------------------------------------------
42 #               Set SRCS, LOOPS, HCS, OBJS
43 #
44 # First figure out DIRS, the source sub-directories
45 # Then derive SRCS by looking in them
46 #
47
48 DIRS = \
49   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
50   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
51   reader profiling parser
52
53
54 ifeq ($(GhcWithNativeCodeGen),YES)
55 DIRS += nativeGen
56 else
57 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
58 endif
59
60
61 HS_SRCS = $(SRCS_UGNHS) \
62           $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
63           rename/ParseIface.hs
64
65 ifneq "$(Ghc2_0)" "YES"
66 HS_SRCS += main/LoopHack.hc 
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
73 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
74
75 #
76 # When booting using a ghc-2.xx compiler, the loop breakers are actually written in
77 # Haskell, source stubs just re-exporting info from the various .hi-boot files.
78 # (Reason: we don't want to fiddle with the imports in the sources). We give them
79 # the suffix .hs, since they're special and don't fall under the umbrella of $(HS_SRCS)
80 # always (only when $(Ghc2_0) is equal to YES)
81 ifeq "$(Ghc2_0)" "YES"
82 MKDEPENDHS_SRCS = $(HS_SRCS)
83 else
84 LOOPS   = $(patsubst %.lhi, %.hi, $(wildcard */*.lhi))
85 endif
86  
87 HS_OBJS  = \
88   $(patsubst %.hc, %.o, $(HCS)) \
89   parser/hsclink.o parser/hschooks.o libhsp.a
90
91
92 DESTDIR         = $(INSTALL_LIBRARY_DIR_GHC)
93
94 SRCS_UGN      = $(wildcard parser/*.ugn)
95 SRCS_UGNC     = $(patsubst %.ugn, %.c, $(SRCS_UGN))
96 SRCS_UGNH     = $(patsubst %.ugn, %.h, $(SRCS_UGN))
97 SRCS_UGNHS    = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
98 SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))
99
100 #
101 # Add the generated C files to the C_SRCS, so as to let `depend'
102 # generate correct dependencies for them.
103 #
104 C_SRCS += $(SRCS_UGNC)
105
106 LIBOBJS = \
107   $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
108   parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
109   parser/util.o
110
111 #
112 # stuff you get for free in a source distribution
113
114 SRC_DIST_FILES += rename/ParseIface.hs \
115  parser/U_tree.c parser/tree.h parser/tree.c \
116  parser/hsparser.tab.c parser/hsparser.tab.h \
117  parser/hslexer.c
118
119 # -----------------------------------------------------------------------------
120 #               Haskell compilations
121
122 # Compiler to use for building hsc
123 #
124 HC=$(WithGhcHc)
125
126 # magic from GNU make manual to convert a list of values
127 # into a colon-separated list
128 empty:=
129 space:= $(empty) $(empty)
130
131 SRC_HC_OPTS += \
132   -cpp -fglasgow-exts -Rghc-timing \
133   -I. -IcodeGen -InativeGen -Iparser \
134   -i$(subst $(space),:,$(DIRS))
135
136 ifeq "$(Ghc2_0)" "NO"
137 SRC_HC_OPTS += -fhaskell-1.3
138 endif
139
140 # -syslib ghc just needed for use of PackedString.hPutPS
141
142 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
143
144 ifeq "$(Ghc2_0)" "NO"
145 SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
146 else
147 SRC_HC_OPTS += -recomp
148 endif
149
150 SRC_HC_OPTS += $(GhcHcOpts)
151
152 #       Special flags for particular modules
153 #       The standard suffix rule for compiling a Haskell file
154 #       adds these flags to the command line
155
156 absCSyn/AbsCSyn_HC_OPTS         = -fno-omit-reexported-instances
157 absCSyn/CStrings_HC_OPTS        = -monly-3-regs
158
159 # Was 6m with 2.10
160 absCSyn/PprAbsC_HC_OPTS         = -H10m
161
162 basicTypes/IdInfo_HC_OPTS       = -K2m
163 coreSyn/AnnCoreSyn_HC_OPTS      = -fno-omit-reexported-instances
164 hsSyn/HsExpr_HC_OPTS            = -K2m
165 hsSyn/HsSyn_HC_OPTS             = -fno-omit-reexported-instances
166 main/Main_HC_OPTS               = -fvia-C -DPROJECTVERSION=$(GhcProjectVersion)
167 main/CmdLineOpts_HC_OPTS        = -fvia-C
168 nativeGen/PprMach_HC_OPTS       = -K2m
169 nativeGen/MachMisc_HC_OPTS      = -K2m -fvia-C
170 nativeGen/MachCode_HC_OPTS      = -H10m
171 parser/UgenAll_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
172 parser/UgenUtil_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
173 parser/U_constr_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
174 parser/U_binding_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
175 parser/U_pbinding_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
176 parser/U_entidt_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
177 parser/U_list_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
178 parser/U_literal_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
179 parser/U_maybe_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
180 parser/U_either_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
181 parser/U_qid_HC_OPTS            = -fvia-C '-\#include"hspincl.h"'
182 parser/U_tree_HC_OPTS           = -H12m -fvia-C '-\#include"hspincl.h"'
183 parser/U_ttype_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
184 prelude/PrimOp_HC_OPTS          = -H12m -K3m
185 reader/Lex_HC_OPTS              = -K2m -H16m -fvia-C
186
187 # Heap was 6m with 2.10
188 reader/ReadPrefix_HC_OPTS       = -fvia-C '-\#include"hspincl.h"' -H10m
189
190 rename/ParseIface_HC_OPTS       += -Onot -H30m
191 ifeq "$(Ghc2_0)" "YES"
192 rename/ParseIface_HC_OPTS       += -fno-warn-incomplete-patterns
193 endif
194
195 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
196 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
197 else
198 ifeq "$(Ghc2_0)" "NO"
199 rename/RnMonad_HC_OPTS          = -fvia-C
200 endif
201 endif
202 rename/RnEnv_HC_OPTS            = -fvia-C
203 rename/RnSource_HC_OPTS         = -H12m
204 rename/RnIfaces_HC_OPTS         = -H8m -fvia-C
205 rename/RnExpr_HC_OPTS           = -H10m
206 rename/RnNames_HC_OPTS          = -H12m
207 rename/RnMonad_HC_OPTS          = -fvia-C
208 # Urk!  Really big heap for ParseUnfolding
209 #rename/ParseUnfolding_HC_OPTS  = -H45m         
210 specialise/Specialise_HC_OPTS   = -Onot -H12m
211 stgSyn/StgSyn_HC_OPTS           = -fno-omit-reexported-instances
212 typecheck/TcGenDeriv_HC_OPTS    = -H10m
213
214 # Was 10m for 2.10
215 typecheck/TcHsSyn_HC_OPTS       = -H15m 
216
217 # Was 10m for 2.10
218 typecheck/TcExpr_HC_OPTS        = -H15m
219
220 typecheck/TcEnv_HC_OPTS         = -H10m
221 ifeq "$(Ghc2_0)" "NO"
222 typecheck/TcMonad_HC_OPTS       = -fvia-C       
223 endif
224 utils/Argv_HC_OPTS              = -fvia-C -monly-3-regs
225 utils/SST_HC_OPTS               = -fvia-C
226 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs
227 utils/FastString_HC_OPTS        = -fvia-C -monly-3-regs
228 utils/StringBuffer_HC_OPTS      = -fvia-C
229 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
230 utils/Outputable_HC_OPTS        = -monly-3-regs
231
232 # optimiser misbehaving in 0.29, occurrence analyser fails to terminate when
233 # compiling lib/required/Time.lhs
234 ifeq "$(Ghc2_0)" "NO"
235 simplCore/OccurAnal_HC_OPTS     = -Onot
236 endif
237
238 # Strictness analyser misbehaving in 2.10, fails to terminate on
239 # UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
240 # separate bugfix to the fixpoint finder.
241 simplStg/UpdAnal_HC_OPTS        = -fno-strictness
242
243 # ----------------------------------------------------------------------------
244 #               C compilations
245
246 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
247
248
249 # ----------------------------------------------------------------------------
250 #               Parsers
251
252 # Main parser uses Yacc/Bison
253 SRC_YACC_OPTS  += -d -v
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 $@ $(HCFLAGS) parser/hschooks.c
263
264
265 # Interface-file parser uses Happy
266 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
267
268 ifeq ($(Ghc2_0),NO)
269 SRC_HAPPY_OPTS+= -1.2
270 endif
271
272 rename/ParseIface.hs : rename/ParseIface.y
273         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
274         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
275         @chmod 444 rename/ParseIface.hs
276
277 #----------------------------------------------------------------------
278 #
279 # Building the stand-alone parser
280 #
281 all :: hsp
282
283 hsp: parser/printtree.o parser/main.o libhsp.a 
284         $(CC) -o $@ $(CC_OPTS) $^
285
286 CLEAN_FILES += hsp
287 #-----------------------------------------------------------------------------
288 #               Interface files
289
290 # LoopHack.lhc is an SLPJ addition to fix a profiling problem.  See comments
291 # inside it. (compilation is handled by the suffix rules).
292
293 #
294 # Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
295 #
296 ifeq "$(Ghc2_0)" "NO"
297 hi-boot :: $(LOOPS)
298
299 %.hi : %.lhi
300         $(RM) $@
301         $(UNLIT) $<  $@ || ( $(RM) $@ && exit 1 )
302         @chmod 444 $@
303
304 boot :: hi-boot
305 else
306 # hi-boot not needed when using 2.04+ as HC, defining it here
307 # to be consistent across setting of Ghc2_0
308 hi-boot :
309         @echo "Done."
310 endif
311
312 #-----------------------------------------------------------------------------
313 #               Linking
314
315 SRC_LD_OPTS += -no-link-chk
316
317 #-----------------------------------------------------------------------------
318 #               install
319
320 # We don't want hsc treated as an ordinary executable,
321 # but put it together with the libraries.
322 # Also don't want any interface files intstalled
323
324 INSTALL_LIBEXECS += hsc hsp
325
326 #-----------------------------------------------------------------------------
327 #               depend
328
329 # If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
330 #
331 # ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
332 # in a build.mk file.
333 #
334 ifeq ($(Ghc2_0),NO)
335 MKDEPENDHS      = $(MKDEPENDHS_1_2)
336 endif
337
338 #
339 # Before doing `make depend', need to build all derived Haskell source files
340 #
341 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs
342
343
344 ifeq "$(GhcWithHscBuiltViaC)" "YES"
345 ifeq "$(Ghc2_0)" "NO"
346 SRC_MKDEPENDHS_OPTS += -o hc
347 else
348 SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
349 endif
350 # When booting from .hc, (hackily) remove the suffix rule for 
351 # .l?hs -> .o, so that the .hc -> .o is used instead.
352 %.$(way_)o : %.lhs
353 %.$(way_)o : %.hs
354 else
355   SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
356 endif
357
358
359 #-----------------------------------------------------------------------------
360 #               clean
361
362 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
363                $(SRCS_UGNC) $(SRCS_UGNH) \
364                $(SRCS_UGNHS)\
365                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
366
367 # Extra tidy, remove the .hc files (if you've got them).
368 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
369
370
371 #-----------------------------------------------------------------------------
372 #               TAGS setup
373
374 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
375 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
376 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
377
378 #-----------------------------------------------------------------------------
379 #               Include target-rule boilerplate
380
381 include $(TOP)/mk/target.mk
382
383
384 #
385 # Special extra dependencies for yukky ugen stuff
386 #
387
388 parser/%.o : parser/%.c $(SRCS_UGNH)
389 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
390
391 parser/hspincl.h : $(SRCS_UGNH)
392 parser/UgenAll.o : parser/hspincl.h
393 parser/UgenUtil.o : parser/hspincl.h
394 parser/U_constr.o : parser/hspincl.h
395 parser/U_binding.o : parser/hspincl.h
396 parser/U_pbinding.o : parser/hspincl.h
397 parser/U_entidt.o : parser/hspincl.h
398 parser/U_list.o : parser/hspincl.h
399 parser/U_literal.o : parser/hspincl.h
400 parser/U_maybe.o : parser/hspincl.h
401 parser/U_either.o : parser/hspincl.h
402 parser/U_qid.o : parser/hspincl.h
403 parser/U_tree.o : parser/hspincl.h
404 parser/U_ttype.o : parser/hspincl.h
405 parser/printtree.o : parser/hspincl.h
406 reader/ReadPrefix.o : parser/hspincl.h