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