[project @ 1999-06-24 13:05:53 by simonmar]
[ghc-hetmet.git] / ghc / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # $Id: Makefile,v 1.63 1999/06/24 13:05:53 simonmar 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
21 # Note: there have been reports of people running up against the ARG_MAX limit
22 # when linking hsc with all its constituent object files. The likely source of 
23 # the problem is that the environment is a bit too big, so a workaround could
24 # be to do ` env PATH=$(PATH) make hsc 'to minimise the environment. (or the
25 # equivalent of `env' if it doesn't exist locally).
26 #
27 HS_PROG=hsc$(_way)
28
29
30 # -----------------------------------------------------------------------------
31 #               Compilation history for Patrick
32
33 # Make the sources first, because that's what the compilation history needs
34 $(HS_PROG) :: $(HS_SRCS)
35
36
37 # -----------------------------------------------------------------------------
38 #               Set SRCS, LOOPS, HCS, OBJS
39 #
40 # First figure out DIRS, the source sub-directories
41 # Then derive SRCS by looking in them
42 #
43
44 DIRS = \
45   utils basicTypes types hsSyn prelude rename typecheck deSugar coreSyn \
46   specialise simplCore stranal stgSyn simplStg codeGen absCSyn main \
47   profiling parser usageSP cprAnalysis
48
49
50 ifeq ($(GhcWithNativeCodeGen),YES)
51 DIRS += nativeGen
52 else
53 SRC_HC_OPTS += -DOMIT_NATIVE_CODEGEN
54 endif
55
56
57 HS_SRCS = $(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
58
59 ifneq "$(GhcWithHscBuiltViaC)" "YES"
60 HS_SRCS += rename/ParseIface.hs parser/Parser.hs
61 endif
62
63 HCS      = $(patsubst %.lhs, %.hc, $(patsubst %.hs, %.hc, $(HS_SRCS)))
64
65 # ParseIface.hs ain't part of HS_SRCS when this is on..
66 ifeq "$(GhcWithHscBuiltViaC)" "YES"
67 HCS      += rename/ParseIface.hc parser/Parser.hc
68 endif
69
70 HS_OBJS  = \
71   $(patsubst %.hc, %.o, $(HCS)) \
72   parser/ctypes.o parser/hschooks.o
73
74
75 DESTDIR       = $(INSTALL_LIBRARY_DIR_GHC)
76
77 #
78 # Add misc .c helper code (used by the frontend.)
79 #
80 C_SRCS += parser/ctypes.c parser/hschooks.c
81
82 #
83 # Big Fudge to get around inherent problem that Makefile setup
84 # has got with 'mkdependC'.
85
86 SRC_MKDEPENDC_OPTS += -D__GLASGOW_HASKELL__=$(ProjectVersionInt)
87
88 # stuff you get for free in a source distribution
89
90 # SRC_DIST_FILES += rename/ParseIface.hs \
91 #  parser/U_tree.c parser/tree.h parser/tree.c \
92 #  parser/hsparser.tab.c parser/hsparser.tab.h \
93 #  parser/hslexer.c
94
95 # -----------------------------------------------------------------------------
96 #               Haskell compilations
97
98 #
99 # Compiler to use for building hsc, use the build tree
100 # driver when booting.
101 #
102 ifneq "$(GhcWithHscBuiltViaC)" "YES"
103 HC=$(WithGhcHc)
104 else
105 HC=$(GHC_DRIVER_DIR)/ghc
106 endif
107
108 # magic from GNU make manual to convert a list of values
109 # into a colon-separated list
110 empty:=
111 space:= $(empty) $(empty)
112
113 SRC_HC_OPTS += \
114   -cpp -fglasgow-exts -Rghc-timing \
115   -I. -IcodeGen -InativeGen -Iparser \
116   -i$(subst $(space),:,$(DIRS))
117
118 SRC_CC_OPTS += -Iparser -I. -I$(TOP)/includes -O
119
120 SRC_HC_OPTS += -recomp $(GhcHcOpts)
121
122 #       Special flags for particular modules
123 #       The standard suffix rule for compiling a Haskell file
124 #       adds these flags to the command line
125
126 # Was 6m with 2.10
127 absCSyn/PprAbsC_HC_OPTS         = -H10m
128
129 basicTypes/IdInfo_HC_OPTS       = -K2m
130 codeGen/CgCase_HC_OPTS          = -fno-prune-tydecls
131 hsSyn/HsExpr_HC_OPTS            = -K2m
132 main/Main_HC_OPTS               = -fvia-C
133 main/Constants_HC_OPTS          = -DHscIfaceFileVersion=$(HscIfaceFileVersion)
134
135 ifneq "$(GhcWithHscBuiltViaC)" "YES"
136 ifeq "$(GhcReportCompiles)" "YES"
137 main/Main_HC_OPTS               += -syslib misc -DREPORT_TO_MOTHERLODE
138 endif
139 endif
140
141 main/CmdLineOpts_HC_OPTS        = -fvia-C -K6m
142 nativeGen/PprMach_HC_OPTS       = -K2m
143 nativeGen/MachMisc_HC_OPTS      = -K2m -fvia-C
144 nativeGen/MachCode_HC_OPTS      = -H10m
145
146 # Avoids Bug in 3.02, it seems
147 usageSP/UsageSPInf_HC_OPTS      = -Onot
148
149 prelude/PrimOp_HC_OPTS          = -H12m -K3m
150 parser/Lex_HC_OPTS              = -K2m -H16m -fvia-C
151
152 # -dcore-lint is *temporary* to work around ghc space leak.
153 rename/ParseIface_HC_OPTS       += -Onot -H45m -K2m -dcore-lint -fno-warn-incomplete-patterns -dcore-lint
154 rename/ParseIface_HAPPY_OPTS    += -g
155
156 parser/Parser_HC_OPTS           += -Onot -H80m -K2m -dcore-lint -fno-warn-incomplete-patterns -dcore-lint
157 parser/Parser_HAPPY_OPTS        += -g
158
159 ifeq "$(TARGETPLATFORM)" "hppa1.1-hp-hpux9"
160 rename/RnMonad_HC_OPTS          = -fvia-C -O2 -O2-for-C
161 endif
162
163 rename/RnEnv_HC_OPTS            = -fvia-C
164 rename/RnSource_HC_OPTS         = -H12m
165 rename/RnIfaces_HC_OPTS         = -H8m -fvia-C
166 rename/RnExpr_HC_OPTS           = -H10m
167 rename/RnNames_HC_OPTS          = -H12m
168 rename/RnMonad_HC_OPTS          = -fvia-C
169 specialise/Specialise_HC_OPTS   = -Onot -H12m
170 simplCore/Simplify_HC_OPTS      = -H15m 
171 typecheck/TcGenDeriv_HC_OPTS    = -H10m
172
173 # tmp, -- SDM
174 specialise/Specialise_HC_OPTS   += -fno-prune-tydecls
175 hsSyn/HsBasic_HC_OPTS           += -fno-prune-tydecls
176 simplCore/SimplMonad_HC_OPTS    += -fno-prune-tydecls
177 absCSyn/AbsCSyn_HC_OPTS         += -fno-prune-tydecls
178 absCSyn/AbsCUtils_HC_OPTS       += -fno-prune-tydecls
179 codeGen/CgBindery_HC_OPTS       += -fno-prune-tydecls
180 codeGen/CgLetNoEscape_HC_OPTS   += -fno-prune-tydecls
181 codeGen/CgExpr_HC_OPTS          += -fno-prune-tydecls
182 nativeGen/AbsCStixGen_HC_OPTS   += -fno-prune-tydecls
183
184 # Was 10m for 2.10
185 typecheck/TcHsSyn_HC_OPTS       = -H15m 
186
187
188 # Was 10m for 2.10
189 typecheck/TcExpr_HC_OPTS        = -H15m
190 typecheck/TcBinds_HC_OPTS       = -H10m
191
192 typecheck/TcEnv_HC_OPTS         = -H10m
193 utils/Argv_HC_OPTS              = -fvia-C
194 utils/SST_HC_OPTS               = -fvia-C
195 utils/FastString_HC_OPTS        = -fvia-C
196 utils/StringBuffer_HC_OPTS      = -fvia-C -fno-prune-tydecls
197 utils/Digraph_HC_OPTS           = -fglasgow-exts -fvia-C
198 utils/DirUtils_HC_OPTS          = -fvia-C
199
200 ifeq "$(alpha_HOST_ARCH)" "1"
201 # "stbu" bug in alpha native code generator...
202 basicTypes/Unique_HC_OPTS       = -fvia-C
203 endif
204
205 # flags for PrimPacked:
206 #
207 # -monly-3-regs 
208 #       because it contains a 'ccall strlen', which gets inlined by
209 #       gcc, causing a lack of registers.
210 #
211 # -optC-funfolding-interface-threshold10
212 #       To stop the definition of 'strLength', which calls strlen, getting
213 #       into the interface file and spreading the -monly-3-regs virus.
214 #       We need -optC here because the driver before 3.02 didn't understand
215 #       the -funfolding flags.
216
217 utils/PrimPacked_HC_OPTS        = -fvia-C -monly-3-regs -optC-funfolding-interface-threshold10
218
219 # Strictness analyser misbehaving in 2.10, fails to terminate on
220 # UpdAnal.lhs due to weird recursive datatype.  Bug was exposed by a
221 # separate bugfix to the fixpoint finder.
222 simplStg/UpdAnal_HC_OPTS        = -fno-strictness
223
224 # ----------------------------------------------------------------------------
225 #               C compilations
226
227 SRC_C_OPTS     += -O -I. -IcodeGen
228
229
230 # ----------------------------------------------------------------------------
231 #               Parsers/lexers
232
233 parser/hschooks.o : parser/hschooks.c
234         @$(RM) $@
235         $(HC) -c -o $@ -I$(GHC_INCLUDE_DIR) $(HC_OPTS) parser/hschooks.c
236
237
238 # Interface-file parser uses Happy
239 SRC_HAPPY_OPTS += +RTS -K2m -H10m -RTS
240
241 rename/ParseIface.hs : rename/ParseIface.y
242         @$(RM) rename/ParseIface.hs rename/ParseIface.hinfo
243         $(HAPPY) $(HAPPY_OPTS) -g rename/ParseIface.y
244         @chmod 444 rename/ParseIface.hs
245
246 parser/Parser.hs : parser/Parser.y
247         @$(RM) parser/Parser.hs parser/ParseIface.hinfo
248         $(HAPPY) $(HAPPY_OPTS) -g parser/Parser.y
249         @chmod 444 parser/Parser.hs
250
251 #-----------------------------------------------------------------------------
252 #               Linking
253
254 SRC_LD_OPTS += -no-link-chk
255
256 ifneq "$(GhcWithHscBuiltViaC)" "YES"
257 ifeq "$(GhcReportCompiles)" "YES"
258 SRC_LD_OPTS += -syslib misc -syslib exts
259 endif
260 endif
261
262 #-----------------------------------------------------------------------------
263 #               install
264
265 # We don't want hsc treated as an ordinary executable,
266 # but put it together with the libraries.
267 # Also don't want any interface files intstalled
268
269 INSTALL_LIBEXECS += hsc
270
271 #-----------------------------------------------------------------------------
272 #               depend
273
274 #
275 # Before doing `make depend', need to build all derived Haskell source files
276 #
277 depend :: $(LOOPS)
278
279 ifneq "$(GhcWithHscBuiltViaC)" "YES"
280 depend :: rename/ParseIface.hs
281 endif
282
283 #-----------------------------------------------------------------------------
284 #               clean
285
286 CLEAN_FILES += $(wildcard */*.$(way_)o */*.$(way_)hi)
287
288 # Extra tidy, remove the .hc files (if you've got them).
289 MAINTAINER_CLEAN_FILES += $(wildcard */*.hc)
290
291
292 #-----------------------------------------------------------------------------
293 #               TAGS setup
294
295 SRC_HSTAGS_OPTS += -fglasgow-exts -cpp
296 TAGS_HS_SRCS=$(foreach dir,$(DIRS),$(wildcard $(dir)/*.lhs))
297 TAGS_C_SRCS=$(strip $(foreach f,$(foreach dir,$(DIRS),$(wildcard $(dir)/*.c)),$(shell if [ -w $(f) ]; then echo $(f); else echo ''; fi)))
298
299 #-----------------------------------------------------------------------------
300 #               Include target-rule boilerplate
301
302 include $(TOP)/mk/target.mk
303
304 parser/%.o : parser/%.c
305