1- # Gitmit Makefile
1+ BINARY_NAME := gitmit
22
3- # Variables
4- BINARY_NAME =gitmit
5- VERSION =$(shell git describe --tags --always --dirty)
6- BUILD_TIME =$(shell date -u '+% Y-% m-% d_% H:% M:% S')
7- LDFLAGS =-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
3+ ifeq ($(OS ) ,Windows_NT)
4+ EXE_NAME := $(BINARY_NAME ) .exe
5+ INSTALL_DIR := $(USERPROFILE ) \bin
6+ else
7+ EXE_NAME := $(BINARY_NAME )
8+ INSTALL_DIR := /usr/local/bin
9+ endif
10+
11+ VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
12+ BUILD_TIME := $(shell date -u '+% Y-% m-% d_% H:% M:% S')
13+ LDFLAGS := -ldflags "-X main.version=$(VERSION ) -X main.buildTime=$(BUILD_TIME ) "
14+
15+ BIN_DIR := bin
16+ BIN_PATH := $(BIN_DIR ) /$(EXE_NAME )
817
9- # Default target
1018.PHONY : all
11- all : clean test build
19+ all : test build
20+
21+ .PHONY : prepare
22+ prepare :
23+ mkdir -p $(BIN_DIR )
1224
13- # Build the binary
1425.PHONY : build
15- build :
16- @echo " Building ${ BINARY_NAME} ..."
17- go build ${ LDFLAGS} -o ${BINARY_NAME}
26+ build : prepare
27+ @echo " Building $( BINARY_NAME) ..."
28+ go build $( LDFLAGS ) -o $( BIN_PATH ) .
1829
19- # Build for multiple platforms
2030.PHONY : build-all
21- build-all : clean
31+ build-all :
2232 @echo " Building for multiple platforms..."
23- GOOS=linux GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME} -linux-amd64
24- GOOS=darwin GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME} -darwin-amd64
25- GOOS=darwin GOARCH=arm64 go build ${LDFLAGS} -o dist/${BINARY_NAME} -darwin-arm64
26- GOOS=windows GOARCH=amd64 go build ${LDFLAGS} -o dist/${BINARY_NAME} -windows-amd64.exe
33+ mkdir -p dist
34+
35+ GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-linux-amd64 .
36+ GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-amd64 .
37+ GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-darwin-arm64 .
38+ GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o dist/$(BINARY_NAME)-windows-amd64.exe .
2739
28- # Run tests
2940.PHONY : test
3041test :
31- @echo " Running tests..."
3242 go test -v ./...
3343
34- # Run tests with coverage
3544.PHONY : test-coverage
3645test-coverage :
37- @echo " Running tests with coverage..."
38- go test -v -coverprofile=coverage.out ./...
46+ go test -coverprofile=coverage.out ./...
3947 go tool cover -html=coverage.out -o coverage.html
4048
41- # Run linting
42- .PHONY : lint
43- lint :
44- @echo " Running linter..."
45- golangci-lint run
46-
47- # Format code
4849.PHONY : fmt
4950fmt :
50- @echo " Formatting code..."
51- go fmt -s ./...
51+ go fmt -s ./...
5252
53- # Vet code
5453.PHONY : vet
5554vet :
56- @echo " Vetting code..."
5755 go vet ./...
5856
59- # Clean build artifacts
60- .PHONY : clean
61- clean :
62- @echo " Cleaning..."
63- rm -f ${BINARY_NAME}
64- rm -rf dist/
65- rm -f coverage.out coverage.html
57+ .PHONY : lint
58+ lint :
59+ golangci-lint run
6660
67- # Install dependencies
6861.PHONY : deps
6962deps :
70- @echo " Installing dependencies..."
7163 go mod download
7264 go mod tidy
7365
74- # Install the binary
75- .PHONY : install
76- install : build
77- @echo " Installing ${BINARY_NAME} ..."
78- sudo mv ${BINARY_NAME} /usr/local/bin/
79-
80- # Uninstall the binary
81- .PHONY : uninstall
82- uninstall :
83- @echo " Uninstalling ${BINARY_NAME} ..."
84- sudo rm -f /usr/local/bin/${BINARY_NAME}
66+ .PHONY : clean
67+ clean :
68+ rm -rf $(BIN_DIR )
69+ rm -rf dist
70+ rm -f coverage.out coverage.html
8571
86- # Run the application
8772.PHONY : run
8873run : build
89- ./${BINARY_NAME}
74+ ./$(BIN_PATH )
75+
76+ .PHONY : install
77+ install :
78+ go install .
9079
91- # Development setup
9280.PHONY : dev-setup
9381dev-setup :
94- @echo " Setting up development environment..."
9582 go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
9683 go mod download
9784
98- # Help
9985.PHONY : help
10086help :
101- @echo " Available targets:"
102- @echo " all - Clean, test, and build"
103- @echo " build - Build the binary"
104- @echo " build-all - Build for multiple platforms"
105- @echo " test - Run tests"
106- @echo " test-coverage- Run tests with coverage report"
107- @echo " lint - Run linter"
108- @echo " fmt - Format code"
109- @echo " vet - Vet code"
110- @echo " clean - Clean build artifacts"
111- @echo " deps - Install dependencies"
112- @echo " install - Install binary to /usr/local/bin"
113- @echo " uninstall - Remove binary from /usr/local/bin"
114- @echo " run - Build and run the application"
115- @echo " dev-setup - Set up development environment"
116- @echo " help - Show this help message"
87+ @echo " Targets:"
88+ @echo " build"
89+ @echo " build-all"
90+ @echo " test"
91+ @echo " test-coverage"
92+ @echo " fmt"
93+ @echo " vet"
94+ @echo " lint"
95+ @echo " deps"
96+ @echo " clean"
97+ @echo " run"
98+ @echo " install"
99+ @echo " dev-setup"
0 commit comments