-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
117 lines (98 loc) · 6.99 KB
/
Copy pathMakefile
File metadata and controls
117 lines (98 loc) · 6.99 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
BINARY = xutils
VERSION = 1.0.0
BUILD_DATE = $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GIT_COMMIT = $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
LDFLAGS = -ldflags "-X main.Version=$(VERSION) -X main.BuildDate=$(BUILD_DATE) -X main.GitCommit=$(GIT_COMMIT) -s -w"
DIST_DIR = dist
.PHONY: all build clean test lint install cross-build package deb rpm arch winget
# ─── Default ───────────────────────────────────────────────
all: build
# ─── Build for current OS ──────────────────────────────────
build:
@echo "→ Building $(BINARY) $(VERSION)..."
@go build $(LDFLAGS) -o $(BINARY) .
@echo "✓ Built: ./$(BINARY)"
# ─── Run ───────────────────────────────────────────────────
run: build
./$(BINARY)
# ─── Tests ─────────────────────────────────────────────────
test:
@go test ./... -v -cover
# ─── Lint ──────────────────────────────────────────────────
lint:
@golangci-lint run ./...
# ─── Install system-wide ───────────────────────────────────
install: build
@install -Dm755 $(BINARY) /usr/local/bin/$(BINARY)
@echo "✓ Installed to /usr/local/bin/$(BINARY)"
# ─── Uninstall ─────────────────────────────────────────────
uninstall:
@rm -f /usr/local/bin/$(BINARY)
@echo "✓ Removed /usr/local/bin/$(BINARY)"
# ─── Cross-compile all platforms ───────────────────────────
cross-build:
@mkdir -p $(DIST_DIR)
@echo "→ Cross-compiling..."
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(DIST_DIR)/$(BINARY)-linux-amd64 .
GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o $(DIST_DIR)/$(BINARY)-linux-arm64 .
GOOS=linux GOARCH=386 go build $(LDFLAGS) -o $(DIST_DIR)/$(BINARY)-linux-386 .
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(DIST_DIR)/$(BINARY)-darwin-amd64 .
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(DIST_DIR)/$(BINARY)-darwin-arm64 .
GOOS=windows GOARCH=amd64 go build $(LDFLAGS) -o $(DIST_DIR)/$(BINARY)-windows-amd64.exe .
@echo "✓ Binaries in ./$(DIST_DIR)/"
@ls -lh $(DIST_DIR)/
# ─── Build tarballs ────────────────────────────────────────
package: cross-build
@cd $(DIST_DIR) && for f in $(BINARY)-linux-* $(BINARY)-darwin-*; do \
tar czf $${f}.tar.gz $$f && rm $$f; \
done
@cd $(DIST_DIR) && zip $(BINARY)-windows-amd64.zip $(BINARY)-windows-amd64.exe && rm $(BINARY)-windows-amd64.exe
@echo "✓ Packages ready in ./$(DIST_DIR)/"
# ─── Debian .deb package ───────────────────────────────────
deb: build
@echo "→ Building .deb package..."
@mkdir -p $(DIST_DIR)/deb/DEBIAN
@mkdir -p $(DIST_DIR)/deb/usr/local/bin
@cp $(BINARY) $(DIST_DIR)/deb/usr/local/bin/
@printf "Package: xutils\nVersion: $(VERSION)\nSection: utils\nPriority: optional\nArchitecture: amd64\nDepends: \nMaintainer: xUtils Team <team@xutils.dev>\nDescription: System Monitoring Automation Tool\n" \
> $(DIST_DIR)/deb/DEBIAN/control
@dpkg-deb --build $(DIST_DIR)/deb $(DIST_DIR)/$(BINARY)_$(VERSION)_amd64.deb
@echo "✓ Package: $(DIST_DIR)/$(BINARY)_$(VERSION)_amd64.deb"
# ─── RPM spec (requires rpmbuild) ──────────────────────────
rpm: cross-build
@echo "→ Building .rpm package..."
@mkdir -p ~/rpmbuild/{SOURCES,SPECS,RPMS,SRPMS,BUILD}
@cp $(DIST_DIR)/$(BINARY)-linux-amd64 ~/rpmbuild/SOURCES/$(BINARY)
@printf 'Name: xutils\nVersion: $(VERSION)\nRelease: 1%%{?dist}\nSummary: System Monitoring Automation Tool\nLicense: MIT\n\n%%description\nxUtils automates installation and configuration of monitoring/SIEM tools.\n\n%%install\nmkdir -p %%{buildroot}/usr/local/bin\ncp %%{SOURCE0} %%{buildroot}/usr/local/bin/xutils\n\n%%files\n/usr/local/bin/xutils\n' \
> ~/rpmbuild/SPECS/xutils.spec
@rpmbuild -bb ~/rpmbuild/SPECS/xutils.spec
@echo "✓ RPM built in ~/rpmbuild/RPMS/"
# ─── Arch PKGBUILD ─────────────────────────────────────────
arch:
@mkdir -p $(DIST_DIR)/arch
@printf 'pkgname=xutils\npkgver=$(VERSION)\npkgrel=1\npkgdesc="System Monitoring Automation Tool"\narch=("x86_64")\nurl="https://github.com/xutils/xutils"\nlicense=("MIT")\ndepends=()\nmakedepends=("go")\nsource=("$$pkgname-$$pkgver.tar.gz::https://github.com/xutils/xutils/archive/refs/tags/v$$pkgver.tar.gz")\nsha256sums=("SKIP")\n\nbuild() {\n\tcd "$$pkgname-$$pkgver"\n\tgo build -ldflags "-X main.Version=$$pkgver -s -w" -o xutils .\n}\n\npackage() {\n\tinstall -Dm755 "$$pkgname-$$pkgver/xutils" "$$pkgdir/usr/bin/xutils"\n}\n' \
> $(DIST_DIR)/arch/PKGBUILD
@echo "✓ PKGBUILD: $(DIST_DIR)/arch/PKGBUILD"
# ─── WinGet manifest ───────────────────────────────────────
winget:
@mkdir -p $(DIST_DIR)/winget
@printf 'PackageIdentifier: xutils.xutils\nPackageVersion: $(VERSION)\nPackageName: xUtils\nPublisher: xUtils Team\nShortDescription: System Monitoring Automation Tool\nLicense: MIT\nPackageUrl: https://github.com/xutils/xutils\nInstallers:\n- Architecture: x64\n InstallerType: portable\n InstallerUrl: https://github.com/xutils/xutils/releases/download/v$(VERSION)/xutils-windows-amd64.exe\n InstallerSha256: REPLACE_WITH_SHA256\nManifestType: singleton\nManifestVersion: 1.4.0\n' \
> $(DIST_DIR)/winget/xutils.xutils.yaml
@echo "✓ WinGet manifest: $(DIST_DIR)/winget/xutils.xutils.yaml"
# ─── Generate SHA256 checksums ─────────────────────────────
checksums:
@cd $(DIST_DIR) && sha256sum * > SHA256SUMS
@echo "✓ Checksums written to $(DIST_DIR)/SHA256SUMS"
# ─── Clean ─────────────────────────────────────────────────
clean:
@rm -rf $(BINARY) $(DIST_DIR)
@echo "✓ Cleaned"
# ─── Download dependencies ─────────────────────────────────
deps:
@go mod download
@go mod tidy
@echo "✓ Dependencies downloaded"
# ─── Docker build image ────────────────────────────────────
docker:
@docker build -t xutils:$(VERSION) .
@echo "✓ Docker image: xutils:$(VERSION)"