Fix SPARC build, missing #include
[ghc-hetmet.git] / compiler / Makefile
1 # -----------------------------------------------------------------------------
2 # Main compiler Makefile
3
4 # Targets:
5 #
6 #       all     builds stage1 compiler
7 #
8 #       boot stage=N   generate build dirs and dependencies for stage N.
9 #                      NB. Must be done before 'make stageN'.
10 #                      NB. Cannot 'make boot stage=2' until stage1 has
11 #                          been built (similarly for stage3).
12 #
13 #       stage1  (or stage=1) builds stage1 compiler
14 #       stage2  (or stage=2) builds stage2 compiler
15 #       stage3  (or stage=3) builds stage3 compiler
16 #
17
18 TOP = ..
19
20 ifeq "$(stage)" ""
21 stage=1
22 endif
23
24 include $(TOP)/mk/boilerplate.mk
25 include $(TOP)/mk/cabal-flags.mk
26
27 ifeq "$(GhcThreaded) $(GhcProfiled)" "YES YES"
28 $(error Cannot make GHC both threaded and profiled)
29 endif
30
31 CONFIG_HS       = main/Config.hs
32 PRIMOP_BITS = primop-data-decl.hs-incl        \
33               primop-tag.hs-incl              \
34               primop-list.hs-incl             \
35               primop-has-side-effects.hs-incl \
36               primop-out-of-line.hs-incl      \
37               primop-commutable.hs-incl       \
38               primop-needs-wrapper.hs-incl    \
39               primop-can-fail.hs-incl         \
40               primop-strictness.hs-incl       \
41               primop-primop-info.hs-incl
42
43 boot:: boot.stage.$(stage)
44
45 all:: build.stage.$(stage)
46
47 doc:: doc.stage.$(stage)
48
49 stage1 ::
50         $(MAKE) stage=1
51
52 stage2 ::
53         $(MAKE) stage=2
54
55 stage3 ::
56         $(MAKE) stage=3
57
58 ifeq "$(CLEAN_ALL_STAGES)" "YES"
59 clean distclean maintainer-clean::
60         $(RM) -f prelude/primops.txt
61         $(RM) -f $(PRIMOP_BITS)
62         $(RM) -f $(CONFIG_HS)
63         $(RM) -f parser/Parser.y
64         $(RM) -rf stage1 stage2plus
65         $(RM) -f $(STAGE3_PACKAGE_CONF)
66 endif
67
68 ifeq "$(CLEAN_ALL_STAGES)" "YES"
69 clean distclean maintainer-clean:: clean.stage.1 clean.stage.2 clean.stage.3
70 else
71 clean distclean maintainer-clean:: clean.stage.$(stage)
72 endif
73
74 ifeq "$(CLEAN_ALL_STAGES)" "YES"
75 distclean maintainer-clean::
76         $(RM) -f ghc.cabal
77 endif
78
79 clean.stage.%:
80         $(RM) -f Makefile-stage$*
81 # This is a bit naughty. We ought to use:
82 #       -$(CABAL) clean --distpref dist-stage$*
83 # but that won't work if the Cabal file (a generated file) doesn't
84 # exist. So we do this instead:
85         $(RM) -rf dist-stage$*
86
87 CONFIGURE_FLAGS_STAGE1 += --flags=stage1
88 CONFIGURE_FLAGS_STAGE2 += --flags=-stage1
89
90 ifeq "$(GhcWithNativeCodeGen)" "YES"
91 CONFIGURE_FLAGS_STAGE1 += --flags=ncg
92 CONFIGURE_FLAGS_STAGE2 += --flags=ncg
93 endif
94
95 ifeq "$(GhcWithInterpreter)" "YES"
96 CONFIGURE_FLAGS_STAGE2 += --flags=ghci
97
98 ifeq "$(BuildSharedLibs)" "YES"
99 CONFIGURE_FLAGS_STAGE2 += --enable-shared
100 # If we are going to use dynamic libraries instead of .o files for ghci,
101 # we will need to always retain CAFs in the compiler.
102 # ghci/keepCAFsForGHCi contains a GNU C __attribute__((constructor))
103 # function which sets the keepCAFs flag for the RTS before any Haskell
104 # code is run.
105 CONFIGURE_FLAGS_STAGE2 += --flags=dynlibs
106 endif
107
108 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
109 # Should GHCI be building info tables in the TABLES_NEXT_TO_CODE style
110 # or not?
111 # XXX This should logically be a CPP option, but there doesn't seem to
112 # be a flag for that
113 CONFIGURE_FLAGS_STAGE2 += --ghc-option=-DGHCI_TABLES_NEXT_TO_CODE
114 endif
115
116 # Should the debugger commands be enabled?
117 ifeq "$(GhciWithDebugger)" "YES"
118 CONFIGURE_FLAGS_STAGE2 += --ghc-option=-DDEBUGGER
119 endif
120
121 # Enable editline if:
122 #   - we're building stage 2/3, and we have built the editline package
123 #
124 # But we don't enable editline on Windows, as Windows terminals have
125 # editline-like support builtin.
126 #
127 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
128 ifeq "$(wildcard $(FPTOOLS_TOP_ABS)/libraries/editline/unbuildable)" ""
129 CONFIGURE_FLAGS_STAGE2 += --flags=editline
130 endif
131 endif
132 endif
133
134 ifeq "$(GhcWithNativeCodeGen)" "NO"
135 # XXX This should logically be a CPP option, but there doesn't seem to
136 # be a flag for that
137 COMMON_CONFIGURE_FLAGS += --ghc-option=-DOMIT_NATIVE_CODEGEN
138 endif
139
140 ifeq "$(TargetOS_CPP)" "openbsd"
141 COMMON_CONFIGURE_FLAGS += --ld-options=-E
142 endif
143
144 ifeq "$(GhcUnregisterised)" "NO"
145 ifeq "$(HOSTPLATFORM)" "ia64-unknown-linux"
146 # needed for generating proper relocation in large binaries: trac #856
147 COMMON_CONFIGURE_FLAGS += --ld-option=-Wl,--relax
148 endif
149 endif
150
151 # We need to turn on profiling either if we have been asked to
152 # (GhcLibProfiled = YES) or if we want GHC itself to be compiled with
153 # profiling enabled (GhcProfiled = YES).
154 ifneq "$(GhcLibProfiled) $(GhcProfiled)" "NO NO"
155 CONFIGURE_FLAGS_STAGE2 += --enable-library-profiling
156 # And if we're profiling GHC then we want lots of SCCs.
157 # We also don't want to waste time building the non-profiling library,
158 # either normally or for ghci. Unfortunately this means that we have to
159 # tell ghc-pkg --force as it gets upset when libHSghc-6.9.a doesn't
160 # exist.
161 ifeq "$(GhcProfiled)" "YES"
162 CONFIGURE_FLAGS_STAGE2 += --ghc-option=-auto-all
163 CONFIGURE_FLAGS_STAGE2 += --disable-library-vanilla
164 CONFIGURE_FLAGS_STAGE2 += --disable-library-for-ghci
165 CONFIGURE_FLAGS_STAGE2 += --ghc-pkg-option=--force
166 endif
167 endif
168
169 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
170 # The #include is vital for the via-C route with older compilers, else the C
171 # compiler doesn't realise that the stcall foreign imports are indeed
172 # stdcall, and doesn't generate the Foo@8 name for them
173 # As it's only important for older compilers we don't need to do anything
174 # for stage2+.
175 CONFIGURE_FLAGS_STAGE1 += --ghc-option='-\#include'    \
176                           --ghc-option='"<windows.h>"' \
177                           --ghc-option='-\#include'    \
178                           --ghc-option='"<process.h>"'
179 endif
180
181 # ghc_strlen percolates through so many modules that it is easier to get its
182 # prototype via a global option instead of a myriad of per-file OPTIONS.
183 # Again, this is only important for older compilers, so we don't do it in
184 # stage 2+.
185 CONFIGURE_FLAGS_STAGE1 += --ghc-options='-\#include "cutils.h"'
186
187 CONFIGURE_FLAGS_STAGE3 = $(CONFIGURE_FLAGS_STAGE2)
188 CONFIGURE_FLAGS_STAGE1 += $(USE_BOOT_CONFIGURE_FLAGS)
189 CONFIGURE_FLAGS_STAGE2 += $(USE_STAGE1_CONFIGURE_FLAGS)
190 CONFIGURE_FLAGS_STAGE3 += $(USE_STAGE2_CONFIGURE_FLAGS)
191 CONFIGURE_FLAGS_STAGE3 += --package-db $(STAGE3_PACKAGE_CONF)
192
193 # In a source dist we don't need to worry about Parser.y(.pp) as we have
194 # the .hs file pre-generated
195 ifneq "$(wildcard parser/Parser.y.pp)" ""
196 PARSER_Y = parser/Parser.y
197 endif
198
199 boot.stage.%: $(PRIMOP_BITS) $(CONFIG_HS) $(PARSER_Y)
200         test -f $(STAGE3_PACKAGE_CONF) || echo "[]" > $(STAGE3_PACKAGE_CONF)
201         $(CABAL) configure --distpref dist-stage$* \
202                            $(CONFIGURE_FLAGS_STAGE$*) \
203                            $(INSTALL_DIRS_CONFIGURE_FLAGS) \
204                            $(COMMON_CONFIGURE_FLAGS) \
205                            --ghc-option=-DSTAGE=$*
206         $(RM) -f Makefile-stage$*
207         $(CABAL) makefile  --distpref dist-stage$* -f Makefile-stage$*
208
209 build.stage.%:
210         $(MAKE) -f Makefile-stage$* stage=$*
211         $(CABAL) register  --distpref dist-stage$* --inplace
212         $(MAKE) -C ../ghc stage=$*
213
214 doc.stage.%:
215         $(CABAL) haddock --distpref dist-stage$* \
216                                          --html-location='../$$pkg' \
217                          --haddock-option=--optghc=-DSTAGE=$* \
218                          --haddock-option=+RTS --haddock-option=-s --haddock-option=-c --haddock-option=-RTS \
219                          --with-haddock=$(FPTOOLS_TOP_ABS)/utils/haddock/install-inplace/bin/haddock
220
221 install:
222         $(INSTALL_PACKAGE) install '$(GHC_PKG_INSTALL_PROG)' '$(DESTDIR)$(datadir)/package.conf' '$(DESTDIR)' '$(prefix)' '$(iprefix)' '$(ibindir)' '$(ilibdir)' '$(ilibexecdir)' '$(idynlibdir)' '$(idatadir)' '$(idocdir)' '$(ihtmldir)' '$(ihaddockdir)' --distpref dist-stage2
223
224 # -----------------------------------------------------------------------------
225 # Create compiler configuration
226 #
227 # The 'echo' commands simply spit the values of various make variables
228 # into Config.hs, whence they can be compiled and used by GHC itself
229
230 $(CONFIG_HS) : $(FPTOOLS_TOP)/mk/config.mk
231         @$(RM) -f $(CONFIG_HS)
232         @echo "Creating $(CONFIG_HS) ... "
233         @echo "module Config where" >>$(CONFIG_HS)
234         @echo "cProjectName          :: String" >> $(CONFIG_HS)
235         @echo "cProjectName          = \"$(ProjectName)\"" >> $(CONFIG_HS)
236         @echo "cProjectVersion       :: String" >> $(CONFIG_HS)
237         @echo "cProjectVersion       = \"$(ProjectVersion)\"" >> $(CONFIG_HS)
238         @echo "cProjectVersionInt    :: String" >> $(CONFIG_HS)
239         @echo "cProjectVersionInt    = \"$(ProjectVersionInt)\"" >> $(CONFIG_HS)
240         @echo "cProjectPatchLevel    :: String" >> $(CONFIG_HS)
241         @echo "cProjectPatchLevel    = \"$(ProjectPatchLevel)\"" >> $(CONFIG_HS)
242         @echo "cBooterVersion        :: String" >> $(CONFIG_HS)
243         @echo "cBooterVersion        = \"$(GhcVersion)\"" >> $(CONFIG_HS)
244         @echo "cStage                :: String" >> $(CONFIG_HS)
245         @echo "cStage                = show (STAGE :: Int)" >> $(CONFIG_HS)
246         @echo "cHscIfaceFileVersion  :: String" >> $(CONFIG_HS)
247         @echo "cHscIfaceFileVersion  = \"$(HscIfaceFileVersion)\"" >> $(CONFIG_HS)
248         @echo "cSplitObjs            :: String" >> $(CONFIG_HS)
249         @echo "cSplitObjs            = \"$(SupportsSplitObjs)\"" >> $(CONFIG_HS)
250         @echo "cGhcWithInterpreter   :: String" >> $(CONFIG_HS)
251         @echo "cGhcWithInterpreter   = \"$(GhcWithInterpreter)\"" >> $(CONFIG_HS)
252         @echo "cGhcWithNativeCodeGen :: String" >> $(CONFIG_HS)
253         @echo "cGhcWithNativeCodeGen = \"$(GhcWithNativeCodeGen)\"" >> $(CONFIG_HS)
254         @echo "cGhcWithSMP           :: String" >> $(CONFIG_HS)
255         @echo "cGhcWithSMP           = \"$(GhcWithSMP)\"" >> $(CONFIG_HS)
256         @echo "cGhcRTSWays           :: String" >> $(CONFIG_HS)
257         @echo "cGhcRTSWays           = \"$(GhcRTSWays)\"" >> $(CONFIG_HS)
258         @echo "cGhcUnregisterised    :: String" >> $(CONFIG_HS)
259         @echo "cGhcUnregisterised    = \"$(GhcUnregisterised)\"" >> $(CONFIG_HS)
260         @echo "cGhcEnableTablesNextToCode :: String" >> $(CONFIG_HS)
261         @echo "cGhcEnableTablesNextToCode = \"$(GhcEnableTablesNextToCode)\"" >> $(CONFIG_HS)
262         @echo "cLeadingUnderscore    :: String" >> $(CONFIG_HS)
263         @echo "cLeadingUnderscore    = \"$(LeadingUnderscore)\"" >> $(CONFIG_HS)
264         @echo "cRAWCPP_FLAGS         :: String" >> $(CONFIG_HS)
265         @echo "cRAWCPP_FLAGS         = \"$(RAWCPP_FLAGS)\"" >> $(CONFIG_HS)
266         @echo "cGCC                  :: String" >> $(CONFIG_HS)
267         @echo "cGCC                  = \"$(WhatGccIsCalled)\"" >> $(CONFIG_HS)
268         @echo "cMKDLL                :: String" >> $(CONFIG_HS)
269         @echo "cMKDLL                = \"$(BLD_DLL)\"" >> $(CONFIG_HS)
270         @echo "cLdIsGNULd            :: String" >> $(CONFIG_HS)
271         @echo "cLdIsGNULd            = \"$(LdIsGNULd)\"" >> $(CONFIG_HS)
272         @echo "cLD_X                 :: String" >> $(CONFIG_HS)
273         @echo "cLD_X                 = \"$(LD_X)\"" >> $(CONFIG_HS)
274         @echo "cGHC_DRIVER_DIR_REL   :: String" >> $(CONFIG_HS)
275         @echo "cGHC_DRIVER_DIR_REL   = \"$(GHC_DRIVER_DIR_REL)\"" >> $(CONFIG_HS)
276         @echo "cGHC_TOUCHY_PGM       :: String" >> $(CONFIG_HS)
277         @echo "cGHC_TOUCHY_PGM       = \"$(GHC_TOUCHY_PGM)\"" >> $(CONFIG_HS)
278         @echo "cGHC_TOUCHY_DIR_REL   :: String" >> $(CONFIG_HS)
279         @echo "cGHC_TOUCHY_DIR_REL   = \"$(GHC_TOUCHY_DIR_REL)\"" >> $(CONFIG_HS)
280         @echo "cGHC_UNLIT_PGM        :: String" >> $(CONFIG_HS)
281         @echo "cGHC_UNLIT_PGM        = \"$(GHC_UNLIT_PGM)\"" >> $(CONFIG_HS)
282         @echo "cGHC_UNLIT_DIR_REL    :: String" >> $(CONFIG_HS)
283         @echo "cGHC_UNLIT_DIR_REL    = \"$(GHC_UNLIT_DIR_REL)\"" >> $(CONFIG_HS)
284         @echo "cGHC_MANGLER_PGM      :: String" >> $(CONFIG_HS)
285         @echo "cGHC_MANGLER_PGM      = \"$(GHC_MANGLER_PGM)\"" >> $(CONFIG_HS)
286         @echo "cGHC_MANGLER_DIR_REL  :: String" >> $(CONFIG_HS)
287         @echo "cGHC_MANGLER_DIR_REL  = \"$(GHC_MANGLER_DIR_REL)\"" >> $(CONFIG_HS)
288         @echo "cGHC_SPLIT_PGM        :: String" >> $(CONFIG_HS)
289         @echo "cGHC_SPLIT_PGM        = \"$(GHC_SPLIT_PGM)\"" >> $(CONFIG_HS)
290         @echo "cGHC_SPLIT_DIR_REL    :: String" >> $(CONFIG_HS)
291         @echo "cGHC_SPLIT_DIR_REL    = \"$(GHC_SPLIT_DIR_REL)\"" >> $(CONFIG_HS)
292         @echo "cGHC_SYSMAN_PGM       :: String" >> $(CONFIG_HS)
293         @echo "cGHC_SYSMAN_PGM       = \"$(GHC_SYSMAN)\"" >> $(CONFIG_HS)
294         @echo "cGHC_SYSMAN_DIR_REL   :: String" >> $(CONFIG_HS)
295         @echo "cGHC_SYSMAN_DIR_REL   = \"$(GHC_SYSMAN_DIR)\"" >> $(CONFIG_HS)
296         @echo "cGHC_CP               :: String" >> $(CONFIG_HS)
297         @echo "cGHC_CP               = \"$(GHC_CP)\"" >> $(CONFIG_HS)
298         @echo "cGHC_PERL             :: String" >> $(CONFIG_HS)
299         @echo "cGHC_PERL             = \"$(GHC_PERL)\"" >> $(CONFIG_HS)
300         @echo "cEnableWin32DLLs      :: String" >> $(CONFIG_HS)
301         @echo "cEnableWin32DLLs      = \"$(EnableWin32DLLs)\"" >> $(CONFIG_HS)
302         @echo "cCONTEXT_DIFF         :: String" >> $(CONFIG_HS)
303         @echo "cCONTEXT_DIFF         = \"$(CONTEXT_DIFF)\"" >> $(CONFIG_HS)
304         @echo "cUSER_WAY_NAMES       :: String" >> $(CONFIG_HS)
305         @echo "cUSER_WAY_NAMES       = \"$(USER_WAY_NAMES)\"" >> $(CONFIG_HS)
306         @echo "cUSER_WAY_OPTS        :: String" >> $(CONFIG_HS)
307         @echo "cUSER_WAY_OPTS        = \"$(USER_WAY_OPTS)\"" >> $(CONFIG_HS)
308         @echo "cDEFAULT_TMPDIR       :: String" >> $(CONFIG_HS)
309         @echo "cDEFAULT_TMPDIR       = \"$(DEFAULT_TMPDIR)\"" >> $(CONFIG_HS)
310         @echo "cRelocatableBuild     :: Bool"                 >> $(CONFIG_HS)
311 ifeq "$(RelocatableBuild)" "YES"
312         @echo "cRelocatableBuild     = True"                  >> $(CONFIG_HS)
313 else
314         @echo "cRelocatableBuild     = False"                 >> $(CONFIG_HS)
315 endif
316         @echo "cLibFFI               :: Bool"                 >> $(CONFIG_HS)
317 ifeq "$(UseLibFFIForAdjustors)" "YES"
318         @echo "cLibFFI               = True"                  >> $(CONFIG_HS)
319 else
320         @echo "cLibFFI               = False"                 >> $(CONFIG_HS)
321 endif
322         @echo done.
323
324 # -----------------------------------------------------------------------------
325 # Create platform includes
326
327 # Here we generate a little header file containing CPP symbols that GHC
328 # uses to determine which platform it is building on/for.  The platforms
329 # can differ between stage1 and stage2 if we're cross-compiling, so we
330 # need one of these header files per stage.
331
332 PLATFORM_H = ghc_boot_platform.h
333
334 stage1/$(PLATFORM_H) : $(FPTOOLS_TOP)/mk/config.mk
335         $(MKDIRHIER) stage1
336         @echo "Creating $@..."
337         @$(RM) $@
338         @echo "#ifndef __PLATFORM_H__"  >$@
339         @echo "#define __PLATFORM_H__" >>$@
340         @echo >> $@
341         @echo "#define BuildPlatform_NAME  \"$(BUILDPLATFORM)\"" >> $@
342         @echo "#define HostPlatform_NAME   \"$(HOSTPLATFORM)\"" >> $@
343         @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
344         @echo >> $@
345         @echo "#define $(BuildPlatform_CPP)_BUILD       1" >> $@
346         @echo "#define $(HostPlatform_CPP)_HOST         1" >> $@
347         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
348         @echo >> $@
349         @echo "#define $(BuildArch_CPP)_BUILD_ARCH      1" >> $@
350         @echo "#define $(HostArch_CPP)_HOST_ARCH        1" >> $@
351         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
352         @echo "#define BUILD_ARCH \"$(BuildArch_CPP)\"" >> $@
353         @echo "#define HOST_ARCH \"$(HostArch_CPP)\"" >> $@
354         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
355         @echo >> $@
356         @echo "#define $(BuildOS_CPP)_BUILD_OS          1" >> $@
357         @echo "#define $(HostOS_CPP)_HOST_OS            1" >> $@
358         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
359         @echo "#define BUILD_OS \"$(BuildOS_CPP)\"" >> $@
360         @echo "#define HOST_OS \"$(HostOS_CPP)\"" >> $@
361         @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
362 ifeq "$(HostOS_CPP)" "irix"
363         @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS           " >> $@  
364         @echo "#define $(IRIX_MAJOR)_TARGET_OS          1" >> $@  
365         @echo "#endif                                    " >> $@  
366 endif
367         @echo >> $@
368         @echo "#define $(BuildVendor_CPP)_BUILD_VENDOR  1" >> $@
369         @echo "#define $(HostVendor_CPP)_HOST_VENDOR    1" >> $@
370         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
371         @echo "#define BUILD_VENDOR \"$(BuildVendor_CPP)\"" >> $@
372         @echo "#define HOST_VENDOR \"$(HostVendor_CPP)\"" >> $@
373         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
374         @echo >> $@
375         @echo "#endif /* __PLATFORM_H__ */"          >> $@
376         @echo "Done."
377
378 # For stage2 and above, the BUILD platform is the HOST of stage1, and
379 # the HOST platform is the TARGET of stage1.  The TARGET remains the same
380 # (stage1 is the cross-compiler, not stage2).
381 stage2plus/$(PLATFORM_H) : $(FPTOOLS_TOP)/mk/config.mk
382         $(MKDIRHIER) stage2plus
383         @echo "Creating $@..."
384         @$(RM) $@
385         @echo "#ifndef __PLATFORM_H__"  >$@
386         @echo "#define __PLATFORM_H__" >>$@
387         @echo >> $@
388         @echo "#define BuildPlatform_NAME  \"$(HOSTPLATFORM)\"" >> $@
389         @echo "#define HostPlatform_NAME   \"$(TARGETPLATFORM)\"" >> $@
390         @echo "#define TargetPlatform_NAME \"$(TARGETPLATFORM)\"" >> $@
391         @echo >> $@
392         @echo "#define $(HostPlatform_CPP)_BUILD        1" >> $@
393         @echo "#define $(TargetPlatform_CPP)_HOST               1" >> $@
394         @echo "#define $(TargetPlatform_CPP)_TARGET     1" >> $@
395         @echo >> $@
396         @echo "#define $(HostArch_CPP)_BUILD_ARCH       1" >> $@
397         @echo "#define $(TargetArch_CPP)_HOST_ARCH      1" >> $@
398         @echo "#define $(TargetArch_CPP)_TARGET_ARCH    1" >> $@
399         @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
400         @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
401         @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
402         @echo >> $@
403         @echo "#define $(HostOS_CPP)_BUILD_OS           1" >> $@
404         @echo "#define $(TargetOS_CPP)_HOST_OS          1" >> $@
405         @echo "#define $(TargetOS_CPP)_TARGET_OS        1" >> $@  
406         @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
407         @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
408         @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
409 ifeq "$(HostOS_CPP)" "irix"
410         @echo "#ifndef $(IRIX_MAJOR)_TARGET_OS           " >> $@  
411         @echo "#define $(IRIX_MAJOR)_TARGET_OS          1" >> $@  
412         @echo "#endif                                    " >> $@  
413 endif
414         @echo >> $@
415         @echo "#define $(HostVendor_CPP)_BUILD_VENDOR   1" >> $@
416         @echo "#define $(TargetVendor_CPP)_HOST_VENDOR  1" >> $@
417         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
418         @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
419         @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
420         @echo "#define TARGET_VENDOR \"$(TargetVendor_CPP)\"" >> $@
421         @echo >> $@
422         @echo "#endif /* __PLATFORM_H__ */"          >> $@
423         @echo "Done."
424
425 ifeq "$(stage)" "1"
426 STAGE_PLATFORM_H = stage1/$(PLATFORM_H)
427 else
428 STAGE_PLATFORM_H = stage2plus/$(PLATFORM_H)
429 endif
430
431 boot :: $(STAGE_PLATFORM_H)
432
433 # ----------------------------------------------------------------------------
434 #               Generate supporting stuff for prelude/PrimOp.lhs 
435 #               from prelude/primops.txt
436
437 SRC_CPP_OPTS += -I$(GHC_INCLUDE_DIR)
438 SRC_CPP_OPTS += ${GhcCppOpts}
439
440 prelude/primops.txt parser/Parser.y: %: %.pp stage1/$(PLATFORM_H)
441         $(CPP) $(RAWCPP_FLAGS) -P $(CPP_OPTS) -x c $< | grep -v '^#pragma GCC' > $@
442
443 primop-data-decl.hs-incl: prelude/primops.txt
444         $(GENPRIMOP) --data-decl          < $< > $@
445 primop-tag.hs-incl: prelude/primops.txt
446         $(GENPRIMOP) --primop-tag         < $< > $@
447 primop-list.hs-incl: prelude/primops.txt
448         $(GENPRIMOP) --primop-list        < $< > $@
449 primop-has-side-effects.hs-incl: prelude/primops.txt
450         $(GENPRIMOP) --has-side-effects   < $< > $@
451 primop-out-of-line.hs-incl: prelude/primops.txt
452         $(GENPRIMOP) --out-of-line        < $< > $@
453 primop-commutable.hs-incl: prelude/primops.txt
454         $(GENPRIMOP) --commutable         < $< > $@
455 primop-needs-wrapper.hs-incl: prelude/primops.txt
456         $(GENPRIMOP) --needs-wrapper      < $< > $@
457 primop-can-fail.hs-incl: prelude/primops.txt
458         $(GENPRIMOP) --can-fail           < $< > $@
459 primop-strictness.hs-incl: prelude/primops.txt
460         $(GENPRIMOP) --strictness         < $< > $@
461 primop-primop-info.hs-incl: prelude/primops.txt
462         $(GENPRIMOP) --primop-primop-info < $< > $@
463
464 # Usages aren't used any more; but the generator 
465 # can still generate them if we want them back
466 primop-usage.hs-incl: prelude/primops.txt
467         $(GENPRIMOP) --usage              < $< > $@
468
469 html:
470         $(MAKE) doc stage=2
471
472 install-docs:
473         @:
474
475 #-----------------------------------------------------------------------------
476 # binary-dist
477 #
478
479 # Ideally we'd get these from the Cabal file's Install-Includes:
480 BINDIST_EXTRAS += HsVersions.h
481 ifeq "$(stage)" "1"
482 BINDIST_EXTRAS += stage1/ghc_boot_platform.h
483 else
484 BINDIST_EXTRAS += stage2plus/ghc_boot_platform.h
485 endif
486
487 include $(TOP)/mk/bindist.mk
488 LIB_DIST_DIR = dist-stage2
489
490 #-----------------------------------------------------------------------------
491 # etags generation
492 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
493 GHCTAGS = $(TOP)/utils/ghctags/ghctags.exe
494 else
495 GHCTAGS = $(TOP)/utils/ghctags/ghctags-inplace
496 endif
497 GHCTAGS_ROOT = main/GHC.hs ghci/InteractiveUI.hs main/PprTyThing.hs
498
499 # etags for stage2 is actually broken since it requires building
500 # ghctags against an older ghc api
501 etags: etags.stage.2
502 etags.stage.%:
503         $(GHCTAGS) --topdir $(FPTOOLS_TOP_ABS) --etags --use-cabal-config=./dist-stage$* -- -DSTAGE=$* -- $(GHCTAGS_ROOT)