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