1 # -----------------------------------------------------------------------------
3 # (c) 2009 The University of Glasgow
5 # This file is part of the GHC build system.
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
11 # -----------------------------------------------------------------------------
14 # Header files built from the configure script's findings
16 # XXX: these should go in includes/dist/build?
17 includes_H_CONFIG = includes/ghcautoconf.h
18 includes_H_PLATFORM = includes/ghcplatform.h
23 includes_H_FILES = $(filter-out $(includes_H_CONFIG) $(includes_H_PLATFORM),$(wildcard includes/*.h includes/*/*.h includes/*/*/*.h))
28 ifeq "$(GhcUnregisterised)" "YES"
29 includes_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
32 ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
33 includes_CC_OPTS += -DTABLES_NEXT_TO_CODE
36 includes_CC_OPTS += -Iincludes -Irts
38 ifneq "$(GhcWithSMP)" "YES"
39 includes_CC_OPTS += -DNOSMP
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
47 ifneq "$(BINDIST)" "YES"
49 ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
51 $(includes_H_CONFIG) :
52 @echo "*** Cross-compiling: please copy $(includes_H_CONFIG) from the target system"
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__ */" >> $@
68 $(includes_H_PLATFORM) : includes/Makefile
70 @echo "Creating $@..."
71 @echo "#ifndef __GHCPLATFORM_H__" >$@
72 @echo "#define __GHCPLATFORM_H__" >>$@
74 @echo "#define BuildPlatform_TYPE $(HostPlatform_CPP)" >> $@
75 @echo "#define HostPlatform_TYPE $(TargetPlatform_CPP)" >> $@
77 @echo "#define $(HostPlatform_CPP)_BUILD 1" >> $@
78 @echo "#define $(TargetPlatform_CPP)_HOST 1" >> $@
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)\"" >> $@
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" >> $@
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)\"" >> $@
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" >> $@
109 @echo "#endif /* __GHCPLATFORM_H__ */" >> $@
114 # ---------------------------------------------------------------------------
115 # Make DerivedConstants.h for the compiler
117 includes_DERIVEDCONSTANTS = includes/DerivedConstants.h
119 ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
122 @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
127 includes_dist-derivedconstants_C_SRCS = mkDerivedConstants.c
128 includes_dist-derivedconstants_PROG = mkDerivedConstants$(exeext)
130 $(eval $(call build-prog,includes,dist-derivedconstants,0))
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)
135 ifneq "$(BINDIST)" "YES"
136 $(includes_DERIVEDCONSTANTS) : $(INPLACE_BIN)/mkDerivedConstants$(exeext)
142 # -----------------------------------------------------------------------------
145 includes_GHCCONSTANTS = includes/GHCConstants.h
147 ifneq "$(TARGETPLATFORM)" "$(HOSTPLATFORM)"
149 $(includes_GHCCONSTANTS) :
150 @echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
155 includes_dist-ghcconstants_C_SRCS = mkDerivedConstants.c
156 includes_dist-ghcconstants_PROG = mkGHCConstants$(exeext)
157 includes_dist-ghcconstants_CC_OPTS = -DGEN_HASKELL
159 $(eval $(call build-prog,includes,dist-ghcconstants,0))
161 ifneq "$(BINDIST)" "YES"
162 $(includes_dist-ghcconstants_depfile) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(wildcard includes/*.h) $(wildcard rts/*.h)
164 includes/dist-ghcconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)
166 $(includes_GHCCONSTANTS) : $(INPLACE_BIN)/mkGHCConstants$(exeext)
172 # ---------------------------------------------------------------------------
173 # Install all header files
175 $(eval $(call clean-target,includes,,\
176 $(includes_H_CONFIG) $(includes_H_PLATFORM) \
177 $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))
179 $(eval $(call all-target,includes,,\
180 $(includes_H_CONFIG) $(includes_H_PLATFORM) \
181 $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))
183 includes_subdirs = $(sort $(subst includes/,,$(foreach d,$(includes_H_FILES),$(dir $(d)))))
185 install: install_includes
187 .PHONY: install_includes
189 $(INSTALL_DIR) $(DESTDIR)$(ghcheaderdir)
190 for d in $(includes_subdirs); do \
191 $(INSTALL_DIR) $(DESTDIR)$(ghcheaderdir)/$$d; \
193 for i in $(subst includes/,,$(includes_H_FILES) $(includes_H_CONFIG) $(includes_H_PLATFORM)); do \
194 $(INSTALL_HEADER) $(INSTALL_OPTS) includes/$$i $(DESTDIR)$(ghcheaderdir)/$$i; \