forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGNUmakefile
More file actions
235 lines (190 loc) · 5.81 KB
/
Copy pathGNUmakefile
File metadata and controls
235 lines (190 loc) · 5.81 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
############################################################################
# Variables
############################################################################
# Set this to change the target installation path
PREFIX = /usr/local
BINDIR = ${PREFIX}/bin
SHAREDIR = ${PREFIX}/share
MANDIR = ${SHAREDIR}/man
DISTDIR ?= dist
# filename of the executable
exe = direnv$(shell go env GOEXE)
# Override the go executable
GO = go
# BASH_PATH can also be passed to hard-code the path to bash at build time
SHELL = bash
############################################################################
# Common
############################################################################
.PHONY: all
all: build man ## Build direnv and generate man pages (default)
.PHONY: help
help: ## Show this help message
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*##"; printf "\n"} /^[a-zA-Z_-]+:.*##/ { printf " %-20s %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
export GO111MODULE=on
############################################################################
# Build
############################################################################
.PHONY: build
build: direnv ## Build the direnv binary
.PHONY: clean
clean: ## Remove build artifacts
rm -rf \
.gopath \
direnv
GO_LDFLAGS =
ifeq ($(shell uname), Darwin)
# Fixes DYLD_INSERT_LIBRARIES issues
# See https://github.com/direnv/direnv/issues/194
GO_LDFLAGS += -linkmode=external
endif
ifdef BASH_PATH
GO_LDFLAGS += -X main.bashPath=$(BASH_PATH)
endif
ifneq ($(strip $(GO_LDFLAGS)),)
GO_BUILD_FLAGS = -ldflags '$(GO_LDFLAGS)'
endif
SOURCES = $(wildcard *.go internal/*/*.go pkg/*/*.go)
direnv: $(SOURCES)
$(GO) build $(GO_BUILD_FLAGS) -o $(exe)
############################################################################
# Format all the things
############################################################################
.PHONY: fmt fmt-go fmt-sh
fmt: fmt-go fmt-sh
fmt-go:
$(GO) fmt
fmt-sh:
@command -v shfmt >/dev/null || (echo "Could not format stdlib.sh because shfmt is missing. Run: go install mvdan.cc/sh/cmd/shfmt@latest"; false)
shfmt -i 2 -w stdlib.sh
############################################################################
# Documentation
############################################################################
man_md = $(wildcard man/*.md)
roffs = $(man_md:.md=)
.PHONY: man
man: $(roffs) ## Generate man pages
%.1: %.1.md
@command -v go-md2man >/dev/null || (echo "Could not generate man page because go-md2man is missing. Run: go install github.com/cpuguy83/go-md2man/v2@latest"; false)
go-md2man -in $< -out $@
############################################################################
# Testing
############################################################################
tests = \
test-shellcheck \
test-stdlib \
test-go \
test-go-lint \
test-go-fmt \
test-bash \
test-elvish \
test-fish \
test-tcsh \
test-zsh \
test-pwsh \
test-mx
# Skip few checks for IBM Z mainframe's z/OS aka OS/390
ifeq ($(shell uname), OS/390)
tests = \
test-stdlib \
test-go \
test-go-fmt \
test-bash
endif
.PHONY: $(tests)
test: build $(tests) ## Run all tests
@echo
@echo SUCCESS!
test-shellcheck:
shellcheck stdlib.sh
shellcheck ./test/stdlib.bash
test-stdlib: build
./test/stdlib.bash
test-go:
$(GO) test -v ./...
test-go-lint:
golangci-lint run
test-bash:
bash ./test/direnv-test.bash
# Needs elvish 0.12+
test-elvish:
elvish ./test/direnv-test.elv
test-fish:
fish ./test/direnv-test.fish
test-tcsh:
tcsh -e ./test/direnv-test.tcsh
test-zsh:
zsh ./test/direnv-test.zsh
test-pwsh:
pwsh ./test/direnv-test.ps1
test-mx:
murex -trypipe ./test/direnv-test.mx
############################################################################
# Installation
############################################################################
.PHONY: install
install: all ## Install direnv to PREFIX (default: /usr/local)
install -d $(DESTDIR)$(BINDIR)
install $(exe) $(DESTDIR)$(BINDIR)
install -d $(DESTDIR)$(MANDIR)/man1
cp -R man/*.1 $(DESTDIR)$(MANDIR)/man1
install -d $(DESTDIR)$(SHAREDIR)/fish/vendor_conf.d
echo "$(BINDIR)/direnv hook fish | source" > $(DESTDIR)$(SHAREDIR)/fish/vendor_conf.d/direnv.fish
.PHONY: dist
dist: ## Build cross-platform binaries
@mkdir -p $(DISTDIR)
@echo "Building cross-platform binaries..."
@platforms=" \
darwin/amd64 \
darwin/arm64 \
freebsd/386 \
freebsd/amd64 \
freebsd/arm \
linux/386 \
linux/amd64 \
linux/arm \
linux/arm64 \
linux/mips \
linux/mips64 \
linux/mips64le \
linux/mipsle \
linux/ppc64 \
linux/ppc64le \
linux/s390x \
netbsd/386 \
netbsd/amd64 \
netbsd/arm \
openbsd/386 \
openbsd/amd64 \
windows/386 \
windows/amd64 \
windows/arm64 \
"; \
for platform in $$platforms; do \
os=$${platform%/*}; \
arch=$${platform#*/}; \
echo "Building for $$os/$$arch..."; \
suffix=""; \
if [ "$$os" = "windows" ]; then \
suffix=".exe"; \
fi; \
CGO_ENABLED=0 GOFLAGS="-trimpath" GOOS=$$os GOARCH=$$arch \
$(GO) build -ldflags="-s -w" -o "$(DISTDIR)/direnv.$$os-$$arch$$suffix"; \
done
.PHONY: prepare-release
prepare-release: ## Interactive release preparation (changelog, PR, tag)
./script/prepare-release.sh $(VERSION) $(REPO)
.PHONY: create-release
create-release: dist ## Create GitHub release with binaries (CI only)
@if [ -z "$$GITHUB_REF_NAME" ]; then \
echo "GITHUB_REF_NAME is not set. This target is meant to be run in GitHub Actions."; \
exit 1; \
fi
@echo "Extracting release notes from CHANGELOG.md..."
@release_notes=$$(awk '/^==================/{if(headers>0) exit} /^==================/{headers++; next} headers>0' CHANGELOG.md | sed '/^v[0-9]/d'); \
gh release create "$$GITHUB_REF_NAME" \
--title "Release $$GITHUB_REF_NAME" \
--notes "$$release_notes" \
--verify-tag
gh release upload "$$GITHUB_REF_NAME" $(DISTDIR)/direnv.*