Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # NVML GPU Home Assistant Monitor
  2. # Build configuration
  3. BINARY_NAME=nvml-gpu-ha
  4. GO_VERSION=1.21
  5. LDFLAGS=-s -w
  6. # Default target
  7. .PHONY: all
  8. all: build
  9. # Build for current platform
  10. .PHONY: build
  11. build:
  12. go build -ldflags="$(LDFLAGS)" -o $(BINARY_NAME) .
  13. # Build for Linux (production target)
  14. .PHONY: build-linux
  15. build-linux:
  16. GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(BINARY_NAME)-linux-amd64 .
  17. # Build for Linux ARM64 (for ARM servers)
  18. .PHONY: build-linux-arm64
  19. build-linux-arm64:
  20. GOOS=linux GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(BINARY_NAME)-linux-arm64 .
  21. # Build for Windows (development)
  22. .PHONY: build-windows
  23. build-windows:
  24. GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(BINARY_NAME)-windows-amd64.exe .
  25. # Download dependencies
  26. .PHONY: deps
  27. deps:
  28. go mod download
  29. go mod tidy
  30. # Run tests
  31. .PHONY: test
  32. test:
  33. go test -v ./...
  34. # Clean build artifacts
  35. .PHONY: clean
  36. clean:
  37. rm -f $(BINARY_NAME)
  38. rm -f $(BINARY_NAME)-*
  39. go clean
  40. # Install on current system
  41. .PHONY: install
  42. install: build
  43. sudo cp $(BINARY_NAME) /usr/local/bin/
  44. # Create systemd service file
  45. .PHONY: systemd-service
  46. systemd-service:
  47. @echo "Creating systemd service file..."
  48. @cat > nvml-gpu-ha.service << EOF
  49. [Unit]
  50. Description=NVIDIA GPU Monitoring for Home Assistant
  51. After=network.target
  52. Wants=network.target
  53. [Service]
  54. Type=simple
  55. User=nobody
  56. ExecStart=/usr/local/bin/$(BINARY_NAME)
  57. Restart=always
  58. RestartSec=10
  59. [Install]
  60. WantedBy=multi-user.target
  61. EOF
  62. @echo "Service file created: nvml-gpu-ha.service"
  63. @echo "NOTE: Configure settings in /etc/nvml-gpu-ha.conf before starting"
  64. @echo "To install: sudo cp nvml-gpu-ha.service /etc/systemd/system/"
  65. @echo "To copy config: sudo cp nvml-gpu-ha.conf.example /etc/nvml-gpu-ha.conf"
  66. @echo "To enable: sudo systemctl enable nvml-gpu-ha"
  67. @echo "To start: sudo systemctl start nvml-gpu-ha"
  68. # Docker build
  69. .PHONY: docker-build
  70. docker-build:
  71. docker build -t nvml-gpu-ha .
  72. # Help
  73. .PHONY: help
  74. help:
  75. @echo "Available targets:"
  76. @echo " build - Build for current platform"
  77. @echo " build-linux - Build for Linux amd64"
  78. @echo " build-linux-arm64 - Build for Linux arm64"
  79. @echo " build-windows - Build for Windows amd64"
  80. @echo " deps - Download and tidy dependencies"
  81. @echo " test - Run tests"
  82. @echo " clean - Clean build artifacts"
  83. @echo " install - Install to /usr/local/bin"
  84. @echo " systemd-service - Create systemd service file"
  85. @echo " docker-build - Build Docker image"
  86. @echo " help - Show this help"