From d4efc0411ac8cc21c338ba30fd676f620de066d2 Mon Sep 17 00:00:00 2001 From: Ken Cochrane Date: Mon, 21 Mar 2016 12:58:53 -0400 Subject: [PATCH] Add a static build target to Makefile This allows us to build a static binary for all three binaries, from the make file using ``make static``. Signed-off-by: Ken Cochrane --- Makefile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 234b235..8a57a47 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ BUILDTAGS= GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true) -LDFLAGS := "-X github.com/docker/containerd.GitCommit=${GIT_COMMIT} ${LDFLAGS}" +LDFLAGS := -X github.com/docker/containerd.GitCommit=${GIT_COMMIT} ${LDFLAGS} # if this session isn't interactive, then we don't want to allocate a # TTY, which would fail, but if it is interactive, we do want to attach @@ -19,6 +19,8 @@ export GOPATH:=$(CURDIR)/vendor:$(GOPATH) all: client daemon shim +static: client-static daemon-static shim-static + bin: mkdir -p bin/ @@ -26,14 +28,23 @@ clean: rm -rf bin client: bin - cd ctr && go build -ldflags ${LDFLAGS} -o ../bin/ctr + cd ctr && go build -ldflags "${LDFLAGS}" -o ../bin/ctr + +client-static: + cd ctr && go build -ldflags "-w -extldflags -static ${LDFLAGS}" -tags "$(BUILDTAGS)" -o ../bin/ctr daemon: bin - cd containerd && go build -ldflags ${LDFLAGS} -tags "$(BUILDTAGS)" -o ../bin/containerd + cd containerd && go build -ldflags "${LDFLAGS}" -tags "$(BUILDTAGS)" -o ../bin/containerd + +daemon-static: + cd containerd && go build -ldflags "-w -extldflags -static ${LDFLAGS}" -tags "$(BUILDTAGS)" -o ../bin/containerd shim: bin cd containerd-shim && go build -tags "$(BUILDTAGS)" -o ../bin/containerd-shim +shim-static: + cd containerd-shim && go build -ldflags "-w -extldflags -static ${LDFLAGS}" -tags "$(BUILDTAGS)" -o ../bin/containerd-shim + dbuild: @docker build --rm --force-rm -t "$(DOCKER_IMAGE)" .