-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (111 loc) · 3.68 KB
/
Copy pathMakefile
File metadata and controls
133 lines (111 loc) · 3.68 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
# Makefile for Thoth Network
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Go build flags
BUILD_FLAGS := -v -ldflags "-X 'version.BuildTime=$(shell date -u)'"
GOBUILD_FLAGS := $(BUILD_FLAGS) -o
# Detect the operating system and architecture
GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)
ifeq ($(GOOS), windows)
GOOS := windows
else ifeq ($(GOOS), darwin)
GOOS := darwin
else ifeq ($(GOOS), linux)
GOOS := linux
endif
# Binary names
BINARY_BASE_NAME=latex2go
BINARY_NAME := $(BINARY_BASE_NAME)_$(GOOS)_$(GOARCH)
# Binary path
BINARY_PATH_PREFIX := ./bin
BINARY_PATH := $(BINARY_PATH_PREFIX)/$(GOOS)_$(GOARCH)
# Module path
MODULE_PATH := ./cmd/$(BINARY_BASE_NAME).go
# Default target
.DEFAULT_GOAL := build
# Temporary paths
TEMP_PATHS := /tmp/$(BINARY_BASE_NAME)_test_*
# Build the application
all: test build
build:
@echo "Building $(BINARY_NAME)..."
@mkdir -p $(BINARY_PATH)
@CGO_ENABLED=1 GOOS=$(GOOS) go build $(BUILD_FLAGS) -o $(BINARY_PATH)/$(BINARY_NAME) $(MODULE_PATH)
@echo "Binary built at $(BINARY_PATH)/$(BINARY_NAME)"
test:
$(GOTEST) -v ./...
run: build
# Execute the built CLI binary
$(BINARY_PATH)/$(BINARY_NAME) -i "x^2 + 1" # Example usage
deps:
$(GOMOD) download
tidy:
$(GOMOD) tidy
lint: vet
golangci-lint run ./...
@echo "Linting completed."
vet:
go vet ./...
@echo "Vet completed."
# Clean targets
clean-all:
@echo "Cleaning all build artifacts..."
@rm -rf $(BINARY_PATH_PREFIX)
@go clean -cache -modcache -i -r
@echo "All build artifacts cleaned successfully."
clean:
@echo "Cleaning binary and temporary files..."
@[ -f $(DEFAULT_DB_PATH) ] && { echo "Removing $(DEFAULT_DB_PATH)..."; rm -f $(DEFAULT_DB_PATH); } || true
@[ -d $(BINARY_PATH_PREFIX) ] && { echo "Removing $(BINARY_PATH_PREFIX)..."; rm -rf $(BINARY_PATH_PREFIX); } || true
@find /tmp -name "$(BINARY_BASE_NAME)_test_*" -type d -exec rm -rf {} + 2>/dev/null || true
@echo "Binary and temporary files cleaned successfully."
# Detect the operating system
OS := $(shell uname -s)
# Define terminal commands based on OS
ifeq ($(OS),Linux)
# Check for common Linux terminal emulators in order of preference
ifeq ($(shell command -v gnome-terminal),)
ifeq ($(shell command -v kitty),)
ifeq ($(shell command -v konsole),)
ifeq ($(shell command -v xterm),)
TERMINAL := echo "No terminal emulator found."
else
TERMINAL := xterm
endif
else
TERMINAL := konsole
endif
else
TERMINAL := kitty
endif
else
TERMINAL := gnome-terminal
endif
else ifeq ($(OS),Darwin) # macOS
TERMINAL := open -a Terminal
else # Assume Windows if not Linux or macOS
TERMINAL := powershell -Command "Start-Process powershell -ArgumentList '-NoExit', '-Command', 'Get-Content %1 -Wait'"
endif
# Help target
help:
@echo "Thoth Network Makefile Help"
@echo "===================="
@echo "Main targets:"
@echo " all - Build and test the application"
@echo " build - Build the application"
@echo " test - Run tests"
@echo " run - Run the application"
@echo ""
@echo "Cleaning targets:"
@echo " clean - Clean binary and temporary files"
@echo " clean-all - Clean all build artifacts including caches"
# Mark all targets as phony (not associated with files)
.PHONY: all build docker-run docker-down test run dev stop-dev monitor-logs build-binary \
proto proto-deps proto-lint proto-format proto-gen proto-breaking proto-clean proto-verify \
clean clean-all help