forked from haskell/haskell-ide-engine
/
Makefile
158 lines (123 loc) · 5.04 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
BASEDIR=$(CURDIR)
STACKLOCALBINDIR:=$(shell stack path --local-bin)
GHC_VERSIONS= 8.6.3 8.6.2 8.6.1 8.4.4 8.4.3 8.4.2 8.2.2 8.2.1
all: help
.PHONY: all
## Builds hie for all supported GHC versions (8.2.1, 8.2.2, 8.4.2, 8.4.3, 8.4.4, 8.6.1, 8.6.2 and 8.6.3)
build: $(foreach version, $(GHC_VERSIONS), hie-$(version))
.PHONY: build
## Builds hie and hoogle databases for all supported GHC versions
build-all: build build-docs
.PHONY: build-all
GHC := $(shell stack path --compiler-exe)
ghc:
$(GHC) --version
@echo GHC
.PHONY: ghc
# ------------------------------------------------------
## Builds hie for GHC version % only
hie-%: submodules cabal
stack --stack-yaml=stack-$*.yaml install happy
stack --stack-yaml=stack-$*.yaml build
stack --stack-yaml=stack-$*.yaml install \
&& cp '$(STACKLOCALBINDIR)/hie' '$(STACKLOCALBINDIR)/hie-$*' \
&& cp '$(STACKLOCALBINDIR)/hie-$*' '$(STACKLOCALBINDIR)/hie-$(basename $*)'
.PHONY: hie-%
# ------------------------------------------------------
## Updates local git submodules
submodules:
git submodule sync --recursive
git submodule update --init --recursive
.PHONY: submodules
# ------------------------------------------------------
## Makes sure that Cabal the lib is available for cabal-helper-wapper,
## to speed up project start
## NOTE 1: cabal-helper-wrapper builds with old style cabal build, so
## must be installed this way.
## NOTE 2: this is temporary, will go away once the new cabal-helper lands.
## NOTE 3: This is needed for stack only projects too
cabal:
stack install cabal-install
cabal update
cabal install Cabal-2.4.1.0 --with-compiler=$(GHC)
.PHONY: cabal
# ------------------------------------------------------
## Builds the Hoogle database for all supported GHC versions
build-docs: $(foreach version, $(GHC_VERSIONS), build-doc-$(version))
.PHONY: build-docs
## Builds the Hoogle database for GHC version % only
build-doc-%:
stack --stack-yaml=stack-$*.yaml exec hoogle generate
# ------------------------------------------------------
## Runs hie tests
test: $(foreach version, $(GHC_VERSIONS), test-$(version))
.PHONY: test
test-%: submodules cabal
stack --stack-yaml=stack-$*.yaml test
build-copy-compiler-tool: $(foreach version, $(GHC_VERSIONS), build-copy-compiler-tool-$(version))
.PHONY: build-copy-compiler-tool
build-copy-compiler-tool-%: submodules cabal
stack --stack-yaml=stack-$*.yaml build --copy-compiler-tool
## Fixes icu related problems in MacOS
icu-macos-fix: icu-macos-fix-install icu-macos-fix-build
.PHONY: icu-macos-fix
icu-macos-fix-install:
brew install icu4c
.PHONY: icu-macos-fix-install
icu-macos-fix-build: $(foreach version, $(GHC_VERSIONS), icu-macos-fix-build-$(version))
.PHONY: icu-macos-fix-build
icu-macos-fix-build-%:
stack --stack-yaml=stack-$*.yaml build text-icu \
--extra-lib-dirs=/usr/local/opt/icu4c/lib \
--extra-include-dirs=/usr/local/opt/icu4c/include
# ------------------------------------------------------
HIE_GIT_REF:=$(shell git describe --tags)
HIE_DIST_NAME:=hie-${HIE_GIT_REF}-$(shell uname -m)-$(shell uname -s)
HIE_DIST_DIR:=/tmp/${HIE_DIST_NAME}
## Creates a tarball containing all the hie binaries
dist: $(foreach version, $(GHC_VERSIONS), dist-$(version))
cp .stack-work/install/*/*/$(firstword $(GHC_VERSIONS))/bin/hie ${HIE_DIST_DIR}
cp .stack-work/install/*/*/$(firstword $(GHC_VERSIONS))/bin/hie-wrapper ${HIE_DIST_DIR}
tar -czf ${HIE_DIST_NAME}.tar.gz -C ${HIE_DIST_DIR} .
rm -r ${HIE_DIST_DIR}
dist-%:
mkdir -p ${HIE_DIST_DIR}
stack --stack-yaml=stack-$*.yaml build
cp .stack-work/install/*/*/$*/bin/hie ${HIE_DIST_DIR}
mv ${HIE_DIST_DIR}/hie ${HIE_DIST_DIR}/hie-$*
.PHONY: dist
#######################################################################################################################
# Help task
#######################################################################################################################
# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)
TARGET_MAX_CHAR_NUM=20
## Show help
help:
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\.\_0-9%]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = $$1; sub(/:$$/, "", helpCommand); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
hasWildcard = match(helpCommand, /%/); \
if (hasWildcard) {\
split("$(GHC_VERSIONS)", versions); \
for (version in versions) { \
expandedCommand = helpCommand; sub(/%/, versions[version], expandedCommand);\
expandedMessage = helpMessage; sub(/%/, versions[version], expandedMessage);\
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", expandedCommand, expandedMessage; \
} \
} else { \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)