Last active
January 12, 2025 18:56
-
-
Save straight-shoota/275685fcb8187062208c0871318c4a23 to your computer and use it in GitHub Desktop.
Makefile for Crystal + Shards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.POSIX: | |
all: | |
# Recipes | |
## Build application | |
## $ make | |
## Run tests | |
## $ make test | |
## Install application | |
## $ sudo make install | |
-include Makefile.local # for optional local options | |
APP_NAME := app | |
BUILD_TARGET := bin/$(APP_NAME) | |
DESTDIR ?= ## Install destination dir | |
PREFIX ?= /usr/local## Install path prefix | |
BINDIR ?= $(DESTDIR)$(PREFIX)/bin | |
# The shards command to use | |
SHARDS ?= shards | |
# The crystal command to use | |
CRYSTAL ?= crystal | |
# The install command to use | |
INSTALL ?= /usr/bin/install | |
DOC_SOURCE := src/cli.cr | |
SRC_SOURCES := $(shell find src -name '*.cr' 2>/dev/null) | |
LIB_SOURCES := $(shell find lib -name '*.cr' 2>/dev/null) | |
SPEC_SOURCES := $(shell find spec -name '*.cr' 2>/dev/null) | |
.PHONY: all | |
all: build | |
.PHONY: build | |
build: ## Build the application binary | |
build: $(BUILD_TARGET) | |
$(BUILD_TARGET): $(SRC_SOURCES) $(LIB_SOURCES) lib | |
mkdir -p $(shell dirname "$(@)") | |
$(CRYSTAL) build src/cli.cr -o "$(@)" | |
.PHONY: test | |
test: ## Run the test suite | |
test: lib | |
$(CRYSTAL) spec | |
.PHONY: format | |
format: ## Apply source code formatting | |
format: $(SRC_SOURCES) $(SPEC_SOURCES) | |
$(CRYSTAL) tool format src spec | |
docs: ## Generate API docs | |
docs: $(SRC_SOURCES) lib | |
$(CRYSTAL) docs -o docs $(DOC_SOURCE) | |
lib: shard.lock | |
$(SHARDS) install | |
shard.lock: shard.yml | |
$(SHARDS) update | |
.PHONY: clean | |
clean: ## Remove application binary | |
clean: | |
@rm -f "$(BUILD_TARGET)" | |
.PHONY: install | |
install: ## Install application into $DESTDIR | |
install: $(BUILD_TARGET) | |
$(INSTALL) -m 0755 "$(BUILD_TARGET)" "$(BINDIR)/$(APP_NAME)" | |
.PHONY: uninstall | |
uninstall: ## Uninstall application | |
uninstall: | |
rm -f "$(BINDIR)/$(APP_NAME)" | |
.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}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment