Skip to content

Commit f2a18f7

Browse files
Add make help recipe (#609)
1 parent 32d9574 commit f2a18f7

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

Makefile

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
.POSIX:
22

3+
# Recipes for this Makefile
4+
5+
## Build shards
6+
## $ make
7+
## Build shards in release mode
8+
## $ make release=1
9+
## Run tests
10+
## $ make test
11+
## Run tests without fossil tests
12+
## $ make test skip_fossil=1
13+
## Generate docs
14+
## $ make docs
15+
## Install shards
16+
## $ make install
17+
## Uninstall shards
18+
## $ make uninstall
19+
## Build and install shards
20+
## $ make build && sudo make install
21+
322
release ?= ## Compile in release mode
423
debug ?= ## Add symbolic debug info
524
static ?= ## Enable static linking
625
skip_fossil ?= ## Skip fossil tests
726
skip_git ?= ## Skip git tests
827
skip_hg ?= ## Skip hg tests
928

29+
DESTDIR ?= ## Install destination dir
30+
PREFIX ?= /usr/local## Install path prefix
31+
1032
CRYSTAL ?= crystal
1133
SHARDS ?= shards
1234
override FLAGS += $(if $(release),--release )$(if $(debug),-d )$(if $(static),--static )
@@ -20,8 +42,6 @@ SHARDS_CONFIG_BUILD_COMMIT := $(shell git rev-parse --short HEAD 2> /dev/null)
2042
SHARDS_VERSION := $(shell cat VERSION)
2143
SOURCE_DATE_EPOCH := $(shell (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile) 2> /dev/null)
2244
EXPORTS := SHARDS_CONFIG_BUILD_COMMIT="$(SHARDS_CONFIG_BUILD_COMMIT)" SOURCE_DATE_EPOCH="$(SOURCE_DATE_EPOCH)"
23-
DESTDIR ?=
24-
PREFIX ?= /usr/local
2545
BINDIR ?= $(DESTDIR)$(PREFIX)/bin
2646
MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
2747
INSTALL ?= /usr/bin/install
@@ -33,31 +53,38 @@ all: build
3353

3454
include docs.mk
3555

56+
build: ## Build shards
3657
build: phony bin/shards
3758

59+
clean: ## Remove build artifacts
3860
clean: phony clean_docs
3961
rm -f bin/shards
4062

4163
bin/shards: $(SOURCES) $(TEMPLATES) lib
4264
@mkdir -p bin
4365
$(EXPORTS) $(CRYSTAL) build $(FLAGS) src/shards.cr -o bin/shards
4466

67+
install: ## Install shards
4568
install: bin/shards man/shards.1.gz man/shard.yml.5.gz phony
4669
$(INSTALL) -m 0755 -d "$(BINDIR)" "$(MANDIR)/man1" "$(MANDIR)/man5"
4770
$(INSTALL) -m 0755 bin/shards "$(BINDIR)"
4871
$(INSTALL) -m 0644 man/shards.1.gz "$(MANDIR)/man1"
4972
$(INSTALL) -m 0644 man/shard.yml.5.gz "$(MANDIR)/man5"
5073

74+
uninstall: ## Uninstall shards
5175
uninstall: phony
5276
rm -f "$(BINDIR)/shards"
5377
rm -f "$(MANDIR)/man1/shards.1.gz"
5478
rm -f "$(MANDIR)/man5/shard.yml.5.gz"
5579

80+
test: ## Run all tests
5681
test: test_unit test_integration
5782

83+
test_unit: ## Run unit tests
5884
test_unit: phony lib
5985
$(CRYSTAL) spec ./spec/unit/ $(if $(skip_fossil),--tag ~fossil) $(if $(skip_git),--tag ~git) $(if $(skip_hg),--tag ~hg)
6086

87+
test_integration: ## Run integration tests
6188
test_integration: bin/shards phony
6289
$(CRYSTAL) spec ./spec/integration/
6390

@@ -72,3 +99,20 @@ man/%.gz: man/%
7299
gzip -c -9 $< > $@
73100

74101
phony:
102+
103+
.PHONY: help
104+
help: ## Show this help
105+
@echo
106+
@printf '\033[34mtargets:\033[0m\n'
107+
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\
108+
sort |\
109+
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
110+
@echo
111+
@printf '\033[34moptional variables:\033[0m\n'
112+
@grep -hE '^[a-zA-Z_-]+ \?=.*?## .*$$' $(MAKEFILE_LIST) |\
113+
sort |\
114+
awk 'BEGIN {FS = " \\?=.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
115+
@echo
116+
@printf '\033[34mrecipes:\033[0m\n'
117+
@grep -hE '^##.*$$' $(MAKEFILE_LIST) |\
118+
awk 'BEGIN {FS = "## "}; /^## [a-zA-Z_-]/ {printf " \033[36m%s\033[0m\n", $$2}; /^## / {printf " %s\n", $$2}'

docs.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ HTML_FILES := docs/shards.html docs/shard.yml.html
88
SHARDS_VERSION := $(shell cat VERSION)
99
SOURCE_DATE_EPOCH := $(shell (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile) 2> /dev/null)
1010

11+
docs: ## Build documentation
1112
docs: manpages
1213

14+
manpages: ## Generate manpages from adoc
1315
manpages: $(MAN_FILES)
1416

17+
htmlpages: ## Generate HTML files from adoc
1518
htmlpages: $(HTML_FILES)
1619

1720
man/%.1 man/%.5: docs/%.adoc
@@ -20,6 +23,7 @@ man/%.1 man/%.5: docs/%.adoc
2023
docs/%.html: docs/%.adoc
2124
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) $(ASCIIDOC) $(ASCIIDOC_OPTIONS) $< -b html5 -o $@
2225

26+
clean_docs: ## Remove documentation data
2327
clean_docs: phony
2428
rm -f $(MAN_FILES)
2529
rm -rf docs/*.html

0 commit comments

Comments
 (0)