DESTDIR ?=
PREFIX ?= /usr/local
LIBEXECDIR ?= ${PREFIX}/libexec
LIBEXECPODMAN ?= ${LIBEXECDIR}/podman
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
CRATE_VERSION ?= $(shell grep ^version Cargo.toml | awk '{print $$3}')
GIT_TAG ?= $(shell git describe --tags)
debug ?=
CARGO_TARGET_DIR ?= targets
export CARGO_TARGET_DIR # 'cargo' is sensitive to this env. var. value.
ifdef debug
$(info debug is $(debug))
release :=
profile :=debug
else
release :=--release
profile :=release
endif
.PHONY: all
all: build
bin:
mkdir -p $@
$(CARGO_TARGET_DIR):
mkdir -p $@
.PHONY: build
build: bin $(CARGO_TARGET_DIR)
cargo build $(release)
cp $(CARGO_TARGET_DIR)/$(profile)/netavark bin/netavark$(if $(debug),.debug,)
.PHONY: crate-publish
crate-publish:
@if [ "$(CRATE_VERSION)" != "$(GIT_TAG)" ]; then\
echo "Git tag is not equivalent to the version set in Cargo.toml. Please checkout the correct tag";\
exit 1;\
fi
@echo "It is expected that you have already done 'cargo login' before running this command. If not command may fail later"
cargo publish --dry-run
cargo publish
.PHONY: clean
clean:
rm -rf bin
if [ "$(CARGO_TARGET_DIR)" = "targets" ]; then rm -rf targets; fi
$(MAKE) -C docs clean
.PHONY: docs
docs:
$(MAKE) -C docs
.PHONY: install
install:
install ${SELINUXOPT} -D -m0755 bin/netavark $(DESTDIR)/$(LIBEXECPODMAN)/netavark
$(MAKE) -C docs install
.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)/$(LIBEXECPODMAN)/netavark
rm -f $(PREFIX)/share/man/man1/netavark*.1
.PHONY: test
test: unit integration
.PHONY: build_unit
build_unit: $(CARGO_TARGET_DIR)
cargo test --no-run
.PHONY: unit
unit: $(CARGO_TARGET_DIR)
cargo test
.PHONY: integration
integration: $(CARGO_TARGET_DIR)
bats test/
.PHONY: validate
validate: $(CARGO_TARGET_DIR)
cargo fmt --all -- --check
cargo clippy -p netavark -- -D warnings
.PHONY: vendor-tarball
vendor-tarball: build install.cargo-vendor-filterer
VERSION=$(shell bin/netavark --version | cut -f2 -d" ") && \
cargo vendor-filterer '--platform=*-unknown-linux-*' --format=tar.gz --prefix vendor/ && \
mv vendor.tar.gz netavark-v$$VERSION-vendor.tar.gz && \
gzip -c bin/netavark > netavark.gz && \
sha256sum netavark.gz netavark-v$$VERSION-vendor.tar.gz > sha256sum
.PHONY: install.cargo-vendor-filterer
install.cargo-vendor-filterer:
cargo install cargo-vendor-filterer
.PHONY: mock-rpm
mock-rpm:
rpkg local
.PHONY: help
help:
@echo "usage: make $(prog) [debug=1]"