2017-05-22 14:04:03 +02:00
|
|
|
PWD := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2017-05-23 14:22:19 +02:00
|
|
|
UPX ?= $(shell command -v upx 2>/dev/null) # Make sure it is uxp 3.94 or higher (https://github.com/upx/upx/releases)
|
|
|
|
GOARCH ?= $(shell go env GOARCH)
|
|
|
|
|
2017-05-23 15:08:54 +02:00
|
|
|
VERSION = $(shell git describe --tags --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo git)
|
|
|
|
BUILDSTAMP = $(shell date -u '+%Y-%m-%dT%T%z')
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2017-05-22 14:04:03 +02:00
|
|
|
DIST := $(PWD)/dist
|
2014-03-09 16:53:21 +01:00
|
|
|
DIST_SRC := $(DIST)/src
|
|
|
|
|
2017-05-22 14:04:03 +02:00
|
|
|
FOLDERS = $(shell find -mindepth 1 -maxdepth 1 -type d -not -path "*.git" -not -path "*debian" -not -path "*vendor" -not -path "*doc" -not -path "*bin")
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
export GO111MODULE=on
|
|
|
|
|
2017-05-22 14:04:03 +02:00
|
|
|
all: build
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2017-05-22 14:04:03 +02:00
|
|
|
$(DIST_SRC):
|
|
|
|
mkdir -p $@
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
generate: mods client/bindata.go
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
client/bindata.go: bin/go-bindata
|
|
|
|
bin/go-bindata -prefix "client/static/" -pkg client -o client/bindata.go client/static/...
|
2017-05-22 15:05:16 +02:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
generate-dev: bin/go-bindata
|
|
|
|
bin/go-bindata -dev -prefix "client/static/" -pkg client -o client/bindata.go client/static/...
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
mods: go.mod go.sum
|
|
|
|
go mod download
|
|
|
|
go mod verify
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
bin/go-bindata:
|
|
|
|
go build -v -o bin/go-bindata github.com/kevinburke/go-bindata/go-bindata
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
binary-%: mods generate client/bindata.go
|
|
|
|
GOOS=linux GOARCH=$(GOARCH) GOARM=$(GOARM) CGO_ENABLED=0 \
|
2017-05-23 15:08:54 +02:00
|
|
|
go build \
|
|
|
|
-ldflags="-s -w \
|
|
|
|
-X main.Version=$(VERSION) \
|
|
|
|
-X main.BuildStamp=$(BUILDSTAMP) \
|
|
|
|
" \
|
2017-05-23 15:23:47 +02:00
|
|
|
-o bin/realtimetrafficd_$(GOARCH) realtimetrafficd/*.go
|
2017-05-23 14:22:19 +02:00
|
|
|
|
|
|
|
binary: binary-$(GOARCH)
|
2017-05-23 15:23:47 +02:00
|
|
|
cp -va bin/realtimetrafficd_$(GOARCH) bin/realtimetrafficd
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
build: binary
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2017-05-23 15:23:47 +02:00
|
|
|
$(DIST)/realtimetrafficd-$(VERSION)_%: binary-$(GOARCH)
|
2017-05-23 14:22:19 +02:00
|
|
|
@mkdir -p $(DIST)
|
2017-05-23 15:23:47 +02:00
|
|
|
if [ -n "$(UPX)" ]; then UPX= $(UPX) -f --brute -o $@ bin/realtimetrafficd_$(GOARCH); else cp -va bin/realtimetrafficd_$(GOARCH) $@; fi
|
2017-05-23 14:22:19 +02:00
|
|
|
|
|
|
|
release-amd64:
|
2017-05-23 15:23:47 +02:00
|
|
|
$(MAKE) GOARCH=amd64 $(DIST)/realtimetrafficd-$(VERSION)_amd64
|
2017-05-23 14:22:19 +02:00
|
|
|
|
|
|
|
release-armhf:
|
2017-05-23 15:23:47 +02:00
|
|
|
$(MAKE) GOARCH=arm GOARM=7 $(DIST)/realtimetrafficd-$(VERSION)_armhf
|
2017-05-23 14:22:19 +02:00
|
|
|
|
|
|
|
release-arm64:
|
2017-05-23 15:23:47 +02:00
|
|
|
$(MAKE) GOARCH=arm64 $(DIST)/realtimetrafficd-$(VERSION)_arm64
|
2017-05-23 14:22:19 +02:00
|
|
|
|
|
|
|
release: release-amd64 release-armhf release-arm64
|
|
|
|
|
2017-05-22 14:04:03 +02:00
|
|
|
format:
|
|
|
|
find $(FOLDERS) \( -name "*.go" ! -name "bindata.go" \) -print0 | xargs -0 -n 1 go fmt
|
2014-03-09 16:53:21 +01:00
|
|
|
|
2018-10-27 15:52:02 +02:00
|
|
|
.PHONY: all client/bindata.go mods generate-dev binary build release
|