@@ -9,51 +9,149 @@ SHELL := bash
9
9
# See https://stackoverflow.com/questions/25752543/make-delete-on-error-for-directory-targets
10
10
.DELETE_ON_ERROR :
11
11
12
- INSTALL_DIR =$(shell go env GOPATH) /bin
13
- GOOS =$(shell go env GOOS)
14
- GOARCH =$(shell go env GOARCH)
15
- VERSION =$(shell ./scripts/version.sh)
16
-
17
- bin : $(shell find . -not -path './vendor/* ' -type f -name '* .go') go.mod go.sum $(shell find ./examples/templates)
18
- @echo " == This builds slim binaries for command-line usage."
19
- @echo " == Use \" make build\" to embed the site."
20
-
21
- mkdir -p ./dist
22
- rm -rf ./dist/coder-slim_*
23
- rm -f ./site/out/bin/coder*
24
- ./scripts/build_go_slim.sh \
25
- --compress 6 \
26
- --version "$(VERSION)" \
27
- --output ./dist/ \
28
- linux:amd64,armv7,arm64 \
29
- windows:amd64,arm64 \
30
- darwin:amd64,arm64
31
- .PHONY : bin
32
-
33
- build : site/out/index.html $(shell find . -not -path './vendor/* ' -type f -name '* .go') go.mod go.sum $(shell find ./examples/templates)
34
- rm -rf ./dist
35
- mkdir -p ./dist
36
- rm -f ./site/out/bin/coder*
37
-
38
- # build slim artifacts and copy them to the site output directory
39
- ./scripts/build_go_slim.sh \
12
+ INSTALL_DIR = $(shell go env GOPATH) /bin
13
+ GOOS = $(shell go env GOOS)
14
+ GOARCH = $(shell go env GOARCH)
15
+ VERSION = $(shell ./scripts/version.sh)
16
+
17
+ # All ${OS}_${ARCH} combos we build for. Windows binaries have the .exe suffix.
18
+ OS_ARCHES = \
19
+ linux_amd64 linux_arm64 linux_armv7 \
20
+ darwin_amd64 darwin_arm64 \
21
+ windows_amd64.exe windows_arm64.exe
22
+
23
+ # Archive formats and their corresponding ${OS}_${ARCH} combos.
24
+ ARCHIVE_TAR_GZ = linux_amd64 linux_arm64 linux_armv7
25
+ ARCHIVE_ZIP = \
26
+ darwin darwin_arm64 \
27
+ windows_amd64 windows_arm64
28
+
29
+ # All ${OS}_${ARCH} combos we build packages for.
30
+ PACKAGE_OS_ARCHES = linux_amd64 linux_armv7 linux_arm64
31
+
32
+ # All package formats we build.
33
+ PACKAGE_FORMATS = apk deb rpm
34
+
35
+ bin build-slim : $(addprefix build/coder-slim_$(VERSION ) _,$(OS_ARCHES ) )
36
+ .PHONY : bin build-slim
37
+
38
+ build build-full : $(addprefix build/coder_$(VERSION ) _,$(OS_ARCHES ) )
39
+ .PHONY : build build-full
40
+
41
+ # Redirect from version-less targets to the versioned ones. This is kinda gross
42
+ # since it's make shelling out to make, but it's the easiest way less we write
43
+ # out every target manually.
44
+ $(addprefix build/coder_,$(OS_ARCHES ) ) : site/out/index.html build-slim
45
+ @target=" coder_$( VERSION) _$( @:build/coder_%=%) "
46
+ @$(MAKE ) \
47
+ --no-print-directory \
48
+ --assume-old site/out/index.html \
49
+ --assume-old build-slim \
50
+ " build/$$ target"
51
+ @rm -f " $@ "
52
+ @ln -s " $$ target" " $@ "
53
+ .PHONY : $(addprefix build/coder_,$(OS_ARCHES ) )
54
+
55
+ $(addprefix build/coder-slim_,$(OS_ARCHES ) ) :
56
+ @target=" coder-slim_$( VERSION) _$( @:build/coder-slim_%=%) "
57
+ @echo $(MAKE ) \
58
+ --no-print-directory \
59
+ " build/$$ target"
60
+ @rm -f " $@ "
61
+ @ln -s " $$ target" " $@ "
62
+ .PHONY : $(addprefix build/coder-slim_,$(OS_ARCHES ) )
63
+
64
+ # "full" binaries always depend on all "slim" binaries.
65
+ $(addprefix build/coder_$(VERSION ) _,$(OS_ARCHES ) ) : site/out/index.html build-slim
66
+
67
+ # This task handles all builds, for both "full" and "slim" binaries. It parses
68
+ # the target name to get the metadata for the build, so it must be specified in
69
+ # this format:
70
+ # build/coder(-slim)?_$version_$os_$arch(.exe)?
71
+ $(addprefix build/coder_$(VERSION ) _,$(OS_ARCHES ) ) $(addprefix build/coder-slim_$(VERSION ) _,$(OS_ARCHES ) ) : \
72
+ go.mod go.sum \
73
+ $(shell find . -not -path './vendor/* ' -type f -name '* .go') \
74
+ $(shell find ./examples/templates)
75
+
76
+ @mkdir -p build
77
+ @mode=$$([[ "$@" = build/coder-slim* ]] && echo "slim" || echo "full")
78
+ @os=$$(echo $@ | cut -d_ -f3)
79
+ @arch=$$(echo $@ | cut -d_ -f4)
80
+ @if [ "$$mode" != "full" ] && [ "$$mode" != "slim" ]; then
81
+ @echo "Invalid build mode: $$mode"
82
+ @exit 1
83
+ @fi
84
+ @if [[ "$$os" == "windows" ]] && [[ "$$arch" == *.exe ]]; then
85
+ @arch=$${arch%.exe}
86
+ @fi
87
+
88
+ @build_args=( \
89
+ --os "$$os" \
90
+ --arch "$$arch" \
40
91
--version "$(VERSION)" \
41
- --compress 6 \
42
- --output ./dist/ \
43
- linux:amd64,armv7,arm64 \
44
- windows:amd64,arm64 \
45
- darwin:amd64,arm64
46
-
47
- # build not-so-slim artifacts with the default name format
48
- ./scripts/build_go_matrix.sh \
92
+ --output "$@" \
93
+ )
94
+ @if [ "$$mode" == "slim" ]; then
95
+ @build_args+=(--slim)
96
+ @fi
97
+
98
+ ./scripts/build_go.sh "$${build_args[@]}"
99
+
100
+ # This task builds all archives. It parses the target name to get the metadata
101
+ # for the build, so it must be specified in this format:
102
+ # build/coder_${version}_${os}_${arch}.${format}
103
+ #
104
+ # The following OS/arch/format combinations are supported:
105
+ # .tar.gz: linux_amd64, linux_arm64, linux_armv7
106
+ # .zip: darwin_amd64, darwin_arm64, windows_amd64, windows_arm64
107
+ #
108
+ # This depends on build-full because it's difficult to do dynamic dependencies.
109
+ $(foreach os_arch, $(ARCHIVE_TAR_GZ), build/coder_$(VERSION)_$(os_arch).tar.gz) \
110
+ $(foreach os_arch, $(ARCHIVE_ZIP ) , build/coder_$(VERSION ) _$(os_arch ) .zip) : \
111
+ build-full
112
+
113
+ @mkdir -p build
114
+ @os=$$(echo $@ | cut -d_ -f3)
115
+ @arch_format=$$(echo $@ | cut -d_ -f4)
116
+ @arch=$$(echo $$arch_format | cut -d. -f1)
117
+ @format=$${arch_format# *.}
118
+
119
+ @bin_ext=""
120
+ @if [[ "$$os" == "windows" ]]; then
121
+ @bin_ext=".exe"
122
+ @fi
123
+
124
+ ./script/archive.sh \
125
+ --format "$$format" \
126
+ --output "$@" \
127
+ "build/coder_$(VERSION)_$${os}_$${arch}$${bin_ext}"
128
+
129
+ # This task builds all packages. It parses the target name to get the metadata
130
+ # for the build, so it must be specified in this format:
131
+ # build/coder_${version}_${os}_${arch}.${format}
132
+ #
133
+ # Supports apk, deb, rpm for all linux targets.
134
+ #
135
+ # This depends on build-full because it's difficult to do dynamic dependencies.
136
+ $(foreach os_arch, $(PACKAGE_OS_ARCHES ) , $(addprefix build/coder_$(VERSION ) _$(os_arch ) .,$(PACKAGE_FORMATS ) ) ) : \
137
+ build-full
138
+
139
+ @mkdir -p build
140
+ @os=$$(echo $@ | cut -d_ -f3)
141
+ @arch_format=$$(echo $@ | cut -d_ -f4)
142
+ @arch=$$(echo $$arch_format | cut -d. -f1)
143
+ @format=$${arch_format# *.}
144
+
145
+ ./scripts/package.sh \
146
+ --arch "$$arch" \
147
+ --format "$$format" \
49
148
--version "$(VERSION)" \
50
- --output ./dist/ \
51
- --archive \
52
- --package-linux \
53
- linux:amd64,armv7,arm64 \
54
- windows:amd64,arm64 \
55
- darwin:amd64,arm64
56
- .PHONY : build
149
+ --output "$@" \
150
+ "build/coder_$(VERSION)_$${os}_$${arch}"
151
+
152
+ clean :
153
+ rm -rf build
154
+ .PHONY : clean
57
155
58
156
# Runs migrations to output a dump of the database.
59
157
coderd/database/dump.sql : coderd/database/dump/main.go $(wildcard coderd/database/migrations/* .sql)
0 commit comments