-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
164 lines (144 loc) · 5.66 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
159
160
161
162
163
164
################################################################################
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html
# https://ftp.gnu.org/old-gnu/Manuals/make-3.80/html_node/make_17.html
ALPINE_HASKELL_MKFILE_PATH := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
ALPINE_HASKELL_ROOT_DIR := $(shell cd $(shell dirname $(ALPINE_HASKELL_MKFILE_PATH)); pwd)
# Common aliases lifted from other Makefiles
package = alpine-haskell
main_exe = demo
# Use GHC options informed by this blog post:
# https://rybczak.net/2016/03/26/how-to-reduce-compilation-times-of-haskell-projects/
ghc_opts = -j +RTS -A128m -RTS
stack_yaml = STACK_YAML="stack.yaml"
stack = $(stack_yaml) stack
# Stack commands that will be executed in the Docker container
stack_docker = $(stack) --docker
# GHC version to build
TARGET_GHC_VERSION ?= 8.6.5
################################################################################
# Standard build (runs in the Docker container)
.PHONY: build
build:
$(stack_docker) build $(package) \
--ghc-options='$(ghc_opts)'
# Static build (runs in the Docker container)
.PHONY: build-static
build-static:
$(stack_docker) build $(package) --flag $(package):static \
--ghc-options='$(ghc_opts)'
# Fast build (-O0) (runs in the Docker container)
.PHONY: build-fast
build-fast:
$(stack_docker) build $(package) \
--ghc-options='$(ghc_opts)' \
--fast
# Clean up all build artifacts
clean:
$(stack_docker) clean
# Run ghcid (runs in the Docker container)
ghcid:
$(stack) exec -- ghcid \
--command "$(stack_docker) ghci \
--ghci-options='-fobject-code $(ghc_opts)' \
--main-is $(package):$(main_exe)"
################################################################################
# Convenience targets for building GHC locally
#
# The intermediate layers of the multi-stage Docker build file are cached so
# that changes to the Dockerfile don't force us to rebuild GHC when developing
# Build GHC with support for 'integer-gmp' and 'libgmp'
.PHONY: docker-build-gmp
docker-build-gmp: docker-base-gmp docker-ghc-gmp docker-tooling-gmp docker-image-gmp
.PHONY: docker-base-gmp
docker-base-gmp:
docker build \
--build-arg GHC_BUILD_TYPE=gmp \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--target base \
--tag alpine-haskell-gmp:base \
--cache-from alpine-haskell-gmp:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)
.PHONY: docker-ghc-gmp
docker-ghc-gmp:
docker build \
--build-arg GHC_BUILD_TYPE=gmp \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--target build-ghc \
--tag alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-gmp:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)
.PHONY: docker-tooling-gmp
docker-tooling-gmp:
docker build \
--build-arg GHC_BUILD_TYPE=gmp \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--target build-tooling \
--tag alpine-haskell-gmp:build-tooling \
--cache-from alpine-haskell-gmp:build-tooling\
--cache-from alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-gmp:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)
.PHONY: docker-image-gmp
docker-image-gmp:
docker build \
--build-arg GHC_BUILD_TYPE=gmp \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--tag alpine-haskell-gmp:$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-gmp:$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-gmp:build-tooling \
--cache-from alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-gmp:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)
# Build GHC with support for 'integer-simple'
.PHONY: docker-build-simple
docker-build-simple: docker-base-simple docker-ghc-simple docker-tooling-simple docker-image-simple
.PHONY: docker-base-simple
docker-base-simple:
docker build \
--build-arg GHC_BUILD_TYPE=simple \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--target base \
--tag alpine-haskell-simple:base \
--cache-from alpine-haskell-simple:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)
.PHONY: docker-ghc-simple
docker-ghc-simple:
docker build \
--build-arg GHC_BUILD_TYPE=simple \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--target build-ghc \
--tag alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-simple:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)
.PHONY: docker-tooling-simple
docker-tooling-simple:
docker build \
--build-arg GHC_BUILD_TYPE=simple \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--target build-tooling \
--tag alpine-haskell-simple:build-tooling \
--cache-from alpine-haskell-simple:build-tooling\
--cache-from alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-simple:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)
.PHONY: docker-image-simple
docker-image-simple:
docker build \
--build-arg GHC_BUILD_TYPE=simple \
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
--tag alpine-haskell-simple:$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-simple:$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-simple:build-tooling \
--cache-from alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
--cache-from alpine-haskell-simple:base \
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
$(ALPINE_HASKELL_ROOT_DIR)