boilerplate.mk 3.03 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 56 57 58
$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)" ""

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)
59
ifneq "$(wildcard $(NEW_BUILD_SYSTEM_STAGE1_GHC) $(NEW_BUILD_SYSTEM_STAGE1_GHC).exe)" ""
60

61 62 63 64 65 66 67 68 69
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
70
endif
71

72 73 74 75 76
else
TEST_HC := $(shell which ghc)
endif

endif
77

78 79 80
ifeq "$(GHC_PKG)" ""
GHC_PKG := $(dir $(TEST_HC))/ghc-pkg
endif
81

82 83 84 85
ifeq "$(HSC2HS)" ""
HSC2HS := $(dir $(TEST_HC))/hsc2hs
endif

86 87 88 89
ifeq "$(HP2PS_ABS)" ""
HP2PS_ABS := $(dir $(TEST_HC))/hp2ps
endif

90 91 92 93
ifeq "$(HPC)" ""
HPC := $(dir $(TEST_HC))/hpc
endif

94
$(eval $(call canonicaliseExecutable,TEST_HC))
95
ifeq "$(wildcard $(TEST_HC))" ""
Ian Lynagh's avatar
Ian Lynagh committed
96
$(error Cannot find ghc: $(TEST_HC))
97
endif
98

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

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

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

114 115 116 117 118
$(eval $(call canonicaliseExecutable,HPC))
ifeq "$(wildcard $(HPC))" ""
$(error Cannot find hpc: $(HPC))
endif

119 120
$(eval $(call get-ghc-field,GhcRTSWays,RTS ways))

121 122 123
TOP_ABS := $(abspath $(TOP))
$(eval $(call canonicalise,TOP_ABS))

124 125 126
GS = gs
CP = cp
RM = rm -f
127
PYTHON = python
128