Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
112 lines (96 loc) · 4.34 KB
/
Copy pathMakefile
File metadata and controls
112 lines (96 loc) · 4.34 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
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
SHELL := /bin/bash
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOMOD=$(GOCMD) mod
BINARY_NAME=linux-windows-switcher
BUILD_TAGS=glib_2_66,pango_1_42
# AppImage parameters
APPIMAGE_DIR=generate_appImage
APPIMAGE_OUTPUT=$(APPIMAGE_DIR)/output
APPIMAGE_BUILDER_IMAGE=appimagecrafters/appimage-builder:1.1.0
APPIMAGE_RECIPE=/source/$(APPIMAGE_DIR)/AppImageBuilder.yml
# Colors for output
RED=\033[0;31m
GREEN=\033[0;32m
YELLOW=\033[1;33m
BLUE=\033[0;34m
NC=\033[0m # No Color
# Go bin path for format/lint tools (portable across GOPATH locations)
GOBIN := $(shell go env GOPATH)/bin
# golangci-lint (version string must match output of golangci-lint --version, e.g. "has version 2.10.1")
GOLANGCI_LINT_VERSION := v2.10.1
GOLANGCI_LINT_VERSION_GREP := 2.10.1
GOLANGCI := $(GOBIN)/golangci-lint
.PHONY: all build clean deps run format lint appimage ensure-golangci-lint help
# Default target
all: deps build
# Help target
help: ## Show this help message
@printf '%b\n' "$(BLUE)Available targets:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(GREEN)%-15s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Dependencies
deps: ## Download dependencies
@printf '%b\n' "$(BLUE)Downloading dependencies...$(NC)"
$(GOMOD) download
$(GOMOD) tidy
@printf '%b\n' "$(GREEN)Dependencies ready$(NC)"
# Build targets
build: ## Build the application
@printf '%b\n' "$(BLUE)Building Linux Windows Switcher...$(NC)"
@mkdir -p bin
$(GOBUILD) -tags $(BUILD_TAGS) -o bin/$(BINARY_NAME) .
@printf '%b\n' "$(GREEN)Build completed! Binary: bin/$(BINARY_NAME)$(NC)"
# Clean targets
clean: ## Clean build artifacts
@printf '%b\n' "$(BLUE)Cleaning...$(NC)"
$(GOCLEAN)
rm -rf bin/
rm -f $(BINARY_NAME)
rm -rf $(APPIMAGE_OUTPUT)
rm -rf $(APPIMAGE_DIR)/AppDir
@printf '%b\n' "$(GREEN)Clean completed!$(NC)"
ensure-golangci-lint:
@need_install=0; \
if [ ! -f "$(GOLANGCI)" ]; then need_install=1; \
elif ! "$(GOLANGCI)" --version 2>&1 | grep -qF '$(GOLANGCI_LINT_VERSION_GREP)'; then need_install=1; fi; \
if [ $$need_install -eq 1 ]; then \
printf '%b\n' "$(BLUE)Installing golangci-lint $(GOLANGCI_LINT_VERSION)...$(NC)"; \
curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(GOBIN) $(GOLANGCI_LINT_VERSION); \
printf '%b\n' "$(GREEN)golangci-lint installed$(NC)"; \
fi
format: ## Format code: modernize, golines, gofumpt (run from project root)
@printf '%b\n' "$(BLUE)1. Running modernize...$(NC)"
$(GOCMD) run golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest -fix ./...
@printf '%b\n' "$(BLUE)2. Running golines (goimports + line wrap)...$(NC)"
$(GOCMD) install golang.org/x/tools/cmd/goimports@latest
$(GOCMD) install github.com/segmentio/golines@latest
PATH=$(GOBIN):$$PATH $(GOBIN)/golines --max-len=120 --base-formatter=goimports -w .
@printf '%b\n' "$(BLUE)3. Running gofumpt...$(NC)"
$(GOCMD) install mvdan.cc/gofumpt@latest
$(GOBIN)/gofumpt -w .
@printf '%b\n' "$(GREEN)Format completed!$(NC)"
lint: ensure-golangci-lint ## Run golangci-lint (install v2.10.1 to $(GOBIN) if missing or version mismatch)
@printf '%b\n' "$(BLUE)Running golangci-lint...$(NC)"
@$(GOLANGCI) run && printf '%b\n' "$(GREEN)Lint passed$(NC)" || (printf '%b\n' "$(RED)Lint failed$(NC)" && exit 1)
# Run target (builds the application first, then runs the binary)
run: build ## Build and run Linux Windows Switcher
@printf '%b\n' "$(BLUE)Starting Linux Windows Switcher...$(NC)"
./bin/$(BINARY_NAME)
# AppImage target (see generate_appImage/how to generate AppImage locally)
appimage: ## Build AppImage using Docker (requires sudo and Docker)
@printf '%b\n' "$(BLUE)Pulling AppImage builder image...$(NC)"
sudo docker pull $(APPIMAGE_BUILDER_IMAGE)
@printf '%b\n' "$(BLUE)Building AppImage...$(NC)"
sudo rm -rf $(APPIMAGE_OUTPUT) | true
mkdir -p $(APPIMAGE_OUTPUT)
sudo docker run -it --rm \
-v "$(CURDIR)/$(APPIMAGE_OUTPUT)":/AppImageOutPutDir \
-v "$(CURDIR)":/source:ro \
-e GITHUB_WORKSPACE=/source \
$(APPIMAGE_BUILDER_IMAGE) /bin/bash -c \
"useradd -u $$(id -u) $$USER && cd /AppImageOutPutDir && appimage-builder --recipe $(APPIMAGE_RECIPE) --skip-tests && chown -R $$USER:$$(id -g) /AppImageOutPutDir"
@printf '%b\n' "$(GREEN)AppImage build completed! Output: $(APPIMAGE_OUTPUT)/$(NC)"
@ls -1 $(APPIMAGE_OUTPUT)/*AppImage* 2>/dev/null || printf '%b\n' "$(YELLOW)No .AppImage file found in $(APPIMAGE_OUTPUT)$(NC)"