boilerplate.mk 3.98 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
ifneq "$$($1_CYGPATH)" ""
Ian Lynagh's avatar
Ian Lynagh committed
22 23 24
# We use 'override' in case we are trying to update a value given on
# the commandline (e.g. TEST_HC)
override $1 := $$($1_CYGPATH)
25 26 27
endif
endef

28 29
define canonicaliseExecutable
# $1 = program path variable
30
ifneq "$$(shell test -x '$$($1).exe' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
31 32 33
# We use 'override' in case we are trying to update a value given on
# the commandline (e.g. TEST_HC)
override $1 := $$($1).exe
34 35 36 37
endif
$(call canonicalise,$1)
endef

38 39
ifeq "$(TEST_HC)" ""

40 41 42
STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1)
STAGE2_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage2)
STAGE3_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage3)
43

44
ifneq "$(wildcard $(STAGE1_GHC) $(STAGE1_GHC).exe)" ""
45

46
IN_TREE_COMPILER = YES
47
ifeq "$(BINDIST)" "YES"
48
TEST_HC := $(abspath $(TOP)/../)/bindisttest/install dir/bin/ghc
49 50 51
else ifeq "$(stage)" "1"
TEST_HC := $(STAGE1_GHC)
else ifeq "$(stage)" "3"
52
TEST_HC := $(STAGE3_GHC)
53 54
else
# use stage2 by default
55
TEST_HC := $(STAGE2_GHC)
56 57
endif

58
else
59
IN_TREE_COMPILER = NO
60 61 62
TEST_HC := $(shell which ghc)
endif

63 64
else
IN_TREE_COMPILER = NO
Ian Lynagh's avatar
Ian Lynagh committed
65 66 67 68 69 70 71
# We want to support both "ghc" and "/usr/bin/ghc" as values of TEST_HC
# passed in by the user, but
#     which ghc          == /usr/bin/ghc
#     which /usr/bin/ghc == /usr/bin/ghc
# so we can just always 'which' it. We need to use 'override' in order
# to override a value given on the commandline.
override TEST_HC := $(shell which '$(TEST_HC)')
72
endif
73

74 75 76
# 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
77

78
ifeq "$(GHC_PKG)" ""
Ian Lynagh's avatar
Ian Lynagh committed
79
GHC_PKG := $(BIN_ROOT)/ghc-pkg
80
endif
81

82
ifeq "$(HSC2HS)" ""
Ian Lynagh's avatar
Ian Lynagh committed
83
HSC2HS := $(BIN_ROOT)/hsc2hs
84 85
endif

86
ifeq "$(HP2PS_ABS)" ""
Ian Lynagh's avatar
Ian Lynagh committed
87
HP2PS_ABS := $(BIN_ROOT)/hp2ps
88 89
endif

90
ifeq "$(HPC)" ""
Ian Lynagh's avatar
Ian Lynagh committed
91
HPC := $(BIN_ROOT)/hpc
92 93
endif

Ian Lynagh's avatar
Ian Lynagh committed
94
$(eval $(call canonicaliseExecutable,TEST_HC))
95
ifeq "$(shell test -x '$(TEST_HC)' && echo exists)" ""
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 "$(shell test -x '$(GHC_PKG)' && echo exists)" ""
Ian Lynagh's avatar
Ian Lynagh committed
101
$(error Cannot find ghc-pkg: $(GHC_PKG))
102
endif
103

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

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

114
$(eval $(call canonicaliseExecutable,HPC))
115
ifeq "$(shell test -x '$(HPC)' && echo exists)" ""
116 117 118
$(error Cannot find hpc: $(HPC))
endif

119 120 121 122
ifeq "$(AR)" ""
AR = ar
endif

123 124 125
# Be careful when using this. On Windows it ends up looking like
# c:/foo/bar which confuses make, as make thinks that the : is Makefile
# syntax
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

134 135 136 137 138 139 140
# -----------------------------------------------------------------------------
# configuration of TEST_HC

# ghc-config.hs is a short Haskell program that runs ghc --info, parses
# the results, and emits a little .mk file with make bindings for the values.
# This way we cache the results for different values of $(TEST_HC)

141
$(TOP)/mk/ghc-config : $(TOP)/mk/ghc-config.hs
142 143
	"$(TEST_HC)" --make -o $@ $<

Simon Marlow's avatar
Simon Marlow committed
144 145
empty=
space=$(empty) $(empty)
146
ghc-config-mk = $(TOP)/mk/ghcconfig$(subst $(space),_,$(subst :,_,$(subst /,_,$(subst \,_,$(TEST_HC))))).mk
147

148 149
$(ghc-config-mk) : $(TOP)/mk/ghc-config
	$(TOP)/mk/ghc-config "$(TEST_HC)" >"$@" || $(RM) "$@"
150 151 152 153 154

include $(ghc-config-mk)

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

155 156 157 158 159
ifeq "$(HostOS)" "mingw32"
WINDOWS = YES
else
WINDOWS = NO
endif
Ian Lynagh's avatar
Ian Lynagh committed
160 161 162 163 164
ifeq "$(HostOS)" "darwin"
DARWIN = YES
else
DARWIN = NO
endif
165