forked from zookinheimer/Lunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
135 lines (117 loc) · 3.78 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
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/make -f
.DEFAULT_GOAL := help
.ONESHELL:
# ENV VARS
export SHELL := $(shell which sh)
export UNAME := $(shell uname -s)
export ASDF_VERSION := v0.13.1
# check commands and OS
ifeq ($(UNAME), Darwin)
export XCODE := $(shell xcode-select -p 2>/dev/null)
export HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK := 1
else ifeq ($(UNAME), Linux)
include /etc/os-release
endif
# colors
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
CYAN := $(shell tput -Txterm setaf 6)
RESET := $(shell tput -Txterm sgr0)
# Usage: $(call check_bin,command_name)
# Returns empty string if command not found, command path if found
define check_bin
$(shell which $(1) 2>/dev/null)
endef
# Usage: $(call brew_install,package_name)
# For packages where binary name differs from package name, add a mapping in the case statement
define brew_install
@if [ "${UNAME}" = "Darwin" ] || [ "${UNAME}" = "Linux" ]; then \
binary_name=""; \
case "$(1)" in \
"go-task") binary_name="task" ;; \
*) binary_name="$(1)" ;; \
esac; \
if ! command -v $$binary_name >/dev/null 2>&1; then \
echo "Installing $(1)..."; \
brew install $(1); \
else \
echo "$(1) already installed."; \
fi \
else \
echo "$(1) not supported."; \
fi
endef
# targets
.PHONY: all
all: help asdf xcode brew jq pre-commit sccache task yq ## run all targets
xcode: ## install xcode command line tools
ifeq ($(UNAME), Darwin)
@if [ -z "${XCODE}" ]; then \
echo "Installing Xcode command line tools..."; \
xcode-select --install; \
else \
echo "xcode already installed."; \
fi
else
@echo "xcode not supported."
endif
brew: xcode ## install homebrew
ifeq ($(UNAME), Darwin)
@if ! command -v brew >/dev/null 2>&1; then \
echo "Installing Homebrew..."; \
NONINTERACTIVE=1 /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
else \
echo "brew already installed."; \
fi
else ifeq ($(UNAME), Linux)
@if [ "${ID_LIKE}" = "debian" ]; then \
if ! command -v brew >/dev/null 2>&1; then \
echo "Installing Homebrew..."; \
NONINTERACTIVE=1 /bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
echo ""; \
echo "To add Homebrew to your PATH, run these commands:"; \
echo 'eval "$$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"'; \
echo 'Add to ~/.profile or ~/.bashrc:'; \
echo 'eval "$$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"'; \
else \
echo "brew already installed."; \
fi \
else \
echo "brew not supported on this Linux distribution."; \
fi
else
@echo "brew not supported."
endif
asdf: xcode ## install asdf
@if ! command -v asdf >/dev/null 2>&1; then \
echo "Installing asdf..."; \
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch ${ASDF_VERSION}; \
echo "To use asdf, add the following to your shell rc (.bashrc/.zshrc):"; \
echo "export PATH=\"$$HOME/.asdf/shims:$$PATH\""; \
echo ". $$HOME/.asdf/asdf.sh"; \
echo ". $$HOME/.asdf/completions/asdf.bash"; \
else \
echo "asdf already installed."; \
fi
jq: brew ## install jq
$(call brew_install,jq)
pre-commit: brew ## install pre-commit
$(call brew_install,pre-commit)
sccache: brew ## install sccache
$(call brew_install,sccache)
task: brew ## install taskfile
$(call brew_install,go-task)
yq: brew ## install yq
$(call brew_install,yq)
install: xcode asdf brew jq pre-commit sccache task yq ## install dependencies
help: ## show this help
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} { \
if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \
else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \
}' $(MAKEFILE_LIST)