makefile: agent: Add self documented help

Add comments that allow self document variables and targets

Fixes: #1436

Signed-off-by: Carlos Venegas <jos.c.venegas.munoz@intel.com>
This commit is contained in:
Carlos Venegas 2021-02-18 22:22:54 +00:00
parent e830192fca
commit a494c4de23

View File

@ -3,6 +3,11 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
# To show variables or targets help on `make help`
# Use the following format:
# '##VAR VARIABLE_NAME: help about variable'
# '##TARGET TARGET_NAME: help about target'
PROJECT_NAME = Kata Containers PROJECT_NAME = Kata Containers
PROJECT_URL = https://github.com/kata-containers PROJECT_URL = https://github.com/kata-containers
PROJECT_COMPONENT = kata-agent PROJECT_COMPONENT = kata-agent
@ -23,9 +28,12 @@ COMMIT_MSG = $(if $(COMMIT),$(COMMIT),unknown)
# Exported to allow cargo to see it # Exported to allow cargo to see it
export VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION)) export VERSION_COMMIT := $(if $(COMMIT),$(VERSION)-$(COMMIT),$(VERSION))
##VAR BUILD_TYPE=release|debug type of rust build
BUILD_TYPE = release BUILD_TYPE = release
##VAR ARCH=arch target to build (format: uname -m)
ARCH = $(shell uname -m) ARCH = $(shell uname -m)
##VAR LIBC=musl|gnu
LIBC ?= musl LIBC ?= musl
ifneq ($(LIBC),musl) ifneq ($(LIBC),musl)
ifeq ($(LIBC),gnu) ifeq ($(LIBC),gnu)
@ -57,10 +65,12 @@ TRIPLE = $(ARCH)-unknown-linux-$(LIBC)
TARGET_PATH = target/$(TRIPLE)/$(BUILD_TYPE)/$(TARGET) TARGET_PATH = target/$(TRIPLE)/$(BUILD_TYPE)/$(TARGET)
##VAR DESTDIR=<path> is a directory prepended to each installed target file
DESTDIR := DESTDIR :=
##VAR BINDIR=<path> is a directory for installing executable programs
BINDIR := /usr/bin BINDIR := /usr/bin
# Define if agent will be installed as init ##VAR INIT=yes|no define if agent will be installed as init
INIT := no INIT := no
# Path to systemd unit directory if installed as not init. # Path to systemd unit directory if installed as not init.
@ -108,6 +118,7 @@ define INSTALL_FILE
install -D -m 644 $1 $(DESTDIR)$2/$1 || exit 1; install -D -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
endef endef
##TARGET default: build code
default: $(TARGET) show-header default: $(TARGET) show-header
$(TARGET): $(GENERATED_CODE) $(TARGET_PATH) $(TARGET): $(GENERATED_CODE) $(TARGET_PATH)
@ -115,42 +126,51 @@ $(TARGET): $(GENERATED_CODE) $(TARGET_PATH)
$(TARGET_PATH): $(SOURCES) | show-summary $(TARGET_PATH): $(SOURCES) | show-summary
@RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE) @RUSTFLAGS="$(EXTRA_RUSTFLAGS) --deny warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE)
$(GENERATED_FILES): %: %.in
@sed $(foreach r,$(GENERATED_REPLACEMENTS),-e 's|@$r@|$($r)|g') "$<" > "$@"
##TARGET optimize: optimized build
optimize: $(SOURCES) | show-summary show-header optimize: $(SOURCES) | show-summary show-header
@RUSTFLAGS="-C link-arg=-s $(EXTRA_RUSTFLAGS) --deny-warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE) @RUSTFLAGS="-C link-arg=-s $(EXTRA_RUSTFLAGS) --deny-warnings" cargo build --target $(TRIPLE) --$(BUILD_TYPE)
show-header:
@printf "%s - version %s (commit %s)\n\n" "$(TARGET)" "$(VERSION)" "$(COMMIT_MSG)"
##TARGET clippy: run clippy linter
clippy: $(GENERATED_CODE) clippy: $(GENERATED_CODE)
cargo clippy --all-targets --all-features --release \ cargo clippy --all-targets --all-features --release \
-- \ -- \
-Aclippy::redundant_allocation \ -Aclippy::redundant_allocation \
-D warnings -D warnings
$(GENERATED_FILES): %: %.in
@sed $(foreach r,$(GENERATED_REPLACEMENTS),-e 's|@$r@|$($r)|g') "$<" > "$@"
install: build-service ##TARGET install: install agent
install: install-services
@install -D $(TARGET_PATH) $(DESTDIR)/$(BINDIR)/$(TARGET) @install -D $(TARGET_PATH) $(DESTDIR)/$(BINDIR)/$(TARGET)
##TARGET clean: clean build
clean: clean:
@cargo clean @cargo clean
@rm -f $(GENERATED_FILES) @rm -f $(GENERATED_FILES)
#TARGET test: run cargo tests
test: test:
@cargo test --all --target $(TRIPLE) @cargo test --all --target $(TRIPLE)
##TARGET check: run test
check: test check: test
##TARGET run: build and run agent
run: run:
@cargo run --target $(TRIPLE) @cargo run --target $(TRIPLE)
build-service: $(GENERATED_FILES) install-services: $(GENERATED_FILES)
ifeq ($(INIT),no) ifeq ($(INIT),no)
@echo "Installing systemd unit files..." @echo "Installing systemd unit files..."
$(foreach f,$(UNIT_FILES),$(call INSTALL_FILE,$f,$(UNIT_DIR))) $(foreach f,$(UNIT_FILES),$(call INSTALL_FILE,$f,$(UNIT_DIR)))
endif endif
show-header:
@printf "%s - version %s (commit %s)\n\n" "$(TARGET)" "$(VERSION)" "$(COMMIT_MSG)"
show-summary: show-header show-summary: show-header
@printf "project:\n" @printf "project:\n"
@printf " name: $(PROJECT_NAME)\n" @printf " name: $(PROJECT_NAME)\n"
@ -166,7 +186,14 @@ show-summary: show-header
@printf " %s\n" "$(call get_toolchain_version)" @printf " %s\n" "$(call get_toolchain_version)"
@printf "\n" @printf "\n"
help: show-summary ## help: Show help comments that start with `##VAR` and `##TARGET`
help: Makefile show-summary
@echo "==========================Help============================="
@echo "Variables:"
@sed -n 's/^##VAR//p' $< | sort
@echo ""
@echo "Targets:"
@sed -n 's/^##TARGET//p' $< | sort
.PHONY: \ .PHONY: \
help \ help \
@ -174,5 +201,6 @@ help: show-summary
show-summary \ show-summary \
optimize optimize
##TARGET generate-protocols: generate/update grpc agent protocols
generate-protocols: generate-protocols:
protocols/hack/update-generated-proto.sh all protocols/hack/update-generated-proto.sh all