-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
92 lines (81 loc) · 2.3 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Makefile for opnsense module
# run make help for options
# Variables
GO=go
BUILD_DIR=build
BINARY_NAME=opnsense
# Phony Targets
.PHONY: all clean build test install fmt cross-build help
# Default Target
all: clean build
# Display Help
help:
@echo "Makefile commands for opnsense:"
@echo "all Build the binary"
@echo "clean Remove build artifacts"
@echo "build Build the binary"
@echo "test Run tests"
@echo "install Install the binary"
@echo "fmt Format the source code"
@echo "cross-build Cross-compile for different platforms"
# Clean up
clean:
@echo "Cleaning..."
ifeq ($(OS),Windows_NT)
@if exist $(BUILD_DIR) rmdir /s /q $(BUILD_DIR)
else
-@rm -rf $(BUILD_DIR)
endif
@echo "Cleaning done"
# Download Dependencies
deps:
@echo "Downloading dependencies..."
@$(GO) mod tidy
# Build the binary
build: deps
@echo "Building..."
ifeq ($(OS),Windows_NT)
@if not exist $(BUILD_DIR) mkdir $(BUILD_DIR)
@$(GO) build -o $(BUILD_DIR)/$(BINARY_NAME).exe .
else
@mkdir -p $(BUILD_DIR)
@$(GO) build -o $(BUILD_DIR)/$(BINARY_NAME) .
endif
# Run tests
test: deps
@echo "Testing..."
@$(GO) test -v ./...
# Install the binary
install:
@echo "Installing..."
ifeq ($(OS),Windows_NT)
@$(GO) install .
else
@sudo $(GO) install .
endif
# Format the code
fmt:
@echo "Formatting..."
@$(GO) fmt ./...
# Cross-compile for different platforms
cross-build: deps
@echo "Cross-building..."
ifeq ($(OS),Windows_NT)
@set GOOS=linux&& set GOARCH=amd64&& $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME)-lnx .
@echo "Linux binary done"
@set GOOS=windows&& set GOARCH=amd64&& $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME).exe .
@echo "Windows binary done"
@set GOOS=darwin&& set GOARCH=amd64&& $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME)-mac .
@echo "MacOS binary done"
@set GOOS=freebsd&& set GOARCH=amd64&& $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME)-bsd .
@echo "FreeBSD binary done"
else
@GOOS=linux GOARCH=amd64 $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME)-lnx .
@echo "Linux binary done"
@GOOS=windows GOARCH=amd64 $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME).exe .
@echo "Windows binary done"
@GOOS=darwin GOARCH=amd64 $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME)-mac .
@echo "MacOS binary done"
@GOOS=freebsd GOARCH=amd64 $(GO) build -o $(BUILD_DIR)/$(BINARY_NAME)-bsd .
@echo "FreeBSD binary done"
endif