forked from crystal-lang/shards
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (101 loc) · 3.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
.POSIX:
# Recipes for this Makefile
## Build shards
## $ make
## Build shards in release mode
## $ make release=1
## Run tests
## $ make test
## Run tests without fossil tests
## $ make test skip_fossil=1
## Generate docs
## $ make docs
## Install shards
## $ make install
## Uninstall shards
## $ make uninstall
## Build and install shards
## $ make build && sudo make install
release ?= ## Compile in release mode
debug ?= ## Add symbolic debug info
static ?= ## Enable static linking
skip_fossil ?= ## Skip fossil tests
skip_git ?= ## Skip git tests
skip_hg ?= ## Skip hg tests
DESTDIR ?= ## Install destination dir
PREFIX ?= /usr/local## Install path prefix
CRYSTAL ?= crystal
SHARDS ?= shards
override FLAGS += $(if $(release),--release )$(if $(debug),-d )$(if $(static),--static )
SHARDS_SOURCES = $(shell find src -name '*.cr')
MOLINILLO_SOURCES = $(shell find lib/molinillo -name '*.cr' 2> /dev/null)
SOURCES = $(SHARDS_SOURCES) $(MOLINILLO_SOURCES)
TEMPLATES = src/templates/*.ecr
SHARDS_CONFIG_BUILD_COMMIT := $(shell git rev-parse --short HEAD 2> /dev/null)
SHARDS_VERSION := $(shell cat VERSION)
SOURCE_DATE_EPOCH := $(shell (git show -s --format=%ct HEAD || stat -c "%Y" Makefile || stat -f "%m" Makefile) 2> /dev/null)
EXPORTS := SHARDS_CONFIG_BUILD_COMMIT="$(SHARDS_CONFIG_BUILD_COMMIT)" SOURCE_DATE_EPOCH="$(SOURCE_DATE_EPOCH)"
BINDIR ?= $(DESTDIR)$(PREFIX)/bin
MANDIR ?= $(DESTDIR)$(PREFIX)/share/man
INSTALL ?= /usr/bin/install
MOLINILLO_VERSION = $(shell $(CRYSTAL) eval 'require "yaml"; puts YAML.parse(File.read("shard.lock"))["shards"]["molinillo"]["version"]')
MOLINILLO_URL = "https://github.com/crystal-lang/crystal-molinillo/archive/v$(MOLINILLO_VERSION).tar.gz"
.PHONY: all
all: build
include docs.mk
.PHONY: build
build: bin/shards
.PHONY: clean
clean: ## Remove build artifacts
clean: clean_docs
rm -f bin/shards
bin/shards: $(SOURCES) $(TEMPLATES) lib
@mkdir -p bin
$(EXPORTS) $(CRYSTAL) build $(FLAGS) src/shards.cr -o bin/shards
.PHONY: install
install: ## Install shards
install: bin/shards man/shards.1.gz man/shard.yml.5.gz
$(INSTALL) -m 0755 -d "$(BINDIR)" "$(MANDIR)/man1" "$(MANDIR)/man5"
$(INSTALL) -m 0755 bin/shards "$(BINDIR)"
$(INSTALL) -m 0644 man/shards.1.gz "$(MANDIR)/man1"
$(INSTALL) -m 0644 man/shard.yml.5.gz "$(MANDIR)/man5"
.PHONY: uninstall
uninstall: ## Uninstall shards
uninstall:
rm -f "$(BINDIR)/shards"
rm -f "$(MANDIR)/man1/shards.1.gz"
rm -f "$(MANDIR)/man5/shard.yml.5.gz"
.PHONY: test
test: ## Run all tests
test: test_unit test_integration
.PHONY: test_unit
test_unit: ## Run unit tests
test_unit: lib
$(CRYSTAL) spec ./spec/unit/ $(if $(skip_fossil),--tag ~fossil) $(if $(skip_git),--tag ~git) $(if $(skip_hg),--tag ~hg)
.PHONY: test_integration
test_integration: ## Run integration tests
test_integration: bin/shards
$(CRYSTAL) spec ./spec/integration/
lib: shard.lock
mkdir -p lib/molinillo
$(SHARDS) install || (curl -L $(MOLINILLO_URL) | tar -xzf - -C lib/molinillo --strip-components=1)
shard.lock: shard.yml
[ $(SHARDS) = false ] || $(SHARDS) update
man/%.gz: man/%
gzip -c -9 $< > $@
.PHONY: help
help: ## Show this help
@echo
@printf '\033[34mtargets:\033[0m\n'
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\
sort |\
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo
@printf '\033[34moptional variables:\033[0m\n'
@grep -hE '^[a-zA-Z_-]+ \?=.*?## .*$$' $(MAKEFILE_LIST) |\
sort |\
awk 'BEGIN {FS = " \\?=.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo
@printf '\033[34mrecipes:\033[0m\n'
@grep -hE '^##.*$$' $(MAKEFILE_LIST) |\
awk 'BEGIN {FS = "## "}; /^## [a-zA-Z_-]/ {printf " \033[36m%s\033[0m\n", $$2}; /^## / {printf " %s\n", $$2}'