boilerplate.mk 3.4 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
Ian Lynagh's avatar
Ian Lynagh committed
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
define canonicaliseExecutable
# $1 = program path variable
28
ifneq "$$(shell test -x '$$($1).exe' && echo exists)" ""
29 30 31 32 33
$1 := $$($1).exe
endif
$(call canonicalise,$1)
endef

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

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

Ian Lynagh's avatar
Ian Lynagh committed
42
define get-ghc-feature-bool # $1 = result variable, $2 = field name
Ian Lynagh's avatar
Ian Lynagh committed
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
IN_TREE_COMPILER = YES
63
ifeq "$(BINDIST)" "YES"
64
TEST_HC := $(abspath $(TOP)/../)/bindisttest/install dir/bin/ghc
65 66 67
else ifeq "$(stage)" "1"
TEST_HC := $(STAGE1_GHC)
else ifeq "$(stage)" "3"
68
TEST_HC := $(STAGE3_GHC)
69 70
else
# use stage2 by default
71
TEST_HC := $(STAGE2_GHC)
72 73
endif

74
else
75
IN_TREE_COMPILER = NO
76 77 78
TEST_HC := $(shell which ghc)
endif

79 80
else
IN_TREE_COMPILER = NO
81
endif
82

83 84 85
# We can't use $(dir ...) here as TEST_HC might be in a path
# containing spaces
BIN_ROOT = $(shell dirname '$(TEST_HC)')
Ian Lynagh's avatar
Ian Lynagh committed
86

87
ifeq "$(GHC_PKG)" ""
Ian Lynagh's avatar
Ian Lynagh committed
88
GHC_PKG := $(BIN_ROOT)/ghc-pkg
89
endif
90

91
ifeq "$(HSC2HS)" ""
Ian Lynagh's avatar
Ian Lynagh committed
92
HSC2HS := $(BIN_ROOT)/hsc2hs
93 94
endif

95
ifeq "$(HP2PS_ABS)" ""
Ian Lynagh's avatar
Ian Lynagh committed
96
HP2PS_ABS := $(BIN_ROOT)/hp2ps
97 98
endif

99
ifeq "$(HPC)" ""
Ian Lynagh's avatar
Ian Lynagh committed
100
HPC := $(BIN_ROOT)/hpc
101 102
endif

Ian Lynagh's avatar
Ian Lynagh committed
103
$(eval $(call canonicaliseExecutable,TEST_HC))
104
ifeq "$(shell test -x '$(TEST_HC)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
105
$(error Cannot find ghc: $(TEST_HC))
106
endif
107

108
$(eval $(call canonicaliseExecutable,GHC_PKG))
109
ifeq "$(shell test -x '$(GHC_PKG)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
110
$(error Cannot find ghc-pkg: $(GHC_PKG))
111
endif
112

113
$(eval $(call canonicaliseExecutable,HSC2HS))
114
ifeq "$(shell test -x '$(HSC2HS)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
115
$(error Cannot find hsc2hs: $(HSC2HS))
116 117
endif

118
$(eval $(call canonicaliseExecutable,HP2PS_ABS))
119
ifeq "$(shell test -x '$(HP2PS_ABS)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
120
$(error Cannot find hp2ps: $(HP2PS_ABS))
121 122
endif

123
$(eval $(call canonicaliseExecutable,HPC))
124
ifeq "$(shell test -x '$(HPC)' && echo exists)" ""
125 126 127
$(error Cannot find hpc: $(HPC))
endif

128 129
$(eval $(call get-ghc-field,GhcRTSWays,RTS ways))

130 131 132
TOP_ABS := $(abspath $(TOP))
$(eval $(call canonicalise,TOP_ABS))

133 134 135
GS = gs
CP = cp
RM = rm -f
136
PYTHON = python
137

138 139 140 141 142 143 144
$(eval $(call get-ghc-rts-field,HostOS,Host OS))
ifeq "$(HostOS)" "mingw32"
WINDOWS = YES
else
WINDOWS = NO
endif