-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathMakefile
77 lines (69 loc) · 1.66 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
.PHONY: all install-taskfile run clean
# Default target
all: install-taskfile run
# Detect OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS := linux
endif
ifeq ($(UNAME_S),Darwin)
OS := darwin
endif
ifeq ($(findstring MINGW,$(UNAME_S)),MINGW)
OS := windows
endif
# Detect architecture
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
ARCH := amd64
endif
ifneq ($(filter %86,$(UNAME_M)),)
ARCH := 386
endif
ifneq ($(filter arm%,$(UNAME_M)),)
ARCH := arm
endif
ifeq ($(UNAME_M),aarch64)
ARCH := arm64
endif
# Installation directory
ifeq ($(OS),windows)
INSTALL_DIR := $(HOME)/bin
else
INSTALL_DIR := /usr/local/bin
endif
# Check if sudo is needed
SUDO :=
ifeq ($(shell test -w $(INSTALL_DIR) || echo "no"),no)
SUDO := sudo
endif
# Install Taskfile
install-taskfile:
@echo "Detected OS: $(OS), Architecture: $(ARCH)"
@if command -v task > /dev/null 2>&1; then \
echo "Task is already installed, skipping installation."; \
else \
echo "Installing Task..."; \
curl -sL https://taskfile.dev/install.sh -o install_task.sh; \
$(SUDO) sh install_task.sh -d -b $(INSTALL_DIR); \
rm install_task.sh; \
echo "Task installed successfully."; \
fi
# Run Taskfile
run:
@if [ -f Taskfile.yml ] || [ -f Taskfile.yaml ]; then \
echo "Running Taskfile..."; \
task; \
else \
echo "No Taskfile.yml or Taskfile.yaml found in the current directory."; \
exit 1; \
fi
# Clean up
clean:
@echo "Cleaning up..."
@if command -v task > /dev/null 2>&1 && [ -n "$(SUDO)" ]; then \
$(SUDO) rm -f $(INSTALL_DIR)/task; \
elif command -v task > /dev/null 2>&1; then \
rm -f $(INSTALL_DIR)/task; \
fi
@echo "Task removed successfully."