-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmakefile
More file actions
64 lines (59 loc) · 1.86 KB
/
makefile
File metadata and controls
64 lines (59 loc) · 1.86 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
.PHONY: build install clean
BINARY_NAME := go-typer
BUILD_DIR := ./bin
BUILD_PATH := $(BUILD_DIR)/$(BINARY_NAME)
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BUILD_DIR)
@go build -o $(BUILD_PATH)
install: build
@echo "Starting installation process..."
@if [ ! -f "$(BUILD_PATH)" ]; then \
echo "❌ Error: Binary not found at $(BUILD_PATH)"; \
exit 1; \
fi
@echo "Please select your preferred installation method:"
@echo "1) Local user install (~/.local/bin) - Recommended for single user"
@echo "2) System-wide install (/usr/local/bin) - Requires sudo, for all users"
@read -p "Enter your choice [1-2]: " install_choice; \
if [[ ! "$$install_choice" =~ ^[12]$$ ]]; then \
echo "❌ Invalid selection. Please choose 1 or 2."; \
exit 1; \
fi; \
case "$$(uname -s)" in \
Linux*) OS=Linux ;; \
Darwin*) OS=macOS ;; \
*) OS="UNKNOWN" ;; \
esac; \
if [[ "$$OS" == "UNKNOWN" ]]; then \
echo "⚠️ Unsupported operating system detected. Proceeding with basic installation."; \
fi; \
case $$install_choice in \
1) \
TARGET_DIR="$$HOME/.local/bin"; \
mkdir -p "$$TARGET_DIR"; \
if cp "$(BUILD_PATH)" "$$TARGET_DIR/"; then \
echo "✅ Successfully installed to $$TARGET_DIR/$(BINARY_NAME)"; \
else \
echo "❌ Local installation failed. Please check permissions."; \
exit 1; \
fi; \
;; \
2) \
TARGET_DIR="/usr/local/bin"; \
echo "Installing system-wide (requires sudo privileges)..."; \
if sudo cp "$(BUILD_PATH)" "$$TARGET_DIR/"; then \
echo "✅ Successfully installed to $$TARGET_DIR/$(BINARY_NAME)"; \
else \
echo "❌ System-wide installation failed. Please check sudo permissions."; \
exit 1; \
fi; \
;; \
esac; \
# --- Clean Target ---
clean:
@echo "Cleaning up build artifacts..."
@rm -rf $(BUILD_DIR)
@echo "✅ Cleanup complete."
# --------------------------
.DEFAULT_GOAL := install