Improve support for cross-compilation
[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://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
9 # http://hackage.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 ifeq "$(GhcUnregisterised)" "YES"
37 includes_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
38 endif
39
40 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
41 includes_CC_OPTS += -DTABLES_NEXT_TO_CODE
42 endif
43
44 includes_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
45 includes_CC_OPTS += -Irts
46
47 ifneq "$(GhcWithSMP)" "YES"
48 includes_CC_OPTS += -DNOSMP
49 endif
50
51 # The fptools configure script creates the configuration header file and puts it
52 # in fptools/mk/config.h. We copy it down to here (without any PACKAGE_FOO
53 # definitions to avoid clashes), prepending some make variables specifying cpp
54 # platform variables.
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 # Turn '#define PACKAGE_FOO "blah"' into '/* #undef PACKAGE_FOO */'.
71 @sed 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$$,\1/* #undef \2 */,' mk/config.h >> $@
72 @echo "#endif /* __GHCAUTOCONF_H__ */" >> $@
73 @echo "Done."
74
75 endif
76
77 $(includes_H_PLATFORM) : includes/Makefile | $$(dir $$@)/.
78 $(call removeFiles,$@)
79 @echo "Creating $@..."
80 @echo "#ifndef __GHCPLATFORM_H__" >$@
81 @echo "#define __GHCPLATFORM_H__" >>$@
82 @echo >> $@
83 @echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
84 @echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
85 @echo >> $@
86 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
87 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
88 @echo >> $@
89 @echo "#define $(HostArch_CPP)_BUILD_ARCH 1" >> $@
90 @echo "#define $(TargetArch_CPP)_HOST_ARCH 1" >> $@
91 @echo "#define BUILD_ARCH \"$(HostArch_CPP)\"" >> $@
92 @echo "#define HOST_ARCH \"$(TargetArch_CPP)\"" >> $@
93 @echo >> $@
94 @echo "#define $(HostOS_CPP)_BUILD_OS 1" >> $@
95 @echo "#define $(TargetOS_CPP)_HOST_OS 1" >> $@
96 @echo "#define BUILD_OS \"$(HostOS_CPP)\"" >> $@
97 @echo "#define HOST_OS \"$(TargetOS_CPP)\"" >> $@
98 ifeq "$(HostOS_CPP)" "irix"
99 @echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@
100 @echo "#define $(IRIX_MAJOR)_HOST_OS 1" >> $@
101 @echo "#endif" >> $@
102 endif
103 @echo >> $@
104 @echo "#define $(HostVendor_CPP)_BUILD_VENDOR 1" >> $@
105 @echo "#define $(TargetVendor_CPP)_HOST_VENDOR 1" >> $@
106 @echo "#define BUILD_VENDOR \"$(HostVendor_CPP)\"" >> $@
107 @echo "#define HOST_VENDOR \"$(TargetVendor_CPP)\"" >> $@
108 ifeq "$(CC_LLVM_BACKEND)" "1"
109 @echo >> $@
110 @echo "#define llvm_CC_FLAVOR 1" >> $@
111 endif
112 @echo >> $@
113 @echo "/* These TARGET macros are for backwards compatibily... DO NOT USE! */" >> $@
114 @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
115 @echo "#define $(TargetPlatform_CPP)_TARGET 1" >> $@
116 @echo "#define $(TargetArch_CPP)_TARGET_ARCH 1" >> $@
117 @echo "#define TARGET_ARCH \"$(TargetArch_CPP)\"" >> $@
118 @echo "#define $(TargetOS_CPP)_TARGET_OS 1" >> $@
119 @echo "#define TARGET_OS \"$(TargetOS_CPP)\"" >> $@
120 @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR 1" >> $@
121 @echo >> $@
122 @echo "#endif /* __GHCPLATFORM_H__ */" >> $@
123 @echo "Done."
124
125 endif
126
127 # ---------------------------------------------------------------------------
128 # Make DerivedConstants.h for the compiler
129
130 includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
131
132 ifeq "$(PORTING_HOST)-$(AlienScript)" "YES-"
133
134 DerivedConstants.h :
135 @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
136 @exit 1
137
138 else
139
140 includes_dist-derivedconstants_C_SRCS = mkDerivedConstants.c
141 includes_dist-derivedconstants_PROG = mkDerivedConstants$(exeext)
142
143 $(eval $(call build-prog,includes,dist-derivedconstants,0))
144
145 $(includes_dist-derivedconstants_depfile_c_asm) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_FILES) $$(rts_H_FILES)
146 includes/dist-derivedconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
147
148 ifneq "$(AlienScript)" ""
149 $(INPLACE_BIN)/mkDerivedConstants$(exeext): includes/$(includes_dist-derivedconstants_C_SRCS) | $$(dir $$@)/.
150 $(WhatGccIsCalled) -o $@ $< $(CFLAGS) $(includes_CC_OPTS)
151 endif
152
153 ifneq "$(BINDIST)" "YES"
154 $(includes_DERIVEDCONSTANTS) : $(INPLACE_BIN)/mkDerivedConstants$(exeext) | $$(dir $$@)/.
155 ifeq "$(AlienScript)" ""
156 ./$< >$@
157 else
158 $(AlienScript) run ./$< >$@
159 endif
160 endif
161
162 endif
163
164 # -----------------------------------------------------------------------------
165 #
166
167 includes_GHCCONSTANTS = includes/dist-ghcconstants/header/GHCConstants.h
168
169 ifeq "$(PORTING_HOST)-$(AlienScript)" "YES-"
170
171 $(includes_GHCCONSTANTS) :
172 @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
173 @exit 1
174
175 else
176
177 includes_dist-ghcconstants_C_SRCS = mkDerivedConstants.c
178 includes_dist-ghcconstants_PROG = mkGHCConstants$(exeext)
179 includes_dist-ghcconstants_CC_OPTS = -DGEN_HASKELL
180
181 $(eval $(call build-prog,includes,dist-ghcconstants,0))
182
183 ifneq "$(BINDIST)" "YES"
184 $(includes_dist-ghcconstants_depfile_c_asm) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_FILES) $$(rts_H_FILES)
185
186 includes/dist-ghcconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
187
188 ifneq "$(AlienScript)" ""
189 $(INPLACE_BIN)/mkGHCConstants$(exeext): includes/$(includes_dist-ghcconstants_C_SRCS) | $$(dir $$@)/.
190 $(WhatGccIsCalled) -o $@ $< $(CFLAGS) $(includes_CC_OPTS) $(includes_dist-ghcconstants_CC_OPTS)
191 endif
192
193 $(includes_GHCCONSTANTS) : $(INPLACE_BIN)/mkGHCConstants$(exeext) | $$(dir $$@)/.
194 ifeq "$(AlienScript)" ""
195 ./$< >$@
196 else
197 $(AlienScript) run ./$< >$@
198 endif
199 endif
200
201 endif
202
203 # ---------------------------------------------------------------------------
204 # Install all header files
205
206 $(eval $(call clean-target,includes,,\
207 $(includes_H_CONFIG) $(includes_H_PLATFORM) \
208 $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))
209
210 $(eval $(call all-target,includes,,\
211 $(includes_H_CONFIG) $(includes_H_PLATFORM) \
212 $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))
213
214 install: install_includes
215
216 .PHONY: install_includes
217 install_includes :
218 $(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)")
219 $(foreach d,$(includes_H_SUBDIRS), \
220 $(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)/$d") && \
221 $(call INSTALL_HEADER,$(INSTALL_OPTS),includes/$d/*.h,"$(DESTDIR)$(ghcheaderdir)/$d/") && \
222 ) true
223 $(call INSTALL_HEADER,$(INSTALL_OPTS),$(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS),"$(DESTDIR)$(ghcheaderdir)/")
224