[project @ 1997-07-04 01:19:20 by sof]
[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 override 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 ($(GhcWithDeforester),YES)
48   DIRS += deforest
49 endif
50
51 ifeq ($(GhcWithNativeCodeGen),YES)
52 DIRS += nativeGen
53 else
54 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
55 endif
56
57
58 HS_SRCS = $(SRCS_UGNHS) \
59           $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
60           rename/ParseIface.hs rename/ParseType.hs rename/ParseUnfolding.hs \
61           main/LoopHack.hc 
62
63 # NB: it's no good to include *.hs in the top-line wildcard, because the .hs files
64 #     in parser/ may not have been created at that point.
65
66
67 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
68
69 #
70 # When booting using a ghc-2.xx compiler, the loop breakers are actually written in
71 # Haskell, source stubs just re-exporting info from the various .hi-boot files.
72 # (Reason: we don't want to fiddle with the imports in the sources). We give them
73 # the suffix .hs, since they're special and don't fall under the umbrella of $(HS_SRCS)
74 # always (only when $(Ghc2_0) is equal to YES)
75 ifeq "$(Ghc2_0)" "YES"
76 MKDEPENDHS_SRCS = $(HS_SRCS)
77 else
78 LOOPS   = $(patsubst %.lhi, %.hi, $(wildcard */*.lhi))
79 endif
80  
81 HS_OBJS  = \
82   $(patsubst %.hc, %.o, $(HCS)) \
83   parser/hsclink.o parser/hschooks.o libhsp.a
84
85
86 DESTDIR         = $(INSTALL_LIBRARY_DIR_GHC)
87
88 SRCS_UGN      = $(wildcard parser/*.ugn)
89 SRCS_UGNC     = $(patsubst %.ugn, %.c, $(SRCS_UGN))
90 SRCS_UGNH     = $(patsubst %.ugn, %.h, $(SRCS_UGN))
91 SRCS_UGNHS    = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
92 SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))
93
94 #
95 # Add the generated C files to the C_SRCS, so as to let `depend'
96 # generate correct dependencies for them.
97 #
98 C_SRCS += $(SRCS_UGNC)
99
100 LIBOBJS = \
101   $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
102   parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
103   parser/util.o
104
105 #
106 # stuff you get for free in a source distribution
107
108 SRC_DIST_FILES += rename/ParseIface.hs \
109  rename/ParseType.hs rename/ParseUnfolding.hs \
110  parser/U_tree.c parser/tree.h parser/tree.c \
111  parser/hsparser.tab.c parser/hsparser.tab.h \
112  parser/hslexer.c
113
114 # -----------------------------------------------------------------------------
115 #               Haskell compilations
116
117 # Compiler to use for building hsc
118 #
119 HC=$(WithGhcHc)
120
121 SRC_HC_OPTS += \
122   -cpp -fhaskell-1.3 \
123   -fglasgow-exts -DCOMPILING_GHC -Rghc-timing -I. -IcodeGen \
124   -InativeGen -Iparser $(foreach dir,$(DIRS),-i$(dir))
125
126 # -syslib ghc just needed for use of PackedString.hPutPS
127
128 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
129
130 ifeq "$(Ghc2_0)" "NO"
131 SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
132 endif
133
134 ifeq ($(GhcWithDeforester),NO)
135  ifeq "$(Ghc2_0)" "NO"
136   SRC_MKDEPENDHS_OPTS += -DOMIT_DEFORESTER
137  endif
138 SRC_HC_OPTS += -DOMIT_DEFORESTER
139 endif
140
141 SRC_HC_OPTS += $(GhcHcOpts)
142
143 #       Special flags for particular modules
144 #       The standard suffix rule for compiling a Haskell file
145 #       adds these flags to the command line
146
147 absCSyn/AbsCSyn_HC_OPTS         = -fno-omit-reexported-instances
148 basicTypes/IdInfo_HC_OPTS       = -K2m
149 coreSyn/AnnCoreSyn_HC_OPTS      = -fno-omit-reexported-instances
150 hsSyn/HsExpr_HC_OPTS            = -K2m
151 hsSyn/HsSyn_HC_OPTS             = -fno-omit-reexported-instances
152 main/Main_HC_OPTS               = -fvia-C
153 main/CmdLineOpts_HC_OPTS        = -fvia-C
154 nativeGen/PprMach_HC_OPTS       = -K2m
155 nativeGen/MachMisc_HC_OPTS      = -K2m -fvia-C
156 parser/UgenAll_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
157 parser/UgenUtil_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
158 parser/U_constr_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
159 parser/U_binding_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
160 parser/U_pbinding_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
161 parser/U_entidt_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
162 parser/U_list_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
163 parser/U_literal_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
164 parser/U_maybe_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
165 parser/U_either_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
166 parser/U_qid_HC_OPTS            = -fvia-C '-\#include"hspincl.h"'
167 parser/U_tree_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
168 parser/U_ttype_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
169 prelude/PrimOp_HC_OPTS          = -K3m
170 reader/Lex_HC_OPTS              = -K2m -H16m -fvia-C
171 ifeq "$(Ghc2_0)" "NO"
172 reader/Lex_HC_OPTS              += -fomit-derived-read
173 endif
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 -H16m
178 ifeq "$(Ghc2_0)" "YES"
179 rename/ParseIface_HC_OPTS       += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
180 rename/ParseType_HC_OPTS        += -fno-warn-incomplete-patterns -fno-warn-overlapped-patterns
181 rename/ParseUnfolding_HC_OPTS   += -fno-warn-incomplete-patterns -fno-warn-overlapped-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 specialise/Specialise_HC_OPTS   = -Onot -H12m
197 stgSyn/StgSyn_HC_OPTS           = -fno-omit-reexported-instances
198 typecheck/TcGenDeriv_HC_OPTS    = -H10m
199 typecheck/TcExpr_HC_OPTS        = -H10m
200 typecheck/TcEnv_HC_OPTS         = -H10m
201 ifeq "$(Ghc2_0)" "NO"
202 typecheck/TcMonad_HC_OPTS       = -fvia-C       
203 endif
204 utils/Argv_HC_OPTS              = -fvia-C
205 utils/SST_HC_OPTS               = -fvia-C
206 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs
207 utils/FastString_HC_OPTS        = -fvia-C
208 utils/StringBuffer_HC_OPTS      = -fvia-C
209 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
210
211
212 # ----------------------------------------------------------------------------
213 #               C compilations
214
215 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
216
217
218 # ----------------------------------------------------------------------------
219 #               Parsers
220
221 # Main parser uses Yacc/Bison
222 SRC_YACC_OPTS  += -d -v
223
224 #
225 # Want to keep the intermediate (included in src distribs).
226 #
227 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
228
229 parser/hschooks.o : parser/hschooks.c
230         @$(RM) $@
231         $(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c
232
233
234 # Interface-file parser uses Happy
235 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
236
237 rename/ParseIface.hs : rename/ParseIface.y
238         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
239         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
240         @chmod 444 rename/ParseIface.hs
241
242 rename/ParseType.hs : rename/ParseType.y
243         @$(RM) rename/ParseType.hs rename/ParseType.hinfo
244         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseType.y
245         @chmod 444 rename/ParseType.hs
246
247 rename/ParseUnfolding.hs : rename/ParseUnfolding.y
248         @$(RM) rename/ParseUnfolding.hs rename/ParseUnfolding.hinfo
249         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseUnfolding.y
250         @chmod 444 rename/ParseUnfolding.hs
251
252 #----------------------------------------------------------------------
253 #
254 # Building the stand-alone parser
255 #
256 all :: hsp
257
258 hsp: parser/printtree.o parser/main.o libhsp.a 
259         $(CC) -o $@ $(CC_OPTS) $^
260
261 CLEAN_FILES += hsp
262 #-----------------------------------------------------------------------------
263 #               Interface files
264
265 # LoopHack.lhc is an SLPJ addition to fix a profiling problem.  See comments
266 # inside it. (compilation is handled by the suffix rules).
267
268 #
269 # Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
270 #
271 ifeq "$(Ghc2_0)" "NO"
272 hi-boot :: $(LOOPS)
273
274 %.hi : %.lhi
275         $(RM) $@
276         $(UNLIT) $<  $@ || ( $(RM) $@ && exit 1 )
277         @chmod 444 $@
278
279 boot :: hi-boot
280 else
281 # hi-boot not needed when using 2.04+ as HC, defining it here
282 # to be consistent across setting of Ghc2_0
283 hi-boot :
284         @echo "Done."
285 endif
286
287 #-----------------------------------------------------------------------------
288 #               Linking
289
290 SRC_LD_OPTS += -no-link-chk
291
292 #-----------------------------------------------------------------------------
293 #               install
294
295 # We don't want hsc treated as an ordinary executable,
296 # but put it together with the libraries.
297 # Also don't want any interface files intstalled
298
299 INSTALL_LIBEXECS += hsc hsp
300
301 #-----------------------------------------------------------------------------
302 #               depend
303
304 # If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
305 #
306 # ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
307 # in a build.mk file.
308 #
309 ifeq ($(Ghc2_0),NO)
310 MKDEPENDHS      = $(MKDEPENDHS_1_2)
311 endif
312
313 #
314 # Before doing `make depend', need to build all derived Haskell source files
315 #
316 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs rename/ParseUnfolding.hs rename/ParseType.hs
317
318
319 ifeq "$(GhcWithHscBuiltViaC)" "YES"
320 ifeq "$(Ghc2_0)" "NO"
321 SRC_MKDEPENDHS_OPTS += -o hc
322 else
323 SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
324 endif
325 # When booting from .hc, (hackily) remove the suffix rule for 
326 # .l?hs -> .o, so that the .hc -> .o is used instead.
327 %.$(way_)o : %.lhs
328 %.$(way_)o : %.hs
329 else
330   SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
331 endif
332
333
334 #-----------------------------------------------------------------------------
335 #               clean
336
337 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
338                $(SRCS_UGNC) $(SRCS_UGNH) \
339                $(SRCS_UGNHS)\
340                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
341
342 # Extra tidy, remove the .hc files (if you've got them).
343 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
344
345
346 #-----------------------------------------------------------------------------
347 #               TAGS
348
349 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
350
351
352 #-----------------------------------------------------------------------------
353 #               Include target-rule boilerplate
354
355 include $(TOP)/mk/target.mk
356
357
358 #
359 # Special extra dependencies for yukky ugen stuff
360 #
361
362 parser/%.o : parser/%.c $(SRCS_UGNH)
363 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
364
365 parser/hspincl.h : $(SRCS_UGNH)
366 parser/UgenAll.o : parser/hspincl.h
367 parser/UgenUtil.o : parser/hspincl.h
368 parser/U_constr.o : parser/hspincl.h
369 parser/U_binding.o : parser/hspincl.h
370 parser/U_pbinding.o : parser/hspincl.h
371 parser/U_entidt.o : parser/hspincl.h
372 parser/U_list.o : parser/hspincl.h
373 parser/U_literal.o : parser/hspincl.h
374 parser/U_maybe.o : parser/hspincl.h
375 parser/U_either.o : parser/hspincl.h
376 parser/U_qid.o : parser/hspincl.h
377 parser/U_tree.o : parser/hspincl.h
378 parser/U_ttype.o : parser/hspincl.h
379 parser/printtree.o : parser/hspincl.h
380 reader/ReadPrefix.o : parser/hspincl.h