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