ghc.mk 8.59 KB
Newer Older
1 2 3 4 5 6 7
# -----------------------------------------------------------------------------
#
# (c) 2009 The University of Glasgow
#
# This file is part of the GHC build system.
#
# To understand how the build system works and how to modify it, see
8 9
#      http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
#      http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
10 11 12
#
# -----------------------------------------------------------------------------

Ian Lynagh's avatar
Ian Lynagh committed
13 14 15 16 17 18
#
# Header files built from the configure script's findings
#
# XXX: these should go in includes/dist/build?
includes_H_CONFIG   = includes/ghcautoconf.h
includes_H_PLATFORM = includes/ghcplatform.h
19
includes_H_VERSION  = includes/ghcversion.h
Ian Lynagh's avatar
Ian Lynagh committed
20 21

#
22
# All header files are in includes/{one of these subdirectories}
Ian Lynagh's avatar
Ian Lynagh committed
23
#
24 25 26 27 28 29 30
includes_H_SUBDIRS += .
includes_H_SUBDIRS += rts
includes_H_SUBDIRS += rts/prof
includes_H_SUBDIRS += rts/storage
includes_H_SUBDIRS += stg

includes_H_FILES := $(wildcard $(patsubst %,includes/%/*.h,$(includes_H_SUBDIRS)))
31 32
# This isn't necessary, but it makes the paths look a little prettier
includes_H_FILES := $(subst /./,/,$(includes_H_FILES))
Ian Lynagh's avatar
Ian Lynagh committed
33 34 35 36

#
# Options
#
37 38 39 40 41

includes_CC_OPTS += $(SRC_CC_OPTS)
includes_CC_OPTS += $(SRC_CC_WARNING_OPTS)
includes_CC_OPTS += $(CONF_CC_OPTS_STAGE1)

Ian Lynagh's avatar
Ian Lynagh committed
42
ifeq "$(GhcUnregisterised)" "YES"
43
includes_CC_OPTS += -DUSE_MINIINTERPRETER
Ian Lynagh's avatar
Ian Lynagh committed
44 45
endif

Ian Lynagh's avatar
Ian Lynagh committed
46
includes_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
47
includes_CC_OPTS += -Irts
Ian Lynagh's avatar
Ian Lynagh committed
48 49 50 51 52

ifneq "$(GhcWithSMP)" "YES"
includes_CC_OPTS += -DNOSMP
endif

53 54 55 56
ifeq "$(DYNAMIC_BY_DEFAULT)" "YES"
includes_CC_OPTS += -DDYNAMIC_BY_DEFAULT
endif

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

$(includes_H_VERSION) : mk/project.mk | $$(dir $$@)/.
	@echo "Creating $@..."
	@echo "#ifndef __GHCVERSION_H__"  > $@
	@echo "#define __GHCVERSION_H__" >> $@
	@echo >> $@
	@echo "#ifndef __GLASGOW_HASKELL__" >> $@
	@echo "# define __GLASGOW_HASKELL__ $(ProjectVersionInt)" >> $@
	@echo "#endif" >> $@
	@echo >> $@
	@if [ -n "$(ProjectPatchLevel1)" ]; then \
	  echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $(ProjectPatchLevel1)" >> $@; \
	fi
	@if [ -n "$(ProjectPatchLevel2)" ]; then \
	  echo "#define __GLASGOW_HASKELL_PATCHLEVEL1__ $(ProjectPatchLevel2)" >> $@; \
	fi
	@echo >> $@
	@echo '#define MIN_VERSION_GLASGOW_HASKELL(ma,mi,pl1,pl2) (\\'     >> $@
	@echo '   ((ma)*100+(mi)) <  __GLASGOW_HASKELL__ || \\'            >> $@
	@echo '   ((ma)*100+(mi)) == __GLASGOW_HASKELL__    \\'            >> $@
	@echo '          && (pl1) <  __GLASGOW_HASKELL_PATCHLEVEL1__ || \\'>> $@
	@echo '   ((ma)*100+(mi)) == __GLASGOW_HASKELL__    \\'            >> $@
	@echo '          && (pl1) == __GLASGOW_HASKELL_PATCHLEVEL1__ \\'   >> $@
	@echo '          && (pl2) <= __GLASGOW_HASKELL_PATCHLEVEL2__ )'    >> $@
	@echo >> $@
	@echo "#endif /* __GHCVERSION_H__ */"          >> $@
	@echo "Done."

Ian Lynagh's avatar
Ian Lynagh committed
85 86
ifneq "$(BINDIST)" "YES"

87
ifeq "$(PORTING_HOST)" "YES"
Ian Lynagh's avatar
Ian Lynagh committed
88 89 90 91 92 93 94

$(includes_H_CONFIG) :
	@echo "*** Cross-compiling: please copy $(includes_H_CONFIG) from the target system"
	@exit 1

else

Ian Lynagh's avatar
Ian Lynagh committed
95
$(includes_H_CONFIG) : mk/config.h mk/config.mk includes/ghc.mk | $$(dir $$@)/.
Ian Lynagh's avatar
Ian Lynagh committed
96 97 98
	@echo "Creating $@..."
	@echo "#ifndef __GHCAUTOCONF_H__"  >$@
	@echo "#define __GHCAUTOCONF_H__" >>$@
99 100 101 102
#
#	Copy the contents of mk/config.h, turning '#define PACKAGE_FOO
#	"blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
#
Ian Lynagh's avatar
Ian Lynagh committed
103
	@sed 's,^\([	 ]*\)#[	 ]*define[	 ][	 ]*\(PACKAGE_[A-Z]*\)[	 ][ 	]*".*".*$$,\1/* #undef \2 */,' mk/config.h >> $@
104 105 106 107 108 109 110 111 112 113 114 115
#
#	Tack on some extra config information from the build system
#
ifeq "$(GhcEnableTablesNextToCode) $(GhcUnregisterised)" "YES NO"
	@echo >> $@
	@echo "#define TABLES_NEXT_TO_CODE 1" >> $@
endif
#
ifeq "$(CC_LLVM_BACKEND)" "1"
	@echo >> $@
	@echo "#define llvm_CC_FLAVOR 1" >> $@
endif
116 117 118 119 120
#
ifeq "$(CC_CLANG_BACKEND)" "1"
	@echo >> $@
	@echo "#define clang_CC_FLAVOR 1" >> $@
endif
121
#
Ian Lynagh's avatar
Ian Lynagh committed
122 123 124 125 126
	@echo "#endif /* __GHCAUTOCONF_H__ */"          >> $@
	@echo "Done."

endif

Ian Lynagh's avatar
Ian Lynagh committed
127
$(includes_H_PLATFORM) : includes/Makefile | $$(dir $$@)/.
128
	$(call removeFiles,$@)
Ian Lynagh's avatar
Ian Lynagh committed
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
	@echo "Creating $@..."
	@echo "#ifndef __GHCPLATFORM_H__"  >$@
	@echo "#define __GHCPLATFORM_H__" >>$@
	@echo >> $@
	@echo "#define BuildPlatform_TYPE  $(HostPlatform_CPP)" >> $@
	@echo "#define HostPlatform_TYPE   $(TargetPlatform_CPP)" >> $@
	@echo >> $@
	@echo "#define $(HostPlatform_CPP)_BUILD  1" >> $@
	@echo "#define $(TargetPlatform_CPP)_HOST  1" >> $@
	@echo >> $@
	@echo "#define $(HostArch_CPP)_BUILD_ARCH  1" >> $@
	@echo "#define $(TargetArch_CPP)_HOST_ARCH  1" >> $@
	@echo "#define BUILD_ARCH  \"$(HostArch_CPP)\"" >> $@
	@echo "#define HOST_ARCH  \"$(TargetArch_CPP)\"" >> $@
	@echo >> $@
	@echo "#define $(HostOS_CPP)_BUILD_OS  1" >> $@
	@echo "#define $(TargetOS_CPP)_HOST_OS  1" >> $@
	@echo "#define BUILD_OS  \"$(HostOS_CPP)\"" >> $@
	@echo "#define HOST_OS  \"$(TargetOS_CPP)\"" >> $@
ifeq "$(HostOS_CPP)" "irix"
	@echo "#ifndef $(IRIX_MAJOR)_HOST_OS" >> $@  
	@echo "#define $(IRIX_MAJOR)_HOST_OS  1" >> $@  
	@echo "#endif" >> $@  
endif
	@echo >> $@
	@echo "#define $(HostVendor_CPP)_BUILD_VENDOR  1" >> $@
	@echo "#define $(TargetVendor_CPP)_HOST_VENDOR  1" >> $@
	@echo "#define BUILD_VENDOR  \"$(HostVendor_CPP)\"" >> $@
	@echo "#define HOST_VENDOR  \"$(TargetVendor_CPP)\"" >> $@
	@echo >> $@
Gabor Greif's avatar
typo  
Gabor Greif committed
159
	@echo "/* These TARGET macros are for backwards compatibility... DO NOT USE! */" >> $@
Ian Lynagh's avatar
Ian Lynagh committed
160 161 162 163 164 165 166
	@echo "#define TargetPlatform_TYPE $(TargetPlatform_CPP)" >> $@
	@echo "#define $(TargetPlatform_CPP)_TARGET  1" >> $@
	@echo "#define $(TargetArch_CPP)_TARGET_ARCH  1" >> $@
	@echo "#define TARGET_ARCH  \"$(TargetArch_CPP)\"" >> $@
	@echo "#define $(TargetOS_CPP)_TARGET_OS  1" >> $@  
	@echo "#define TARGET_OS  \"$(TargetOS_CPP)\"" >> $@
	@echo "#define $(TargetVendor_CPP)_TARGET_VENDOR  1" >> $@
167 168 169
ifeq "$(GhcUnregisterised)" "YES"
	@echo "#define UnregisterisedCompiler 1" >> $@
endif
Ian Lynagh's avatar
Ian Lynagh committed
170 171 172 173 174 175 176 177 178
	@echo >> $@
	@echo "#endif /* __GHCPLATFORM_H__ */"          >> $@
	@echo "Done."

endif

# ---------------------------------------------------------------------------
# Make DerivedConstants.h for the compiler

179
includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
180 181
includes_GHCCONSTANTS_HASKELL_TYPE = includes/dist-derivedconstants/header/GHCConstantsHaskellType.hs
includes_GHCCONSTANTS_HASKELL_VALUE = includes/dist-derivedconstants/header/platformConstants
182 183
includes_GHCCONSTANTS_HASKELL_WRAPPERS = includes/dist-derivedconstants/header/GHCConstantsHaskellWrappers.hs
includes_GHCCONSTANTS_HASKELL_EXPORTS = includes/dist-derivedconstants/header/GHCConstantsHaskellExports.hs
Ian Lynagh's avatar
Ian Lynagh committed
184

185
INSTALL_LIBS += $(includes_GHCCONSTANTS_HASKELL_VALUE)
186

187 188 189
DERIVE_CONSTANTS_FLAGS += --gcc-program "$(WhatGccIsCalled)"
DERIVE_CONSTANTS_FLAGS += $(addprefix --gcc-flag$(space),$(includes_CC_OPTS) -fcommon)
DERIVE_CONSTANTS_FLAGS += --nm-program "$(NM)"
190

Ian Lynagh's avatar
Ian Lynagh committed
191
ifneq "$(BINDIST)" "YES"
192 193
$(includes_DERIVEDCONSTANTS):           $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
$(includes_GHCCONSTANTS_HASKELL_VALUE): $$(includes_H_CONFIG) $$(includes_H_PLATFORM) $$(includes_H_VERSION) $$(includes_H_FILES) $$(rts_H_FILES)
194

195
$(includes_DERIVEDCONSTANTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
196
	$< --gen-header -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
197

198
$(includes_GHCCONSTANTS_HASKELL_TYPE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
199
	$< --gen-haskell-type -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
200

201
$(includes_GHCCONSTANTS_HASKELL_VALUE): $(deriveConstants_INPLACE) | $$(dir $$@)/.
202
	$< --gen-haskell-value -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
203

204
$(includes_GHCCONSTANTS_HASKELL_WRAPPERS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
205
	$< --gen-haskell-wrappers -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
Ian Lynagh's avatar
Ian Lynagh committed
206

207
$(includes_GHCCONSTANTS_HASKELL_EXPORTS): $(deriveConstants_INPLACE) | $$(dir $$@)/.
208
	$< --gen-haskell-exports -o $@ --tmpdir $(dir $@) $(DERIVE_CONSTANTS_FLAGS)
Ian Lynagh's avatar
Ian Lynagh committed
209 210 211 212 213 214
endif

# ---------------------------------------------------------------------------
# Install all header files

$(eval $(call clean-target,includes,,\
215
  $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION)))
Ian Lynagh's avatar
Ian Lynagh committed
216

217
$(eval $(call all-target,includes,\
218
  $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) \
219 220 221 222 223
  $(includes_GHCCONSTANTS_HASKELL_TYPE) \
  $(includes_GHCCONSTANTS_HASKELL_VALUE) \
  $(includes_GHCCONSTANTS_HASKELL_WRAPPERS) \
  $(includes_GHCCONSTANTS_HASKELL_EXPORTS) \
  $(includes_DERIVEDCONSTANTS)))
Ian Lynagh's avatar
Ian Lynagh committed
224

225 226 227 228
install: install_includes

.PHONY: install_includes
install_includes :
229
	$(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)")
Ian Lynagh's avatar
Ian Lynagh committed
230 231 232 233
	$(foreach d,$(includes_H_SUBDIRS), \
	    $(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)/$d") && \
	    $(call INSTALL_HEADER,$(INSTALL_OPTS),includes/$d/*.h,"$(DESTDIR)$(ghcheaderdir)/$d/") && \
	) true
234
	$(call INSTALL_HEADER,$(INSTALL_OPTS),$(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_VERSION) $(includes_DERIVEDCONSTANTS),"$(DESTDIR)$(ghcheaderdir)/")
235