github.com/cilium/cilium@v1.16.2/Makefile.defs (about)

     1  # Copyright Authors of Cilium
     2  # SPDX-License-Identifier: Apache-2.0
     3  
     4  SHELL := /usr/bin/env bash
     5  .SHELLFLAGS := -eu -o pipefail -c
     6  
     7  # define a function replacing spaces with commas in a list
     8  empty :=
     9  space := $(empty) $(empty)
    10  comma := ,
    11  join-with-comma = $(subst $(space),$(comma),$(strip $1))
    12  
    13  define newline
    14  
    15  
    16  endef
    17  
    18  ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
    19  RELATIVE_DIR := $(shell echo $(realpath .) | sed "s;$(ROOT_DIR)[/]*;;")
    20  include $(ROOT_DIR)/Makefile.quiet
    21  
    22  PREFIX?=/usr
    23  BINDIR?=$(PREFIX)/bin
    24  CNIBINDIR?=/opt/cni/bin
    25  CNICONFDIR?=/etc/cni/net.d
    26  LIBDIR?=$(PREFIX)/lib
    27  LOCALSTATEDIR?=/var
    28  RUNDIR?=/var/run
    29  CONFDIR?=/etc
    30  
    31  export GO ?= go
    32  NATIVE_ARCH = $(shell GOARCH= $(GO) env GOARCH)
    33  export GOARCH ?= $(NATIVE_ARCH)
    34  
    35  INSTALL = install
    36  
    37  CONTAINER_ENGINE?=docker
    38  DOCKER_FLAGS?=
    39  DOCKER_BUILD_FLAGS?=
    40  
    41  # use gsed if available, otherwise use sed.
    42  # gsed is needed for MacOS to make in-place replacement work correctly.
    43  SED ?= $(if $(shell command -v gsed),gsed,sed)
    44  
    45  # Set DOCKER_DEV_ACCOUNT with "cilium" by default
    46  ifeq ($(DOCKER_DEV_ACCOUNT),)
    47      DOCKER_DEV_ACCOUNT=cilium
    48  endif
    49  
    50  ifneq ($(CI_BUILD),)
    51      DOCKER_IMAGE_SUFFIX=-ci
    52      DOCKER_IMAGE_TAG=$(shell git rev-parse HEAD)
    53  endif
    54  
    55  # Set DOCKER_IMAGE_TAG with "latest" by default
    56  ifeq ($(DOCKER_IMAGE_TAG),)
    57      DOCKER_IMAGE_TAG=latest
    58  endif
    59  
    60  # renovate: datasource=docker depName=gcr.io/etcd-development/etcd
    61  ETCD_IMAGE_VERSION = v3.5.16
    62  ETCD_IMAGE_SHA = sha256:0d0a9fe2d8344722acfb6f456beb0c64328b58f51dc6dee6291976e62a7b5a3f
    63  ETCD_IMAGE=gcr.io/etcd-development/etcd:$(ETCD_IMAGE_VERSION)@$(ETCD_IMAGE_SHA)
    64  
    65  CONSUL_IMAGE=consul:1.7.2
    66  
    67  CILIUM_BUILDER_IMAGE=$(shell cat $(ROOT_DIR)/images/cilium/Dockerfile | grep "ARG CILIUM_BUILDER_IMAGE=" | cut -d"=" -f2)
    68  
    69  export CILIUM_CLI ?= cilium
    70  export KUBECTL ?= kubectl
    71  
    72  # Till the self-hosted renovate PR #30185 is merged, we might need to run the below
    73  # command locally for any version update.
    74  # make generate-api generate-health-api generate-hubble-api generate-operator-api generate-kvstoremesh-api
    75  # renovate: datasource=docker depName=quay.io/goswagger/swagger
    76  SWAGGER_VERSION := v0.30.5
    77  SWAGGER := $(CONTAINER_ENGINE) run -u $(shell id -u):$(shell id -g) --rm -v $(ROOT_DIR):$(ROOT_DIR) -w $(ROOT_DIR) --entrypoint swagger quay.io/goswagger/swagger:$(SWAGGER_VERSION)
    78  
    79  # go build/test/clean flags
    80  # these are declared here so they are treated explicitly
    81  # as non-immediate variables
    82  GO_BUILD_FLAGS ?=
    83  GO_TEST_FLAGS ?=
    84  GO_CLEAN_FLAGS ?=
    85  GO_BUILD_LDFLAGS ?=
    86  # go build/test -tags values
    87  GO_TAGS_FLAGS += osusergo
    88  
    89  # This is declared here as it is needed to change the covermode depending on if
    90  # RACE is specified.
    91  GOTEST_COVER_OPTS =
    92  
    93  # By default, just print go test output immediately to the terminal. If tparse
    94  # is installed, use it to format the output. Use -progress instead of -follow,
    95  # as the latter is too verbose for most of the test suite.
    96  GOTEST_FORMATTER ?= cat
    97  ifneq ($(shell command -v tparse),)
    98  	GOTEST_COVER_OPTS += -json
    99  	GOTEST_FORMATTER = tparse
   100  ifneq ($(V),0)
   101  	GOTEST_FORMATTER += -progress
   102  endif
   103  endif
   104  
   105  # renovate: datasource=docker depName=golangci/golangci-lint
   106  GOLANGCILINT_WANT_VERSION = v1.59.1
   107  GOLANGCILINT_IMAGE_SHA = sha256:b5f8712114561f1e2fbe74d04ed07ddfd992768705033a6251f3c7b848eac38e
   108  GOLANGCILINT_VERSION = $(shell golangci-lint version --format short 2>/dev/null)
   109  
   110  VERSION = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION)
   111  VERSION_MAJOR = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION | cut -d. -f1)
   112  # Use git only if in a Git repo
   113  ifneq ($(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/.git/HEAD),)
   114      GIT_VERSION = $(shell git show -s --format='format:%h %aI')
   115  else
   116      GIT_VERSION = $(shell cat 2>/dev/null $(ROOT_DIR)/GIT_VERSION)
   117  endif
   118  FULL_BUILD_VERSION = $(VERSION) $(GIT_VERSION)
   119  GO_BUILD_LDFLAGS += -X "github.com/cilium/cilium/pkg/version.ciliumVersion=$(FULL_BUILD_VERSION)"
   120  
   121  ifeq ($(NOSTRIP),)
   122      # Note: these options will not remove annotations needed for stack
   123      # traces, so panic backtraces will still be readable.
   124      #
   125      # -w: Omit the DWARF symbol table.
   126      # -s: Omit the symbol table and debug information.
   127      GO_BUILD_LDFLAGS += -s -w
   128  endif
   129  
   130  ifneq ($(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/images/cilium/Dockerfile),)
   131      CILIUM_ENVOY_REF=$(shell sed -E -e 's/^ARG CILIUM_ENVOY_IMAGE=([^ ]*)/\1/p;d' < $(ROOT_DIR)/images/cilium/Dockerfile)
   132      CILIUM_ENVOY_SHA=$(shell echo $(CILIUM_ENVOY_REF) | sed -E -e 's/[^/]*\/[^:]*:(.*-)?([^:@]*).*/\2/p;d')
   133      GO_BUILD_LDFLAGS += -X "github.com/cilium/cilium/pkg/envoy.requiredEnvoyVersionSHA=$(CILIUM_ENVOY_SHA)"
   134  endif
   135  
   136  # Use git only if in a Git repo, otherwise find the files from the file system
   137  BPF_SRCFILES_IGNORE = bpf/.gitignore
   138  ifneq ($(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/.git/HEAD),)
   139      BPF_SRCFILES := $(shell git ls-files $(ROOT_DIR)/bpf/ | LC_ALL=C sort | tr "\n" ' ')
   140  else
   141      # this line has to be in-sync with bpf/.gitignore, please note usage of make patterns like `%.i`
   142      BPF_SRCFILES_IGNORE += bpf/%.i bpf/%.s bpf/.rebuild_all
   143      BPF_SRCFILES := $(shell find $(ROOT_DIR)/bpf/ -type f | LC_ALL=C sort | tr "\n" ' ')
   144  endif
   145  
   146  # ROOT_DIR can be either `../` or absolute path, each of these need to be stripped
   147  BPF_SRCFILES := $(filter-out $(BPF_SRCFILES_IGNORE),$(subst ../,,$(subst $(ROOT_DIR)/,,$(BPF_SRCFILES))))
   148  
   149  GO_BUILD_FLAGS += -mod=vendor
   150  GO_TEST_FLAGS += -mod=vendor -vet=all
   151  GO_CLEAN_FLAGS += -mod=vendor
   152  
   153  GO_BUILD = CGO_ENABLED=0 $(GO) build
   154  
   155  # Support CGO cross-compiling for amd64 and arm64 targets
   156  CGO_CC =
   157  CROSS_ARCH =
   158  ifneq ($(GOARCH),$(NATIVE_ARCH))
   159      CROSS_ARCH = $(GOARCH)
   160  endif
   161  ifeq ($(CROSS_ARCH),arm64)
   162      CGO_CC = CC=aarch64-linux-gnu-gcc
   163  else ifeq ($(CROSS_ARCH),amd64)
   164      CGO_CC = CC=x86_64-linux-gnu-gcc
   165  endif
   166  GO_BUILD_WITH_CGO = CGO_ENABLED=1 $(CGO_CC) $(GO) build
   167  
   168  ifneq ($(RACE),)
   169      GO_BUILD_FLAGS += -race
   170      GO_TEST_FLAGS += -race
   171      GOTEST_COVER_OPTS += -covermode=atomic
   172  
   173      # GO_BUILD becomes GO_BUILD_WITH_CGO as `-race` requires CGO
   174      GO_BUILD = $(GO_BUILD_WITH_CGO)
   175      ifeq ($(LOCKDEBUG),)
   176          LOCKDEBUG=1
   177      endif
   178  else
   179      GOTEST_COVER_OPTS += -covermode=count
   180  endif
   181  
   182  ifneq ($(LOCKDEBUG),)
   183      GO_TAGS_FLAGS += lockdebug
   184  endif
   185  
   186  GO_BUILD_FLAGS += -ldflags '$(GO_BUILD_LDFLAGS) $(EXTRA_GO_BUILD_LDFLAGS)' -tags=$(call join-with-comma,$(GO_TAGS_FLAGS)) $(EXTRA_GO_BUILD_FLAGS)
   187  GO_TEST_FLAGS += -tags=$(call join-with-comma,$(GO_TAGS_FLAGS))
   188  
   189  ifeq ($(NOOPT),1)
   190      GO_BUILD_FLAGS += -gcflags="all=-N -l"
   191  endif
   192  
   193  GO_BUILD += $(GO_BUILD_FLAGS)
   194  GO_BUILD_WITH_CGO += $(GO_BUILD_FLAGS)
   195  
   196  GO_TEST = CGO_ENABLED=0 $(GO) test $(GO_TEST_FLAGS)
   197  GO_CLEAN = $(GO) clean $(GO_CLEAN_FLAGS)
   198  
   199  GO_VET = $(GO) vet
   200  GO_LIST = $(GO) list
   201  
   202  HELM_TOOLBOX_VERSION ?= "v1.1.0"
   203  HELM_TOOLBOX_SHA ?= "961693f182b9b456ed90e5274ac5df81e4af4343104e252666959cdf9570ce9e"
   204  HELM_TOOLBOX_IMAGE ?= "quay.io/cilium/helm-toolbox:$(HELM_TOOLBOX_VERSION)@sha256:$(HELM_TOOLBOX_SHA)"
   205  
   206  YQ_VERSION ?= "4.40.5"
   207  YQ_SHA ?= "32be61dc94d0acc44f513ba69d0fc05f1f92c2e760491f2a27e11fc13cde6327"
   208  YQ_IMAGE ?= "mikefarah/yq:$(YQ_VERSION)@sha256:$(YQ_SHA)"
   209  
   210  define print_help_line
   211    @printf "  \033[36m%-29s\033[0m %s.\n" $(1) $(2)
   212  endef
   213  
   214  define print_help_from_makefile
   215    @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9][a-zA-Z0-9 _-]*:.*?##/ { split($$1, targets, " "); for (i in targets) { printf "  \033[36m%-28s\033[0m %s\n", targets[i], $$2 } } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
   216  endef
   217  
   218  # Use to ensure the CWD, or any child of it, belongs to Cilium's go module.
   219  CILIUM_GO_MODULE = github.com/cilium/cilium
   220  CURRENT_GO_MODULE = $(shell go list -m)
   221  define ASSERT_CILIUM_MODULE
   222  	$(if $(filter $(CILIUM_GO_MODULE), $(CURRENT_GO_MODULE)) ,, $(error "Could not locate Cilium's go.mod file, are you in Cilium's repository?"))
   223  endef