-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
73 lines (60 loc) · 2.6 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
# Name of the output binary
BINARY_NAME=autocommit
# Output directory
OUTPUT_DIR=bin
# Tag for the release
TAG ?= $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
# Build the application and put the binary in the output directory.
.PHONY: build
build:
@echo "Building the application..."
@go build -o $(OUTPUT_DIR)/$(BINARY_NAME) main.go
@chmod +x $(OUTPUT_DIR)/$(BINARY_NAME)
@echo "Done!"
# Create the output directory if it does not exist.
$(OUTPUT_DIR):
@mkdir -p $(OUTPUT_DIR)
# Clean the output directory.
.PHONY: clean
clean:
@echo "Cleaning the output directory..."
@rm -rf $(OUTPUT_DIR)
# Move the binary to the user's bin directory to make it available in the terminal.
.PHONY: install
install:
@echo "Installing the binary..."
@sudo mv $(OUTPUT_DIR)/$(BINARY_NAME) /usr/local/bin/$(BINARY_NAME)
@echo "Done!"
# Build the application for Linux.
.PHONY: build-linux-amd64
build-linux-amd64:
@echo "Building the application for Linux..."
@GOOS=linux GOARCH=amd64 go build -o $(OUTPUT_DIR)/$(BINARY_NAME) main.go
@chmod +x $(OUTPUT_DIR)/$(BINARY_NAME)
@tar -czvf $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-linux-amd64.tar.gz -C $(OUTPUT_DIR) $(BINARY_NAME)
# Build the application for macOS.
.PHONY: build-macos-amd64
build-macos-amd64:
@echo "Building the application for macOS..."
@GOOS=darwin GOARCH=amd64 go build -o $(OUTPUT_DIR)/$(BINARY_NAME) main.go
@chmod +x $(OUTPUT_DIR)/$(BINARY_NAME)
@tar -czvf $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-darwin-amd64.tar.gz -C $(OUTPUT_DIR) $(BINARY_NAME)
# Build the application for macOS arm64.
.PHONY: build-macos-arm64
build-macos-arm64:
@echo "Building the application for macOS arm64..."
@GOOS=darwin GOARCH=arm64 go build -o $(OUTPUT_DIR)/$(BINARY_NAME) main.go
@chmod +x $(OUTPUT_DIR)/$(BINARY_NAME)
@tar -czvf $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-darwin-arm64.tar.gz -C $(OUTPUT_DIR) $(BINARY_NAME)
# Build the application for Windows.
.PHONY: build-windows-amd64
build-windows-amd64:
@echo "Building the application for Windows..."
@GOOS=windows GOARCH=amd64 go build -o $(OUTPUT_DIR)/$(BINARY_NAME).exe main.go
@chmod +x $(OUTPUT_DIR)/$(BINARY_NAME)
@zip -j $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-windows-amd64.zip $(OUTPUT_DIR)/$(BINARY_NAME).exe
# Release the application.
.PHONY: release
release: build-linux-amd64 build-macos-amd64 build-macos-arm64 build-windows-amd64
@echo "Releasing the application..."
@gh release create $(TAG) $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-linux-amd64.tar.gz $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-darwin-amd64.tar.gz $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-darwin-arm64.tar.gz $(OUTPUT_DIR)/$(BINARY_NAME)-$(TAG)-windows-amd64.zip