ghc.mk 7.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
# -----------------------------------------------------------------------------
#
# (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
#      http://hackage.haskell.org/trac/ghc/wiki/Building/Architecture
#      http://hackage.haskell.org/trac/ghc/wiki/Building/Modifying
#
# -----------------------------------------------------------------------------

Ian Lynagh's avatar
Ian Lynagh committed
13 14 15 16 17 18 19 20
#
# 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

#
21
# All header files are in includes/{one of these subdirectories}
Ian Lynagh's avatar
Ian Lynagh committed
22
#
23 24 25 26 27 28 29
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)))
30 31
# 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
32 33 34 35 36 37 38 39

#
# Options
#
ifeq "$(GhcUnregisterised)" "YES"
includes_CC_OPTS += -DNO_REGS -DUSE_MINIINTERPRETER
endif

Ian Lynagh's avatar
Ian Lynagh committed
40
includes_CC_OPTS += $(addprefix -I,$(GHC_INCLUDE_DIRS))
41
includes_CC_OPTS += -Irts
Ian Lynagh's avatar
Ian Lynagh committed
42 43 44 45 46 47 48

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

ifneq "$(BINDIST)" "YES"

Ian Lynagh's avatar
Ian Lynagh committed
49
ifeq "$(PORTING_HOST)" "YES"
Ian Lynagh's avatar
Ian Lynagh committed
50 51 52 53 54 55 56

$(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
57
$(includes_H_CONFIG) : mk/config.h mk/config.mk includes/ghc.mk | $$(dir $$@)/.
Ian Lynagh's avatar
Ian Lynagh committed
58 59 60
	@echo "Creating $@..."
	@echo "#ifndef __GHCAUTOCONF_H__"  >$@
	@echo "#define __GHCAUTOCONF_H__" >>$@
61 62 63 64
#
#	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
65
	@sed 's,^\([	 ]*\)#[	 ]*define[	 ][	 ]*\(PACKAGE_[A-Z]*\)[	 ][ 	]*".*".*$$,\1/* #undef \2 */,' mk/config.h >> $@
66 67 68 69 70 71 72 73 74 75 76 77 78
#
#	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
#
Ian Lynagh's avatar
Ian Lynagh committed
79 80 81 82 83
	@echo "#endif /* __GHCAUTOCONF_H__ */"          >> $@
	@echo "Done."

endif

Ian Lynagh's avatar
Ian Lynagh committed
84
$(includes_H_PLATFORM) : includes/Makefile | $$(dir $$@)/.
85
	$(call removeFiles,$@)
Ian Lynagh's avatar
Ian Lynagh committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	@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
116
	@echo "/* These TARGET macros are for backwards compatibility... DO NOT USE! */" >> $@
Ian Lynagh's avatar
Ian Lynagh committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
	@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" >> $@
	@echo >> $@
	@echo "#endif /* __GHCPLATFORM_H__ */"          >> $@
	@echo "Done."

endif

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

133
includes_DERIVEDCONSTANTS = includes/dist-derivedconstants/header/DerivedConstants.h
Ian Lynagh's avatar
Ian Lynagh committed
134

135
ifeq "$(PORTING_HOST)-$(AlienScript)" "YES-"
Ian Lynagh's avatar
Ian Lynagh committed
136 137 138 139 140 141 142 143 144 145

DerivedConstants.h :
	@echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
	@exit 1

else

includes_dist-derivedconstants_C_SRCS = mkDerivedConstants.c
includes_dist-derivedconstants_PROG   = mkDerivedConstants$(exeext)

146
$(eval $(call build-prog,includes,dist-derivedconstants,0))
Ian Lynagh's avatar
Ian Lynagh committed
147

148
$(includes_dist-derivedconstants_depfile_c_asm) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_FILES) $$(rts_H_FILES)
Ian Lynagh's avatar
Ian Lynagh committed
149 150
includes/dist-derivedconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)

151 152 153 154 155
ifneq "$(AlienScript)" ""
$(INPLACE_BIN)/mkDerivedConstants$(exeext): includes/$(includes_dist-derivedconstants_C_SRCS) | $$(dir $$@)/.
	$(WhatGccIsCalled) -o $@ $< $(CFLAGS) $(includes_CC_OPTS)
