hs_add_root() RTS API removal
[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 "#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 # Make DerivedConstants.h for the compiler
171
172 includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
173 includes_GHCCONSTANTS_HASKELL_TYPE = includes/dist-derivedconstants/header/GHCConstantsHaskellType.hs
174 includes_GHCCONSTANTS_HASKELL_VALUE = includes/dist-derivedconstants/header/platformConstants
175 includes_GHCCONSTANTS_HASKELL_WRAPPERS = includes/dist-derivedconstants/header/GHCConstantsHaskellWrappers.hs
176 includes_GHCCONSTANTS_HASKELL_EXPORTS = includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs
177
178 INSTALL_LIBS += $(includes_GHCCONSTANTS_HASKELL_VALUE)
179
180 DERIVE_CONSTANTS_FLAGS += --gcc-program "$(CC)"
181 DERIVE_CONSTANTS_FLAGS += $(addprefix --gcc-flag$(space),$(includes_CC_OPTS) -fcommon)
182 DERIVE_CONSTANTS_FLAGS += --nm-program "$(NM)"
183 ifneq "$(OBJDUMP)" ""
184 DERIVE_CONSTANTS_FLAGS += --objdump-program "$(OBJDUMP)"
185 endif
186 DERIVE_CONSTANTS_FLAGS += --target-os "$(TargetOS_CPP)"
187
188 ifneq "$(BINDIST)" "YES"
189 $(includes_DERIVEDCONSTANTS): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
190 $(includes_GHCCONSTANTS_HASKELL_VALUE): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
191
192 $(includes_DERIVEDCONSTANTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
193 $< --gen-header -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
194
195 $(includes_GHCCONSTANTS_HASKELL_TYPE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
196 $< --gen-haskell-type -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
197
198 $(includes_GHCCONSTANTS_HASKELL_VALUE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
199 $< --gen-haskell-value -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
200
201 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
202 $< --gen-haskell-wrappers -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
203
204 $(includes_GHCCONSTANTS_HASKELL_EXPORTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
205 $< --gen-haskell-exports -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
206 endif
207
208 # ---------------------------------------------------------------------------
209 # Install all header files
210
211 $(eval $(call clean-target,includes,,\
212 $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION)))
213
214 $(eval $(call all-target,includes,\
215 $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) \
216 $(includes_GHCCONSTANTS_HASKELL_TYPE) \
217 $(includes_GHCCONSTANTS_HASKELL_VALUE) \
218 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS) \
219 $(includes_GHCCONSTANTS_HASKELL_EXPORTS) \
220 $(includes_DERIVEDCONSTANTS)))
221
222 install: install_includes
223
224 .PHONY: install_includes
225 install_includes :
226 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)"
227 $(foreach d,$(includes_H_SUBDIRS), \
228 $(INSTALL_DIR) "$(DESTDIR)$(ghcheaderdir)/$d" && \
229 $(INSTALL_HEADER) $(INSTALL_OPTS) includes/$d/*.h "$(DESTDIR)$(ghcheaderdir)/$d/" && \
230 ) true
231 $(INSTALL_HEADER) $(INSTALL_OPTS) $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) $(includes_DERIVEDCONSTANTS) "$(DESTDIR)$(ghcheaderdir)/"
232