forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GNUmakefile
163 lines (122 loc) · 3.79 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
############################################################################
# Variables
############################################################################
# Set this to change the target installation path
DESTDIR ?= /usr/local
BINDIR = ${DESTDIR}/bin
MANDIR = ${DESTDIR}/share/man
# 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 GOPATH = $(CURDIR)/.gopath
export GO15VENDOREXPERIMENT=1
# Creates the GOPATH for us
base = $(GOPATH)/src/$(PACKAGE)
$(base):
@mkdir -p "$(dir $@)"
@ln -sf "$(CURDIR)" "$@"
############################################################################
# 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
ifdef GO_LDFLAGS
GO_FLAGS += -ldflags '$(GO_LDFLAGS)'
endif
direnv: stdlib.go *.go | $(base)
cd "$(base)" && $(GO) build $(GO_FLAGS) -o direnv
stdlib.go: stdlib.sh
cat $< | ./script/str2go main STDLIB $< > $@
version.go: version.txt
echo package main > $@
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-go \
test-go-fmt \
test-bash \
test-elvish \
test-fish \
test-tcsh \
test-zsh
.PHONY: $(tests)
test: build $(tests)
@echo
@echo SUCCESS!
test-go: | $(base)
cd "$(base)" && $(GO) test -v ./...
test-go-fmt:
[ $$($(GO) fmt | tee /dev/stderr | wc -l) = 0 ]
test-shellcheck:
shellcheck stdlib.sh
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:
# Currently broken
#tcsh -e ./test/direnv-test.tcsh
test-zsh:
# Currently missing
#zsh ./test/direnv-test.zsh
############################################################################
# Installation
############################################################################
.PHONY: install
install: all
install -d $(BINDIR)
install direnv $(BINDIR)
install -d $(MANDIR)/man1
cp -R man/*.1 $(MANDIR)/man1
.PHONY: dist
dist: | $(base)
@command -v gox >/dev/null || (echo "Could not generate dist because gox is missing. Run: go get -u github.com/mitchellh/gox"; false)
cd "$(base)" && gox -output "dist/direnv.{{.OS}}-{{.Arch}}"