Debian Codegraph @

Makefile

raw
1 SHELL = /bin/bash
2 PREFIX ?= $(DESTDIR)/usr/local
3 BINDIR ?= $(PREFIX)/bin
4 GO ?= go
5 GOPATH := $(shell $(GO) env GOPATH)
6 GOBIN := $(shell $(GO) env GOBIN)
7 GO_SRC = $(shell find . -name \*.go)
8 GO_BUILD = $(GO) build
9 NAME = checkpointctl
10
11 BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
12 ZSHINSTALLDIR=${PREFIX}/share/zsh/site-functions
13 FISHINSTALLDIR=${PREFIX}/share/fish/vendor_completions.d
14
15 include Makefile.versions
16
17 COVERAGE_PATH ?= $(shell pwd)/.coverage
18
19 .PHONY: all
20 all: $(NAME)
21
22 $(NAME): $(GO_SRC)
23 $(GO_BUILD) -o $@ -ldflags "-X main.name=$(NAME) -X main.version=${VERSION}"
24
25 $(NAME).coverage: $(GO_SRC)
26 $(GO) build \
27 -cover \
28 -o $@ \
29 -ldflags "-X main.name=$(NAME) -X main.version=${VERSION}"
30
31 .PHONY: release
32 release:
33 CGO_ENABLED=0 $(GO_BUILD) -o $(NAME) -ldflags "-X main.name=$(NAME) -X main.version=${VERSION}"
34
35 .PHONY: install
36 install: $(NAME) install.completions
37 @echo " INSTALL " $<
38 @mkdir -p $(DESTDIR)$(BINDIR)
39 @install -m0755 $< $(DESTDIR)$(BINDIR)
40 @make -C docs install
41
42 .PHONY: uninstall
43 uninstall: uninstall.completions
44 @make -C docs uninstall
45 @echo " UNINSTALL" $(NAME)
46 @$(RM) $(addprefix $(DESTDIR)$(BINDIR)/,$(NAME))
47
48 .PHONY: clean
49 clean:
50 rm -f $(NAME) junit.xml $(NAME).coverage $(COVERAGE_PATH)/*
51 if [ -d $(COVERAGE_PATH) ]; then rmdir $(COVERAGE_PATH); fi
52 @make -C docs clean
53
54 .PHONY: golang-lint
55 golang-lint:
56 golangci-lint run
57
58 .PHONY: shellcheck
59 shellcheck:
60 shellcheck test/*bats
61
62 .PHONY: lint
63 lint: golang-lint shellcheck
64
65 .PHONY: test
66 test: $(NAME)
67 $(GO) test -v ./...
68 make -C test
69
70 .PHONY: test-junit
71 test-junit: $(NAME)
72 make -C test test-junit clean
73
74 .PHONY: coverage
75 coverage: $(NAME).coverage
76 mkdir -p $(COVERAGE_PATH)
77 COVERAGE_PATH=$(COVERAGE_PATH) COVERAGE=1 make -C test
78 # Print coverage from this run
79 $(GO) tool covdata percent -i=${COVERAGE_PATH}
80 $(GO) tool covdata textfmt -i=${COVERAGE_PATH} -o ${COVERAGE_PATH}/coverage.out
81
82 .PHONY: vendor
83 vendor:
84 go mod tidy
85 go mod vendor
86 go mod verify
87
88 .PHONY: docs
89 docs:
90 @make -C docs
91
92 .PHONY: completions
93 completions: $(NAME)
94 declare -A outfiles=([bash]=%s [zsh]=_%s [fish]=%s.fish);\
95 for shell in $${!outfiles[*]}; do \
96 outfile=$$(printf "completions/$$shell/$${outfiles[$$shell]}" $(NAME)); \
97 ./$(NAME) completion $$shell >| $$outfile; \
98 done
99
100 .PHONY: validate.completions
101 validate.completions: SHELL:=/usr/bin/env bash # Set shell to bash for this target
102 validate.completions:
103 # Check if the files can be loaded by the shell
104 . completions/bash/$(NAME)
105 if [ -x /bin/zsh ]; then /bin/zsh completions/zsh/_$(NAME); fi
106 if [ -x /bin/fish ]; then /bin/fish completions/fish/$(NAME).fish; fi
107
108 .PHONY: install.completions
109 install.completions:
110 @install -d -m 755 ${DESTDIR}${BASHINSTALLDIR}
111 @install -m 644 completions/bash/$(NAME) ${DESTDIR}${BASHINSTALLDIR}
112 @install -d -m 755 ${DESTDIR}${ZSHINSTALLDIR}
113 @install -m 644 completions/zsh/_$(NAME) ${DESTDIR}${ZSHINSTALLDIR}
114 @install -d -m 755 ${DESTDIR}${FISHINSTALLDIR}
115 @install -m 644 completions/fish/$(NAME).fish ${DESTDIR}${FISHINSTALLDIR}
116
117 .PHONY: uninstall.completions
118 uninstall.completions:
119 @$(RM) $(addprefix ${DESTDIR}${BASHINSTALLDIR}/,$(NAME))
120 @$(RM) $(addprefix ${DESTDIR}${ZSHINSTALLDIR}/,_$(NAME))
121 @$(RM) $(addprefix ${DESTDIR}${FISHINSTALLDIR}/,$(NAME).fish)
122
123 .PHONY: help
124 help:
125 @echo "Usage: make <target>"
126 @echo " * completions - generate auto-completion files"
127 @echo " * clean - remove artifacts"
128 @echo " * docs - build man pages"
129 @echo " * lint - verify the source code (shellcheck/golangci-lint)"
130 @echo " * golang-lint - run golangci-lint"
131 @echo " * shellcheck - run shellcheck"
132 @echo " * vendor - update go.mod, go.sum, and vendor directory"
133 @echo " * test - run tests"
134 @echo " * test-junit - run tests and create junit output"
135 @echo " * coverage - generate test coverage report"
136 @echo " * install - install the binary to $(BINDIR)"
137 @echo " * uninstall - remove the installed binary from $(BINDIR)"
138 @echo " * release - build a static binary"
139 @echo " * help - show help"