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