Skip to content

Commit

Permalink
build(make): moved make helpers to a separate file (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus authored Oct 30, 2024
1 parent d7c37c5 commit 2933d6c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
58 changes: 28 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Common makefile helpers
include build/make/common.mk

.DEFAULT_GOAL := build
SHELL = /bin/bash

Expand All @@ -11,50 +14,45 @@ export RUST_BACKTRACE=1
# The list of files that are intentionally ignored while being tracked
ignored-tracked-files = .vscode/settings.json

## Print help
help:
@echo "$$(tput setaf 2)Usage$$(tput sgr0)";sed -ne"/^## /{h;s/.*//;:d" -e"H;n;s/^## /---/;td" -e"s/:.*//;G;s/\\n## /===/;s/\\n//g;p;}" ${MAKEFILE_LIST}|awk -F === -v n=$$(tput cols) -v i=4 -v a="$$(tput setaf 6)" -v z="$$(tput sgr0)" '{printf" '$$(tput setaf 2)make$$(tput sgr0)' %s%s%s\t",a,$$1,z;m=split($$2,w,"---");l=n-i;for(j=1;j<=m;j++){l-=length(w[j])+1;if(l<= 0){l=n-i-length(w[j])-1;}printf"%*s%s\n",-i," ",w[j];}}' | column -ts $$'\t'
.PHONY: help
## Build debug target
.PHONY: build
build: contrib-build
@cargo build --benches

## Run continuous integration tests
.PHONY: ci
ci: check-fmt check-schema test build
@cargo run -- --version
.PHONY: ci

## Run code formatting tests
.PHONY: check-fmt
check-fmt: contrib-build-nightly
@cargo +nightly fmt --all -- --check
.PHONY: check-fmt

## Run schema validation tests
.PHONY: check-schema
check-schema: contrib-schema
@taplo check
.PHONY: check-schema

## Automatically format code
.PHONY: fmt
fmt: contrib-build-nightly
@cargo +nightly fmt --all
.PHONY: fmt

## Build debug target
build: contrib-build
@cargo build --benches
.PHONY: build

## Build release target
.PHONY: build-release
build-release: contrib-build
@cargo build --release --locked
.PHONY: build-release

## Install binary and man pages
.PHONY: install
install: contrib-build install-man-pages
@cargo install --path . --locked
.PHONY: install

## Install man pages
.PHONY: install-man-pages
install-man-pages: ~/share/man/man1/hl.1
@echo $$(tput setaf 3)NOTE:$$(tput sgr0) ensure $$(tput setaf 2)~/share/man$$(tput sgr0) is added to $$(tput setaf 2)MANPATH$$(tput sgr0) environment variable
.PHONY: install-man-pages

~/share/man/man1/hl.1: contrib-build | ~/share/man/man1
@HL_CONFIG= cargo run --release --locked -- --man-page >"$@"
Expand All @@ -63,34 +61,34 @@ install-man-pages: ~/share/man/man1/hl.1
@mkdir -p "$@"

## Install versioned binary
.PHONY: install-versioned
install-versioned: contrib-build
@cargo install --path . --locked
@cp ${HOME}/.cargo/bin/hl ${HOME}/.cargo/bin/$$(${HOME}/.cargo/bin/hl --version | tr ' ' '-')
.PHONY: install-versioned

## Run tests
.PHONY: test
test: contrib-build
@cargo test --workspace
.PHONY: test

## Run benchmarks
.PHONY: bench
bench: contrib-build
@cargo bench --workspace
.PHONY: bench

## Show usage of the binary
.PHONY: usage
usage: build
@env -i HL_CONFIG= ./target/debug/hl --help
.PHONY: usage

## Clean build artifacts
.PHONY: clean
clean: contrib-build
@cargo clean
.PHONY: clean

## Create screenshots
screenshots: build $(THEMES:%=screenshot-%)
.PHONY: screenshots
screenshots: build $(THEMES:%=screenshot-%)

screenshot-%: build contrib-screenshots
@defaults write org.alacritty NSRequiresAquaSystemAppearance -bool yes
Expand All @@ -101,37 +99,37 @@ screenshot-%: build contrib-screenshots
.PHONY: screenshot-%

## Collect coverage
.PHONY: coverage
coverage: contrib-coverage
@$(SHELL) contrib/bin/setup.sh coverage
@$(SHELL) build/ci/coverage.sh
.PHONY: coverage

## Skip ignored tracked files
.PHONY: skip-ignored
skip-ignored:
@git update-index --skip-worktree $(ignored-tracked-files)
.PHONY: skip-ignored

## Undo skip-ignored
.PHONY: no-skip-ignored
no-skip-ignored:
@git update-index --no-skip-worktree $(ignored-tracked-files)
.PHONY: no-skip-ignored

.PHONY: contrib-build
contrib-build:
@$(SHELL) contrib/bin/setup.sh build
.PHONY: contrib-build

.PHONY: contrib-build-nightly
contrib-build-nightly:
@$(SHELL) contrib/bin/setup.sh build-nightly
.PHONY: contrib-build-nightly

.PHONY: contrib-coverage
contrib-coverage:
@$(SHELL) contrib/bin/setup.sh coverage
.PHONY: contrib-coverage

.PHONY: contrib-schema
contrib-schema:
@$(SHELL) contrib/bin/setup.sh schema
.PHONY: contrib-schema

.PHONY: contrib-screenshots
contrib-screenshots:
@$(SHELL) contrib/bin/setup.sh screenshots
.PHONY: contrib-screenshots
12 changes: 12 additions & 0 deletions build/make/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Print help
.PHONY: help
help:
@ echo "$$(tput setaf 2)Usage$$(tput sgr0)"
@ sed -E '/^\.[a-z_]+:/Id' \
${MAKEFILE_LIST} \
| sed -n \
-e '/^## /{h;s/.*//;:d' \
-e 'H;n;s/^## /\t/;td' \
-e 's/:.*//;G;s/\n## /\t/;s/\n//g;p;}' \
| sed -E 's/^(.+)\t/ $(shell tput setaf 2)make$(shell tput sgr0) $(shell tput setaf 6)\1$(shell tput sgr0)\t/' \
| column -ts $$'\t'

0 comments on commit 2933d6c

Please sign in to comment.