[project @ 1997-10-13 09:34: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 basicTypes/IdInfo_HC_OPTS       = -K2m
151 coreSyn/AnnCoreSyn_HC_OPTS      = -fno-omit-reexported-instances
152 hsSyn/HsExpr_HC_OPTS            = -K2m
153 hsSyn/HsSyn_HC_OPTS             = -fno-omit-reexported-instances
154 main/Main_HC_OPTS               = -fvia-C -DPROJECTVERSION=$(GhcProjectVersion)
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_constr_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
162 parser/U_binding_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
163 parser/U_pbinding_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
164 parser/U_entidt_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
165 parser/U_list_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
166 parser/U_literal_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
167 parser/U_maybe_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
168 parser/U_either_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
169 parser/U_qid_HC_OPTS            = -fvia-C '-\#include"hspincl.h"'
170 parser/U_tree_HC_OPTS           = -H12m -fvia-C '-\#include"hspincl.h"'
171 parser/U_ttype_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
172 prelude/PrimOp_HC_OPTS          = -H12m -K3m
173 reader/Lex_HC_OPTS              = -K2m -H16m -fvia-C
174 reader/ReadPrefix_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
175 rename/ParseIface_HC_OPTS       += -Onot -H16m
176 rename/ParseType_HC_OPTS        += -Onot -H16m
177 rename/ParseUnfolding_HC_OPTS   += -Onot -H30m
178 ifeq "$(Ghc2_0)" "YES"
179 rename/ParseIface_HC_OPTS       += -fno-warn-incomplete-patterns
180 rename/ParseType_HC_OPTS        += -fno-warn-incomplete-patterns
181 rename/ParseUnfolding_HC_OPTS   += -fno-warn-incomplete-patterns
182 endif
183
184 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
185 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
186 else
187 ifeq "$(Ghc2_0)" "NO"
188 rename/RnMonad_HC_OPTS          = -fvia-C
189 endif
190 endif
191 rename/RnEnv_HC_OPTS            = -fvia-C
192 rename/RnSource_HC_OPTS         = -H12m
193 rename/RnIfaces_HC_OPTS         = -H8m -fvia-C
194 rename/RnNames_HC_OPTS          = -H12m
195 rename/RnMonad_HC_OPTS          = -fvia-C
196 # Urk!  Really big heap for ParseUnfolding
197 #rename/ParseUnfolding_HC_OPTS  = -H45m         
198 specialise/Specialise_HC_OPTS   = -Onot -H12m
199 stgSyn/StgSyn_HC_OPTS           = -fno-omit-reexported-instances
200 typecheck/TcGenDeriv_HC_OPTS    = -H10m
201 typecheck/TcHsSyn_HC_OPTS       = -H10m
202 typecheck/TcExpr_HC_OPTS        = -H10m
203 typecheck/TcEnv_HC_OPTS         = -H10m
204 ifeq "$(Ghc2_0)" "NO"
205 typecheck/TcMonad_HC_OPTS       = -fvia-C       
206 endif
207 utils/Argv_HC_OPTS              = -fvia-C
208 utils/SST_HC_OPTS               = -fvia-C
209 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs
210 utils/FastString_HC_OPTS        = -fvia-C -monly-3-regs
211 utils/StringBuffer_HC_OPTS      = -fvia-C
212 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
213
214 # optimiser misbehaving in 0.29, occurrence analyser fails to terminate when
215 # compiling lib/required/Time.lhs
216 ifeq "$(Ghc2_0)" "NO"
217 simplCore/OccurAnal_HC_OPTS     = -Onot
218 endif
219
220 # ----------------------------------------------------------------------------
221 #               C compilations
222
223 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
224
225
226 # ----------------------------------------------------------------------------
227 #               Parsers
228
229 # Main parser uses Yacc/Bison
230 SRC_YACC_OPTS  += -d -v
231
232 #
233 # Want to keep the intermediate (included in src distribs).
234 #
235 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
236
237 parser/hschooks.o : parser/hschooks.c
238         @$(RM) $@
239         $(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c
240
241
242 # Interface-file parser uses Happy
243 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
244
245 ifeq ($(Ghc2_0),NO)
246 SRC_HAPPY_OPTS+= -1.2
247 endif
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 rename/ParseType.hs : rename/ParseType.y
255         @$(RM) rename/ParseType.hs rename/ParseType.hinfo
256         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseType.y
257         @chmod 444 rename/ParseType.hs
258
259 rename/ParseUnfolding.hs : rename/ParseUnfolding.y
260         @$(RM) rename/ParseUnfolding.hs rename/ParseUnfolding.hinfo
261         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseUnfolding.y
262         @chmod 444 rename/ParseUnfolding.hs
263
264 #----------------------------------------------------------------------
265 #
266 # Building the stand-alone parser
267 #
268 all :: hsp
269
270 hsp: parser/printtree.o parser/main.o libhsp.a 
271         $(CC) -o $@ $(CC_OPTS) $^
272
273 CLEAN_FILES += hsp
274 #-----------------------------------------------------------------------------
275 #               Interface files
276
277 # LoopHack.lhc is an SLPJ addition to fix a profiling problem.  See comments
278 # inside it. (compilation is handled by the suffix rules).
279
280 #
281 # Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
282 #
283 ifeq "$(Ghc2_0)" "NO"
284 hi-boot :: $(LOOPS)
285
286 %.hi : %.lhi
287         $(RM) $@
288         $(UNLIT) $<  $@ || ( $(RM) $@ && exit 1 )
289         @chmod 444 $@
290
291 boot :: hi-boot
292 else
293 # hi-boot not needed when using 2.04+ as HC, defining it here
294 # to be consistent across setting of Ghc2_0
295 hi-boot :
296         @echo "Done."
297 endif
298
299 #-----------------------------------------------------------------------------
300 #               Linking
301
302 SRC_LD_OPTS += -no-link-chk
303
304 #-----------------------------------------------------------------------------
305 #               install
306
307 # We don't want hsc treated as an ordinary executable,
308 # but put it together with the libraries.
309 # Also don't want any interface files intstalled
310
311 INSTALL_LIBEXECS += hsc hsp
312
313 #-----------------------------------------------------------------------------
314 #               depend
315
316 # If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
317 #
318 # ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
319 # in a build.mk file.
320 #
321 ifeq ($(Ghc2_0),NO)
322 MKDEPENDHS      = $(MKDEPENDHS_1_2)
323 endif
324
325 #
326 # Before doing `make depend', need to build all derived Haskell source files
327 #
328 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs rename/ParseUnfolding.hs rename/ParseType.hs
329
330
331 ifeq "$(GhcWithHscBuiltViaC)" "YES"
332 ifeq "$(Ghc2_0)" "NO"
333 SRC_MKDEPENDHS_OPTS += -o hc
334 else
335 SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
336 endif
337 # When booting from .hc, (hackily) remove the suffix rule for 
338 # .l?hs -> .o, so that the .hc -> .o is used instead.
339 %.$(way_)o : %.lhs
340 %.$(way_)o : %.hs
341 else
342   SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
343 endif
344
345
346 #-----------------------------------------------------------------------------
347 #               clean
348
349 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
350                $(SRCS_UGNC) $(SRCS_UGNH) \
351                $(SRCS_UGNHS)\
352                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
353
354 # Extra tidy, remove the .hc files (if you've got them).
355 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
356
357
358 #-----------------------------------------------------------------------------
359 #               TAGS setup
360
361 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
362 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
363 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
364
365 #-----------------------------------------------------------------------------
366 #               Include target-rule boilerplate
367
368 include $(TOP)/mk/target.mk
369
370
371 #
372 # Special extra dependencies for yukky ugen stuff
373 #
374
375 parser/%.o : parser/%.c $(SRCS_UGNH)
376 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
377
378 parser/hspincl.h : $(SRCS_UGNH)
379 parser/UgenAll.o : parser/hspincl.h
380 parser/UgenUtil.o : parser/hspincl.h
381 parser/U_constr.o : parser/hspincl.h
382 parser/U_binding.o : parser/hspincl.h
383 parser/U_pbinding.o : parser/hspincl.h
384 parser/U_entidt.o : parser/hspincl.h
385 parser/U_list.o : parser/hspincl.h
386 parser/U_literal.o : parser/hspincl.h
387 parser/U_maybe.o : parser/hspincl.h
388 parser/U_either.o : parser/hspincl.h
389 parser/U_qid.o : parser/hspincl.h
390 parser/U_tree.o : parser/hspincl.h
391 parser/U_ttype.o : parser/hspincl.h
392 parser/printtree.o : parser/hspincl.h
393 reader/ReadPrefix.o : parser/hspincl.h