Skip to content

Commit

Permalink
Simplify Makefile
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Faria <[email protected]>
  • Loading branch information
albertofaria committed Apr 23, 2024
1 parent 91ce0d6 commit 4186e59
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 72 deletions.
91 changes: 26 additions & 65 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,82 +1,43 @@
# This Makefile is intended for developer convenience. For the most part
# all the targets here simply wrap calls to the `cargo` tool. Therefore,
# most targets must be marked 'PHONY' to prevent `make` getting in the way
#
#prog :=xnixperms
# SPDX-License-Identifier: GPL-2.0-or-later

DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
PREFIX ?= /usr/local

CARGO ?= cargo
SELINUXOPT ?= $(shell test -x /usr/sbin/selinuxenabled && selinuxenabled && echo -Z)
# Get crate version by parsing the line that starts with version.
CRATE_VERSION ?= $(shell grep ^version Cargo.toml | awk '{print $$3}')
GIT_TAG ?= $(shell git describe --tags)

# Set this to any non-empty string to enable unoptimized
# build w/ debugging features.
debug ?=

# Set path to cargo executable
CARGO ?= cargo

# All complication artifacts, including dependencies and intermediates
# will be stored here, for all architectures. Use a non-default name
# since the (default) 'target' is used/referenced ambiguously in many
# places in the tool-chain (including 'make' itself).
CARGO_TARGET_DIR ?= targets
export CARGO_TARGET_DIR # 'cargo' is sensitive to this env. var. value.

ifdef debug
$(info debug is $(debug))
# These affect both $(CARGO_TARGET_DIR) layout and contents
# Ref: https://doc.rust-lang.org/cargo/guide/build-cache.html
release :=
profile :=debug
else
release :=--release
profile :=release
endif

.PHONY: all
all: build

bin:
mkdir -p $@

$(CARGO_TARGET_DIR):
mkdir -p $@
binpath := $(DESTDIR)/$(PREFIX)/bin/crun-vm

.PHONY: build
build: bin $(CARGO_TARGET_DIR)
$(CARGO) build $(release)
cp $(CARGO_TARGET_DIR)/$(profile)/crun-vm bin/crun-vm$(if $(debug),.debug,)
build:
$(CARGO) build --release
mkdir -p bin
cp target/release/crun-vm bin/crun-vm

.PHONY: build-debug
build-debug:
$(CARGO) build
mkdir -p bin
cp target/debug/crun-vm bin/crun-vm.debug

.PHONY: clean
clean:
rm -rf bin
if [ "$(CARGO_TARGET_DIR)" = "targets" ]; then rm -rf targets; fi
rm -fr bin target

.PHONY: install
install:
install ${SELINUXOPT} -D -m0755 bin/crun-vm $(DESTDIR)/$(BINDIR)/crun-vm
install: install
install ${SELINUXOPT} -D -m 0755 bin/crun-vm $(binpath)

.PHONY: uninstall
uninstall:
rm -f $(DESTDIR)/$(BINDIR)/crun-vm

#.PHONY: unit
unit: $(CARGO_TARGET_DIR)
$(SHELL) tests/env.sh build
$(SHELL) tests/env.sh start
$(SHELL) tests/env.sh run all all
rm -f $(binpath)

#.PHONY: code_coverage
code_coverage: $(CARGO_TARGET_DIR)
# Downloads tarpaulin only if same version is not present on local
$(CARGO) install cargo-tarpaulin
$(CARGO) tarpaulin -v
.PHONY: lint
lint:
tests/lint.sh

.PHONY: validate
validate: $(CARGO_TARGET_DIR)
$(SHELL) lint.sh
.PHONY: test
test:
tests/env.sh build
tests/env.sh start
tests/env.sh run all all
13 changes: 6 additions & 7 deletions plans/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ prepare:
script:
- sudo systemctl start virtqemud

/unit_test:
summary: Run unit tests
/test:
summary: Test
execute:
how: tmt
script: |
PATH=$PATH:/root/.cargo/bin make unit
script: PATH=$PATH:/root/.cargo/bin make test

/validate_test:
summary: Run validate test
/lint:
summary: Lint
execute:
how: tmt
script: make validate
script: make lint

0 comments on commit 4186e59

Please sign in to comment.