allow build settings to be overriden by adding mk/validate.mk
[ghc-hetmet.git] / includes / Makefile
1 # -----------------------------------------------------------------------------
2
3 TOP = ..
4 include $(TOP)/mk/boilerplate.mk
5
6 #
7 # Header files built from the configure script's findings
8 #
9 H_CONFIG   = ghcautoconf.h
10 H_PLATFORM = ghcplatform.h
11
12 #
13 # All header files
14 #
15 H_FILES = $(filter-out $(H_CONFIG) $(H_PLATFORM),$(wildcard *.h))
16
17 ifneq "$(DOING_BIN_DIST)" "YES"
18
19 #
20 # Options
21 #
22 ifeq "$(GhcUnregisterised)" "YES"
23 SRC_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
24 endif
25
26 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
27 SRC_CC_OPTS += -DTABLES_NEXT_TO_CODE
28 endif
29
30 SRC_CC_OPTS += -I. -I../rts -I../gmp/gmpbuild
31
32 ifneq "$(GhcWithSMP)" "YES"
33 SRC_CC_OPTS += -DNOSMP
34 endif
35
36 all :: $(H_CONFIG) $(H_PLATFORM)
37
38 # The fptools configure script creates the configuration header file and puts it
39 # in fptools/mk/config.h. We copy it down to here (without any PACKAGE_FOO
40 # definitions to avoid clashes), prepending some make variables specifying cpp
41 # platform variables.
42
43 ifneq "$(TARGETPLATFORM)"  "$(HOSTPLATFORM)"
44
45 $(H_CONFIG) :
46         @echo "*** Cross-compiling: please copy $(H_CONFIG) from the target system"
47         @exit 1
48
49 else
50
51 $(H_CONFIG) : $(FPTOOLS_TOP)/mk/config.h $(FPTOOLS_TOP)/mk/config.mk
52
53 $(H_CONFIG) : Makefile
54         @echo "Creating $@..."
55         @echo "#ifndef __GHCAUTOCONF_H__"  >$@
56         @echo "#define __GHCAUTOCONF_H__" >>$@
57 #       Turn '#define PACKAGE_FOO "blah"' into '/* #undef PACKAGE_FOO */'.
58         @sed 's,^\([     ]*\)#[  ]*define[       ][      ]*\(PACKAGE_[A-Z]*\)[   ][     ]*".*".*$$,\1/* #undef \2 */,' $(FPTOOLS_TOP)/mk/config.h >> $@
59         @echo "#endif /* __GHCAUTOCONF_H__ */"          >> $@
60         @echo "Done."
61
62 endif
63
64 $(H_PLATFORM) : Makefile
65         @echo "Creating $@..."
66         @$(RM) $@
67         @echo "#ifndef __GHCPLATFORM_H__"  >$@
68         @echo "#define __GHCPLATFORM_H__" >>$@
69         @echo >> $@
70         @echo "#define BuildPlatform_TYPE  $(HostPlatform_CPP)" >> $@
71         @echo "#define HostPlatform_TYPE   $(TargetPlatform_CPP)" >> $@
72         @echo >> $@
73         @echo "#define $(HostPlatform_CPP)_BUILD  1" >> $@
74         @echo "#define $(TargetPlatform_CPP)_HOST  1" >> $@
75         @echo >> $@
76         @echo "#define $(HostArch_CPP)_BUILD_ARCH  1" >> $@
77         @echo "#define $(TargetArch_CPP)_HOST_ARCH  1" >> $@
78         @echo "#define BUILD_ARCH  \"$(HostArch_CPP)\"" >> $@
79         @echo "#define HOST_ARCH  \"$(TargetArch_CPP)\"" >> $@
80         @echo >> $@
81         @echo "#define $(HostOS_CPP)_BUILD_OS  1" >> $@
82         @echo "#define $(TargetOS_CPP)_HOST_OS  1" >> $@
83         @echo "#define BUILD_OS  \"$(HostOS_CPP)\"" >> $@
84         @echo "#define HOST_OS  \"$(TargetOS_CPP)\"" >> $@
85 ifeq "$(HostOS_CPP)" "irix"
86         @echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@  
87         @echo "#define $(IRIX_MAJOR)_HOST_OS  1" >> $@  
88         @echo "#endif" >> $@  
89 endif
90         @echo >> $@
91         @echo "#define $(HostVendor_CPP)_BUILD_VENDOR  1" >> $@
92         @echo "#define $(TargetVendor_CPP)_HOST_VENDOR  1" >> $@
93         @echo "#define BUILD_VENDOR  \"$(HostVendor_CPP)\"" >> $@
94         @echo "#define HOST_VENDOR  \"$(TargetVendor_CPP)\"" >> $@
95         @echo >> $@
96         @echo "/* These TARGET macros are for backwards compatibily... DO NOT USE! */" >> $@
97         @echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
98         @echo "#define $(TargetPlatform_CPP)_TARGET  1" >> $@
99         @echo "#define $(TargetArch_CPP)_TARGET_ARCH  1" >> $@
100         @echo "#define TARGET_ARCH  \"$(TargetArch_CPP)\"" >> $@
101         @echo "#define $(TargetOS_CPP)_TARGET_OS  1" >> $@  
102         @echo "#define TARGET_OS  \"$(TargetOS_CPP)\"" >> $@
103         @echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
104         @echo >> $@
105         @echo "#endif /* __GHCPLATFORM_H__ */"          >> $@
106         @echo "Done."
107
108 # ---------------------------------------------------------------------------
109 # Make DerivedConstants.h for the compiler
110
111 all :: DerivedConstants.h
112
113 ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
114
115 DerivedConstants.h :
116         @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
117         @exit 1
118
119 else
120
121 mkDerivedConstants.c : $(H_CONFIG) $(H_PLATFORM)
122
123 mkDerivedConstantsHdr : mkDerivedConstants.o
124         $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkDerivedConstants.o
125
126 DerivedConstants.h : mkDerivedConstantsHdr
127         ./mkDerivedConstantsHdr >$@
128
129 endif
130
131 CLEAN_FILES += mkDerivedConstantsHdr$(exeext) DerivedConstants.h
132
133 # -----------------------------------------------------------------------------
134 #
135
136 all :: GHCConstants.h
137
138 ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
139
140 GHCConstants.h :
141         @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
142         @exit 1
143
144 else
145
146 mkGHCConstants : mkGHCConstants.o
147         $(CC) -o $@ $(CC_OPTS) $(LD_OPTS) mkGHCConstants.o
148
149 mkGHCConstants.o : mkDerivedConstants.c
150         $(CC) -o $@ $(CC_OPTS) -c $<  -DGEN_HASKELL
151
152 GHCConstants.h : mkGHCConstants
153         ./mkGHCConstants >$@
154
155 endif
156
157 CLEAN_FILES += mkGHCConstants$(exeext) GHCConstants.h
158
159 endif
160
161 # ---------------------------------------------------------------------------
162 # boot setup:
163 #
164 #
165 # Install all header files
166 #
167 # Hackily set the install destination here:
168 #
169 # Note: we keep per-platform copies of all the include files
170 # (ditto for interface files). This is not *really* needed, but
171 # it gives (perhaps) a cleaner binary dist structure..might change.
172 #
173 override datadir:=$(libdir)/include
174 INSTALL_DATAS += $(H_FILES) $(H_CONFIG) $(H_PLATFORM)
175
176 binary-dist:
177         $(INSTALL_DIR)                   $(BIN_DIST_DIR)/includes
178         $(INSTALL_DATA) Makefile         $(BIN_DIST_DIR)/includes/
179         $(INSTALL_DATA) $(INSTALL_DATAS) $(BIN_DIST_DIR)/includes/
180
181 #
182 # `make clean' settings:
183 #
184 CLEAN_FILES += $(H_CONFIG) $(H_PLATFORM)
185
186 #
187 # Finally, slurp in the standard targets.
188 #
189 include $(TOP)/mk/target.mk
190
191 # We need DerivedConstants.h in order to make dependencies in the RTS
192 # sources, so 'make boot' here should behave like 'make all'.
193 #
194 # However, note that we should do this only *after* 'make boot' has
195 # created .depend in here; otherwise an out-of-date .depend file can
196 # prevent 'make boot' from working, requiring manual removal of
197 # .depend (see #1095).  This is why the following target comes *after*
198 # target.mk is included above (target.mk contains "boot :: depend").
199 #
200 boot :: all