-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
122 lines (87 loc) · 2.8 KB
/
Makefile
File metadata and controls
122 lines (87 loc) · 2.8 KB
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
# 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
APP_NAME = squarectl
SOURCE_FILE = src/$(APP_NAME).cr
OUTPUT_DIR = bin
OUTPUT_FILE = $(APP_NAME)
SPEC_OPTS =
COMPILE_OPTS_DEV = --threads 4
COMPILE_OPTS_RELEASE = --threads 4 --release --error-trace
# Use sudo if current user is not root
UID := $(shell id -u)
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
(which brew && brew bundle install) || true
asdf plugin add crystal || 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
format: ## Format code
crystal tool format src/
.PHONY: setup build deps clean spec doc ameba format
############################
# Docker Development tasks #
############################
docker-image: ## Build local platform Docker image for local development
docker buildx bake docker-image
.PHONY: docker-image
#################
# 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 squarectl in $(INSTALL_DIR)
$(sudo) cp $(OUTPUT_DIR)/$(OUTPUT_FILE) $(INSTALL_DIR)/$(OUTPUT_FILE)
uninstall: ## Uninstall squarectl from $(INSTALL_DIR)
$(sudo) rm -f $(INSTALL_DIR)/$(OUTPUT_FILE)
release-static: ## Build static binary with Docker Bake
docker buildx bake binary
mv packages/linux_arm64/$(OUTPUT_FILE)-linux-arm64 packages/
mv packages/linux_amd64/$(OUTPUT_FILE)-linux-amd64 packages/
rmdir packages/linux_arm64/ packages/linux_amd64/
rm -f packages/*.sha256
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