ef994f2329a87df72805df06f951a079146b4226
[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)" "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 "$(BINDIST)" "YES"
149 $(includes_DERIVEDCONSTANTS) : $(INPLACE_BIN)/mkDerivedConstants$(exeext) | $$(dir $$@)/.
150 ./$< >$@
151 endif
152
153 endif
154
155 # -----------------------------------------------------------------------------
156 #
157
158 includes_GHCCONSTANTS = includes/dist-ghcconstants/header/GHCConstants.h
159
160 ifeq "$(PORTING_HOST)" "YES"
161
162 $(includes_GHCCONSTANTS) :
163 @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
164 @exit 1
165
166 else
167
168 includes_dist-ghcconstants_C_SRCS = mkDerivedConstants.c
169 includes_dist-ghcconstants_PROG = mkGHCConstants$(exeext)
170 includes_dist-ghcconstants_CC_OPTS = -DGEN_HASKELL
171
172 $(eval $(call build-prog,includes,dist-ghcconstants,0))
173
174 ifneq "$(BINDIST)" "YES"
175 $(includes_dist-ghcconstants_depfile_c_asm) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_FILES) $$(rts_H_FILES)
176
177 includes/dist-ghcconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
178
179 $(includes_GHCCONSTANTS) : $(INPLACE_BIN)/mkGHCConstants$(exeext) | $$(dir $$@)/.
180 ./$< >$@
181 endif
182
183 endif
184
185 # ---------------------------------------------------------------------------
186 # Install all header files
187
188 $(eval $(call clean-target,includes,,\
189 $(includes_H_CONFIG) $(includes_H_PLATFORM) \
190 $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))
191
192 $(eval $(call all-target,includes,,\
193 $(includes_H_CONFIG) $(includes_H_PLATFORM) \
194 $(includes_GHCCONSTANTS) $(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_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS),"$(DESTDIR)$(ghcheaderdir)/")
206