github.com/containerd/nerdctl/v2@v2.0.0-beta.5.0.20240520001846-b5758f54fa28/Makefile (about) 1 # Copyright The containerd Authors. 2 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 7 # http://www.apache.org/licenses/LICENSE-2.0 8 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # ----------------------------------------------------------------------------- 16 # Portions from https://github.com/kubernetes-sigs/cri-tools/blob/v1.19.0/Makefile 17 # Copyright The Kubernetes Authors. 18 # Licensed under the Apache License, Version 2.0 19 # ----------------------------------------------------------------------------- 20 21 GO ?= go 22 GOOS ?= $(shell $(GO) env GOOS) 23 ifeq ($(GOOS),windows) 24 BIN_EXT := .exe 25 endif 26 27 PACKAGE := github.com/containerd/nerdctl/v2 28 29 # distro builders might wanna override these 30 PREFIX ?= /usr/local 31 BINDIR ?= $(PREFIX)/bin 32 DATADIR ?= $(PREFIX)/share 33 DOCDIR ?= $(DATADIR)/doc 34 35 VERSION ?= $(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags) 36 VERSION_TRIMMED := $(VERSION:v%=%) 37 REVISION ?= $(shell git rev-parse HEAD)$(shell if ! git diff --no-ext-diff --quiet --exit-code; then echo .m; fi) 38 39 GO_BUILD_LDFLAGS ?= -s -w 40 GO_BUILD_FLAGS ?= 41 export GO_BUILD=GO111MODULE=on CGO_ENABLED=0 GOOS=$(GOOS) $(GO) build -ldflags "$(GO_BUILD_LDFLAGS) -X $(PACKAGE)/pkg/version.Version=$(VERSION) -X $(PACKAGE)/pkg/version.Revision=$(REVISION)" 42 43 ifdef VERBOSE 44 VERBOSE_FLAG := -v 45 endif 46 47 all: binaries 48 49 help: 50 @echo "Usage: make <target>" 51 @echo 52 @echo " * 'install' - Install binaries to system locations." 53 @echo " * 'binaries' - Build nerdctl." 54 @echo " * 'clean' - Clean artifacts." 55 56 nerdctl: 57 $(GO_BUILD) $(GO_BUILD_FLAGS) $(VERBOSE_FLAG) -o $(CURDIR)/_output/nerdctl$(BIN_EXT) $(PACKAGE)/cmd/nerdctl 58 59 clean: 60 find . -name \*~ -delete 61 find . -name \#\* -delete 62 rm -rf _output/* vendor 63 64 binaries: nerdctl 65 66 install: 67 install -D -m 755 $(CURDIR)/_output/nerdctl $(DESTDIR)$(BINDIR)/nerdctl 68 install -D -m 755 $(CURDIR)/extras/rootless/containerd-rootless.sh $(DESTDIR)$(BINDIR)/containerd-rootless.sh 69 install -D -m 755 $(CURDIR)/extras/rootless/containerd-rootless-setuptool.sh $(DESTDIR)$(BINDIR)/containerd-rootless-setuptool.sh 70 install -D -m 644 -t $(DESTDIR)$(DOCDIR)/nerdctl docs/*.md 71 72 define make_artifact_full_linux 73 DOCKER_BUILDKIT=1 docker build --output type=tar,dest=$(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar --target out-full --platform $(1) --build-arg GO_VERSION $(CURDIR) 74 gzip -9 $(CURDIR)/_output/nerdctl-full-$(VERSION_TRIMMED)-linux-$(1).tar 75 endef 76 77 TAR_OWNER0_FLAGS=--owner=0 --group=0 78 TAR_FLATTEN_FLAGS=--transform 's/.*\///g' 79 80 artifacts: clean 81 GOOS=linux GOARCH=amd64 make -C $(CURDIR) binaries 82 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-amd64.tar.gz _output/nerdctl extras/rootless/* 83 84 GOOS=linux GOARCH=arm64 make -C $(CURDIR) binaries 85 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-arm64.tar.gz _output/nerdctl extras/rootless/* 86 87 GOOS=linux GOARCH=arm GOARM=7 make -C $(CURDIR) binaries 88 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-arm-v7.tar.gz _output/nerdctl extras/rootless/* 89 90 GOOS=linux GOARCH=ppc64le make -C $(CURDIR) binaries 91 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-ppc64le.tar.gz _output/nerdctl extras/rootless/* 92 93 GOOS=linux GOARCH=riscv64 make -C $(CURDIR) binaries 94 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-riscv64.tar.gz _output/nerdctl extras/rootless/* 95 96 GOOS=linux GOARCH=s390x make -C $(CURDIR) binaries 97 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-linux-s390x.tar.gz _output/nerdctl extras/rootless/* 98 99 GOOS=windows GOARCH=amd64 make -C $(CURDIR) binaries 100 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-windows-amd64.tar.gz _output/nerdctl.exe 101 102 GOOS=freebsd GOARCH=amd64 make -C $(CURDIR) binaries 103 tar $(TAR_OWNER0_FLAGS) $(TAR_FLATTEN_FLAGS) -czvf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-freebsd-amd64.tar.gz _output/nerdctl 104 105 rm -f $(CURDIR)/_output/nerdctl $(CURDIR)/_output/nerdctl.exe 106 107 $(call make_artifact_full_linux,amd64) 108 $(call make_artifact_full_linux,arm64) 109 110 go mod vendor 111 tar $(TAR_OWNER0_FLAGS) -czf $(CURDIR)/_output/nerdctl-$(VERSION_TRIMMED)-go-mod-vendor.tar.gz go.mod go.sum vendor 112 113 .PHONY: \ 114 help \ 115 nerdctl \ 116 clean \ 117 binaries \ 118 install \ 119 artifacts