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