Skip to content

Commit 5e1acf0

Browse files
committed
build: build binary tarball from static binaries.
Add targets for building static binaries and cleaning up built binaries. Change binary-dist to build tarball from static binaries.
1 parent 84a4646 commit 5e1acf0

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Makefile

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,16 @@ all: build update-workflows
241241

242242
build: $(BUILD_BINS)
243243

244+
build-static:
245+
$(MAKE) STATIC=1 build
246+
244247
install: $(BUILD_BINS) $(foreach dir,$(BUILD_DIRS),install-bin-$(dir)) \
245248
$(foreach dir,$(BUILD_DIRS),install-systemd-$(dir)) \
246249
$(foreach dir,$(BUILD_DIRS),install-sysconf-$(dir)) \
247250
$(foreach dir,$(BUILD_DIRS),install-config-$(dir))
248251

249252

250-
clean: $(foreach dir,$(BUILD_DIRS),clean-$(dir)) clean-spec clean-deb clean-ui-assets clean-html
253+
clean: clean-bin clean-spec clean-deb clean-ui-assets clean-html
251254

252255
images: $(foreach dir,$(IMAGE_DIRS),image-$(dir))
253256

@@ -272,13 +275,26 @@ libexec/%.o: elf/%.c
272275
$(Q)mkdir -p libexec
273276
$(Q)$(CLANG) -nostdinc -D __KERNEL__ $(KERNEL_INCLUDES) -O2 -Wall -target bpf -c $< -o $@
274277

275-
bin/%:
278+
bin/%: .static.%.$(STATIC)
276279
$(Q)bin=$(notdir $@); src=cmd/$$bin; \
277-
echo "Building $@ (version $(BUILD_VERSION), build $(BUILD_BUILDID))..."; \
280+
echo "Building $$([ -n "$(STATIC)" ] && echo 'static ')$@ (version $(BUILD_VERSION), build $(BUILD_BUILDID))..."; \
278281
mkdir -p bin && \
279282
cd $$src && \
280283
$(GO_BUILD) $(BUILD_TAGS) $(LDFLAGS) $(GCFLAGS) -o ../../bin/$$bin
281284

285+
.static.%.$(STATIC):
286+
$(Q)if [ ! -f "$@" ]; then \
287+
touch "$@"; \
288+
fi; \
289+
old="$@"; old="$${old%.*}"; \
290+
if [ -n "$(STATIC)" ]; then \
291+
rm -f "$$old."; \
292+
else \
293+
rm -f "$$old.1"; \
294+
fi
295+
296+
.PRECIOUS: $(foreach dir,$(BUILD_DIRS),.static.$(dir).1 .static.$(dir).)
297+
282298
install-bin-%: bin/%
283299
$(Q)bin=$(patsubst install-bin-%,%,$@); dir=cmd/$$bin; \
284300
echo "Installing $$bin in $(DESTDIR)$(BINDIR)..."; \
@@ -330,6 +346,9 @@ install-minimal-docs:
330346
$(INSTALL) -m 0644 -T $$f $(DESTDIR)$(DOCDIR)/$${df}; \
331347
done
332348

349+
clean-bin: $(foreach dir,$(BUILD_DIRS),clean-$(dir))
350+
$(Q)rm -f .static.*
351+
333352
clean-%:
334353
$(Q)bin=$(patsubst clean-%,%,$@); src=cmd/$$bin; \
335354
echo "Cleaning up $$bin..."; \
@@ -514,12 +533,12 @@ vendored-dist: dist
514533
$(GZIP) vendored-$$tarball && \
515534
rm -fr $$tardir
516535

517-
binary-dist: build
536+
binary-dist:
518537
$(Q)tarball=$(OUTPUT)cri-resource-manager-$(TAR_VERSION).$$(uname -m).tar; \
519538
echo "Creating binary dist tarball $$tarball..."; \
520539
tardir=binary-dist; \
521540
rm -fr $$tarball* $$tardir && \
522-
$(MAKE) DESTDIR=$$tardir \
541+
$(MAKE) STATIC=1 DESTDIR=$$tardir \
523542
BUILD_DIRS=cri-resmgr \
524543
PREFIX=/opt/intel \
525544
DEFAULTDIR=/etc/default \

0 commit comments

Comments
 (0)