[ci skip] includes: detabify/dewhitespace rts/Stable.h
[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
20 #
21 # All header files are in includes/{one of these subdirectories}
22 #
23 includes_H_SUBDIRS += .
24 includes_H_SUBDIRS += rts
25 includes_H_SUBDIRS += rts/prof
26 includes_H_SUBDIRS += rts/storage
27 includes_H_SUBDIRS += stg
28
29 includes_H_FILES := $(wildcard $(patsubst %,includes/%/*.h,$(includes_H_SUBDIRS)))
30 # This isn't necessary, but it makes the paths look a little prettier
31 includes_H_FILES := $(subst /./,/,$(includes_H_FILES))
32
33 #
34 # Options
35 #
36
37 includes_CC_OPTS += $(SRC_CC_OPTS)
38 includes_CC_OPTS += $(SRC_CC_WARNING_OPTS)
39 includes_CC_OPTS += $(CONF_CC_OPTS_STAGE1)
40
41 ifeq "$(GhcUnregisterised)" "YES"
42 includes_CC_OPTS += -DUSE_MINIINTERPRETER
43 endif
44
45 includes_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
46 includes_CC_OPTS += -Irts
47
48 ifneq "$(GhcWithSMP)" "YES"
49 includes_CC_OPTS += -DNOSMP
50 endif
51
52 ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
53 includes_CC_OPTS += -DDYNAMIC_BY_DEFAULT
54 endif
55
56 ifneq "$(BINDIST)" "YES"
57
58 ifeq "$(PORTING_HOST)" "YES"
59
60 $(includes_H_CONFIG) :
61 @echo "*** Cross-compiling: please copy $(includes_H_CONFIG) from the target system"
62 @exit 1
63
64 else
65
66 $(includes_H_CONFIG) : mk/config.h mk/config.mk includes/ghc.mk | $$(dir $$@)/.
67 @echo "Creating $@..."
68 @echo "#ifndef __GHCAUTOCONF_H__" >$@
69 @echo "#define __GHCAUTOCONF_H__" >>$@
70 #
71 # Copy the contents of mk/config.h, turning '#define PACKAGE_FOO
72 # "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
73 #
74 @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$,\1/* #undef \2 */,' mk/config.h >> $@
75 #
76 # Tack on some extra config information from the build system
77 #
78 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
79 @echo >> $@
80 @echo "#define TABLES_NEXT_TO_CODE 1" >> $@
81 endif
82 #
83 ifeq "$(CC_LLVM_BACKEND)" "1"
84 @echo >> $@
85 @echo "#define llvm_CC_FLAVOR 1" >> $@
86 endif
87 #
88 ifeq "$(CC_CLANG_BACKEND)" "1"
89 @echo >> $@
90 @echo "#define clang_CC_FLAVOR 1" >> $@
91 endif
92 #
93 @echo "#endif /* __GHCAUTOCONF_H__ */" >> $@
94 @echo "Done."
95
96 endif
97
98 $(includes_H_PLATFORM) : includes/Makefile | $$(dir $$@)/.
99 $(call removeFiles,$@)
100 @echo "Creating $@..."
101 @echo "#ifndef __GHCPLATFORM_H__" >$@
102 @echo "#define __GHCPLATFORM_H__" >>$@
103 @echo >> $@
104 @echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
105 @echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
106 @echo >> $@
107 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
108 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
109 @echo >> $@
110 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
111 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
112 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
113 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
114 @echo >> $@
115 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
116 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
117 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
118 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
119 ifeq "$(HostOS_CPP)" "irix"
120 @echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@
121 @echo "#define $(IRIX_MAJOR)_HOST_OS 1" >> $@
122 @echo "#endif" >> $@
123 endif
124 @echo >> $@
125 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
126 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
127 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
128 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
129 @echo >> $@
130 @echo "/* These TARGET macros are for backwards compatibility... DO NOT USE! */" >> $@
131 @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
132 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
133 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
134 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
135 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
136 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
137 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
138 ifeq "$(GhcUnregisterised)" "YES"
139 @echo "#define UnregisterisedCompiler 1" >> $@
140 endif
141 @echo >> $@
142 @echo "#endif /* __GHCPLATFORM_H__ */" >> $@
143 @echo "Done."
144
145 endif
146
147 # ---------------------------------------------------------------------------
148 # Make DerivedConstants.h for the compiler
149
150 includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
151 includes_GHCCONSTANTS_HASKELL_TYPE = includes/dist-derivedconstants/header/GHCConstantsHaskellType.hs
152 includes_GHCCONSTANTS_HASKELL_VALUE = includes/dist-derivedconstants/header/platformConstants
153 includes_GHCCONSTANTS_HASKELL_WRAPPERS = includes/dist-derivedconstants/header/GHCConstantsHaskellWrappers.hs
154 includes_GHCCONSTANTS_HASKELL_EXPORTS = includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs
155
156 INSTALL_LIBS += $(includes_GHCCONSTANTS_HASKELL_VALUE)
157
158 DERIVE_CONSTANTS_FLAGS += --gcc-program "$(WhatGccIsCalled)"
159 DERIVE_CONSTANTS_FLAGS += $(addprefix --gcc-flag$(space),$(includes_CC_OPTS) -fcommon)
160 DERIVE_CONSTANTS_FLAGS += --nm-program "$(NM)"
161
162 ifneq "$(BINDIST)" "YES"
163 $(includes_DERIVEDCONSTANTS): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_FILES) $$(rts_H_FILES)
164 $(includes_GHCCONSTANTS_HASKELL_VALUE): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_FILES) $$(rts_H_FILES)
165
166 $(includes_DERIVEDCONSTANTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
167 $< --gen-header -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
168
169 $(includes_GHCCONSTANTS_HASKELL_TYPE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
170 $< --gen-haskell-type -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
171
172 $(includes_GHCCONSTANTS_HASKELL_VALUE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
173 $< --gen-haskell-value -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
174
175 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
176 $< --gen-haskell-wrappers -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
177
178 $(includes_GHCCONSTANTS_HASKELL_EXPORTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
179 $< --gen-haskell-exports -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
180 endif
181
182 # ---------------------------------------------------------------------------
183 # Install all header files
184
185 $(eval $(call clean-target,includes,,\
186 $(includes_H_CONFIG) $(includes_H_PLATFORM)))
187
188 $(eval $(call all-target,includes,\
189 $(includes_H_CONFIG) $(includes_H_PLATFORM) \
190 $(includes_GHCCONSTANTS_HASKELL_TYPE) \
191 $(includes_GHCCONSTANTS_HASKELL_VALUE) \
192 $(includes_GHCCONSTANTS_HASKELL_WRAPPERS) \
193 $(includes_GHCCONSTANTS_HASKELL_EXPORTS) \
194 $(includes_DERIVEDCONSTANTS)))
195
196 install: install_includes
197
198 .PHONY: install_includes
199 install_includes :
200 $(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)")
201 $(foreach d,$(includes_H_SUBDIRS), \
202 $(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)/$d") && \
203 $(call INSTALL_HEADER,$(INSTALL_OPTS),includes/$d/*.h,"$(DESTDIR)$(ghcheaderdir)/$d/") && \
204 ) true
205 $(call INSTALL_HEADER,$(INSTALL_OPTS),$(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_DERIVEDCONSTANTS),"$(DESTDIR)$(ghcheaderdir)/")
206