-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
161 lines (141 loc) · 4.35 KB
/
Makefile
File metadata and controls
161 lines (141 loc) · 4.35 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# Makefile for dl - Fast download manager
# Variables
BINARY_NAME=dl
GO=go
GO_BUILD=$(GO) build
GO_TEST=$(GO) test
GO_CLEAN=$(GO) clean
GO_LINT=golangci-lint
GO_MOD=$(GO) mod
GO_FILES=$(wildcard *.go)
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS=-ldflags "-X main.version=$(VERSION)"
# Build variables
GOOS?=$(shell go env GOOS)
GOARCH?=$(shell go env GOARCH)
# Default target
.PHONY: all
all: help
# Build the application
.PHONY: build
build:
@echo "Building $(BINARY_NAME)..."
@$(GO_BUILD) $(LDFLAGS) -o $(BINARY_NAME) ./cmd/dl
# Build for all platforms
.PHONY: build-all
build-all: build-linux build-darwin build-windows
# Build for Linux
.PHONY: build-linux
build-linux:
@echo "Building for Linux..."
@GOOS=linux GOARCH=amd64 $(GO_BUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-amd64 ./cmd/dl
@GOOS=linux GOARCH=arm64 $(GO_BUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-arm64 ./cmd/dl
# Build for macOS
.PHONY: build-darwin
build-darwin:
@echo "Building for macOS..."
@GOOS=darwin GOARCH=amd64 $(GO_BUILD) $(LDFLAGS) -o $(BINARY_NAME)-darwin-amd64 ./cmd/dl
@GOOS=darwin GOARCH=arm64 $(GO_BUILD) $(LDFLAGS) -o $(BINARY_NAME)-darwin-arm64 ./cmd/dl
# Build for Windows
.PHONY: build-windows
build-windows:
@echo "Building for Windows..."
@GOOS=windows GOARCH=amd64 $(GO_BUILD) $(LDFLAGS) -o $(BINARY_NAME)-windows-amd64.exe ./cmd/dl
# Run tests
.PHONY: test
test:
@echo "Running tests..."
@$(GO_TEST) -v ./...
# Run tests with coverage
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
@$(GO_TEST) -v -coverprofile=coverage.out ./...
@$(GO) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
# Run linter
.PHONY: lint
lint:
@if command -v $(GO_LINT) >/dev/null 2>&1; then \
echo "Running linter..."; \
$(GO_LINT) run; \
else \
echo "golangci-lint not installed. Install with:"; \
echo " curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin"; \
fi
# Format code
.PHONY: fmt
fmt:
@echo "Formatting code..."
@$(GO) fmt ./...
# Update dependencies
.PHONY: deps
deps:
@echo "Updating dependencies..."
@$(GO_MOD) download
@$(GO_MOD) tidy
# Clean build artifacts
.PHONY: clean
clean:
@echo "Cleaning..."
@$(GO_CLEAN)
@rm -f $(BINARY_NAME) $(BINARY_NAME)-*
@rm -f coverage.out coverage.html
@rm -f *.dl_progress
# Install locally
.PHONY: install
install:
@echo "Installing $(BINARY_NAME)..."
@$(GO) install $(LDFLAGS) ./cmd/dl
@echo "Installed to $(shell go env GOPATH)/bin/$(BINARY_NAME)"
@if ! echo $$PATH | grep -q "$(shell go env GOPATH)/bin"; then \
echo ""; \
echo "⚠️ Warning: $(shell go env GOPATH)/bin is not in your PATH"; \
echo "Add this to your shell config:"; \
echo ' export PATH="$$HOME/go/bin:$$PATH"'; \
fi
# Uninstall
.PHONY: uninstall
uninstall:
@echo "Uninstalling $(BINARY_NAME)..."
@rm -f $(shell go env GOPATH)/bin/$(BINARY_NAME)
# Run a test download
.PHONY: test-download
test-download: build
@echo "Testing download with 10MB file..."
@./$(BINARY_NAME) -boost 8 http://speedtest.tele2.net/10MB.zip
# Run a test download with resume
.PHONY: test-resume
test-resume: build
@echo "Testing resume functionality..."
@if [ -f test_resume.sh ]; then \
./test_resume.sh; \
else \
echo "test_resume.sh not found"; \
fi
# Development run with race detector
.PHONY: dev
dev:
@echo "Building with race detector..."
@$(GO_BUILD) -race $(LDFLAGS) -o $(BINARY_NAME) ./cmd/dl
@echo "Ready for development testing"
# Show help
.PHONY: help
help:
@echo "dl - Fast download manager"
@echo ""
@echo "Usage:"
@echo " make build - Build the application"
@echo " make build-all - Build for all platforms"
@echo " make test - Run tests"
@echo " make test-coverage - Run tests with coverage report"
@echo " make lint - Run linter"
@echo " make fmt - Format code"
@echo " make deps - Update dependencies"
@echo " make clean - Clean build artifacts"
@echo " make install - Install locally"
@echo " make uninstall - Uninstall from local system"
@echo " make test-download - Test download functionality"
@echo " make test-resume - Test resume functionality"
@echo " make dev - Build with race detector for development"
@echo " make help - Show this help message"