-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (53 loc) · 1.87 KB
/
Makefile
File metadata and controls
64 lines (53 loc) · 1.87 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
# Makefile for the Go Database Backup Tool
# Define the name of the final binary
BINARY_NAME=dbdump
# Define the path to the main package
SRC_DIR=./cmd/dbdump
# Go linker flags to reduce binary size for release builds.
# -s: Omit the symbol table.
# -w: Omit the DWARF debug information.
LDFLAGS_RELEASE = -ldflags="-s -w"
# Default target executed when you just run `make`
.PHONY: all
all: build
# Build the application binary for development (includes debug info)
.PHONY: build
build: tidy
@echo "Building $(BINARY_NAME) for development..."
@go build -o $(BINARY_NAME) $(SRC_DIR)
@echo "$(BINARY_NAME) built successfully."
# Build a small, optimized release binary
# This strips debug information to significantly reduce the file size.
.PHONY: build-release
build-release: tidy
@echo "Building $(BINARY_NAME) for release (optimized for size)..."
@go build $(LDFLAGS_RELEASE) -o $(BINARY_NAME) $(SRC_DIR)
@echo "Release binary built successfully."
# Run the application
# Example: make run ARGS="--all --type=postgres --pgpassword=your_pass"
.PHONY: run
run: build
@echo "Running $(BINARY_NAME) with arguments: $(ARGS)"
@./$(BINARY_NAME) $(ARGS)
# Tidy Go modules
.PHONY: tidy
tidy:
@echo "Tidying Go modules..."
@go mod tidy
# Clean up build artifacts
.PHONY: clean
clean:
@echo "Cleaning up..."
@rm -f $(BINARY_NAME)
@echo "Cleanup complete."
# Display help message
.PHONY: help
help:
@echo "Available commands:"
@echo " build - Build the application binary for development."
@echo " build-release - Build a small, optimized release binary."
@echo " run - Build and run the application. Use ARGS=\"...\" to pass flags."
@echo " Example: make run ARGS=\"--all --pgpassword=secret\""
@echo " tidy - Synchronize go.mod dependencies."
@echo " clean - Remove the compiled binary."
@echo " help - Display this help message."