From 8b34aaf628b0d1f91f68afe0067a2c7fb716c585 Mon Sep 17 00:00:00 2001 From: Hui Zhu Date: Fri, 5 Apr 2019 21:04:36 +0800 Subject: [PATCH] make: Add build option STATIC=1 to statically link Add build option STATIC=1 to statically link kata-agent. Fixes: #522 Signed-off-by: Hui Zhu --- Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6b7e1771fd..6a331e760e 100644 --- a/Makefile +++ b/Makefile @@ -79,7 +79,11 @@ else SECCOMP=no endif # go build common flags -BUILDFLAGS := -buildmode=pie +ifdef STATIC + LDFLAGS := -extldflags '-static' +else + BUILDFLAGS := -buildmode=pie +endif # args for building agent image BUILDARGS := $(if $(http_proxy), --build-arg http_proxy=$(http_proxy)) @@ -90,7 +94,7 @@ AGENT_TAG := $(if $(COMMIT_NO_SHORT),$(COMMIT_NO_SHORT),dev) $(TARGET): $(GENERATED_FILES) $(SOURCES) $(VERSION_FILE) go build $(BUILDFLAGS) -tags "$(BUILDTAGS)" -o $@ \ - -ldflags "-X main.version=$(VERSION_COMMIT) -X main.seccompSupport=$(SECCOMP)" + -ldflags "-X main.version=$(VERSION_COMMIT) -X main.seccompSupport=$(SECCOMP) $(LDFLAGS)" install: install -D $(TARGET) $(DESTDIR)$(BINDIR)/$(TARGET)