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