Generate settings by make/hadrian instead of configure
[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 # 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 "#define __GLASGOW_HASKELL__ $(ProjectVersionInt)" >> $@
64 @echo >> $@
65 @if [ -n "$(ProjectPatchLevel1)" ]; then \
66 echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $(ProjectPatchLevel1)" >> $@; \
67 fi
68 @if [ -n "$(ProjectPatchLevel2)" ]; then \
69 echo "#define __GLASGOW_HASKELL_PATCHLEVEL2__ $(ProjectPatchLevel2)" >> $@; \
70 fi
71 @echo >> $@
72 @echo '#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\' >> $@
73 @echo ' ((ma)*100+(mi)) < __GLASGOW_HASKELL__ || \' >> $@
74 @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $@
75 @echo ' && (pl1) < __GLASGOW_HASKELL_PATCHLEVEL1__ || \' >> $@
76 @echo ' ((ma)*100+(mi)) == __GLASGOW_HASKELL__ \' >> $@
77 @echo ' && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \' >> $@
78 @echo ' && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )' >> $@
79 @echo >> $@
80 @echo "#endif /* __GHCVERSION_H__ */" >> $@
81 @echo "Done."
82
83 ifneq "$(BINDIST)" "YES"
84
85 ifeq "$(PORTING_HOST)" "YES"
86
87 $(includes_H_CONFIG) :
88 @echo "*** Cross-compiling: please copy $(includes_H_CONFIG) from the target system"
89 @exit 1
90
91 else
92
93 $(includes_H_CONFIG) : mk/config.h mk/config.mk includes/ghc.mk | $$(dir $$@)/.
94 @echo "Creating $@..."
95 @echo "#ifndef __GHCAUTOCONF_H__" >$@
96 @echo "#define __GHCAUTOCONF_H__" >>$@
97 #
98 # Copy the contents of mk/config.h, turning '#define PACKAGE_FOO
99 # "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
100 #
101 @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$,\1/* #undef \2 */,' mk/config.h >> $@
102 #
103 # Tack on some extra config information from the build system
104 #
105 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
106 @echo >> $@
107 @echo "#define TABLES_NEXT_TO_CODE 1" >> $@
108 endif
109 #
110 ifeq "$(CC_LLVM_BACKEND)" "1"
111 @echo >> $@
112 @echo "#define llvm_CC_FLAVOR 1" >> $@
113 endif
114 #
115 ifeq "$(CC_CLANG_BACKEND)" "1"
116 @echo >> $@
117 @echo "#define clang_CC_FLAVOR 1" >> $@
118 endif
119 #
120 @echo "#endif /* __GHCAUTOCONF_H__ */" >> $@
121 @echo "Done."
122
123 endif
124
125 $(includes_H_PLATFORM) : includes/Makefile | $$(dir $$@)/.
126 $(call removeFiles,$@)
127 @echo "Creating $@..."
128 @echo "#ifndef __GHCPLATFORM_H__" >$@
129 @echo "#define __GHCPLATFORM_H__" >>$@
130 @echo >> $@
131 @echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
132 @echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
133 @echo >> $@
134 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
135 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
136 @echo >> $@
137 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
138 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
139 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
140 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
141 @echo >> $@
142 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
143 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
144 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
145 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
146 @echo >> $@
147 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
148 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
149 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
150 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
151 @echo >> $@
152 @echo "/* These TARGET macros are for backwards compatibility... DO NOT USE! */" >> $@
153 @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
154 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
155 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
156 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
157 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
158 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
159 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
160 ifeq "$(GhcUnregisterised)" "YES"
161 @echo "#define UnregisterisedCompiler 1" >> $@
162 endif
163 @echo >> $@
164 @echo "#endif /* __GHCPLATFORM_H__ */" >> $@
165 @echo "Done."
166
167 endif
168
169 # -----------------------------------------------------------------------------
170 # Settings
171
172 # These settings are read by GHC at runtime, so as to not cause spurious
173 # rebuilds.
174
175 includes_SETTINGS = includes/dist/build/settings
176
177 $(includes_SETTINGS) : includes/Makefile | $$(dir $$@)/.
178 $(call removeFiles,$@)
179 @echo '[("GCC extra via C opts", "$(GccExtraViaCOpts)")' >> $@
180 @echo ',("C compiler command", "$(SettingsCCompilerCommand)")' >> $@
181 @echo ',("C compiler flags", "$(SettingsCCompilerFlags)")' >> $@
182 @echo ',("C compiler link flags", "$(SettingsCCompilerLinkFlags)")' >> $@
183 @echo ',("C compiler supports -no-pie", "$(SettingsCCompilerSupportsNoPie)")' >> $@
184 @echo ',("Haskell CPP command", "$(SettingsHaskellCPPCommand)")' >> $@
185 @echo ',("Haskell CPP flags", "$(SettingsHaskellCPPFlags)")' >> $@
186 @echo ',("ld command", "$(SettingsLdCommand)")' >> $@
187 @echo ',("ld flags", "$(SettingsLdFlags)")' >> $@
188 @echo ',("ld supports compact unwind", "$(LdHasNoCompactUnwind)")' >> $@
189 @echo ',("ld supports build-id", "$(LdHasBuildId)")' >> $@
190 @echo ',("ld supports filelist", "$(LdHasFilelist)")' >> $@
191 @echo ',("ld is GNU ld", "$(LdIsGNULd)")' >> $@
192 @echo ',("ar command", "$(SettingsArCommand)")' >> $@
193 @echo ',("ar flags", "$(ArArgs)")' >> $@
194 @echo ',("ar supports at file", "$(ArSupportsAtFile)")' >> $@
195 @echo ',("ranlib command", "$(SettingsRanlibCommand)")' >> $@
196 @echo ',("touch command", "$(SettingsTouchCommand)")' >> $@
197 @echo ',("dllwrap command", "$(SettingsDllWrapCommand)")' >> $@
198 @echo ',("windres command", "$(SettingsWindresCommand)")' >> $@
199 @echo ',("libtool command", "$(SettingsLibtoolCommand)")' >> $@
200 @echo ',("cross compiling", "$(CrossCompiling)")' >> $@
201 @echo ',("target os", "$(HaskellTargetOs)")' >> $@
202 @echo ',("target arch", "$(HaskellTargetArch)")' >> $@
203 @echo ',("target word size", "$(TargetWordSize)")' >> $@
204 @echo ',("target has GNU nonexec stack", "$(HaskellHaveGnuNonexecStack)")' >> $@
205 @echo ',("target has .ident directive", "$(HaskellHaveIdentDirective)")' >> $@
206 @echo ',("target has subsections via symbols", "$(HaskellHaveSubsectionsViaSymbols)")' >> $@
207 @echo ',("target has RTS linker", "$(HaskellHaveRTSLinker)")' >> $@
208 @echo ',("Unregisterised", "$(Unregisterised)")' >> $@
209 @echo ',("LLVM llc command", "$(SettingsLlcCommand)")' >> $@
210 @echo ',("LLVM opt command", "$(SettingsOptCommand)")' >> $@
211 @echo ',("LLVM clang command", "$(SettingsClangCommand)")' >> $@
212 @echo ']' >> $@
213
214
215 # ---------------------------------------------------------------------------
216 # Make DerivedConstants.h for the compiler
217
218 includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
219 includes_GHCCONSTANTS_HASKELL_TYPE = includes/dist-derivedconstants/header/GHCConstantsHaskellType.hs
220 includes_GHCCONSTANTS_HASKELL_VALUE = includes/dist-derivedconstants/header/platformConstants
221 includes_GHCCONSTANTS_HASKELL_WRAPPERS = includes/dist-derivedconstants/header/GHCConstantsHaskellWrappers.hs
222 includes_GHCCONSTANTS_HASKELL_EXPORTS = includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs
223
224 INSTALL_LIBS += $(includes_GHCCONSTANTS_HASKELL_VALUE)
225
226 DERIVE_CONSTANTS_FLAGS += --gcc-program "$(CC)"
227 DERIVE_CONSTANTS_FLAGS += $(addprefix --gcc-flag$(space),$(includes_CC_OPTS) -fcommon)
228 DERIVE_CONSTANTS_FLAGS += --nm-program "$(NM)"
229 ifneq "$(OBJDUMP)" ""
230 DERIVE_CONSTANTS_FLAGS += --objdump-program "$(OBJDUMP)"
231 endif
232 DERIVE_CONSTANTS_FLAGS += --target-os "$(TargetOS_CPP)"
233
234 ifneq "$(BINDIST)" "YES"
235 $(includes_DERIVEDCONSTANTS): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
236 $(includes_GHCCONSTANTS_HASKELL_VALUE): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
237
238 $(includes_DERIVEDCONSTANTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
239 $< --gen-header -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
240
241 $(includes_GHCCONSTANTS_HASKELL_TYPE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
242 $< --gen-haskell-type -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
243
244 $(includes_GHCCONSTANTS_HASKELL_VALUE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
245 $< --gen-haskell-value -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
246
247 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
248 $< --gen-haskell-wrappers -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
249
250 $(includes_GHCCONSTANTS_HASKELL_EXPORTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
251 $< --gen-haskell-exports -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
252 endif
253
254 # ---------------------------------------------------------------------------
255 # Install all header files
256
257 $(eval $(call clean-target,includes,,\
258 $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION)))
259
260 $(eval $(call all-target,includes,\
261 $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) \
262 $(includes_GHCCONSTANTS_HASKELL_TYPE) \
263 $(includes_GHCCONSTANTS_HASKELL_VALUE) \
264 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS) \
265 $(includes_GHCCONSTANTS_HASKELL_EXPORTS) \
266 $(includes_DERIVEDCONSTANTS)))
267
268 install: install_includes
269
270 .PHONY: install_includes
271 install_includes :
272 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
273 $(foreach d,$(includes_H_SUBDIRS), \
274 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)/$d" && \
275 $(INSTALL_HEADER) $(INSTALL_OPTS) includes/$d/*.h "$(DESTDIR)$(ghcheaderdir)/$d/" && \
276 ) true
277 $(INSTALL_HEADER) $(INSTALL_OPTS) $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) $(includes_DERIVEDCONSTANTS) "$(DESTDIR)$(ghcheaderdir)/"
278