This repository was archived by the owner on Feb 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
103 lines (84 loc) · 2.41 KB
/
Makefile
File metadata and controls
103 lines (84 loc) · 2.41 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
# Configuration
DESTDIR ?=
prefix ?= /usr/local
exec_prefix ?= $(prefix)
bindir ?= $(exec_prefix)/bin
datarootdir ?= $(prefix)/share
datadir ?= $(datarootdir)
mandir ?= $(datarootdir)/man
man1dir ?= $(mandir)/man1
bash_completion_dir ?= $(datadir)/bash-completion/completions
fish_completion_dir ?= $(datadir)/fish/completions
zsh_completion_dir ?= $(datadir)/zsh/site-functions
# Build
name = ocibuild
build: $(name)
build: completion.bash
build: completion.fish
build: completion.zsh
build: man
build: userdocs
.PHONY: build
.$(name).stamp: FORCE
go build -o $@ .
$(name): .$(name).stamp tools/bin/copy-ifchanged
tools/bin/copy-ifchanged $< $@
completion.%: $(name) main_aux.go
go run -tags=aux . completion $* > $@
man: $(name) main_aux.go
go run -tags=aux . man $@ || { r=$$?; rm -rf $@; exit $$r; }
userdocs: $(name) main_aux.go
go run -tags=aux . mddoc $@ || { r=$$?; rm -rf $@; exit $$r; }
# Generate
generate: userdocs go-mod-tidy
.PHONY: generate
go-mod-tidy:
go mod tidy
go mod vendor
.PHONY: go-mod-tidy
# Install
install: $(DESTDIR)$(bindir)/$(name)
install: $(DESTDIR)$(bash_completion_dir)/$(name)
install: $(DESTDIR)$(fish_completion_dir)/$(name).fish
install: $(DESTDIR)$(zsh_completion_dir)/_$(name)
install: install-man
.PHONY: install
$(DESTDIR)$(bindir)/$(name): $(name)
mkdir -p $(@D)
install -m755 $< $@
$(DESTDIR)$(bash_completion_dir)/$(name): completion.bash
mkdir -p $(@D)
install -m644 $< $@
$(DESTDIR)$(fish_completion_dir)/$(name).fish: completion.fish
mkdir -p $(@D)
install -m644 $< $@
$(DESTDIR)$(zsh_completion_dir)/_$(name): completion.zsh
mkdir -p $(@D)
install -m644 $< $@
install-man: man
mkdir -p $(DESTDIR)$(man1dir)
install -m644 man/*.1 $(DESTDIR)$(man1dir)
.PHONY: install-man
# Check
ocibuild.cov: check
test -e $@
touch $@
check:
go test -count=1 -coverprofile=ocibuild.cov -coverpkg=./... -race ./...
.PHONY: check
%.cov.html: %.cov
go tool cover -html=$< -o=$@
lint: tools/bin/golangci-lint
tools/bin/golangci-lint run ./...
.PHONY: lint
# Aux
tools/bin/%: tools/src/%/pin.go tools/src/%/go.mod
cd $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)
tools/bin/crane: tools/bin/%: tools/src/%/pin.go go.mod
cd $(<D) && GOOS= GOARCH= go build -o $(abspath $@) $$(sed -En 's,^import "(.*)".*,\1,p' pin.go)
tools/bin/%: tools/src/%.sh
mkdir -p $(@D)
install -m755 $< $@
.DELETE_ON_ERROR:
.PHONY: FORCE
FORCE: