[project @ 1997-09-22 09:13:27 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 ($(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 # magic from GNU make manual to convert a list of values
125 # into a colon-separated list
126 empty:=
127 space:= $(empty) $(empty)
128
129 SRC_HC_OPTS += \
130   -cpp -fglasgow-exts -Rghc-timing \
131   -I. -IcodeGen -InativeGen -Iparser \
132   -i$(subst $(space),:,$(DIRS))
133
134 ifeq "$(Ghc2_0)" "NO"
135 SRC_HC_OPTS += -fhaskell-1.3
136 endif
137
138 # -syslib ghc just needed for use of PackedString.hPutPS
139
140 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
141
142 ifeq "$(Ghc2_0)" "NO"
143 SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
144 else
145 SRC_HC_OPTS += -recomp
146 endif
147
148 ifeq ($(GhcWithDeforester),NO)
149  ifeq "$(Ghc2_0)" "NO"
150   SRC_MKDEPENDHS_OPTS += -DOMIT_DEFORESTER
151  endif
152 SRC_HC_OPTS += -DOMIT_DEFORESTER
153 endif
154
155 SRC_HC_OPTS += $(GhcHcOpts)
156
157 #       Special flags for particular modules
158 #       The standard suffix rule for compiling a Haskell file
159 #       adds these flags to the command line
160
161 absCSyn/AbsCSyn_HC_OPTS         = -fno-omit-reexported-instances
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 reader/ReadPrefix_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
187 rename/ParseIface_HC_OPTS       += -Onot -H16m
188 rename/ParseType_HC_OPTS        += -Onot -H16m
189 rename/ParseUnfolding_HC_OPTS   += -Onot -H30m
190 ifeq "$(Ghc2_0)" "YES"
191 rename/ParseIface_HC_OPTS       += -fno-warn-incomplete-patterns
192 rename/ParseType_HC_OPTS        += -fno-warn-incomplete-patterns
193 rename/ParseUnfolding_HC_OPTS   += -fno-warn-incomplete-patterns
194 endif
195
196 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
197 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
198 else
199 ifeq "$(Ghc2_0)" "NO"
200 rename/RnMonad_HC_OPTS          = -fvia-C
201 endif
202 endif
203 rename/RnEnv_HC_OPTS            = -fvia-C
204 rename/RnSource_HC_OPTS         = -H12m
205 rename/RnIfaces_HC_OPTS         = -H8m -fvia-C
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 typecheck/TcHsSyn_HC_OPTS       = -H10m
214 typecheck/TcExpr_HC_OPTS        = -H10m
215 typecheck/TcEnv_HC_OPTS         = -H10m
216 ifeq "$(Ghc2_0)" "NO"
217 typecheck/TcMonad_HC_OPTS       = -fvia-C       
218 endif
219 utils/Argv_HC_OPTS              = -fvia-C
220 utils/SST_HC_OPTS               = -fvia-C
221 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs
222 utils/FastString_HC_OPTS        = -fvia-C -monly-3-regs
223 utils/StringBuffer_HC_OPTS      = -fvia-C
224 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
225
226 # optimiser misbehaving in 0.29, occurrence analyser fails to terminate when
227 # compiling lib/required/Time.lhs
228 ifeq "$(Ghc2_0)" "NO"
229 simplCore/OccurAnal_HC_OPTS     = -Onot
230 endif
231
232 # ----------------------------------------------------------------------------
233 #               C compilations
234
235 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
236
237
238 # ----------------------------------------------------------------------------
239 #               Parsers
240
241 # Main parser uses Yacc/Bison
242 SRC_YACC_OPTS  += -d -v
243
244 #
245 # Want to keep the intermediate (included in src distribs).
246 #
247 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
248
249 parser/hschooks.o : parser/hschooks.c
250         @$(RM) $@
251         $(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c
252
253
254 # Interface-file parser uses Happy
255 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
256
257 ifeq ($(Ghc2_0),NO)
258 SRC_HAPPY_OPTS+= -1.2
259 endif
260
261 rename/ParseIface.hs : rename/ParseIface.y
262         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
263         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
264         @chmod 444 rename/ParseIface.hs
265
266 rename/ParseType.hs : rename/ParseType.y
267         @$(RM) rename/ParseType.hs rename/ParseType.hinfo
268         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseType.y
269         @chmod 444 rename/ParseType.hs
270
271 rename/ParseUnfolding.hs : rename/ParseUnfolding.y
272         @$(RM) rename/ParseUnfolding.hs rename/ParseUnfolding.hinfo
273         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseUnfolding.y
274         @chmod 444 rename/ParseUnfolding.hs
275
276 #----------------------------------------------------------------------
277 #
278 # Building the stand-alone parser
279 #
280 all :: hsp
281
282 hsp: parser/printtree.o parser/main.o libhsp.a 
283         $(CC) -o $@ $(CC_OPTS) $^
284
285 CLEAN_FILES += hsp
286 #-----------------------------------------------------------------------------
287 #               Interface files
288
289 # LoopHack.lhc is an SLPJ addition to fix a profiling problem.  See comments
290 # inside it. (compilation is handled by the suffix rules).
291
292 #
293 # Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
294 #
295 ifeq "$(Ghc2_0)" "NO"
296 hi-boot :: $(LOOPS)
297
298 %.hi : %.lhi
299         $(RM) $@
300         $(UNLIT) $<  $@ || ( $(RM) $@ && exit 1 )
301         @chmod 444 $@
302
303 boot :: hi-boot
304 else
305 # hi-boot not needed when using 2.04+ as HC, defining it here
306 # to be consistent across setting of Ghc2_0
307 hi-boot :
308         @echo "Done."
309 endif
310
311 #-----------------------------------------------------------------------------
312 #               Linking
313
314 SRC_LD_OPTS += -no-link-chk
315
316 #-----------------------------------------------------------------------------
317 #               install
318
319 # We don't want hsc treated as an ordinary executable,
320 # but put it together with the libraries.
321 # Also don't want any interface files intstalled
322
323 INSTALL_LIBEXECS += hsc hsp
324
325 #-----------------------------------------------------------------------------
326 #               depend
327
328 # If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
329 #
330 # ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
331 # in a build.mk file.
332 #
333 ifeq ($(Ghc2_0),NO)
334 MKDEPENDHS      = $(MKDEPENDHS_1_2)
335 endif
336
337 #
338 # Before doing `make depend', need to build all derived Haskell source files
339 #
340 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs rename/ParseUnfolding.hs rename/ParseType.hs
341
342
343 ifeq "$(GhcWithHscBuiltViaC)" "YES"
344 ifeq "$(Ghc2_0)" "NO"
345 SRC_MKDEPENDHS_OPTS += -o hc
346 else
347 SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
348 endif
349 # When booting from .hc, (hackily) remove the suffix rule for 
350 # .l?hs -> .o, so that the .hc -> .o is used instead.
351 %.$(way_)o : %.lhs
352 %.$(way_)o : %.hs
353 else
354   SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
355 endif
356
357
358 #-----------------------------------------------------------------------------
359 #               clean
360
361 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
362                $(SRCS_UGNC) $(SRCS_UGNH) \
363                $(SRCS_UGNHS)\
364                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
365
366 # Extra tidy, remove the .hc files (if you've got them).
367 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
368
369
370 #-----------------------------------------------------------------------------
371 #               TAGS setup
372
373 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
374 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
375 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
376
377 #-----------------------------------------------------------------------------
378 #               Include target-rule boilerplate
379
380 include $(TOP)/mk/target.mk
381
382
383 #
384 # Special extra dependencies for yukky ugen stuff
385 #
386
387 parser/%.o : parser/%.c $(SRCS_UGNH)
388 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
389
390 parser/hspincl.h : $(SRCS_UGNH)
391 parser/UgenAll.o : parser/hspincl.h
392 parser/UgenUtil.o : parser/hspincl.h
393 parser/U_constr.o : parser/hspincl.h
394 parser/U_binding.o : parser/hspincl.h
395 parser/U_pbinding.o : parser/hspincl.h
396 parser/U_entidt.o : parser/hspincl.h
397 parser/U_list.o : parser/hspincl.h
398 parser/U_literal.o : parser/hspincl.h
399 parser/U_maybe.o : parser/hspincl.h
400 parser/U_either.o : parser/hspincl.h
401 parser/U_qid.o : parser/hspincl.h
402 parser/U_tree.o : parser/hspincl.h
403 parser/U_ttype.o : parser/hspincl.h
404 parser/printtree.o : parser/hspincl.h
405 reader/ReadPrefix.o : parser/hspincl.h