021f936c2e81d4b50ab4678e6dce02432b58cd87
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.13 1997/05/19 00:22:33 sof Exp $
3
4 TOP = ..
5 include $(TOP)/mk/boilerplate.mk
6
7 #-----------------------------------------------------------------------------
8 # Building hsc different ways (default is just `normal' sequential)
9 override WAYS=$(GhcCompilerWays)
10
11 #-----------------------------------------------------------------------------
12 #               Set SUBDIRS
13
14 ifeq ($(IncludeTestDirsInBuild),YES)
15   SUBDIRS = tests
16 endif
17
18 # -----------------------------------------------------------------------------
19 #               Set HS_PROG, LIBRARY
20 # Setting HS_PROG and LIBRARY causes all targets in target.mk
21 # (included below) to kick in.
22
23 LIBRARY=libhsp.a
24
25 #
26 # Note: there have been reports of people running up against the ARG_MAX limit
27 # when linking hsc with all its constituent object files. The likely source of 
28 # the problem is that the environment is a bit too big, so a workaround could
29 # be to do ` env PATH=$(PATH) make hsc 'to minimise the environment. (or the
30 # equivalent of `env' if it doesn't exist locally).
31 #
32 HS_PROG=hsc
33
34
35 # -----------------------------------------------------------------------------
36 #               Set SRCS, LOOPS, HCS, OBJS
37 #
38 # First figure out DIRS, the source sub-directories
39 # Then derive SRCS by looking in them
40 #
41
42 DIRS = \
43   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
44   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
45   reader profiling parser
46
47
48 ifeq ($(GhcWithDeforester),YES)
49   DIRS += deforest
50 endif
51
52 ifeq ($(GhcWithNativeCodeGen),YES)
53   ifeq ($(GhcWithHscBuiltViaC),YES)
54     # If building via C, we *assume* that it is the distributed C files,
55     # which do not have a native-code generator in them
56     SRC_MKDEPENDHS_OPTS += -DOMIT_NATIVE_CODEGEN
57   else
58     DIRS += nativeGen
59   endif
60 else
61 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
62 endif
63
64
65 HS_SRCS = $(SRCS_UGNHS) \
66           $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
67           rename/ParseIface.hs rename/ParseType.hs rename/ParseUnfolding.hs \
68           main/LoopHack.hc 
69
70 # NB: it's no good to include *.hs in the top-line wildcard, because the .hs files
71 #     in parser/ may not have been created at that point.
72
73
74 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
75
76 #
77 # When booting using a ghc-2.xx compiler, the loop breakers are actually written in
78 # Haskell, source stubs just re-exporting info from the various .hi-boot files.
79 # (Reason: we don't want to fiddle with the imports in the sources). We give them
80 # the suffix .hs, since they're special and don't fall under the umbrella of $(HS_SRCS)
81 # always (only when $(Ghc2_0) is equal to YES)
82 ifeq "$(Ghc2_0)" "YES"
83 LOOPS_HS  = $(wildcard */*Loop*.hs)
84 MKDEPENDHS_SRCS = $(HS_SRCS)
85 #HS_SRCS  += $(LOOPS_HS)
86 else
87 LOOPS   = $(patsubst %.lhi, %.hi, $(wildcard */*.lhi))
88 endif
89  
90 HS_OBJS  = \
91   $(patsubst %.hc, %.o, $(HCS)) \
92   parser/hsclink.o parser/hschooks.o libhsp.a
93
94
95 DESTDIR         = $(INSTALL_LIBRARY_DIR_GHC)
96
97 SRCS_UGN      = $(wildcard parser/*.ugn)
98 SRCS_UGNC     = $(patsubst %.ugn, %.c, $(SRCS_UGN))
99 SRCS_UGNH     = $(patsubst %.ugn, %.h, $(SRCS_UGN))
100 SRCS_UGNHS    = $(patsubst parser/%.ugn, parser/U_%.hs, $(SRCS_UGN))
101 SRCS_UGN_OBJS = $(patsubst %.c, %.o, $(SRCS_UGNC))
102
103 #
104 # Add the generated C files to the C_SRCS, so as to let `depend'
105 # generate correct dependencies for them.
106 #
107 C_SRCS += $(SRCS_UGNC)
108
109 LIBOBJS = \
110   $(SRCS_UGN_OBJS) parser/hslexer.o parser/hsparser.tab.o \
111   parser/id.o parser/infix.o parser/syntax.o parser/type2context.o \
112   parser/util.o
113
114 #
115 # stuff you get for free in a source distribution
116
117 SRC_DIST_FILES += rename/ParseIface.hs \
118  rename/ParseType.hs rename/ParseUnfolding.hs \
119  parser/U_tree.c parser/tree.h parser/tree.c \
120  parser/hsparser.tab.c parser/hsparser.tab.h \
121  parser/hslexer.c
122
123 # -----------------------------------------------------------------------------
124 #               Haskell compilations
125
126 # Compiler to use for building hsc
127 #
128 HC=$(WithGhcHc)
129
130 SRC_HC_OPTS += \
131   -cpp -fhaskell-1.3 \
132   -fglasgow-exts -DCOMPILING_GHC -Rghc-timing -I. -IcodeGen \
133   -InativeGen -Iparser $(foreach dir,$(DIRS),-i$(dir))
134
135 # -syslib ghc just needed for use of PackedString.hPutPS
136
137
138 SRC_CC_OPTS += -Iparser -I.
139
140 ifeq "$(Ghc2_0)" "NO"
141 SRC_HC_OPTS += -fomit-derived-read -fomit-reexported-instances
142 else
143 # Recompilation checking - unconditionally so (ToDo: move to mk/config.mk.in)
144 SRC_HC_OPTS += -recomp
145 endif
146
147 ifeq ($(GhcWithDeforester),NO)
148 ifeq "$(Ghc2_0)" "NO"
149   SRC_MKDEPENDHS_OPTS += -DOMIT_DEFORESTER
150 endif
151 SRC_HC_OPTS += -DOMIT_DEFORESTER
152 endif
153
154 SRC_HC_OPTS += $(GhcHcOpts)
155
156 #       Special flags for particular modules
157 #       The standard suffix rule for compiling a Haskell file
158 #       adds these flags to the command line
159
160 absCSyn/AbsCSyn_HC_OPTS         = -fno-omit-reexported-instances
161 basicTypes/IdInfo_HC_OPTS       = -K2m
162 coreSyn/AnnCoreSyn_HC_OPTS      = -fno-omit-reexported-instances
163 hsSyn/HsExpr_HC_OPTS            = -K2m
164 hsSyn/HsSyn_HC_OPTS             = -fno-omit-reexported-instances
165 main/Main_HC_OPTS               = -fvia-C
166 main/CmdLineOpts_HC_OPTS        = -fvia-C
167 nativeGen/PprMach_HC_OPTS       = -K2m
168 nativeGen/MachMisc_HC_OPTS      = -K2m -fvia-C
169 parser/UgenAll_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
170 parser/UgenUtil_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
171 parser/U_constr_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
172 parser/U_binding_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
173 parser/U_pbinding_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
174 parser/U_entidt_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
175 parser/U_list_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
176 parser/U_literal_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
177 parser/U_maybe_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
178 parser/U_either_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
179 parser/U_qid_HC_OPTS            = -fvia-C '-\#include"hspincl.h"'
180 parser/U_tree_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
181 parser/U_ttype_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
182 prelude/PrimOp_HC_OPTS          = -K3m
183 reader/Lex_HC_OPTS              = -K2m -H16m -fvia-C
184 ifeq "$(Ghc2_0)" "NO"
185 reader/Lex_HC_OPTS              += -fomit-derived-read
186 endif
187 reader/ReadPrefix_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
188 rename/ParseIface_HC_OPTS       = -Onot -H16m
189 rename/ParseType_HC_OPTS        = -Onot -H16m
190 rename/ParseUnfolding_HC_OPTS   = -Onot -H16m
191 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
192 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
193 else
194 rename/RnMonad_HC_OPTS          = -fvia-C
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 specialise/Specialise_HC_OPTS   = -Onot -H12m
201 stgSyn/StgSyn_HC_OPTS           = -fno-omit-reexported-instances
202 typecheck/TcGenDeriv_HC_OPTS    = -H10m
203 typecheck/TcExpr_HC_OPTS        = -H10m
204 typecheck/TcEnv_HC_OPTS         = -H10m
205 utils/Argv_HC_OPTS              = -fvia-C
206 utils/SST_HC_OPTS               = -fvia-C
207 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs
208 utils/FastString_HC_OPTS        = -fvia-C
209 utils/StringBuffer_HC_OPTS      = -fvia-C
210 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
211
212
213 # ----------------------------------------------------------------------------
214 #               C compilations
215
216 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
217
218
219 # ----------------------------------------------------------------------------
220 #               Parsers
221
222 # Main parser uses Yacc/Bison
223 SRC_YACC_OPTS  += -d -v
224
225 #
226 # Want to keep the intermediate (included in src distribs).
227 #
228 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
229
230 parser/hschooks.o : parser/hschooks.c
231         @$(RM) $@
232         $(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c
233
234
235 # Interface-file parser uses Happy
236 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
237
238 rename/ParseIface.hs : rename/ParseIface.y
239         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
240         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
241         @chmod 444 rename/ParseIface.hs
242
243 rename/ParseType.hs : rename/ParseType.y
244         @$(RM) rename/ParseType.hs rename/ParseType.hinfo
245         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseType.y
246         @chmod 444 rename/ParseType.hs
247
248 rename/ParseUnfolding.hs : rename/ParseUnfolding.y
249         @$(RM) rename/ParseUnfolding.hs rename/ParseUnfolding.hinfo
250         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseUnfolding.y
251         @chmod 444 rename/ParseUnfolding.hs
252
253 #----------------------------------------------------------------------
254 #
255 # Building the stand-alone parser
256 #
257 all :: hsp
258
259 hsp: parser/printtree.o parser/main.o libhsp.a 
260         $(CC) -o $@ $(CC_OPTS) $^
261
262 CLEAN_FILES += hsp
263 #-----------------------------------------------------------------------------
264 #               Interface files
265
266 # LoopHack.lhc is an SLPJ addition to fix a profiling problem.  See comments
267 # inside it. (compilation is handled by the suffix rules).
268
269 #
270 # Building the loop breakers from .lhi (0.2x) or .hi-boot (2.xx) files
271 #
272 ifeq ($(Ghc2_0),YES)
273
274 BOOT_HI_STEMS = $(basename $(wildcard */*.hi-boot))
275
276 hi-boot :: 
277         @for n in $(BOOT_HI_STEMS); \
278         do  \
279           echo Creating $$n.hi ; \
280           $(RM) $$n.hi ; \
281           $(CP) $$n.hi-boot $$n.hi || ( $(RM) $$n.hi && exit 1 ) ; \
282         done 
283 #
284 # Have the collector *Loop.hs interface files be generated just after having
285 # created the .hi's from the .hi-boot's. 
286
287 hi-boot :: $(patsubst %.hs,%.hi,$(LOOPS_HS))
288
289 else
290 %.hi : %.lhi
291         $(RM) $@
292         $(UNLIT) $<  $@ || ( $(RM) $@ && exit 1 )
293         @chmod 444 $@
294 endif
295
296 boot :: hi-boot
297
298 #-----------------------------------------------------------------------------
299 #               Linking
300
301 SRC_LD_OPTS += -no-link-chk
302
303 # Build-specific
304 #SRC_LD_OPTS += "-pgml time gcc -B/projects/unsupported/gnu/sparc-sunos5/bin/g"
305
306
307 #-----------------------------------------------------------------------------
308 #               install
309
310 # We don't want hsc treated as an ordinary executable,
311 # but put it together with the libraries.
312 # Also don't want any interface files intstalled
313
314 INSTALL_LIBEXECS += hsc hsp
315
316 #-----------------------------------------------------------------------------
317 #               depend
318
319 # If we're using a 1.2 compiler to compile the compiler, need the old mkdepend stuff
320 #
321 # ToDo: define sep MKDEPENDHS_1.2 variable so that it can be readily overridden
322 # in a build.mk file.
323 #
324 ifeq ($(Ghc2_0),NO)
325 MKDEPENDHS      = $(MKDEPENDHS_1_2)
326 endif
327
328 #
329 # Before doing `make depend', need to build all derived Haskell source files
330 #
331 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs rename/ParseUnfolding.hs rename/ParseType.hs
332
333
334 ifeq "$(GhcWithHscBuiltViaC)" "YES"
335 SRC_MKDEPENDHS_OPTS += -o .hc
336 # When booting from .hc, (hackily) remove the suffix rule for 
337 # .l?hs -> .o, so that the .hc -> .o is used instead.
338 %.$(way_)o : %.lhs
339 %.$(way_)o : %.hs
340 else
341   SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
342 endif
343
344
345 #-----------------------------------------------------------------------------
346 #               clean
347
348 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
349                $(SRCS_UGNC) $(SRCS_UGNH) \
350                $(SRCS_UGNHS)\
351                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
352
353 # Extra tidy, remove the .hc files (if you've got them).
354 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
355
356
357 #-----------------------------------------------------------------------------
358 #               TAGS
359
360 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
361
362
363 #-----------------------------------------------------------------------------
364 #               Include target-rule boilerplate
365
366 include $(TOP)/mk/target.mk
367
368 #
369 # Special extra dependencies for yukky ugen stuff
370 #
371
372 parser/%.o : parser/%.c $(SRCS_UGNH)
373 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
374
375 parser/hspincl.h : $(SRCS_UGNH)
376 parser/UgenAll.o : parser/hspincl.h
377 parser/UgenUtil.o : parser/hspincl.h
378 parser/U_constr.o : parser/hspincl.h
379 parser/U_binding.o : parser/hspincl.h
380 parser/U_pbinding.o : parser/hspincl.h
381 parser/U_entidt.o : parser/hspincl.h
382 parser/U_list.o : parser/hspincl.h
383 parser/U_literal.o : parser/hspincl.h
384 parser/U_maybe.o : parser/hspincl.h
385 parser/U_either.o : parser/hspincl.h
386 parser/U_qid.o : parser/hspincl.h
387 parser/U_tree.o : parser/hspincl.h
388 parser/U_ttype.o : parser/hspincl.h
389 parser/printtree.o : parser/hspincl.h
390 reader/ReadPrefix.o : parser/hspincl.h