mirror of
https://github.com/unpoller/unpoller.git
synced 2026-04-05 08:54:00 -04:00
Move builds into Makefile.
This commit is contained in:
103
Makefile
103
Makefile
@@ -1,4 +1,7 @@
|
||||
BINARY:=unifi-poller
|
||||
URL=https://github.com/davidnewhall/unifi-poller
|
||||
MAINT="david at sleepers dot pro"
|
||||
DESC="This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database."
|
||||
PACKAGE:=./cmd/$(BINARY)
|
||||
VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v)
|
||||
ITERATION:=$(shell git rev-list --all --count)
|
||||
@@ -6,23 +9,25 @@ ITERATION:=$(shell git rev-list --all --count)
|
||||
all: man build
|
||||
|
||||
# Prepare a release. Called in Travis CI.
|
||||
release: clean test man linux macos rpm deb osxpkg
|
||||
release: clean test rpm deb osxpkg
|
||||
mkdir -p release
|
||||
gzip -9 $(BINARY).linux
|
||||
gzip -9 $(BINARY).macos
|
||||
mv $(BINARY).macos.gz $(BINARY).linux.gz release/
|
||||
mv *.rpm *.deb *.pkg release/
|
||||
mv $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb \
|
||||
$(BINARY)-$(VERSION).pkg $(BINARY).macos.gz $(BINARY).linux.gz release/
|
||||
|
||||
# Delete all build assets.
|
||||
clean:
|
||||
rm -f $(BINARY){.macos,.linux,.1,}{,.gz}
|
||||
rm -f $(BINARY){_,-}*.{deb,rpm,pkg}
|
||||
rm -rf package_build release
|
||||
rm -rf package_build_* release
|
||||
|
||||
# Build a man page from a markdown file using ronn.
|
||||
man: $(BINARY).1.gz
|
||||
$(BINARY).1.gz:
|
||||
scripts/build_manpages.sh ./
|
||||
@ronn --version > /dev/null || (echo "Ronn missing. Install ronn: $(URL)/wiki/Ronn" && false)
|
||||
@echo "Creating Man Page: $(PACKAGE)/README.md -> $(BINARY).1.gz"
|
||||
ronn < "$(PACKAGE)/README.md" | gzip -9 > "$(BINARY).1.gz"
|
||||
|
||||
# Binaries
|
||||
|
||||
@@ -40,30 +45,100 @@ $(BINARY).macos:
|
||||
|
||||
# Packages
|
||||
|
||||
rpm: man linux $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm
|
||||
$(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm:
|
||||
scripts/build_packages.sh rpm "$(VERSION)" "$(ITERATION)"
|
||||
rpm: $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm
|
||||
$(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm: check_fpm package_build_linux
|
||||
@echo "Building 'rpm' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
|
||||
fpm -s dir -t rpm \
|
||||
--name $(BINARY) \
|
||||
--version $(VERSION) \
|
||||
--iteration $(ITERATION) \
|
||||
--after-install scripts/after-install.sh \
|
||||
--before-remove scripts/before-remove.sh \
|
||||
--license MIT \
|
||||
--url $(URL) \
|
||||
--maintainer $(MAINT) \
|
||||
--description $(DESC) \
|
||||
--chdir package_build_linux
|
||||
|
||||
deb: man linux $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb
|
||||
$(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb:
|
||||
scripts/build_packages.sh deb "$(VERSION)" "$(ITERATION)"
|
||||
deb: $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb
|
||||
$(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux
|
||||
@echo "Building 'deb' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
|
||||
fpm -s dir -t deb \
|
||||
--name $(BINARY) \
|
||||
--version $(VERSION) \
|
||||
--iteration $(ITERATION) \
|
||||
--after-install scripts/after-install.sh \
|
||||
--before-remove scripts/before-remove.sh \
|
||||
--license MIT \
|
||||
--url $(URL) \
|
||||
--maintainer $(MAINT) \
|
||||
--description $(DESC) \
|
||||
--chdir package_build_linux
|
||||
|
||||
osxpkg: man macos $(BINARY)-$(VERSION).pkg
|
||||
$(BINARY)-$(VERSION).pkg:
|
||||
scripts/build_packages.sh osxpkg "$(VERSION)" "$(ITERATION)"
|
||||
osxpkg: $(BINARY)-$(VERSION).pkg
|
||||
$(BINARY)-$(VERSION).pkg: check_fpm package_build_osx
|
||||
@echo "Building 'osx' package for $(BINARY) version '$(VERSION)-$(ITERATION)'."
|
||||
fpm -s dir -t osxpkg \
|
||||
--name $(BINARY) \
|
||||
--version $(VERSION) \
|
||||
--iteration $(ITERATION) \
|
||||
--after-install scripts/after-install-osx.sh \
|
||||
--osxpkg-identifier-prefix com.github.davidnewhall \
|
||||
--license MIT \
|
||||
--url $(URL) \
|
||||
--maintainer $(MAINT) \
|
||||
--description $(DESC) \
|
||||
--chdir package_build_osx
|
||||
|
||||
# OSX packages use /usr/local because Apple doesn't allow writing many other places.
|
||||
package_build_osx: man macos
|
||||
# Build package environment for macOS.
|
||||
mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY)
|
||||
mkdir -p $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY)
|
||||
# Copy the binary, config file and man page into the env.
|
||||
cp $(BINARY).macos $@/usr/local/bin/$(BINARY)
|
||||
cp *.1.gz $@/usr/local/share/man/man1
|
||||
cp examples/*.conf.example $@/usr/local/etc/$(BINARY)/
|
||||
cp examples/* $@/usr/local/share/doc/$(BINARY)/
|
||||
mkdir -p $@/usr/local/var/log
|
||||
mkdir -p $@/Library/LaunchAgents
|
||||
cp init/launchd/com.github.davidnewhall.unifi-poller.plist $@/Library/LaunchAgents/
|
||||
|
||||
# Build an environment that can be packaged for linux.
|
||||
package_build_linux: man linux
|
||||
# Build package environment for linux.
|
||||
mkdir -p $@/usr/bin $@/etc/$(BINARY)
|
||||
mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY)
|
||||
# Copy the binary, config file and man page into the env.
|
||||
cp ${BINARY}.linux $@/usr/bin/$(BINARY)
|
||||
cp *.1.gz $@/usr/share/man/man1
|
||||
cp examples/*.conf.example $@/etc/$(BINARY)/
|
||||
cp examples/* $@/usr/share/doc/$(BINARY)/
|
||||
cp examples/up.conf.example $@/etc/$(BINARY)/up.conf
|
||||
# Fix the paths in the systemd unit file before copying it into the emv.
|
||||
mkdir -p $@/lib/systemd/system
|
||||
sed "s%ExecStart.*%ExecStart=/usr/bin/$(BINARY) --config=/etc/${BINARY}/up.conf%" \
|
||||
init/systemd/unifi-poller.service > $@/lib/systemd/system/$(BINARY).service
|
||||
|
||||
check_fpm:
|
||||
@fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false)
|
||||
|
||||
# Extras
|
||||
|
||||
# Run code tests and lint.
|
||||
test: lint
|
||||
go test -race -covermode=atomic $(PACKAGE)
|
||||
lint:
|
||||
golangci-lint run --enable-all -D gochecknoglobals
|
||||
|
||||
# Install locally into /usr/local. Not recommended.
|
||||
install: man
|
||||
scripts/local_install.sh
|
||||
|
||||
# If you installed with `make install` run `make uninstall` before installing a binary package.
|
||||
uninstall:
|
||||
scripts/local_uninstall.sh
|
||||
|
||||
# Don't run this unless you're ready to debug untested vendored dependencies.
|
||||
deps:
|
||||
dep ensure -update
|
||||
|
||||
Reference in New Issue
Block a user