| 1 |
PACKAGE ?= github.com/docker/docker-credential-helpers |
| 2 |
VERSION ?= $(shell ./hack/git-meta version) |
| 3 |
REVISION ?= $(shell ./hack/git-meta revision) |
| 4 |
|
| 5 |
GO_PKG = github.com/docker/docker-credential-helpers |
| 6 |
GO_LDFLAGS = -s -w -X ${GO_PKG}/credentials.Version=${VERSION} -X ${GO_PKG}/credentials.Revision=${REVISION} -X ${GO_PKG}/credentials.Package=${PACKAGE} |
| 7 |
|
| 8 |
BUILDX_CMD ?= docker buildx |
| 9 |
DESTDIR ?= ./bin/build |
| 10 |
COVERAGEDIR ?= ./bin/coverage |
| 11 |
|
| 12 |
# 10.11 is the minimum supported version for osxkeychain |
| 13 |
export MACOSX_DEPLOYMENT_TARGET = 10.11 |
| 14 |
ifeq "$(shell go env GOOS)" "darwin" |
| 15 |
export CGO_CFLAGS = -Wno-atomic-alignment -mmacosx-version-min=$(MACOSX_DEPLOYMENT_TARGET) |
| 16 |
else |
| 17 |
# prevent warnings; see https://github.com/docker/docker-credential-helpers/pull/340#issuecomment-2437593837 |
| 18 |
# gcc_libinit.c:44:8: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Werror,-Watomic-alignment] |
| 19 |
export CGO_CFLAGS = -Wno-atomic-alignment |
| 20 |
endif |
| 21 |
|
| 22 |
ifeq "$(shell go env GOOS)/$(shell go env GOARCH)/$(shell go env GOARM)" "linux/arm/6" |
| 23 |
# Neither the CGo compiler, nor the C toolchain automatically link to |
| 24 |
# libatomic when the architecture doesn't support atomic intrinsics, as is |
| 25 |
# the case for arm/v6. |
| 26 |
# |
| 27 |
# Here's the error we get when this is not done (see https://github.com/docker/docker-credential-helpers/pull/340#issuecomment-2437593837): |
| 28 |
# |
| 29 |
# gcc_libinit.c:44:8: error: large atomic operation may incur significant performance penalty; the access size (4 bytes) exceeds the max lock-free size (0 bytes) [-Werror,-Watomic-alignment] |
| 30 |
export CGO_LDFLAGS=-latomic |
| 31 |
endif |
| 32 |
|
| 33 |
.PHONY: all |
| 34 |
all: cross |
| 35 |
|
| 36 |
.PHONY: clean |
| 37 |
clean: |
| 38 |
rm -rf bin |
| 39 |
|
| 40 |
.PHONY: build-% |
| 41 |
build-%: # build, can be one of build-osxkeychain build-pass build-secretservice build-wincred |
| 42 |
go build -trimpath -ldflags="$(GO_LDFLAGS) -X ${GO_PKG}/credentials.Name=docker-credential-$*" -o "$(DESTDIR)/docker-credential-$*" ./$*/cmd/ |
| 43 |
|
| 44 |
# aliases for build-* targets |
| 45 |
.PHONY: osxkeychain secretservice pass wincred |
| 46 |
osxkeychain: build-osxkeychain |
| 47 |
secretservice: build-secretservice |
| 48 |
pass: build-pass |
| 49 |
wincred: build-wincred |
| 50 |
|
| 51 |
.PHONY: cross |
| 52 |
cross: # cross build all supported credential helpers |
| 53 |
$(BUILDX_CMD) bake binaries |
| 54 |
|
| 55 |
.PHONY: release |
| 56 |
release: # create release |
| 57 |
./hack/release |
| 58 |
|
| 59 |
.PHONY: test |
| 60 |
test: |
| 61 |
mkdir -p $(COVERAGEDIR) |
| 62 |
go test -short -v -coverprofile=$(COVERAGEDIR)/coverage.txt -covermode=atomic ./... |
| 63 |
go tool cover -func=$(COVERAGEDIR)/coverage.txt |
| 64 |
|
| 65 |
.PHONY: lint |
| 66 |
lint: |
| 67 |
$(BUILDX_CMD) bake lint |
| 68 |
|
| 69 |
.PHONY: validate-vendor |
| 70 |
validate-vendor: |
| 71 |
$(BUILDX_CMD) bake vendor-validate |
| 72 |
|
| 73 |
.PHONY: fmt |
| 74 |
fmt: |
| 75 |
gofmt -s -l `ls **/*.go | grep -v vendor` |
| 76 |
|
| 77 |
.PHONY: validate |
| 78 |
validate: lint validate-vendor fmt |
| 79 |
|
| 80 |
BUILDIMG:=docker-credential-secretservice-$(VERSION) |
| 81 |
.PHONY: deb |
| 82 |
deb: |
| 83 |
mkdir -p release |
| 84 |
docker build -f deb/Dockerfile \ |
| 85 |
--build-arg VERSION=$(patsubst v%,%,$(VERSION)) \ |
| 86 |
--build-arg REVISION=$(REVISION) \ |
| 87 |
--tag $(BUILDIMG) \ |
| 88 |
. |
| 89 |
docker run --rm --net=none $(BUILDIMG) tar cf - /release | tar xf - |
| 90 |
docker rmi $(BUILDIMG) |
| 91 |
|
| 92 |
.PHONY: vendor |
| 93 |
vendor: |
| 94 |
$(eval $@_TMP_OUT := $(shell mktemp -d -t docker-output.XXXXXXXXXX)) |
| 95 |
$(BUILDX_CMD) bake --set "*.output=type=local,dest=$($@_TMP_OUT)" vendor |
| 96 |
rm -rf ./vendor |
| 97 |
cp -R "$($@_TMP_OUT)"/* . |
| 98 |
rm -rf "$($@_TMP_OUT)" |
| 99 |
|
| 100 |
.PHONY: print-% |
| 101 |
print-%: ; @echo $($*) |