[project @ 1998-02-25 19:48:54 by sof]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.34 1998/02/25 19:48:54 sof Exp $
3
4 TOP = ..
5 include $(TOP)/mk/boilerplate.mk
6
7 #-----------------------------------------------------------------------------
8 # Building hsc different ways (default is just `normal' sequential)
9 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 #               Compilation history for Patrick
37
38 # Make the sources first, because that's what the compilation history needs
39 $(HS_PROG) :: $(HS_SRCS)
40
41
42 # -----------------------------------------------------------------------------
43 #               Set SRCS, LOOPS, HCS, OBJS
44 #
45 # First figure out DIRS, the source sub-directories
46 # Then derive SRCS by looking in them
47 #
48
49 DIRS = \
50   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
51   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
52   reader profiling parser
53
54
55 ifeq ($(GhcWithNativeCodeGen),YES)
56 DIRS += nativeGen
57 else
58 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
59 endif
60
61
62 HS_SRCS = $(SRCS_UGNHS) \
63           $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs)) \
64           rename/ParseIface.hs
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
78 MKDEPENDHS_SRCS = $(HS_SRCS)
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  parser/U_tree.c parser/tree.h parser/tree.c \
109  parser/hsparser.tab.c parser/hsparser.tab.h \
110  parser/hslexer.c
111
112 # -----------------------------------------------------------------------------
113 #               Haskell compilations
114
115 # Compiler to use for building hsc
116 #
117 HC=$(WithGhcHc)
118
119 # magic from GNU make manual to convert a list of values
120 # into a colon-separated list
121 empty:=
122 space:= $(empty) $(empty)
123
124 SRC_HC_OPTS += \
125   -cpp -fglasgow-exts -Rghc-timing \
126   -I. -IcodeGen -InativeGen -Iparser \
127   -i$(subst $(space),:,$(DIRS))
128
129 # -syslib ghc just needed for use of PackedString.hPutPS
130
131 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
132
133 SRC_HC_OPTS += -recomp $(GhcHcOpts)
134
135 #       Special flags for particular modules
136 #       The standard suffix rule for compiling a Haskell file
137 #       adds these flags to the command line
138
139 absCSyn/AbsCSyn_HC_OPTS         = -fno-omit-reexported-instances
140 absCSyn/CStrings_HC_OPTS        = -monly-3-regs
141
142 # Was 6m with 2.10
143 absCSyn/PprAbsC_HC_OPTS         = -H10m
144
145 basicTypes/IdInfo_HC_OPTS       = -K2m
146 coreSyn/AnnCoreSyn_HC_OPTS      = -fno-omit-reexported-instances
147 hsSyn/HsExpr_HC_OPTS            = -K2m
148 hsSyn/HsSyn_HC_OPTS             = -fno-omit-reexported-instances
149 main/Main_HC_OPTS               = -fvia-C -DPROJECTVERSION=$(GhcProjectVersion)
150 main/MkIface_HC_OPTS            = -DPROJECTVERSION=$(GhcProjectVersionInt)
151 main/CmdLineOpts_HC_OPTS        = -fvia-C
152 nativeGen/PprMach_HC_OPTS       = -K2m
153 nativeGen/MachMisc_HC_OPTS      = -K2m -fvia-C
154 nativeGen/MachCode_HC_OPTS      = -H10m
155 parser/UgenAll_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
156 parser/UgenUtil_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
157 parser/U_constr_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
158 parser/U_binding_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
159 parser/U_pbinding_HC_OPTS       = -fvia-C '-\#include"hspincl.h"'
160 parser/U_entidt_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
161 parser/U_list_HC_OPTS           = -fvia-C '-\#include"hspincl.h"'
162 parser/U_literal_HC_OPTS        = -fvia-C '-\#include"hspincl.h"'
163 parser/U_maybe_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
164 parser/U_either_HC_OPTS         = -fvia-C '-\#include"hspincl.h"'
165 parser/U_qid_HC_OPTS            = -fvia-C '-\#include"hspincl.h"'
166 parser/U_tree_HC_OPTS           = -H12m -fvia-C '-\#include"hspincl.h"'
167 parser/U_ttype_HC_OPTS          = -fvia-C '-\#include"hspincl.h"'
168 prelude/PrimOp_HC_OPTS          = -H12m -K3m
169 reader/Lex_HC_OPTS              = -K2m -H16m -fvia-C -DPROJECTVERSION=$(GhcProjectVersionInt)
170
171 # Heap was 6m with 2.10
172 reader/ReadPrefix_HC_OPTS       = -fvia-C '-\#include"hspincl.h"' -H10m
173
174 rename/ParseIface_HC_OPTS       += -Onot -H30m -fno-warn-incomplete-patterns
175
176 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
177 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
178 else
179 endif
180 rename/RnEnv_HC_OPTS            = -fvia-C
181 rename/RnSource_HC_OPTS         = -H12m
182 rename/RnIfaces_HC_OPTS         = -H8m -fvia-C
183 rename/RnExpr_HC_OPTS           = -H10m
184 rename/RnNames_HC_OPTS          = -H12m
185 rename/RnMonad_HC_OPTS          = -fvia-C
186 # Urk!  Really big heap for ParseUnfolding
187 #rename/ParseUnfolding_HC_OPTS  = -H45m         
188 specialise/Specialise_HC_OPTS   = -Onot -H12m
189 stgSyn/StgSyn_HC_OPTS           = -fno-omit-reexported-instances
190 typecheck/TcGenDeriv_HC_OPTS    = -H10m
191
192 # Was 10m for 2.10
193 typecheck/TcHsSyn_HC_OPTS       = -H15m 
194
195 # Was 10m for 2.10
196 typecheck/TcExpr_HC_OPTS        = -H15m
197
198 typecheck/TcEnv_HC_OPTS         = -H10m
199 utils/Argv_HC_OPTS              = -fvia-C -monly-3-regs
200 utils/SST_HC_OPTS               = -fvia-C
201 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs
202 utils/FastString_HC_OPTS        = -fvia-C -monly-3-regs
203 utils/StringBuffer_HC_OPTS      = -fvia-C
204 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
205 utils/Outputable_HC_OPTS        = -monly-3-regs
206
207 # Strictness analyser misbehaving in 2.10, fails to terminate on
208 # UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
209 # separate bugfix to the fixpoint finder.
210 simplStg/UpdAnal_HC_OPTS        = -fno-strictness
211
212 # ----------------------------------------------------------------------------
213 #               C compilations
214
215 SRC_C_OPTS     += -O -Iparser -I. -IcodeGen
216
217
218 # ----------------------------------------------------------------------------
219 #               Parsers
220
221 # Main parser uses Yacc/Bison
222 SRC_YACC_OPTS  += -d -v
223
224 #
225 # Want to keep the intermediate (included in src distribs).
226 #
227 .PRECIOUS: %.tab.c %.tab.h parser/hslexer.c
228
229 parser/hschooks.o : parser/hschooks.c
230         @$(RM) $@
231         $(HC) -c -o $@ $(HCFLAGS) parser/hschooks.c
232
233
234 # Interface-file parser uses Happy
235 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
236
237 rename/ParseIface.hs : rename/ParseIface.y
238         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
239         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
240         @chmod 444 rename/ParseIface.hs
241
242 #----------------------------------------------------------------------
243 #
244 # Building the stand-alone parser
245 #
246 all :: hsp
247
248 hsp: parser/printtree.o parser/main.o libhsp.a 
249         $(CC) -o $@ $(CC_OPTS) $^
250
251 CLEAN_FILES += hsp
252
253 #-----------------------------------------------------------------------------
254 #               Linking
255
256 SRC_LD_OPTS += -no-link-chk
257
258 #-----------------------------------------------------------------------------
259 #               install
260
261 # We don't want hsc treated as an ordinary executable,
262 # but put it together with the libraries.
263 # Also don't want any interface files intstalled
264
265 INSTALL_LIBEXECS += hsc hsp
266
267 #-----------------------------------------------------------------------------
268 #               depend
269
270 #
271 # Before doing `make depend', need to build all derived Haskell source files
272 #
273 depend :: $(LOOPS) $(SRCS_UGNHS) rename/ParseIface.hs
274
275
276 ifeq "$(GhcWithHscBuiltViaC)" "YES"
277 SRC_MKDEPENDHS_OPTS += -optdep-o -optdephc
278
279 # When booting from .hc, (hackily) remove the suffix rule for 
280 # .l?hs -> .o, so that the .hc -> .o is used instead.
281 %.$(way_)o : %.lhs
282 %.$(way_)o : %.hs
283 else
284   SRCS_MKDEPENDHS = $(SRCS_HC) # should add $(LOOPS) ?
285 endif
286
287
288 #-----------------------------------------------------------------------------
289 #               clean
290
291 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi) \
292                $(SRCS_UGNC) $(SRCS_UGNH) \
293                $(SRCS_UGNHS)\
294                parser/hslexer.c parser/hsparser.tab.h parser/hsparser.tab.c
295
296 # Extra tidy, remove the .hc files (if you've got them).
297 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
298
299
300 #-----------------------------------------------------------------------------
301 #               TAGS setup
302
303 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
304 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
305 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
306
307 #-----------------------------------------------------------------------------
308 #               Include target-rule boilerplate
309
310 include $(TOP)/mk/target.mk
311
312
313 #
314 # Special extra dependencies for yukky ugen stuff
315 #
316
317 parser/%.o : parser/%.c $(SRCS_UGNH)
318 parser/hslexer.o : parser/hslexer.c parser/hsparser.tab.h
319
320 parser/hspincl.h : $(SRCS_UGNH)
321 parser/UgenAll.o : parser/hspincl.h
322 parser/UgenUtil.o : parser/hspincl.h
323 parser/U_constr.o : parser/hspincl.h
324 parser/U_binding.o : parser/hspincl.h
325 parser/U_pbinding.o : parser/hspincl.h
326 parser/U_entidt.o : parser/hspincl.h
327 parser/U_list.o : parser/hspincl.h
328 parser/U_literal.o : parser/hspincl.h
329 parser/U_maybe.o : parser/hspincl.h
330 parser/U_either.o : parser/hspincl.h
331 parser/U_qid.o : parser/hspincl.h
332 parser/U_tree.o : parser/hspincl.h
333 parser/U_ttype.o : parser/hspincl.h
334 parser/printtree.o : parser/hspincl.h
335 reader/ReadPrefix.o : parser/hspincl.h