From 37e34aaff20af7af39acf07565ace83f615b5fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Sat, 2 Sep 2017 01:13:48 +0200 Subject: [PATCH] Automatically use the right CFLAGS and LDFLAGS for gpgme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On macOS, (brew install gpgme) installs it within /usr/local, but /usr/local/include is not in the default search path. Rather than hard-code this directory, use gpgme-config. Sadly that must be done at the top-level user instead of locally in the gpgme subpackage, because cgo supports only pkg-config, not general shell scripts, and gpgme does not install a pkg-config file. If gpgme is not installed or gpgme-config can’t be found for other reasons, the error is silently ignored (and the user will probably find out because the cgo compilation will fail); this is so that users can use the containers_image_openpgp build tag without seeing ugly errors (and without the Makefile having to detect that build tag in even more shell scripts). --- Makefile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index af19a7b8..3f2ea602 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,13 @@ export GO15VENDOREXPERIMENT=1 ifeq ($(shell uname),Darwin) PREFIX ?= ${DESTDIR}/usr/local DARWIN_BUILD_TAG=containers_image_ostree_stub +# On macOS, (brew install gpgme) installs it within /usr/local, but /usr/local/include is not in the default search path. +# Rather than hard-code this directory, use gpgme-config. Sadly that must be done at the top-level user +# instead of locally in the gpgme subpackage, because cgo supports only pkg-config, not general shell scripts, +# and gpgme does not install a pkg-config file. +# If gpgme is not installed or gpgme-config can’t be found for other reasons, the error is silently ignored +# (and the user will probably find out because the cgo compilation will fail). +GPGME_ENV := CGO_CFLAGS="$(shell gpgme-config --cflags 2>/dev/null)" CGO_LDFLAGS="$(shell gpgme-config --libs 2>/dev/null)" else PREFIX ?= ${DESTDIR}/usr endif @@ -64,10 +71,10 @@ binary-static: cmd/skopeo # Build w/o using Docker containers binary-local: - $(GO) build -ldflags "-X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo + $(GPGME_ENV) $(GO) build -ldflags "-X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo binary-local-static: - $(GO) build -ldflags "-extldflags \"-static\" -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo + $(GPGME_ENV) $(GO) build -ldflags "-extldflags \"-static\" -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o skopeo ./cmd/skopeo build-container: docker build ${DOCKER_BUILD_ARGS} -t "$(DOCKER_IMAGE)" . @@ -123,4 +130,4 @@ validate-local: hack/make.sh validate-git-marks validate-gofmt validate-lint validate-vet test-unit-local: - $(GO) test -tags "$(BUILDTAGS)" $$($(GO) list -tags "$(BUILDTAGS)" -e ./... | grep -v '^github\.com/projectatomic/skopeo/\(integration\|vendor/.*\)$$') + $(GPGME_ENV) $(GO) test -tags "$(BUILDTAGS)" $$($(GO) list -tags "$(BUILDTAGS)" -e ./... | grep -v '^github\.com/projectatomic/skopeo/\(integration\|vendor/.*\)$$')