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