From 54390f89a76fef305c4b58703241916c00d7b605 Mon Sep 17 00:00:00 2001 From: Zhao Lei Date: Tue, 14 Jun 2016 18:03:35 +0800 Subject: [PATCH] Introduce make release So we can make all types of release binary with combination of following flags: seccomp selinux apparmor static All binary files are put in release/ dir, like: [root@zlosvm1 runc]# ls -l release total 53556 -rwxr-xr-x 1 root root 9517965 Aug 24 16:59 runc -rwxr-xr-x 1 root root 9673533 Aug 24 17:00 runc.seccomp -rwxr-xr-x 1 root root 9705839 Aug 24 17:00 runc.seccomp.selinux -rwxr-xr-x 1 root root 9546175 Aug 24 16:59 runc.selinux -rwxr-xr-x 1 root root 8205015 Aug 24 16:59 runc.selinux.static -rwxr-xr-x 1 root root 8181789 Aug 24 16:59 runc.static ... Closes #899 Signed-off-by: Zhao Lei --- .gitignore | 1 + Makefile | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/.gitignore b/.gitignore index 76c04941..fecde9ca 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/pkg /runc Godeps/_workspace/src/github.com/opencontainers/runc man/man8 +release diff --git a/Makefile b/Makefile index 0852c71a..200d3265 100644 --- a/Makefile +++ b/Makefile @@ -20,14 +20,44 @@ MAN_PAGES = $(shell ls $(MAN_DIR)/*.8) MAN_PAGES_BASE = $(notdir $(MAN_PAGES)) MAN_INSTALL_PATH := ${PREFIX}/share/man/man8/ +RELEASE_DIR := $(CURDIR)/release + VERSION := ${shell cat ./VERSION} +SHELL ?= $(shell command -v bash 2>/dev/null) + all: $(RUNC_LINK) go build -i -ldflags "-X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -tags "$(BUILDTAGS)" -o runc . static: $(RUNC_LINK) CGO_ENABLED=1 go build -i -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static -X main.gitCommit=${COMMIT} -X main.version=${VERSION}" -o runc . +release: $(RUNC_LINK) + @flag_list=(seccomp selinux apparmor static); \ + unset expression; \ + for flag in "$${flag_list[@]}"; do \ + expression+="' '{'',$${flag}}"; \ + done; \ + eval profile_list=("$$expression"); \ + for profile in "$${profile_list[@]}"; do \ + output=${RELEASE_DIR}/runc; \ + for flag in $$profile; do \ + output+=."$$flag"; \ + done; \ + tags="$$profile"; \ + ldflags="-X main.gitCommit=${COMMIT} -X main.version=${VERSION}"; \ + CGO_ENABLED=; \ + [[ "$$profile" =~ static ]] && { \ + tags="$${tags/static/static_build}"; \ + tags+=" cgo"; \ + ldflags+=" -w -extldflags -static"; \ + CGO_ENABLED=1; \ + }; \ + echo "Building target: $$output"; \ + rm -rf "${GOPATH}/pkg"; \ + go build -i -ldflags "$$ldflags" -tags "$$tags" -o "$$output" .; \ + done + $(RUNC_LINK): ln -sfn $(CURDIR) $(RUNC_LINK) @@ -88,6 +118,7 @@ clean: rm -f runc rm -f $(RUNC_LINK) rm -rf $(GOPATH)/pkg + rm -rf $(RELEASE_DIR) validate: script/validate-gofmt