forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
167 lines (125 loc) · 3.86 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
############################################################################
# Variables
############################################################################
# Set this to change the target installation path
DESTDIR ?= /usr/local
BINDIR = ${DESTDIR}/bin
MANDIR = ${DESTDIR}/share/man
DISTDIR ?= dist
# filename of the executable
exe = direnv$(shell go env GOEXE)
# Override the go executable
GO = go
# Change if you want to fork direnv
PACKAGE = github.com/direnv/direnv
# 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
export GOFLAGS=-mod=vendor
############################################################################
# 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
direnv: stdlib.go *.go
$(GO) build $(GO_BUILD_FLAGS) -o $(exe)
stdlib.go: stdlib.sh
cat $< | ./script/str2go main StdLib $< > $@
version.go: version.txt
echo package main > $@
echo >> $@
echo "// Version is direnv's version"
echo 'const Version = "$(shell cat $<)"' >> $@
############################################################################
# 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"; 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
.PHONY: $(tests)
test: build $(tests)
@echo
@echo SUCCESS!
test-shellcheck:
shellcheck stdlib.sh
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
############################################################################
# Installation
############################################################################
.PHONY: install
install: all
install -d $(BINDIR)
install $(exe) $(BINDIR)
install -d $(MANDIR)/man1
cp -R man/*.1 $(MANDIR)/man1
.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 gox -osarch "linux/arm64" -osarch "linux/ppc64" -output "$(DISTDIR)/direnv.{{.OS}}-{{.Arch}}"
CGO_ENABLED=0 gox -output "$(DISTDIR)/direnv.{{.OS}}-{{.Arch}}"