mirror of
https://github.com/unpoller/unpoller.git
synced 2026-03-31 06:24:19 -04:00
Update application builder
This commit is contained in:
253
Makefile
253
Makefile
@@ -1,12 +1,18 @@
|
||||
# This Makefile is written as generic as possible.
|
||||
# Setting the variables in .metadata.sh and creating the paths in the repo makes this work.
|
||||
# Setting the variables in settings.sh and creating the paths in the repo makes this work.
|
||||
# See more: https://github.com/golift/application-builder
|
||||
|
||||
# Suck in our application information.
|
||||
IGNORED:=$(shell bash -c "source .metadata.sh ; env | sed 's/=/:=/;s/^/export /' > .metadata.make")
|
||||
IGNORED:=$(shell bash -c "source settings.sh ; env | grep -v BASH_FUNC | sed 's/=/:=/;s/^/export /' > .metadata.make")
|
||||
|
||||
# md2roff turns markdown into man files and html files.
|
||||
MD2ROFF_BIN=github.com/github/hub/md2roff-bin
|
||||
MD2ROFF_BIN=github.com/davidnewhall/md2roff
|
||||
|
||||
# rsrc adds an ico file to a Windows exe file.
|
||||
RSRC_BIN=github.com/akavel/rsrc
|
||||
|
||||
# If upx is available, use it to compress the binaries.
|
||||
UPXPATH=$(shell which upx)
|
||||
|
||||
# Travis CI passes the version in. Local builds get it from the current git tag.
|
||||
ifeq ($(VERSION),)
|
||||
@@ -20,13 +26,15 @@ else
|
||||
ITERATION:=$(_ITERATION)
|
||||
endif
|
||||
|
||||
|
||||
# rpm is wierd and changes - to _ in versions.
|
||||
RPMVERSION:=$(shell echo $(VERSION) | tr -- - _)
|
||||
# used for freebsd packages.
|
||||
BINARYU:=$(shell echo $(BINARY) | tr -- - _)
|
||||
|
||||
PACKAGE_SCRIPTS=
|
||||
ifeq ($(FORMULA),service)
|
||||
PACKAGE_SCRIPTS=--after-install scripts/after-install.sh --before-remove scripts/before-remove.sh
|
||||
PACKAGE_SCRIPTS=--after-install after-install-rendered.sh --before-remove before-remove-rendered.sh
|
||||
endif
|
||||
|
||||
define PACKAGE_ARGS
|
||||
@@ -36,118 +44,159 @@ $(PACKAGE_SCRIPTS) \
|
||||
--rpm-os linux \
|
||||
--iteration $(ITERATION) \
|
||||
--license $(LICENSE) \
|
||||
--url $(URL) \
|
||||
--url $(SOURCE_URL) \
|
||||
--maintainer "$(MAINT)" \
|
||||
--vendor "$(VENDOR)" \
|
||||
--description "$(DESC)" \
|
||||
--config-files "/etc/$(BINARY)/$(CONFIG_FILE)" \
|
||||
--freebsd-origin "$(BINARY)/$(BINARY)"
|
||||
--freebsd-origin "$(SOURCE_URL)"
|
||||
endef
|
||||
|
||||
PLUGINS:=$(patsubst plugins/%/main.go,%,$(wildcard plugins/*/main.go))
|
||||
|
||||
VERSION_LDFLAGS:= \
|
||||
-X github.com/prometheus/common/version.Branch=$(BRANCH) \
|
||||
-X github.com/prometheus/common/version.BuildDate=$(DATE) \
|
||||
-X github.com/prometheus/common/version.Revision=$(COMMIT) \
|
||||
-X github.com/prometheus/common/version.Version=$(VERSION)-$(ITERATION)
|
||||
VERSION_LDFLAGS:= -X \"$(VERSION_PATH).Branch=$(BRANCH) ($(COMMIT))\" \
|
||||
-X \"$(VERSION_PATH).BuildDate=$(DATE)\" \
|
||||
-X \"$(VERSION_PATH).BuildUser=$(shell whoami)\" \
|
||||
-X \"$(VERSION_PATH).Revision=$(ITERATION)\" \
|
||||
-X \"$(VERSION_PATH).Version=$(VERSION)\"
|
||||
|
||||
# Makefile targets follow.
|
||||
|
||||
all: clean build
|
||||
|
||||
####################
|
||||
##### Releases #####
|
||||
####################
|
||||
|
||||
# Prepare a release. Called in Travis CI.
|
||||
release: clean macos windows linux_packages freebsd_packages
|
||||
release: clean linux_packages freebsd_packages windows
|
||||
# Prepareing a release!
|
||||
mkdir -p $@
|
||||
mv $(BINARY).*.macos $(BINARY).*.linux $(BINARY).*.freebsd $@/
|
||||
mv $(BINARY).*.linux $(BINARY).*.freebsd $@/
|
||||
gzip -9r $@/
|
||||
for i in $(BINARY)*.exe; do zip -9qm $@/$$i.zip $$i;done
|
||||
for i in $(BINARY)*.exe ; do zip -9qj $@/$$i.zip $$i examples/*.example *.html; rm -f $$i;done
|
||||
mv *.rpm *.deb *.txz $@/
|
||||
# Generating File Hashes
|
||||
openssl dgst -r -sha256 $@/* | sed 's#release/##' | tee $@/checksums.sha256.txt
|
||||
|
||||
dmg: clean macapp
|
||||
mkdir -p release
|
||||
hdiutil create release/$(MACAPP).dmg -srcfolder $(MACAPP).app -ov
|
||||
openssl dgst -r -sha256 release/* | sed 's#release/##' | tee release/dmg_checksum.sha256.txt
|
||||
|
||||
# Delete all build assets.
|
||||
clean:
|
||||
# Cleaning up.
|
||||
rm -f $(BINARY) $(BINARY).*.{macos,freebsd,linux,exe}{,.gz,.zip} $(BINARY).1{,.gz} $(BINARY).rb
|
||||
rm -f $(BINARY) $(BINARY).*.{macos,freebsd,linux,exe,upx}{,.gz,.zip} $(BINARY).1{,.gz} $(BINARY).rb
|
||||
rm -f $(BINARY){_,-}*.{deb,rpm,txz} v*.tar.gz.sha256 examples/MANUAL .metadata.make
|
||||
rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html
|
||||
rm -rf package_build_* release
|
||||
rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rsrc.syso $(MACAPP).app.zip
|
||||
rm -rf package_build_* release after-install-rendered.sh before-remove-rendered.sh $(MACAPP).app
|
||||
|
||||
####################
|
||||
##### Sidecars #####
|
||||
####################
|
||||
|
||||
# Build a man page from a markdown file using md2roff.
|
||||
# This also turns the repo readme into an html file.
|
||||
# md2roff is needed to build the man file and html pages from the READMEs.
|
||||
man: $(BINARY).1.gz
|
||||
$(BINARY).1.gz:
|
||||
$(BINARY).1.gz: md2roff
|
||||
# Building man page. Build dependency first: md2roff
|
||||
go run $(MD2ROFF_BIN) --manual $(BINARY) --version $(VERSION) --date "$(DATE)" examples/MANUAL.md
|
||||
$(shell go env GOPATH)/bin/md2roff --manual $(BINARY) --version $(VERSION) --date "$(DATE)" examples/MANUAL.md
|
||||
gzip -9nc examples/MANUAL > $@
|
||||
mv examples/MANUAL.html $(BINARY)_manual.html
|
||||
|
||||
md2roff: $(shell go env GOPATH)/bin/md2roff
|
||||
$(shell go env GOPATH)/bin/md2roff:
|
||||
cd /tmp ; go get $(MD2ROFF_BIN) ; go install $(MD2ROFF_BIN)
|
||||
|
||||
# TODO: provide a template that adds the date to the built html file.
|
||||
readme: README.html
|
||||
README.html:
|
||||
README.html: md2roff
|
||||
# This turns README.md into README.html
|
||||
go run $(MD2ROFF_BIN) --manual $(BINARY) --version $(VERSION) --date "$(DATE)" README.md
|
||||
$(shell go env GOPATH)/bin/md2roff --manual $(BINARY) --version $(VERSION) --date "$(DATE)" README.md
|
||||
|
||||
# Binaries
|
||||
rsrc: rsrc.syso
|
||||
rsrc.syso: init/windows/application.ico init/windows/manifest.xml $(shell go env GOPATH)/bin/rsrc
|
||||
$(shell go env GOPATH)/bin/rsrc -ico init/windows/application.ico -manifest init/windows/manifest.xml
|
||||
$(shell go env GOPATH)/bin/rsrc:
|
||||
cd /tmp ; go get $(RSRC_BIN) ; go install $(RSRC_BIN)
|
||||
|
||||
####################
|
||||
##### Binaries #####
|
||||
####################
|
||||
|
||||
build: $(BINARY)
|
||||
$(BINARY): main.go
|
||||
go build -o $(BINARY) -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
go build -o $(BINARY) -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
|
||||
|
||||
linux: $(BINARY).amd64.linux
|
||||
$(BINARY).amd64.linux: main.go
|
||||
# Building linux 64-bit x86 binary.
|
||||
GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=linux GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
|
||||
|
||||
linux386: $(BINARY).i386.linux
|
||||
$(BINARY).i386.linux: main.go
|
||||
# Building linux 32-bit x86 binary.
|
||||
GOOS=linux GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=linux GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
|
||||
|
||||
arm: arm64 armhf
|
||||
|
||||
arm64: $(BINARY).arm64.linux
|
||||
$(BINARY).arm64.linux: main.go
|
||||
# Building linux 64-bit ARM binary.
|
||||
GOOS=linux GOARCH=arm64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=linux GOARCH=arm64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
|
||||
|
||||
armhf: $(BINARY).armhf.linux
|
||||
$(BINARY).armhf.linux: main.go
|
||||
# Building linux 32-bit ARM binary.
|
||||
GOOS=linux GOARCH=arm GOARM=6 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=linux GOARCH=arm GOARM=6 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
|
||||
|
||||
macos: $(BINARY).amd64.macos
|
||||
$(BINARY).amd64.macos: main.go
|
||||
GOOS=darwin GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
# Building darwin 64-bit x86 binary.
|
||||
GOOS=darwin GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
|
||||
|
||||
freebsd: $(BINARY).amd64.freebsd
|
||||
$(BINARY).amd64.freebsd: main.go
|
||||
GOOS=freebsd GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=freebsd GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
|
||||
freebsd386: $(BINARY).i386.freebsd
|
||||
$(BINARY).i386.freebsd: main.go
|
||||
GOOS=freebsd GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=freebsd GOARCH=386 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@ || true
|
||||
|
||||
freebsdarm: $(BINARY).armhf.freebsd
|
||||
$(BINARY).armhf.freebsd: main.go
|
||||
GOOS=freebsd GOARCH=arm go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=freebsd GOARCH=arm go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) "
|
||||
|
||||
exe: $(BINARY).amd64.exe
|
||||
windows: $(BINARY).amd64.exe
|
||||
$(BINARY).amd64.exe: main.go
|
||||
$(BINARY).amd64.exe: rsrc.syso main.go
|
||||
# Building windows 64-bit x86 binary.
|
||||
GOOS=windows GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS)"
|
||||
GOOS=windows GOARCH=amd64 go build -o $@ -ldflags "-w -s $(VERSION_LDFLAGS) $(EXTRA_LDFLAGS) $(WINDOWS_LDFLAGS)"
|
||||
[ -z "$(UPXPATH)" ] || $(UPXPATH) -q9 $@
|
||||
|
||||
# Packages
|
||||
####################
|
||||
##### Packages #####
|
||||
####################
|
||||
|
||||
linux_packages: rpm deb rpm386 deb386 debarm rpmarm debarmhf rpmarmhf
|
||||
|
||||
freebsd_packages: freebsd_pkg freebsd386_pkg freebsdarm_pkg
|
||||
|
||||
macapp: $(MACAPP).app
|
||||
$(MACAPP).app: macos
|
||||
@[ "$(MACAPP)" != "" ] || (echo "Must set 'MACAPP' in settings.sh!" && exit 1)
|
||||
mkdir -p init/macos/$(MACAPP).app/Contents/MacOS
|
||||
cp $(BINARY).amd64.macos init/macos/$(MACAPP).app/Contents/MacOS/$(MACAPP)
|
||||
cp -rp init/macos/$(MACAPP).app $(MACAPP).app
|
||||
|
||||
rpm: $(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm
|
||||
$(BINARY)-$(RPMVERSION)-$(ITERATION).x86_64.rpm: package_build_linux check_fpm
|
||||
@echo "Building 'rpm' package for $(BINARY) version '$(RPMVERSION)-$(ITERATION)'."
|
||||
@@ -212,13 +261,12 @@ $(BINARY)-$(VERSION)_$(ITERATION).armhf.txz: package_build_freebsd_arm check_fpm
|
||||
fpm -s dir -t freebsd $(PACKAGE_ARGS) -a arm -v $(VERSION) -p $(BINARY)-$(VERSION)_$(ITERATION).armhf.txz -C $<
|
||||
|
||||
# Build an environment that can be packaged for linux.
|
||||
package_build_linux: readme man plugins_linux_amd64 linux
|
||||
package_build_linux: readme man plugins_linux_amd64 after-install-rendered.sh before-remove-rendered.sh linux
|
||||
# Building package environment for linux.
|
||||
mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) $@/usr/lib/$(BINARY)/web
|
||||
mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) $@/usr/lib/$(BINARY)
|
||||
# Copying the binary, config file, unit file, and man page into the env.
|
||||
cp $(BINARY).amd64.linux $@/usr/bin/$(BINARY)
|
||||
cp *.1.gz $@/usr/share/man/man1
|
||||
cp -r init/webserver/* $@/usr/lib/$(BINARY)/web/
|
||||
rm -f $@/usr/lib/$(BINARY)/*.so
|
||||
[ ! -f *amd64.so ] || cp *amd64.so $@/usr/lib/$(BINARY)/
|
||||
cp examples/$(CONFIG_FILE).example $@/etc/$(BINARY)/
|
||||
@@ -229,6 +277,12 @@ package_build_linux: readme man plugins_linux_amd64 linux
|
||||
sed -e "s/{{BINARY}}/$(BINARY)/g" -e "s/{{DESC}}/$(DESC)/g" \
|
||||
init/systemd/template.unit.service > $@/lib/systemd/system/$(BINARY).service
|
||||
|
||||
after-install-rendered.sh:
|
||||
sed -e "s/{{BINARY}}/$(BINARY)/g" scripts/after-install.sh > after-install-rendered.sh
|
||||
|
||||
before-remove-rendered.sh:
|
||||
sed -e "s/{{BINARY}}/$(BINARY)/g" scripts/before-remove.sh > before-remove-rendered.sh
|
||||
|
||||
package_build_linux_386: package_build_linux linux386
|
||||
mkdir -p $@
|
||||
cp -r $</* $@/
|
||||
@@ -248,11 +302,10 @@ package_build_linux_armhf: package_build_linux armhf
|
||||
cp $(BINARY).armhf.linux $@/usr/bin/$(BINARY)
|
||||
|
||||
# Build an environment that can be packaged for freebsd.
|
||||
package_build_freebsd: readme man freebsd
|
||||
mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY) $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY) $@/usr/local/lib/$(BINARY)/web
|
||||
package_build_freebsd: readme man after-install-rendered.sh before-remove-rendered.sh freebsd
|
||||
mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY) $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY)
|
||||
cp $(BINARY).amd64.freebsd $@/usr/local/bin/$(BINARY)
|
||||
cp *.1.gz $@/usr/local/share/man/man1
|
||||
cp -r init/webserver/* $@/usr/local/lib/$(BINARY)/web/
|
||||
cp examples/$(CONFIG_FILE).example $@/usr/local/etc/$(BINARY)/
|
||||
cp examples/$(CONFIG_FILE).example $@/usr/local/etc/$(BINARY)/$(CONFIG_FILE)
|
||||
cp LICENSE *.html examples/*?.?* $@/usr/local/share/doc/$(BINARY)/
|
||||
@@ -275,41 +328,9 @@ package_build_freebsd_arm: package_build_freebsd freebsdarm
|
||||
check_fpm:
|
||||
@fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false)
|
||||
|
||||
docker:
|
||||
docker build -f init/docker/Dockerfile \
|
||||
--build-arg "BUILD_DATE=$(DATE)" \
|
||||
--build-arg "COMMIT=$(COMMIT)" \
|
||||
--build-arg "VERSION=$(VERSION)-$(ITERATION)" \
|
||||
--build-arg "LICENSE=$(LICENSE)" \
|
||||
--build-arg "DESC=$(DESC)" \
|
||||
--build-arg "URL=$(URL)" \
|
||||
--build-arg "VENDOR=$(VENDOR)" \
|
||||
--build-arg "AUTHOR=$(MAINT)" \
|
||||
--build-arg "BINARY=$(BINARY)" \
|
||||
--build-arg "SOURCE_URL=$(SOURCE_URL)" \
|
||||
--build-arg "CONFIG_FILE=$(CONFIG_FILE)" \
|
||||
--tag $(BINARY) .
|
||||
|
||||
# This builds a Homebrew formula file that can be used to install this app from source.
|
||||
# The source used comes from the released version on GitHub. This will not work with local source.
|
||||
# This target is used by Travis CI to update the released Forumla when a new tag is created.
|
||||
formula: $(BINARY).rb
|
||||
v$(VERSION).tar.gz.sha256:
|
||||
# Calculate the SHA from the Github source file.
|
||||
curl -sL $(URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@
|
||||
$(BINARY).rb: v$(VERSION).tar.gz.sha256 init/homebrew/$(FORMULA).rb.tmpl
|
||||
# Creating formula from template using sed.
|
||||
sed -e "s/{{Version}}/$(VERSION)/g" \
|
||||
-e "s/{{Iter}}/$(ITERATION)/g" \
|
||||
-e "s/{{SHA256}}/$(shell head -c64 $<)/g" \
|
||||
-e "s/{{Desc}}/$(DESC)/g" \
|
||||
-e "s%{{URL}}%$(URL)%g" \
|
||||
-e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \
|
||||
-e "s%{{SOURCE_URL}}%$(SOURCE_URL)%g" \
|
||||
-e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \
|
||||
-e "s%{{Class}}%$(shell echo $(BINARY) | perl -pe 's/(?:\b|-)(\p{Ll})/\u$$1/g')%g" \
|
||||
init/homebrew/$(FORMULA).rb.tmpl | tee $(BINARY).rb
|
||||
# That perl line turns hello-world into HelloWorld, etc.
|
||||
##################
|
||||
##### Extras #####
|
||||
##################
|
||||
|
||||
plugins: $(patsubst %,%.so,$(PLUGINS))
|
||||
$(patsubst %,%.so,$(PLUGINS)):
|
||||
@@ -324,44 +345,84 @@ plugins_darwin: $(patsubst %,%.darwin.so,$(PLUGINS))
|
||||
$(patsubst %,%.darwin.so,$(PLUGINS)):
|
||||
GOOS=darwin go build -o $@ -ldflags "$(VERSION_LDFLAGS)" -buildmode=plugin ./plugins/$(patsubst %.darwin.so,%,$@)
|
||||
|
||||
# Extras
|
||||
|
||||
# Run code tests and lint.
|
||||
test:
|
||||
test: lint
|
||||
# Testing.
|
||||
go test -race -covermode=atomic ./...
|
||||
lint:
|
||||
# Checking lint.
|
||||
golangci-lint run $(GOLANGCI_LINT_ARGS)
|
||||
GOOS=linux $(shell go env GOPATH)/bin/golangci-lint run $(GOLANGCI_LINT_ARGS)
|
||||
GOOS=freebsd $(shell go env GOPATH)/bin/golangci-lint run $(GOLANGCI_LINT_ARGS)
|
||||
GOOS=windows $(shell go env GOPATH)/bin/golangci-lint run $(GOLANGCI_LINT_ARGS)
|
||||
|
||||
# Mockgen and bindata are examples.
|
||||
# Your `go generate` may require other tools; add them!
|
||||
|
||||
# Don't run this unless you're ready to debug untested vendored dependencies.
|
||||
deps:
|
||||
go get -u github.com/unifi-poller/unifi
|
||||
go get -u github.com/unifi-poller/influxunifi
|
||||
go get -u github.com/unifi-poller/promunifi
|
||||
go get -u github.com/unifi-poller/lokiunifi
|
||||
go get -u github.com/unifi-poller/webserver
|
||||
go get -u github.com/unifi-poller/inputunifi
|
||||
go get -u github.com/unifi-poller/poller
|
||||
mockgen: $(shell go env GOPATH)/bin/mockgen
|
||||
$(shell go env GOPATH)/bin/mockgen:
|
||||
cd /tmp ; go get github.com/golang/mock/mockgen ; go install github.com/golang/mock/mockgen
|
||||
|
||||
bindata: $(shell go env GOPATH)/bin/go-bindata
|
||||
$(shell go env GOPATH)/bin/go-bindata:
|
||||
cd /tmp ; go get -u github.com/go-bindata/go-bindata/... ; go install github.com/go-bindata/go-bindata
|
||||
|
||||
# Homebrew stuff. macOS only.
|
||||
generate: mockgen bindata
|
||||
go generate ./...
|
||||
|
||||
##################
|
||||
##### Docker #####
|
||||
##################
|
||||
|
||||
docker:
|
||||
docker build -f init/docker/Dockerfile \
|
||||
--build-arg "BUILD_DATE=$(DATE)" \
|
||||
--build-arg "COMMIT=$(COMMIT)" \
|
||||
--build-arg "VERSION=$(VERSION)-$(ITERATION)" \
|
||||
--build-arg "LICENSE=$(LICENSE)" \
|
||||
--build-arg "DESC=$(DESC)" \
|
||||
--build-arg "VENDOR=$(VENDOR)" \
|
||||
--build-arg "AUTHOR=$(MAINT)" \
|
||||
--build-arg "BINARY=$(BINARY)" \
|
||||
--build-arg "SOURCE_URL=$(SOURCE_URL)" \
|
||||
--build-arg "CONFIG_FILE=$(CONFIG_FILE)" \
|
||||
--tag $(BINARY) .
|
||||
|
||||
####################
|
||||
##### Homebrew #####
|
||||
####################
|
||||
|
||||
# This builds a Homebrew formula file that can be used to install this app from source.
|
||||
# The source used comes from the released version on GitHub. This will not work with local source.
|
||||
# This target is used by Travis CI to update the released Forumla when a new tag is created.
|
||||
formula: $(BINARY).rb
|
||||
v$(VERSION).tar.gz.sha256:
|
||||
# Calculate the SHA from the Github source file.
|
||||
curl -sL $(SOURCE_URL)/archive/v$(VERSION).tar.gz | openssl dgst -r -sha256 | tee $@
|
||||
$(BINARY).rb: v$(VERSION).tar.gz.sha256 init/homebrew/$(FORMULA).rb.tmpl
|
||||
# Creating formula from template using sed.
|
||||
sed -e "s/{{Version}}/$(VERSION)/g" \
|
||||
-e "s/{{Iter}}/$(ITERATION)/g" \
|
||||
-e "s/{{SHA256}}/$(shell head -c64 $<)/g" \
|
||||
-e "s/{{Desc}}/$(DESC)/g" \
|
||||
-e "s%{{SOURCE_URL}}%$(SOURCE_URL)%g" \
|
||||
-e "s%{{SOURCE_PATH}}%$(SOURCE_PATH)%g" \
|
||||
-e "s%{{CONFIG_FILE}}%$(CONFIG_FILE)%g" \
|
||||
-e "s%{{Class}}%$(shell echo $(BINARY) | perl -pe 's/(?:\b|-)(\p{Ll})/\u$$1/g')%g" \
|
||||
init/homebrew/$(FORMULA).rb.tmpl | tee $(BINARY).rb
|
||||
# That perl line turns hello-world into HelloWorld, etc.
|
||||
|
||||
# Used for Homebrew only. Other distros can create packages.
|
||||
install: man readme $(BINARY) plugins_darwin
|
||||
@echo - Done Building! -
|
||||
@echo - Done Building -
|
||||
@echo - Local installation with the Makefile is only supported on macOS.
|
||||
@echo If you wish to install the application manually on Linux, check out the wiki: https://$(SOURCE_URL)/wiki/Installation
|
||||
@echo - Otherwise, build and install a package: make rpm -or- make deb
|
||||
@echo See the Package Install wiki for more info: https://$(SOURCE_URL)/wiki/Package-Install
|
||||
@[ "$(shell uname)" = "Darwin" ] || (echo "Unable to continue, not a Mac." && false)
|
||||
@[ "$(PREFIX)" != "" ] || (echo "Unable to continue, PREFIX not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false)
|
||||
@[ "$(ETC)" != "" ] || (echo "Unable to continue, ETC not set. Use: make install PREFIX=/usr/local ETC=/usr/local/etc" && false)
|
||||
# Copying the binary, config file, unit file, and man page into the env.
|
||||
/usr/bin/install -m 0755 -d $(PREFIX)/bin $(PREFIX)/share/man/man1 $(ETC)/$(BINARY) $(PREFIX)/share/doc/$(BINARY) $(PREFIX)/lib/$(BINARY)/web
|
||||
/usr/bin/install -m 0755 -d $(PREFIX)/bin $(PREFIX)/share/man/man1 $(ETC)/$(BINARY) $(PREFIX)/share/doc/$(BINARY) $(PREFIX)/lib/$(BINARY)
|
||||
/usr/bin/install -m 0755 -cp $(BINARY) $(PREFIX)/bin/$(BINARY)
|
||||
/usr/bin/install -m 0644 -cp $(BINARY).1.gz $(PREFIX)/share/man/man1/
|
||||
/usr/bin/install -m 0644 -cp $(BINARY).1.gz $(PREFIX)/share/man/man1
|
||||
/usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/
|
||||
/usr/bin/install -m 0644 -cp init/webserver/* $(PREFIX)/lib/$(BINARY)/web/
|
||||
[ -f $(ETC)/$(BINARY)/$(CONFIG_FILE) ] || /usr/bin/install -m 0644 -cp examples/$(CONFIG_FILE).example $(ETC)/$(BINARY)/$(CONFIG_FILE)
|
||||
/usr/bin/install -m 0644 -cp LICENSE *.html examples/* $(PREFIX)/share/doc/$(BINARY)/
|
||||
|
||||
Reference in New Issue
Block a user