testsuite: Assert that testsuite ways are known
[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 # https://gitlab.haskell.org/ghc/ghc/wikis/building/architecture
9 # https://gitlab.haskell.org/ghc/ghc/wikis/building/modifying
10 #
11 # -----------------------------------------------------------------------------
12
13 #
14 # Header files built from the configure script's findings
15 #
16 includes_0_H_CONFIG = includes/dist/build/ghcautoconf.h
17 includes_1_H_CONFIG = includes/dist-install/build/ghcautoconf.h
18 includes_2_H_CONFIG = $(includes_1_H_CONFIG)
19
20 includes_0_H_PLATFORM = includes/dist/build/ghcplatform.h
21 includes_1_H_PLATFORM = includes/dist-install/build/ghcplatform.h
22 includes_2_H_PLATFORM = $(includes_1_H_PLATFORM)
23
24 includes_0_H_VERSION = includes/dist/build/ghcversion.h
25 includes_1_H_VERSION = includes/dist-install/build/ghcversion.h
26 includes_2_H_VERSION = $(includes_1_H_VERSION)
27
28 BUILD_0_INCLUDE_DIR = includes/dist/build
29 BUILD_1_INCLUDE_DIR = includes/dist-install/build
30 BUILD_2_INCLUDE_DIR = $(BUILD_1_INCLUDE_DIR)
31
32 #
33 # All header files are in includes/{one of these subdirectories}
34 #
35 includes_H_SUBDIRS += .
36 includes_H_SUBDIRS += rts
37 includes_H_SUBDIRS += rts/prof
38 includes_H_SUBDIRS += rts/storage
39 includes_H_SUBDIRS += stg
40
41 includes_H_FILES := $(wildcard $(patsubst %,includes/%/*.h,$(includes_H_SUBDIRS)))
42 # This isn't necessary, but it makes the paths look a little prettier
43 includes_H_FILES := $(subst /./,/,$(includes_H_FILES))
44
45 #
46 # Options
47 #
48
49 includes_CC_OPTS += $(SRC_CC_OPTS)
50 includes_CC_OPTS += $(SRC_CC_WARNING_OPTS)
51 includes_CC_OPTS += $(CONF_CC_OPTS_STAGE1)
52
53 ifeq "$(GhcUnregisterised)" "YES"
54 includes_CC_OPTS += -DUSE_MINIINTERPRETER
55 endif
56
57 includes_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
58 includes_CC_OPTS += -I$(BUILD_1_INCLUDE_DIR)
59 includes_CC_OPTS += -Irts
60
61 ifneq "$(GhcWithSMP)" "YES"
62 includes_CC_OPTS += -DNOSMP
63 endif
64
65 ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
66 includes_CC_OPTS += -DDYNAMIC_BY_DEFAULT
67 endif
68
69 define includesHeaderVersion
70 # $1 = stage
71 $$(includes_$1_H_VERSION) : mk/project.mk | $$$$(dir $$$$@)/.
72 $$(call removeFiles,$$@)
73 @echo "Creating $$@..."
74 @echo "#if !defined(__GHCVERSION_H__)" > $$@
75 @echo "#define __GHCVERSION_H__" >> $$@
76 @echo >> $$@
77 @echo "#define __GLASGOW_HASKELL__ $$(ProjectVersionInt)" >> $$@
78 @echo >> $$@
79 @if [ -n "$$(ProjectPatchLevel1)" ]; then \
80 echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $$(ProjectPatchLevel1)" >> $$@; \
81 fi
82 @if [ -n "$$(ProjectPatchLevel2)" ]; then \
83 echo "#define __GLASGOW_HASKELL_PATCHLEVEL2__ $$(ProjectPatchLevel2)" >> $$@; \
84 fi
85 @echo >> $$@
86 @echo '#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\' >> $$@
87 @echo ' ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \' >> $$@
88 @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $$@
89 @echo ' && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \' >> $$@
90 @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $$@
91 @echo ' && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \' >> $$@
92 @echo ' && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )' >> $$@
93 @echo >> $$@
94 @echo "#endif /* __GHCVERSION_H__ */" >> $$@
95 @echo "Done."
96
97 endef
98
99 $(eval $(call includesHeaderVersion,0))
100 $(eval $(call includesHeaderVersion,1))
101
102 ifneq "$(BINDIST)" "YES"
103
104 define includesHeaderConfig
105 # $1 = stage
106 $$(includes_$1_H_CONFIG) : mk/config.h mk/config.mk includes/ghc.mk | $$$$(dir $$$$@)/.
107 $$(call removeFiles,$$@)
108 @echo "Creating $$@..."
109 @echo "#if !defined(__GHCAUTOCONF_H__)" > $$@
110 @echo "#define __GHCAUTOCONF_H__" >> $$@
111 #
112 # Copy the contents of mk/config.h, turning '#define PACKAGE_FOO
113 # "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
114 #
115 @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$$$,\1/* #undef \2 */,' mk/config.h >> $$@
116 #
117 @echo "#endif /* __GHCAUTOCONF_H__ */" >> $$@
118 @echo "Done."
119
120 endef
121
122 $(eval $(call includesHeaderConfig,0))
123 $(eval $(call includesHeaderConfig,1))
124
125 BuildPlatform_0_CPP = $(BuildPlatform_CPP)
126 BuildPlatform_1_CPP = $(HostPlatform_CPP)
127 BuildPlatform_2_CPP = $(TargetPlatform_CPP)
128
129 HostPlatform_0_CPP = $(HostPlatform_CPP)
130 HostPlatform_1_CPP = $(TargetPlatform_CPP)
131 HostPlatform_2_CPP = $(TargetPlatform_CPP)
132
133 BuildArch_0_CPP = $(BuildArch_CPP)
134 BuildArch_1_CPP = $(HostArch_CPP)
135 BuildArch_2_CPP = $(TargetArch_CPP)
136
137 HostArch_0_CPP = $(HostArch_CPP)
138 HostArch_1_CPP = $(TargetArch_CPP)
139 HostArch_2_CPP = $(TargetArch_CPP)
140
141 BuildOS_0_CPP = $(BuildOS_CPP)
142 BuildOS_1_CPP = $(HostOS_CPP)
143 BuildOS_2_CPP = $(TargetOS_CPP)
144
145 HostOS_0_CPP = $(HostOS_CPP)
146 HostOS_1_CPP = $(TargetOS_CPP)
147 HostOS_2_CPP = $(TargetOS_CPP)
148
149 BuildVendor_0_CPP = $(BuildVendor_CPP)
150 BuildVendor_1_CPP = $(HostVendor_CPP)
151 BuildVendor_2_CPP = $(TargetVendor_CPP)
152
153 HostVendor_0_CPP = $(HostVendor_CPP)
154 HostVendor_1_CPP = $(TargetVendor_CPP)
155 HostVendor_2_CPP = $(TargetVendor_CPP)
156
157 define includesHeaderPlatform
158 # $1 = stage
159 $$(includes_$1_H_PLATFORM) : includes/ghc.mk includes/Makefile | $$$$(dir $$$$@)/.
160 $$(call removeFiles,$$@)
161 @echo "Creating $$@..."
162 @echo "#if !defined(__GHCPLATFORM_H__)" > $$@
163 @echo "#define __GHCPLATFORM_H__" >> $$@
164 @echo >> $$@
165 @echo "#define GHC_STAGE $1" >> $$@
166 @echo >> $$@
167 @echo "#define BuildPlatform_TYPE $(BuildPlatform_$1_CPP)" >> $$@
168 @echo "#define HostPlatform_TYPE $(HostPlatform_$1_CPP)" >> $$@
169 @echo >> $$@
170 @echo "#define $(BuildPlatform_$1_CPP)_BUILD 1" >> $$@
171 @echo "#define $(HostPlatform_$1_CPP)_HOST 1" >> $$@
172 @echo >> $$@
173 @echo "#define $(BuildArch_$1_CPP)_BUILD_ARCH 1" >> $$@
174 @echo "#define $(HostArch_$1_CPP)_HOST_ARCH 1" >> $$@
175 @echo "#define BUILD_ARCH \"$(BuildArch_$1_CPP)\"" >> $$@
176 @echo "#define HOST_ARCH \"$(HostArch_$1_CPP)\"" >> $$@
177 @echo >> $$@
178 @echo "#define $(BuildOS_$1_CPP)_BUILD_OS 1" >> $$@
179 @echo "#define $(HostOS_$1_CPP)_HOST_OS 1" >> $$@
180 @echo "#define BUILD_OS \"$(BuildOS_$1_CPP)\"" >> $$@
181 @echo "#define HOST_OS \"$(HostOS_$1_CPP)\"" >> $$@
182 @echo >> $$@
183 @echo "#define $(BuildVendor_$1_CPP)_BUILD_VENDOR 1" >> $$@
184 @echo "#define $(HostVendor_$1_CPP)_HOST_VENDOR 1" >> $$@
185 @echo "#define BUILD_VENDOR \"$(BuildVendor_$1_CPP)\"" >> $$@
186 @echo "#define HOST_VENDOR \"$(HostVendor_$1_CPP)\"" >> $$@
187 @echo >> $$@
188 ifeq "$$(GhcUnregisterised)" "YES"
189 @echo "#define UnregisterisedCompiler 1" >> $$@
190 endif
191 @echo >> $$@
192 @echo "#endif /* __GHCPLATFORM_H__ */" >> $$@
193 @echo "Done."
194 endef
195
196 endif
197
198 $(eval $(call includesHeaderPlatform,0))
199 $(eval $(call includesHeaderPlatform,1))
200
201 # -----------------------------------------------------------------------------
202 # Settings
203
204 # These settings are read by GHC at runtime, so as to not cause spurious
205 # rebuilds.
206
207 includes_SETTINGS = includes/dist/build/settings
208
209 $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/.
210 $(call removeFiles,$@)
211 @echo '[("GCC extra via C opts", "$(GccExtraViaCOpts)")' >> $@
212 @echo ',("C compiler command", "$(SettingsCCompilerCommand)")' >> $@
213 @echo ',("C compiler flags", "$(SettingsCCompilerFlags)")' >> $@
214 @echo ',("C++ compiler flags", "$(SettingsCxxCompilerFlags)")' >> $@
215 @echo ',("C compiler link flags", "$(SettingsCCompilerLinkFlags)")' >> $@
216 @echo ',("C compiler supports -no-pie", "$(SettingsCCompilerSupportsNoPie)")' >> $@
217 @echo ',("Haskell CPP command", "$(SettingsHaskellCPPCommand)")' >> $@
218 @echo ',("Haskell CPP flags", "$(SettingsHaskellCPPFlags)")' >> $@
219 @echo ',("ld command", "$(SettingsLdCommand)")' >> $@
220 @echo ',("ld flags", "$(SettingsLdFlags)")' >> $@
221 @echo ',("ld supports compact unwind", "$(LdHasNoCompactUnwind)")' >> $@
222 @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@
223 @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@
224 @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@
225 @echo ',("ar command", "$(SettingsArCommand)")' >> $@
226 @echo ',("ar flags", "$(ArArgs)")' >> $@
227 @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@
228 @echo ',("ranlib command", "$(SettingsRanlibCommand)")' >> $@
229 @echo ',("touch command", "$(SettingsTouchCommand)")' >> $@
230 @echo ',("dllwrap command", "$(SettingsDllWrapCommand)")' >> $@
231 @echo ',("windres command", "$(SettingsWindresCommand)")' >> $@
232 @echo ',("libtool command", "$(SettingsLibtoolCommand)")' >> $@
233 @echo ',("unlit command", "$$topdir/bin/$(utils/unlit_dist_PROG)")' >> $@
234 @echo ',("cross compiling", "$(CrossCompiling)")' >> $@
235 @echo ',("target platform string", "$(TARGETPLATFORM)")' >> $@
236 @echo ',("target os", "$(HaskellTargetOs)")' >> $@
237 @echo ',("target arch", "$(HaskellTargetArch)")' >> $@
238 @echo ',("target word size", "$(TargetWordSize)")' >> $@
239 @echo ',("target has GNU nonexec stack", "$(TargetHasGnuNonexecStack)")' >> $@
240 @echo ',("target has .ident directive", "$(TargetHasIdentDirective)")' >> $@
241 @echo ',("target has subsections via symbols", "$(TargetHasSubsectionsViaSymbols)")' >> $@
242 @echo ',("target has RTS linker", "$(TargetHasRTSLinker)")' >> $@
243 @echo ',("Unregisterised", "$(GhcUnregisterised)")' >> $@
244 @echo ',("LLVM target", "$(LLVMTarget_CPP)")' >> $@
245 @echo ',("LLVM llc command", "$(SettingsLlcCommand)")' >> $@
246 @echo ',("LLVM opt command", "$(SettingsOptCommand)")' >> $@
247 @echo ',("LLVM clang command", "$(SettingsClangCommand)")' >> $@
248 @echo
249 @echo ',("integer library", "$(INTEGER_LIBRARY)")' >> $@
250 @echo ',("Use interpreter", "$(GhcWithInterpreter)")' >> $@
251 @echo ',("Use native code generator", "$(GhcWithNativeCodeGen)")' >> $@
252 @echo ',("Support SMP", "$(GhcWithSMP)")' >> $@
253 @echo ',("RTS ways", "$(GhcRTSWays)")' >> $@
254 @echo ',("Tables next to code", "$(TablesNextToCode)")' >> $@
255 @echo ',("Leading underscore", "$(LeadingUnderscore)")' >> $@
256 @echo ',("Use LibFFI", "$(UseLibFFIForAdjustors)")' >> $@
257 # Note that GhcThreaded just reflects the Makefile variable setting. In
258 # particular, the stage1 compiler is never actually compiled with -threaded, but
259 # it will nevertheless have cGhcThreaded = True. The "+RTS --info" output will
260 # show what RTS GHC is really using.
261 @echo ",(\"Use Threads\", \"$(GhcThreaded)\")" >> $@
262 @echo ",(\"Use Debugging\", \"$(GhcDebugged)\")" >> $@
263 @echo ",(\"RTS expects libdw\", \"$(GhcRtsWithLibdw)\")" >> $@
264 @echo "]" >> $@
265
266
267 # ---------------------------------------------------------------------------
268 # Make DerivedConstants.h for the compiler
269
270 includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
271 includes_GHCCONSTANTS_HASKELL_TYPE = includes/dist-derivedconstants/header/GHCConstantsHaskellType.hs
272 includes_GHCCONSTANTS_HASKELL_VALUE = includes/dist-derivedconstants/header/platformConstants
273 includes_GHCCONSTANTS_HASKELL_WRAPPERS = includes/dist-derivedconstants/header/GHCConstantsHaskellWrappers.hs
274 includes_GHCCONSTANTS_HASKELL_EXPORTS = includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs
275
276 INSTALL_LIBS += $(includes_GHCCONSTANTS_HASKELL_VALUE)
277
278 DERIVE_CONSTANTS_FLAGS += --gcc-program "$(CC)"
279 DERIVE_CONSTANTS_FLAGS += $(addprefix --gcc-flag$(space),$(includes_CC_OPTS) -fcommon)
280 DERIVE_CONSTANTS_FLAGS += --nm-program "$(NM)"
281 ifneq "$(OBJDUMP)" ""
282 DERIVE_CONSTANTS_FLAGS += --objdump-program "$(OBJDUMP)"
283 endif
284 DERIVE_CONSTANTS_FLAGS += --target-os "$(TargetOS_CPP)"
285
286 ifneq "$(BINDIST)" "YES"
287 $(includes_DERIVEDCONSTANTS): $$(includes_H_FILES) $$(rts_H_FILES)
288 $(includes_GHCCONSTANTS_HASKELL_VALUE): $$(includes_H_FILES) $$(rts_H_FILES)
289
290 $(includes_DERIVEDCONSTANTS): $(deriveConstants_INPLACE) $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) | $$(dir $$@)/.
291 $< --gen-header -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
292
293 $(includes_GHCCONSTANTS_HASKELL_TYPE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
294 $< --gen-haskell-type -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
295
296 $(includes_GHCCONSTANTS_HASKELL_VALUE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
297 $< --gen-haskell-value -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
298
299 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
300 $< --gen-haskell-wrappers -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
301
302 $(includes_GHCCONSTANTS_HASKELL_EXPORTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
303 $< --gen-haskell-exports -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
304 endif
305
306 # ---------------------------------------------------------------------------
307 # Install all header files
308
309 $(eval $(call clean-target,includes,,\
310 $(includes_0_H_CONFIG) $(includes_0_H_PLATFORM) $(includes_0_H_VERSION) \
311 $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) $(includes_1_H_VERSION)))
312
313 $(eval $(call all-target,includes,\
314 $(includes_0_H_CONFIG) $(includes_0_H_PLATFORM) $(includes_0_H_VERSION) \
315 $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) $(includes_1_H_VERSION) \
316 $(includes_GHCCONSTANTS_HASKELL_TYPE) \
317 $(includes_GHCCONSTANTS_HASKELL_VALUE) \
318 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS) \
319 $(includes_GHCCONSTANTS_HASKELL_EXPORTS) \
320 $(includes_DERIVEDCONSTANTS)))
321
322 install: install_includes
323
324 .PHONY: install_includes
325 install_includes : $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) $(includes_1_H_VERSION)
326 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
327 $(foreach d,$(includes_H_SUBDIRS), \
328 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)/$d" && \
329 $(INSTALL_HEADER) $(INSTALL_OPTS) includes/$d/*.h "$(DESTDIR)$(ghcheaderdir)/$d/" && \
330 ) true
331 $(INSTALL_HEADER) $(INSTALL_OPTS) \
332 $(includes_1_H_CONFIG) $(includes_1_H_PLATFORM) $(includes_1_H_VERSION) \
333 $(includes_DERIVEDCONSTANTS) \
334 "$(DESTDIR)$(ghcheaderdir)/"
335