60 lines
1.3 KiB
Makefile
60 lines
1.3 KiB
Makefile
SHELL := /bin/bash
|
|
|
|
VERSION=$(shell grep -e 'Version' sonar.go | head -n 1 | cut -d '"' -f 2)
|
|
BUILD=$(shell git describe --always)
|
|
CURDIR=$(shell curdir)
|
|
|
|
# Inject the build version (commit hash) into the executable.
|
|
LDFLAGS := -ldflags "-X main.Build=$(BUILD)"
|
|
|
|
# `make setup` to set up a new environment, pull dependencies, etc.
|
|
.PHONY: setup
|
|
setup: clean
|
|
go get -u ./...
|
|
|
|
# `make build` to build the binary.
|
|
.PHONY: build
|
|
build:
|
|
gofmt -w .
|
|
go build $(LDFLAGS) -i -o bin/sonar cmd/sonar/main.go
|
|
|
|
# `make dist` makes a distribution bundle.
|
|
.PHONY: dist
|
|
dist:
|
|
rm -rf dist
|
|
mkdir dist
|
|
cp -r crontab.in www dist/
|
|
go build $(LDFLAGS) -i -o dist/sonar cmd/sonar/main.go
|
|
cd dist
|
|
tar -czvf sonar-$(VERSION).tar.gz *
|
|
mv *.tar.gz ../
|
|
|
|
# `make pi` makes a distribution for the Raspberry Pi.
|
|
.PHONY: pi
|
|
pi:
|
|
rm -rf sonar.pi
|
|
mkdir sonar.pi
|
|
cp -r crontab.in www sonar.pi/
|
|
GOOS=linux GOARCH=arm go build $(LDFLAGS) -i -o sonar.pi/sonar cmd/sonar/main.go
|
|
zip -r sonar-pi.zip sonar.pi
|
|
|
|
# `make run` to run it in debug mode.
|
|
.PHONY: run
|
|
run:
|
|
go run cmd/sonar/main.go -debug
|
|
|
|
# `make watch` to run it in debug mode.
|
|
.PHONY: watch
|
|
watch:
|
|
./go-reload cmd/sonar/main.go -debug
|
|
|
|
# `make test` to run unit tests.
|
|
.PHONY: test
|
|
test:
|
|
go test ./...
|
|
|
|
# `make clean` cleans everything up.
|
|
.PHONY: clean
|
|
clean:
|
|
rm -rf bin dist
|