boilerplate.mk 4.1 KB
Newer Older
1

2 3
default: all

Ian Lynagh's avatar
Ian Lynagh committed
4 5 6 7
HAVE_EVAL := NO
$(eval HAVE_EVAL := YES)

ifeq "$(HAVE_EVAL)" "NO"
8
$(error Your make does not support eval. You need GNU make >= 3.80)
Ian Lynagh's avatar
Ian Lynagh committed
9 10
endif

Ian Lynagh's avatar
Ian Lynagh committed
11 12 13
show:
	@echo '$(VALUE)="$($(VALUE))"'

14
define canonicalise
15
# $1 = path variable
16
$1_CYGPATH := $$(shell $(SHELL) -c "cygpath -m $$($1)" 2> /dev/null)
17 18 19 20 21
ifneq "$$($1_CYGPATH)" ""
$1 := $$($1_CYGPATH)
endif
endef

22 23 24 25 26 27 28 29
define canonicaliseExecutable
# $1 = program path variable
ifneq "$$(wildcard $$($1).exe)" ""
$1 := $$($1).exe
endif
$(call canonicalise,$1)
endef

30
define get-ghc-rts-field # $1 = rseult variable, $2 = field name
31
$1 := $$(shell $$(TEST_HC) +RTS --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
32 33 34
endef

define get-ghc-field # $1 = rseult variable, $2 = field name
35
$1 := $$(shell $$(TEST_HC) --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
36 37 38
endef

define get-ghc-feature-bool # $1 = rseult variable, $2 = field name
39
SHELL_RES := $$(shell $$(TEST_HC) --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
$1 := $$(strip \
	  $$(if $$(SHELL_RES), \
         $$(if $$(subst YES,,$$(SHELL_RES)), \
            $$(if $$(subst NO,,$$(SHELL_RES)), \
               $$(warning ghc info field not YES or NO: $2: $$(SHELL_RES)), \
               NO), \
            YES), \
         $$(warning ghc info field not found: $2)))
endef

ifeq "$(TEST_HC)" ""

OLD_BUILD_SYSTEM_STAGE1_GHC := $(abspath $(TOP)/../ghc/stage1-inplace/ghc)
OLD_BUILD_SYSTEM_STAGE2_GHC := $(abspath $(TOP)/../ghc/stage2-inplace/ghc)
OLD_BUILD_SYSTEM_STAGE3_GHC := $(abspath $(TOP)/../ghc/stage3-inplace/ghc)
OLD_BUILD_SYSTEM_GHC_PKG    := $(abspath $(TOP)/../utils/ghc-pkg/install-inplace/bin/ghc-pkg)
56
OLD_BUILD_SYSTEM_HSC2HS     := $(abspath $(TOP)/../utils/hsc2hs/install-inplace/bin/hsc2hs)
57
OLD_BUILD_SYSTEM_HP2PS      := $(abspath $(TOP)/../utils/hp2ps/hp2ps)
58
ifneq "$(wildcard $(OLD_BUILD_SYSTEM_STAGE1_GHC) $(OLD_BUILD_SYSTEM_STAGE1_GHC).exe)" ""
59 60 61 62 63 64

ifeq "$(stage)" "1"
TEST_HC := $(OLD_BUILD_SYSTEM_STAGE1_GHC)
else
ifeq "$(stage)" "3"
TEST_HC := $(OLD_BUILD_SYSTEM_STAGE3_GHC)
65
else
66 67 68
# use stage2 by default
TEST_HC := $(OLD_BUILD_SYSTEM_STAGE2_GHC)
endif
69
endif
70
GHC_PKG := $(OLD_BUILD_SYSTEM_GHC_PKG)
71
HSC2HS := $(OLD_BUILD_SYSTEM_HSC2HS)
72
HP2PS_ABS := $(OLD_BUILD_SYSTEM_HP2PS)
73 74 75 76
# XXX This GCC definition is a hack. Once the in-tree GHC has a gcc in the
# right place we won't need to do this, as Cabal will be able to find
# gcc relative to ghc's location.
GCC := $(shell cd $(TOP)/.. && $(MAKE) --no-print-directory show VALUE=WhatGccIsCalled | sed 's/.*"\(.*\)"/\1/')
77

78 79 80 81
else
NEW_BUILD_SYSTEM_STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1)
NEW_BUILD_SYSTEM_STAGE2_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage2)
NEW_BUILD_SYSTEM_STAGE3_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage3)
82
ifneq "$(wildcard $(NEW_BUILD_SYSTEM_STAGE1_GHC) $(NEW_BUILD_SYSTEM_STAGE1_GHC).exe)" ""
83

84 85 86 87 88 89 90 91 92
ifeq "$(stage)" "1"
TEST_HC := $(NEW_BUILD_SYSTEM_STAGE1_GHC)
else
ifeq "$(stage)" "3"
TEST_HC := $(NEW_BUILD_SYSTEM_STAGE3_GHC)
else
# use stage2 by default
TEST_HC := $(NEW_BUILD_SYSTEM_STAGE2_GHC)
endif
93
endif
94

95 96 97 98 99 100
else
TEST_HC := $(shell which ghc)
endif

endif
endif
101

102 103 104
ifeq "$(GHC_PKG)" ""
GHC_PKG := $(dir $(TEST_HC))/ghc-pkg
endif
105

106 107 108 109
ifeq "$(HSC2HS)" ""
HSC2HS := $(dir $(TEST_HC))/hsc2hs
endif

110 111 112 113
ifeq "$(HP2PS_ABS)" ""
HP2PS_ABS := $(dir $(TEST_HC))/hp2ps
endif

114 115 116 117
ifeq "$(HPC)" ""
HPC := $(dir $(TEST_HC))/hpc
endif

118
$(eval $(call canonicaliseExecutable,TEST_HC))
119
ifeq "$(wildcard $(TEST_HC))" ""
Ian Lynagh's avatar
Ian Lynagh committed
120
$(error Cannot find ghc: $(TEST_HC))
121
endif
122

123
$(eval $(call canonicaliseExecutable,GHC_PKG))
124
ifeq "$(wildcard $(GHC_PKG))" ""
Ian Lynagh's avatar
Ian Lynagh committed
125
$(error Cannot find ghc-pkg: $(GHC_PKG))
126
endif
127

128 129
$(eval $(call canonicaliseExecutable,HSC2HS))
ifeq "$(wildcard $(HSC2HS))" ""
Ian Lynagh's avatar
Ian Lynagh committed
130
$(error Cannot find hsc2hs: $(HSC2HS))
131 132
endif

133
$(eval $(call canonicaliseExecutable,HP2PS_ABS))
134
ifeq "$(wildcard $(HP2PS_ABS))" ""
Ian Lynagh's avatar
Ian Lynagh committed
135
$(error Cannot find hp2ps: $(HP2PS_ABS))
136 137
endif

138 139 140 141 142
$(eval $(call canonicaliseExecutable,HPC))
ifeq "$(wildcard $(HPC))" ""
$(error Cannot find hpc: $(HPC))
endif

143 144
$(eval $(call get-ghc-field,GhcRTSWays,RTS ways))

145 146 147
TOP_ABS := $(abspath $(TOP))
$(eval $(call canonicalise,TOP_ABS))

148 149 150
GS = gs
CP = cp
RM = rm -f
151
PYTHON = python
152