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