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