Make `derivedConstants` more crosscompile-friendly
[ghc.git] / includes / ghc.mk
1 # -----------------------------------------------------------------------------
2 #
3 # (c) 2009 The University of Glasgow
4 #
5 # This file is part of the GHC build system.
6 #
7 # To understand how the build system works and how to modify it, see
8 # http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 #
14 # Header files built from the configure script's findings
15 #
16 # XXX: these should go in includes/dist/build?
17 includes_H_CONFIG = includes/ghcautoconf.h
18 includes_H_PLATFORM = includes/ghcplatform.h
19 includes_H_VERSION = includes/ghcversion.h
20
21 #
22 # All header files are in includes/{one of these subdirectories}
23 #
24 includes_H_SUBDIRS += .
25 includes_H_SUBDIRS += rts
26 includes_H_SUBDIRS += rts/prof
27 includes_H_SUBDIRS += rts/storage
28 includes_H_SUBDIRS += stg
29
30 includes_H_FILES := $(wildcard $(patsubst %,includes/%/*.h,$(includes_H_SUBDIRS)))
31 # This isn't necessary, but it makes the paths look a little prettier
32 includes_H_FILES := $(subst /./,/,$(includes_H_FILES))
33
34 #
35 # Options
36 #
37
38 includes_CC_OPTS += $(SRC_CC_OPTS)
39 includes_CC_OPTS += $(SRC_CC_WARNING_OPTS)
40 includes_CC_OPTS += $(CONF_CC_OPTS_STAGE1)
41
42 ifeq "$(GhcUnregisterised)" "YES"
43 includes_CC_OPTS += -DUSE_MINIINTERPRETER
44 endif
45
46 includes_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
47 includes_CC_OPTS += -Irts
48
49 ifneq "$(GhcWithSMP)" "YES"
50 includes_CC_OPTS += -DNOSMP
51 endif
52
53 ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
54 includes_CC_OPTS += -DDYNAMIC_BY_DEFAULT
55 endif
56
57
58 $(includes_H_VERSION) : mk/project.mk | $$(dir $$@)/.
59 @echo "Creating $@..."
60 @echo "#ifndef __GHCVERSION_H__" > $@
61 @echo "#define __GHCVERSION_H__" >> $@
62 @echo >> $@
63 @echo "#ifndef __GLASGOW_HASKELL__" >> $@
64 @echo "# define __GLASGOW_HASKELL__ $(ProjectVersionInt)" >> $@
65 @echo "#endif" >> $@
66 @echo >> $@
67 @if [ -n "$(ProjectPatchLevel1)" ]; then \
68 echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $(ProjectPatchLevel1)" >> $@; \
69 fi
70 @if [ -n "$(ProjectPatchLevel2)" ]; then \
71 echo "#define __GLASGOW_HASKELL_PATCHLEVEL2__ $(ProjectPatchLevel2)" >> $@; \
72 fi
73 @echo >> $@
74 @echo '#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\' >> $@
75 @echo ' ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \' >> $@
76 @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $@
77 @echo ' && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \' >> $@
78 @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $@
79 @echo ' && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \' >> $@
80 @echo ' && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )' >> $@
81 @echo >> $@
82 @echo "#endif /* __GHCVERSION_H__ */" >> $@
83 @echo "Done."
84
85 ifneq "$(BINDIST)" "YES"
86
87 ifeq "$(PORTING_HOST)" "YES"
88
89 $(includes_H_CONFIG) :
90 @echo "*** Cross-compiling: please copy $(includes_H_CONFIG) from the target system"
91 @exit 1
92
93 else
94
95 $(includes_H_CONFIG) : mk/config.h mk/config.mk includes/ghc.mk | $$(dir $$@)/.
96 @echo "Creating $@..."
97 @echo "#ifndef __GHCAUTOCONF_H__" >$@
98 @echo "#define __GHCAUTOCONF_H__" >>$@
99 #
100 # Copy the contents of mk/config.h, turning '#define PACKAGE_FOO
101 # "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
102 #
103 @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$,\1/* #undef \2 */,' mk/config.h >> $@
104 #
105 # Tack on some extra config information from the build system
106 #
107 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
108 @echo >> $@
109 @echo "#define TABLES_NEXT_TO_CODE 1" >> $@
110 endif
111 #
112 ifeq "$(CC_LLVM_BACKEND)" "1"
113 @echo >> $@
114 @echo "#define llvm_CC_FLAVOR 1" >> $@
115 endif
116 #
117 ifeq "$(CC_CLANG_BACKEND)" "1"
118 @echo >> $@
119 @echo "#define clang_CC_FLAVOR 1" >> $@
120 endif
121 #
122 @echo "#endif /* __GHCAUTOCONF_H__ */" >> $@
123 @echo "Done."
124
125 endif
126
127 $(includes_H_PLATFORM) : includes/Makefile | $$(dir $$@)/.
128 $(call removeFiles,$@)
129 @echo "Creating $@..."
130 @echo "#ifndef __GHCPLATFORM_H__" >$@
131 @echo "#define __GHCPLATFORM_H__" >>$@
132 @echo >> $@
133 @echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
134 @echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
135 @echo >> $@
136 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
137 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
138 @echo >> $@
139 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
140 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
141 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
142 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
143 @echo >> $@
144 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
145 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
146 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
147 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
148 ifeq "$(HostOS_CPP)" "irix"
149 @echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@
150 @echo "#define $(IRIX_MAJOR)_HOST_OS 1" >> $@
151 @echo "#endif" >> $@
152 endif
153 @echo >> $@
154 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
155 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
156 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
157 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
158 @echo >> $@
159 @echo "/* These TARGET macros are for backwards compatibility... DO NOT USE! */" >> $@
160 @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
161 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
162 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
163 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
164 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
165 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
166 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
167 ifeq "$(GhcUnregisterised)" "YES"
168 @echo "#define UnregisterisedCompiler 1" >> $@
169 endif
170 @echo >> $@
171 @echo "#endif /* __GHCPLATFORM_H__ */" >> $@
172 @echo "Done."
173
174 endif
175
176 # ---------------------------------------------------------------------------
177 # Make DerivedConstants.h for the compiler
178
179 includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
180 includes_GHCCONSTANTS_HASKELL_TYPE = includes/dist-derivedconstants/header/GHCConstantsHaskellType.hs
181 includes_GHCCONSTANTS_HASKELL_VALUE = includes/dist-derivedconstants/header/platformConstants
182 includes_GHCCONSTANTS_HASKELL_WRAPPERS = includes/dist-derivedconstants/header/GHCConstantsHaskellWrappers.hs
183 includes_GHCCONSTANTS_HASKELL_EXPORTS = includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs
184
185 INSTALL_LIBS += $(includes_GHCCONSTANTS_HASKELL_VALUE)
186
187 DERIVE_CONSTANTS_FLAGS += --gcc-program "$(WhatGccIsCalled)"
188 DERIVE_CONSTANTS_FLAGS += $(addprefix --gcc-flag$(space),$(includes_CC_OPTS) -fcommon)
189 DERIVE_CONSTANTS_FLAGS += --nm-program "$(NM)"
190 ifneq "$(OBJDUMP)" ""
191 DERIVE_CONSTANTS_FLAGS += --objdump-program "$(OBJDUMP)"
192 endif
193 DERIVE_CONSTANTS_FLAGS += --target-os "$(TargetOS_CPP)"
194
195 ifneq "$(BINDIST)" "YES"
196 $(includes_DERIVEDCONSTANTS): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
197 $(includes_GHCCONSTANTS_HASKELL_VALUE): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
198
199 $(includes_DERIVEDCONSTANTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
200 $< --gen-header -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
201
202 $(includes_GHCCONSTANTS_HASKELL_TYPE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
203 $< --gen-haskell-type -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
204
205 $(includes_GHCCONSTANTS_HASKELL_VALUE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
206 $< --gen-haskell-value -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
207
208 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
209 $< --gen-haskell-wrappers -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
210
211 $(includes_GHCCONSTANTS_HASKELL_EXPORTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
212 $< --gen-haskell-exports -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
213 endif
214
215 # ---------------------------------------------------------------------------
216 # Install all header files
217
218 $(eval $(call clean-target,includes,,\
219 $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION)))
220
221 $(eval $(call all-target,includes,\
222 $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) \
223 $(includes_GHCCONSTANTS_HASKELL_TYPE) \
224 $(includes_GHCCONSTANTS_HASKELL_VALUE) \
225 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS) \
226 $(includes_GHCCONSTANTS_HASKELL_EXPORTS) \
227 $(includes_DERIVEDCONSTANTS)))
228
229 install: install_includes
230
231 .PHONY: install_includes
232 install_includes :
233 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
234 $(foreach d,$(includes_H_SUBDIRS), \
235 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)/$d" && \
236 $(INSTALL_HEADER) $(INSTALL_OPTS) includes/$d/*.h "$(DESTDIR)$(ghcheaderdir)/$d/" && \
237 ) true
238 $(INSTALL_HEADER) $(INSTALL_OPTS) $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) $(includes_DERIVEDCONSTANTS) "$(DESTDIR)$(ghcheaderdir)/"
239