endif

Ian Lynagh's avatar
Ian Lynagh committed
156
ifneq "$(BINDIST)" "YES"
157
$(includes_DERIVEDCONSTANTS) : $(INPLACE_BIN)/mkDerivedConstants$(exeext) | $$(dir $$@)/.
158
ifeq "$(AlienScript)" ""
Ian Lynagh's avatar
Ian Lynagh committed
159
	./$< >$@
160 161 162
else
	$(AlienScript) run ./$< >$@
endif
Ian Lynagh's avatar
Ian Lynagh committed
163 164 165 166 167 168 169
endif

endif

# -----------------------------------------------------------------------------
#

170
includes_GHCCONSTANTS = includes/dist-ghcconstants/header/GHCConstants.h
Ian Lynagh's avatar
Ian Lynagh committed
171

172
ifeq "$(PORTING_HOST)-$(AlienScript)" "YES-"
Ian Lynagh's avatar
Ian Lynagh committed
173 174 175 176 177 178 179 180 181 182 183

$(includes_GHCCONSTANTS) :
	@echo "*** Cross-compiling: please copy DerivedConstants.h from the target system"
	@exit 1

else

includes_dist-ghcconstants_C_SRCS = mkDerivedConstants.c
includes_dist-ghcconstants_PROG   = mkGHCConstants$(exeext)
includes_dist-ghcconstants_CC_OPTS = -DGEN_HASKELL

184
$(eval $(call build-prog,includes,dist-ghcconstants,0))
Ian Lynagh's avatar
Ian Lynagh committed
185 186

ifneq "$(BINDIST)" "YES"
187
$(includes_dist-ghcconstants_depfile_c_asm) : $(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_H_FILES) $$(rts_H_FILES)
Ian Lynagh's avatar
Ian Lynagh committed
188 189 190

includes/dist-ghcconstants/build/mkDerivedConstants.o : $(includes_H_CONFIG) $(includes_H_PLATFORM)

191 192 193 194 195
ifneq "$(AlienScript)" ""
$(INPLACE_BIN)/mkGHCConstants$(exeext): includes/$(includes_dist-ghcconstants_C_SRCS) | $$(dir $$@)/.
	$(WhatGccIsCalled) -o $@ $< $(CFLAGS) $(includes_CC_OPTS) $(includes_dist-ghcconstants_CC_OPTS)
endif

196
$(includes_GHCCONSTANTS) : $(INPLACE_BIN)/mkGHCConstants$(exeext) | $$(dir $$@)/.
197
ifeq "$(AlienScript)" ""
Ian Lynagh's avatar
Ian Lynagh committed
198
	./$< >$@
199 200 201
else
	$(AlienScript) run ./$< >$@
endif
Ian Lynagh's avatar
Ian Lynagh committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
endif

endif

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

$(eval $(call clean-target,includes,,\
  $(includes_H_CONFIG) $(includes_H_PLATFORM) \
  $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))

$(eval $(call all-target,includes,,\
  $(includes_H_CONFIG) $(includes_H_PLATFORM) \
  $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS)))

217 218 219 220
install: install_includes

.PHONY: install_includes
install_includes :
221
	$(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)")
Ian Lynagh's avatar
Ian Lynagh committed
222 223 224 225
	$(foreach d,$(includes_H_SUBDIRS), \
	    $(call INSTALL_DIR,"$(DESTDIR)$(ghcheaderdir)/$d") && \
	    $(call INSTALL_HEADER,$(INSTALL_OPTS),includes/$d/*.h,"$(DESTDIR)$(ghcheaderdir)/$d/") && \
	) true
Ian Lynagh's avatar
Ian Lynagh committed
226
	$(call INSTALL_HEADER,$(INSTALL_OPTS),$(includes_H_CONFIG) $(includes_H_PLATFORM) $(includes_GHCCONSTANTS) $(includes_DERIVEDCONSTANTS),"$(DESTDIR)$(ghcheaderdir)/")
227