-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
67 lines (54 loc) · 1.89 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
COMMIT_HASH = $(shell git describe --always --tags --long)
COMMIT = $(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)-dirty,$(COMMIT_HASH))
BINS := lxcri
LIBEXEC_BINS := lxcri-start lxcri-init lxcri-hook lxcri-hook-builtin
# Installation prefix for BINS
PREFIX ?= /usr/local
export PREFIX
LIBEXEC_DIR = $(PREFIX)/libexec/lxcri
export LIBEXEC_DIR
PKG_CONFIG_PATH ?= $(PREFIX)/lib/pkgconfig
# Note: The default pkg-config directory is search after PKG_CONFIG_PATH
# Note: (Exported) environment variables are NOT visible in the environment of the $(shell ...) function.
export PKG_CONFIG_PATH
LDFLAGS=-X main.version=$(COMMIT) -X main.defaultLibexecDir=$(LIBEXEC_DIR)
CC ?= cc
SHELL_SCRIPTS = $(shell find . -name \*.sh)
GO_SRC = $(shell find . -name \*.go | grep -v _test.go)
TESTCOUNT ?= 1
all: fmt test
update-tools:
GO111MODULE=off go get -u mvdan.cc/sh/v3/cmd/shfmt
GO111MODULE=off go get -u golang.org/x/lint/golint
GO111MODULE=off go get -u honnef.co/go/tools/cmd/staticcheck
fmt:
go fmt ./...
shfmt -w $(SHELL_SCRIPTS)
golint ./...
go mod tidy
staticcheck ./...
.PHONY: test
test: build
go build ./pkg/internal/lxcri-test
go test --failfast --count $(TESTCOUNT) -v ./...
build: $(BINS) $(LIBEXEC_BINS)
lxcri: go.mod $(GO_SRC) Makefile
go build -ldflags '$(LDFLAGS)' -o $@ ./cmd/lxcri
lxcri-start: cmd/lxcri-start/lxcri-start.c
$(CC) -Werror -Wpedantic -o $@ $? $$(pkg-config --libs --cflags lxc)
lxcri-init: go.mod $(GO_SRC) Makefile
CGO_ENABLED=0 go build -o $@ ./cmd/lxcri-init
# this is paranoia - but ensure it is statically compiled
! ldd $@ 2>/dev/null
lxcri-hook: go.mod $(GO_SRC) Makefile
go build -o $@ ./cmd/$@
lxcri-hook-builtin: go.mod $(GO_SRC) Makefile
go build -o $@ ./cmd/$@
install: build
mkdir -p $(PREFIX)/bin
cp -v $(BINS) $(PREFIX)/bin
mkdir -p $(LIBEXEC_DIR)
cp -v $(LIBEXEC_BINS) $(LIBEXEC_DIR)
.PHONY: clean
clean:
-rm -f $(BINS) $(LIBEXEC_BINS)