-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
115 lines (81 loc) · 2.63 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
# Ensure that every command in this Makefile
# will run with bash instead of the default sh
SHELL := /usr/bin/env bash
#############
# Constants #
#############
PREFIX ?= /usr/local
INSTALL_DIR = $(PREFIX)/bin
SOURCE_FILE = src/envtpl.cr
OUTPUT_DIR = bin
OUTPUT_FILE = envtpl
SPEC_OPTS =
COMPILE_OPTS_DEV = --threads 4
COMPILE_OPTS_RELEASE = --threads 4 --release --error-trace
# Use sudo if current user is not root
ifneq ($(UID), 0)
sudo = sudo
else
sudo =
endif
ifeq ($(shell tty -s && echo true),true)
SPEC_OPTS += --verbose
COMPILE_OPTS_DEV += --progress
COMPILE_OPTS_RELEASE += --progress
endif
# This is the default task
all: help
.PHONY: all
#####################
# Development tasks #
#####################
setup: ## Setup local environment
asdf plugin add crystal || true
asdf plugin add earthly https://github.com/YR-ZR0/asdf-earthly.git || true
asdf install
asdf current
build: ## Compile to development binary
crystal build $(COMPILE_OPTS_DEV) -o $(OUTPUT_DIR)/$(OUTPUT_FILE) $(SOURCE_FILE)
deps: ## Install development dependencies
shards install
clean: ## Cleanup environment
rm -rf bin/*
rm -rf lib/
spec: ## Run Crystal spec
crystal spec $(SPEC_OPTS)
doc: ## Generate Stacker documentation
rm -rf docs
crystal doc
ameba: ## Run static code analysis
bin/ameba
.PHONY: setup build deps clean spec doc ameba
############################
# Docker Development tasks #
############################
docker-image: ## Build local platform Docker image for local development
docker build . -t envtpl-dev:latest
docker-images: ## Build multiplatforms Docker images with Earthly
earthly --ci --output +all-docker-images
.PHONY: docker-image docker-images
#################
# Release tasks #
#################
release: ## Compile to production binary
crystal build $(COMPILE_OPTS_RELEASE) -o $(OUTPUT_DIR)/$(OUTPUT_FILE) $(SOURCE_FILE)
cd bin; for f in *; do shasum --algorithm 256 $$f > $$f.sha256; done
deps-release: ## Install production dependencies
shards install --production
install: ## Install envtpl in $(INSTALL_DIR)
$(sudo) cp $(OUTPUT_DIR)/$(OUTPUT_FILE) $(INSTALL_DIR)/envtpl
uninstall: ## Uninstall envtpl from $(INSTALL_DIR)
$(sudo) rm -f $(INSTALL_DIR)/envtpl
release-static: ## Build static binary with Earthly
earthly --ci --output +all-binaries
cd packages; for f in *; do shasum --algorithm 256 $$f > $$f.sha256; done
.PHONY: release deps-release install uninstall release-static
#################
# Private tasks #
#################
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help