-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile.defs
107 lines (83 loc) · 2.98 KB
/
Makefile.defs
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
# SPDX-License-Identifier: Apache-2.0
# Copyright 2021 Djalal Harouni
# Copyright 2017-2020 Authors of Cilium
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
# Organization variables
GIT_ORG ?= linux-lock
DOCKER_ORG ?= linuxlock
REPO ?= bpflock
# define a function replacing spaces with commas in a list
empty :=
space := $(empty) $(empty)
comma := ,
join-with-comma = $(subst $(space),$(comma),$(strip $1))
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
RELATIVE_DIR := $(shell echo $(realpath .) | sed "s;$(ROOT_DIR)[/]*;;")
BUILD := $(abspath ./build/)
BUILD_DATE = $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
DIST_DIR := $(abspath ./build/dist/)
DIST_BINDIR := $(abspath ./build/dist/bin)
DIST_BPFDIR := $(abspath ./build/dist/bin/bpf)
BUILDLIB := $(abspath ./build/libs/)
DIST_LIBDIR := $(abspath ./build/dist/libs)
LIBBPF ?= $(abspath ./bpf/cc/libbpf/)
INSTALL ?= install
PREFIX ?= /usr/
BINDIR ?= $(PREFIX)bin
LIBDIR ?= $(PREFIX)lib/bpflock/
LIBDIRBPF ?= $(PREFIX)lib/bpflock/bpf
machine := $(shell uname -m)
ARCH := $(shell echo "$(machine)" | sed -E 's/x86_64|x86/amd64/' | sed -E 's/aarch64/arm64/')
ifeq ($(ARCH),)
$(error " testError: architecture $(machine) is not supported yet. Please open an issue")
endif
# Git and Version
VERSION = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION)
VERSION_MAJOR = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION | cut -d. -f1)
GIT_TAG ?= $(shell git describe --tags --always)
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null | sed -e "s/[^[:alnum:]]/-/g")
# Git Version
ifneq ($(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/.git),)
GIT_VERSION = $(shell git rev-parse --short HEAD)
GIT_BUILD_TIME = $(shell git show -s --format='format:%aI')
endif
FULL_BUILD_VERSION = $(VERSION) $(GIT_VERSION) $(GIT_BUILD_TIME)
# LLVM VERSION
LLVM_VERSION="12"
# BPFTOOL
BPFTOOL ?= $(abspath ./tools/$(ARCH)/bpftool)
BPF2GO ?= $(abspath ./tools/$(ARCH)/bpf2go)
# Go environment
GO ?= $(shell command -v go 2> /dev/null)
ifneq ($(strip $(GO)),)
# go build/test/clean flags
# these are declared here so they are treated explicitly
# as non-immediate variables
GO_BUILD_FLAGS =
GO_TEST_FLAGS =
GO_CLEAN_FLAGS =
GO_BUILD_LDFLAGS =
# go build/test -tags values
GO_TAGS_FLAGS = osusergo
GOARCH ?= $(shell $(GO) env GOARCH)
CGO_CC =
ifeq ($(GOARCH),arm64)
CGO_CC = CC=aarch64-linux-gnu-gcc
endif
GO_BUILD_LDFLAGS += -X "github.com/linux-lock/bpflock/pkg/version.bpflockVersion=$(FULL_BUILD_VERSION)"
ifeq ($(NOSTRIP),)
GO_BUILD_LDFLAGS += -s -w
endif
GO_BUILD = CGO_ENABLED=0 $(GO) build
GO_BUILD_WITH_CGO = CGO_ENABLED=1 $(CGO_CC) $(GO) build
GO_BUILD_FLAGS += -ldflags '$(GO_BUILD_LDFLAGS)' -tags=$(call join-with-comma,$(GO_TAGS_FLAGS)) $(EXTRA_GO_BUILD_FLAGS)
GO_TEST_FLAGS += -tags=$(call join-with-comma,$(GO_TAGS_FLAGS))
GO_BUILD += $(GO_BUILD_FLAGS)
GO_BUILD_WITH_CGO += $(GO_BUILD_FLAGS)
GO_TEST = $(GO) test $(GO_TEST_FLAGS)
GO_CLEAN = $(GO) clean $(GO_CLEAN_FLAGS)
GO_VET = $(GO) vet
GO_LIST = $(GO) list
endif
export