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