boilerplate.mk 3.14 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 9 10 11 12
$(error Your make does not support eval. You need GNU make >= 3.81)
endif

ifeq "$(abspath /)" ""
$(error Your make does not support abspath. You need GNU make >= 3.81)
Ian Lynagh's avatar
Ian Lynagh committed
13 14
endif

Ian Lynagh's avatar
Ian Lynagh committed
15 16 17
show:
	@echo '$(VALUE)="$($(VALUE))"'

18
define canonicalise
19
# $1 = path variable
20
$1_CYGPATH := $$(shell $(SHELL) -c "cygpath -m $$($1)" 2> /dev/null)
21 22 23 24 25
ifneq "$$($1_CYGPATH)" ""
$1 := $$($1_CYGPATH)
endif
endef

26 27 28 29 30 31 32 33
define canonicaliseExecutable
# $1 = program path variable
ifneq "$$(wildcard $$($1).exe)" ""
$1 := $$($1).exe
endif
$(call canonicalise,$1)
endef

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

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

define get-ghc-feature-bool # $1 = rseult variable, $2 = field name
43
SHELL_RES := $$(shell $$(TEST_HC) --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
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)" ""

56 57 58
STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1)
STAGE2_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage2)
STAGE3_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage3)
59

60
ifneq "$(wildcard $(STAGE1_GHC) $(STAGE1_GHC).exe)" ""
61

62
ifeq "$(BINDIST)" "YES"
63
ifeq '$(shell $(STAGE1_GHC) +RTS --info | grep "^ ..\"Host OS\". \"mingw32\".$$")' ''
64
TEST_HC := $(abspath $(TOP)/../)/bindisttest/installed/bin/ghc
65
else
66
TEST_HC := "$(abspath $(TOP)/../)/bindisttest/install dir/bin/ghc.exe"
67 68 69 70
endif
else ifeq "$(stage)" "1"
TEST_HC := $(STAGE1_GHC)
else ifeq "$(stage)" "3"
71
TEST_HC := $(STAGE3_GHC)
72 73
else
# use stage2 by default
74
TEST_HC := $(STAGE2_GHC)
75 76
endif

77 78 79 80 81
else
TEST_HC := $(shell which ghc)
endif

endif
82

83 84 85
ifeq "$(GHC_PKG)" ""
GHC_PKG := $(dir $(TEST_HC))/ghc-pkg
endif
86

87 88 89 90
ifeq "$(HSC2HS)" ""
HSC2HS := $(dir $(TEST_HC))/hsc2hs
endif

91 92 93 94
ifeq "$(HP2PS_ABS)" ""
HP2PS_ABS := $(dir $(TEST_HC))/hp2ps
endif

95 96 97 98
ifeq "$(HPC)" ""
HPC := $(dir $(TEST_HC))/hpc
endif

99
$(eval $(call canonicaliseExecutable,TEST_HC))
100
ifeq "$(wildcard $(TEST_HC))" ""
Ian Lynagh's avatar
Ian Lynagh committed
101
$(error Cannot find ghc: $(TEST_HC))
102
endif
103

104
$(eval $(call canonicaliseExecutable,GHC_PKG))
105
ifeq "$(wildcard $(GHC_PKG))" ""
Ian Lynagh's avatar
Ian Lynagh committed
106
$(error Cannot find ghc-pkg: $(GHC_PKG))
107
endif
108

109 110
$(eval $(call canonicaliseExecutable,HSC2HS))
ifeq "$(wildcard $(HSC2HS))" ""
Ian Lynagh's avatar
Ian Lynagh committed
111
$(error Cannot find hsc2hs: $(HSC2HS))
112 113
endif

114
$(eval $(call canonicaliseExecutable,HP2PS_ABS))
115
ifeq "$(wildcard $(HP2PS_ABS))" ""
Ian Lynagh's avatar
Ian Lynagh committed
116
$(error Cannot find hp2ps: $(HP2PS_ABS))
117 118
endif

119 120 121 122 123
$(eval $(call canonicaliseExecutable,HPC))
ifeq "$(wildcard $(HPC))" ""
$(error Cannot find hpc: $(HPC))
endif

124 125
$(eval $(call get-ghc-field,GhcRTSWays,RTS ways))

126 127 128
TOP_ABS := $(abspath $(TOP))
$(eval $(call canonicalise,TOP_ABS))

129 130 131
GS = gs
CP = cp
RM = rm -f
132
PYTHON = python
133