-
Notifications
You must be signed in to change notification settings - Fork 36
/
Makefile
110 lines (89 loc) · 2.76 KB
/
Makefile
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
export GO111MODULE=off
GO ?= go
GO_BUILD=$(GO) build
# Go module support: set `-mod=vendor` to use the vendored sources
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
endif
BUILDDIR ?= .
DESTDIR ?=
PREFIX ?= /usr/local
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
PROJECT := github.com/containers/oci-seccomp-bpf-hook
HOOK_BIN_DIR ?= $(PREFIX)/libexec/oci/hooks.d
ETCDIR ?= /etc
HOOK_DIR ?= $(PREFIX)/share/containers/oci/hooks.d/
OSBH_VERSION ?= $(shell cat ./VERSION)
# Can be used for local testing (e.g., to set filters)
BATS_OPTS ?=
# If GOPATH not specified, use one in the local directory
ifeq ($(GOPATH),)
export GOPATH := $(CURDIR)/_output
unexport GOBIN
endif
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
GOPKGDIR := $(FIRST_GOPATH)/src/$(PROJECT)
GOPKGBASEDIR ?= $(shell dirname "$(GOPKGDIR)")
GOBIN := $(shell $(GO) env GOBIN)
ifeq ($(GOBIN),)
GOBIN := $(FIRST_GOPATH)/bin
endif
define go-get
env GO111MODULE=off \
$(GO) get -u $(1)
endef
.PHONY: all
all: docs binary
.PHONY: docs
docs:
$(MAKE) -C docs PREFIX=$(PREFIX)
.PHONY: binary
binary:
$(GO_BUILD) -mod=vendor -o $(BUILDDIR)/bin/oci-seccomp-bpf-hook -ldflags "-X main.version=$(OSBH_VERSION)" $(PROJECT)
.PHONY: validate
validate:
./build/golangci-lint run
.PHONY: vendor
vendor:
GO111MODULE=on $(GO) mod tidy
GO111MODULE=on $(GO) mod vendor
GO111MODULE=on $(GO) mod verify
.PHONY: test-integration
test-integration:
@echo
@echo "==> Running integration tests (must be run as root)"
./hack/check_root.sh
bats $(BATS_OPTS) test/
.PHONY: test-unit
test-unit:
$(GO) test -v $(PROJECT)
.PHONY: install.tools
install.tools: .install.golangci-lint .install.md2man
.install.golangci-lint: VERSION=v1.60.3
.install.golangci-lint:
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/$(VERSION)/install.sh | sh -s -- -b ./build $(VERSION)
.install.md2man:
if [ -z "$(shell type -P go-md2man)" ]; then \
$(call go-get,github.com/cpuguy83/go-md2man); \
fi
.PHONY: install.docs-nobuild
install.docs-nobuild:
$(MAKE) -C docs install-nobuild
.PHONY: install.docs
install.docs:
$(MAKE) -C docs install
.PHONY: install-nobuild
install-nobuild: install.docs-nobuild
install $(SELINUXOPT) -d -m 755 $(DESTDIR)$(HOOK_BIN_DIR)
install $(SELINUXOPT) -d -m 755 $(DESTDIR)$(HOOK_DIR)
install $(SELINUXOPT) -m 755 $(BUILDDIR)/bin/oci-seccomp-bpf-hook $(DESTDIR)$(HOOK_BIN_DIR)
install $(SELINUXOPT) -m 644 oci-seccomp-bpf-hook.json $(DESTDIR)$(HOOK_DIR)
sed -i 's|HOOK_BIN_DIR|$(HOOK_BIN_DIR)|g' $(DESTDIR)$(HOOK_DIR)/oci-seccomp-bpf-hook.json
.PHONY: install
install: docs install-nobuild
clean: ## Clean artifacts
$(MAKE) -C docs clean
rm -rf \
bin
find . -name \*~ -delete
find . -name \#\* -delete