-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
121 lines (96 loc) · 3.56 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
# Setting
#===============================================================
SHELL := /bin/bash
OS := $(shell uname | tr A-Z a-z)
# Const
#===============================================================
name := ccclog
# Option
#===============================================================
SHELL := /bin/bash
LOG_LEVEL := debug
PREFIX := $(HOME)/.cargo
LOG := $(shell echo '$(name)' | tr - _)=$(LOG_LEVEL)
CARGO_BIN := cross
ifneq (,$(findstring mingw64, $(OS)))
CARGO_BIN := cargo
endif
ifneq (,$(findstring darwin, $(OS)))
CARGO_BIN := cargo
endif
ifeq (,$(shell command -v cross 2> /dev/null))
CARGO_BIN := cargo
endif
# cross command coudn't recognize environment variable
CARGO_BUILD_TARGET_DIR := $(CURDIR)/target
CARGO_BUILD_TARGET := x86_64-apple-darwin
CARGO_OPTIONS :=
CARGO_SUB_OPTIONS := --target $(CARGO_BUILD_TARGET) --target-dir $(CARGO_BUILD_TARGET_DIR)
CARGO_COMMAND := $(CARGO_BIN) $(CARGO_OPTIONS)
CONTAINER_REPO := watawuwu/ccclog
CONTAINER_TAG := latest
APP_ARGS :=
# Environment
#===============================================================
export RUST_LOG=$(LOG)
export RUST_BACKTRACE=1
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
# Task
#===============================================================
deps: ## Install depend tools
ifneq ($(CARGO_BUILD_TARGET),)
rustup target add $(CARGO_BUILD_TARGET)
endif
rustup component add rustfmt
rustup component add clippy
rustup show # for container
dev-deps: ## Install dev depend tools
rustup component add rust-src
$(CARGO_COMMAND) install --force cargo-outdated
run: fix fmt clippy ## Execute a main.rs
$(CARGO_COMMAND) run -- $(APP_ARGS) $(CARGO_SUB_OPTIONS)
test: fix fmt clippy ## Run the tests
$(CARGO_COMMAND) test $(CARGO_SUB_OPTIONS) -- --nocapture
check: fix fmt ## Check syntax, but don't build object files
$(CARGO_COMMAND) check $(CARGO_SUB_OPTIONS)
build: ## Build all project
$(CARGO_COMMAND) build $(CARGO_SUB_OPTIONS)
release-build: ## Build all project
$(CARGO_COMMAND) build --release $(CARGO_SUB_OPTIONS)
check-lib: ## Check module version
$(CARGO_COMMAND) outdated -R
update: ## Update modules
$(CARGO_COMMAND) update
clean: ## Remove the target directory
$(CARGO_COMMAND) clean
install: ## Install to $(PREFIX) directory
$(CARGO_COMMAND) install --force --root $(PREFIX) --path .
fix: ## Run fmt
$(CARGO_COMMAND) fix --allow-staged --allow-dirty $(CARGO_SUB_OPTIONS)
fmt: ## Run fmt
$(CARGO_COMMAND) fmt
fmt-check: ## Run fmt
$(CARGO_COMMAND) fmt --all -- --check
clippy: ## Run clippy
$(CARGO_COMMAND) clippy --all-features $(CARGO_SUB_OPTIONS) -- -D warnings
gen-test-data:
find tests/assets -maxdepth 1 -mindepth 1 -type d | \
while read -r p; do tar acf $$p.tar.gz -C $$(dirname $$p) $$(basename $$p); done
publish:
ifeq ($(LEVEL),)
$(error LEVEL not set correctly.)
endif
cargo release $(LEVEL) --no-dev-version --tag-name "{{version}}"
container-build:
docker build -t $(CONTAINER_REPO):$(CONTAINER_TAG) .
help: ## Print help
echo -e "Usage: make [task]\n\nTasks:"
perl -nle 'printf(" \033[33m%s%-20s\033[0m %s\n",$$1,$$2,$$3) if /^([a-zA-Z]){1}([a-zA-Z_-]*?):(?:.+?## )?(.*?)$$/' $(MAKEFILE_LIST)
# Config
#===============================================================
.SILENT: help
# If you want `Target` instead of `Task`, you can avoid it by using dot(.) and slash(/)
# ex) node_modules: => ./node_modules:
.PHONY: $(shell egrep -o '^(_)?[a-zA-Z-]+:' $(MAKEFILE_LIST) | sed 's/://')
.DEFAULT_GOAL := build