From 4b54a471a49cfae617c65b2027ae1e7cc1671cfc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 29 Jun 2018 14:47:53 -0700 Subject: Makefile: Use a pattern rule for cross-compilation Pattern-rule documentation is in [1]. This commit follows the basic approach from [2], with the portable build tags from [3]. Using --keep-going allows folks to see errors for multiple target platforms. For example, if the Darwin target dies, we'll still attempt to build the Linux target before erroring out. I've added an ALLOWED_TO_FAIL environment variable to mark script blocks for the the allow_failures block. Currently we're requiring builds from Linux for Linux and OS X to succeed, but allowing builds from OS X to both targets to fail. [1]: https://www.gnu.org/software/make/manual/html_node/Pattern-Intro.html#Pattern-Intro [2]: https://github.com/kubernetes-incubator/cri-o/commit/e5031fcf9af7d6c78d21e38ab9f82d2392ba05e8 [3]: https://github.com/kubernetes-incubator/cri-o/pull/1653 Signed-off-by: W. Trevor King Closes: #1034 Approved by: baude --- Makefile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index b89e6b416..2ad5a3d88 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ ETCDIR_LIBPOD ?= ${ETCDIR}/crio TMPFILESDIR ?= ${PREFIX}/lib/tmpfiles.d SYSTEMDDIR ?= ${PREFIX}/lib/systemd/system BUILDTAGS ?= seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh) $(shell hack/btrfs_installed_tag.sh) $(shell hack/ostree_tag.sh) $(shell hack/selinux_tag.sh) varlink -BUILDTAGS_DARWIN ?= containers_image_ostree_stub containers_image_openpgp +BUILDTAGS_CROSS ?= containers_image_openpgp containers_image_ostree_stub exclude_graphdriver_btrfs exclude_graphdriver_devicemapper exclude_graphdriver_overlay ifneq (,$(findstring varlink,$(BUILDTAGS))) PODMAN_VARLINK_DEPENDENCIES = cmd/podman/varlink/ioprojectatomicpodman.go endif @@ -57,6 +57,10 @@ GOMD2MAN ?= $(shell command -v go-md2man || echo '$(GOBIN)/go-md2man') BOX="fedora_atomic" +CROSS_BUILD_TARGETS := \ + bin/podman.cross.darwin.amd64 \ + bin/podman.cross.linux.amd64 + all: binaries docs default: help @@ -98,8 +102,13 @@ test/checkseccomp/checkseccomp: .gopathok $(wildcard test/checkseccomp/*.go) podman: .gopathok $(PODMAN_VARLINK_DEPENDENCIES) $(GO) build -i -ldflags '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o bin/$@ $(PROJECT)/cmd/podman -darwin: - GOOS=darwin $(GO) build -ldflags '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS_DARWIN)" -o bin/podman.$@ $(PROJECT)/cmd/podman +local-cross: $(CROSS_BUILD_TARGETS) + +bin/podman.cross.%: .gopathok + TARGET="$*"; \ + GOOS="$${TARGET%%.*}" \ + GOARCH="$${TARGET##*.}" \ + $(GO) build -i -ldflags '$(LDFLAGS_PODMAN)' -tags '$(BUILDTAGS_CROSS)' -o "$@" $(PROJECT)/cmd/podman python-podman: ifdef HAS_PYTHON3 @@ -110,7 +119,7 @@ clean: rm -rf \ .gopathok \ _output \ - bin/podman \ + bin \ build \ test/bin2img/bin2img \ test/checkseccomp/checkseccomp \ -- cgit v1.2.3-54-g00ecf