forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
200 lines (158 loc) · 4.62 KB
/
GNUmakefile
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
############################################################################
# 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
export GO111MODULE=on
############################################################################
# Build
############################################################################
.PHONY: build
build: direnv
.PHONY: clean
clean:
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 get -u mvdan.cc/sh/cmd/shfmt"; false)
shfmt -i 2 -w stdlib.sh
############################################################################
# Documentation
############################################################################
man_md = $(wildcard man/*.md)
roffs = $(man_md:.md=)
.PHONY: man
man: $(roffs)
%.1: %.1.md
@command -v go-md2man >/dev/null || (echo "Could not generate man page because go-md2man is missing. Run: go get -u github.com/cpuguy83/go-md2man/v2"; 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)
@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 -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:
@command -v gox >/dev/null || (echo "Could not generate dist because gox is missing. Run: go get -u github.com/mitchellh/gox"; false)
CGO_ENABLED=0 GOFLAGS="-trimpath" \
gox -rebuild -ldflags="-s -w" -output "$(DISTDIR)/direnv.{{.OS}}-{{.Arch}}" \
-osarch darwin/amd64 \
-osarch darwin/arm64 \
-osarch freebsd/386 \
-osarch freebsd/amd64 \
-osarch freebsd/arm \
-osarch linux/386 \
-osarch linux/amd64 \
-osarch linux/arm \
-osarch linux/arm64 \
-osarch linux/mips \
-osarch linux/mips64 \
-osarch linux/mips64le \
-osarch linux/mipsle \
-osarch linux/ppc64 \
-osarch linux/ppc64le \
-osarch linux/s390x \
-osarch netbsd/386 \
-osarch netbsd/amd64 \
-osarch netbsd/arm \
-osarch openbsd/386 \
-osarch openbsd/amd64 \
-osarch windows/386 \
-osarch windows/amd64 \
&& true