webhookd/Makefile

91 lines
2.0 KiB
Makefile
Raw Normal View History

2014-09-19 18:46:04 +00:00
.SILENT :
export GO111MODULE=on
# App name
APPNAME=webhookd
# Go configuration
2021-12-30 11:22:51 +00:00
GOOS?=$(shell go env GOHOSTOS)
GOARCH?=$(shell go env GOHOSTARCH)
# Add exe extension if windows target
is_windows:=$(filter windows,$(GOOS))
EXT:=$(if $(is_windows),".exe","")
2014-09-19 18:46:04 +00:00
# Archive name
ARCHIVE=$(APPNAME)-$(GOOS)-$(GOARCH).tgz
# Executable name
EXECUTABLE=$(APPNAME)$(EXT)
# Extract version infos
2020-03-15 20:45:27 +00:00
PKG_VERSION:=github.com/ncarlier/$(APPNAME)/pkg/version
VERSION:=`git describe --always --dirty`
GIT_COMMIT:=`git rev-list -1 HEAD --abbrev-commit`
BUILT:=`date`
define LDFLAGS
-X '$(PKG_VERSION).Version=$(VERSION)' \
-X '$(PKG_VERSION).GitCommit=$(GIT_COMMIT)' \
-X '$(PKG_VERSION).Built=$(BUILT)'
endef
2014-10-31 23:18:38 +00:00
all: build
2014-09-19 18:46:04 +00:00
# Include common Make tasks
root_dir:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
makefiles:=$(root_dir)/makefiles
include $(makefiles)/help.Makefile
2014-09-19 18:46:04 +00:00
## Clean built files
clean:
-rm -rf release
.PHONY: clean
2014-11-10 16:37:54 +00:00
## Build executable
2019-01-03 15:58:07 +00:00
build:
-mkdir -p release
echo "Building: $(EXECUTABLE) $(VERSION) for $(GOOS)-$(GOARCH) ..."
2020-03-15 20:45:27 +00:00
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -o release/$(EXECUTABLE)
.PHONY: build
2014-11-10 16:37:54 +00:00
release/$(EXECUTABLE): build
## Run tests
test:
2019-01-07 07:39:26 +00:00
go test ./...
.PHONY: test
## Install executable
install: release/$(EXECUTABLE)
echo "Installing $(EXECUTABLE) to ${HOME}/.local/bin/$(EXECUTABLE) ..."
cp release/$(EXECUTABLE) ${HOME}/.local/bin/$(EXECUTABLE)
.PHONY: install
## Create Docker image
image:
echo "Building Docker image ..."
docker build --rm -t ncarlier/$(APPNAME) .
.PHONY: image
2018-02-12 20:18:33 +00:00
## Generate changelog
changelog:
standard-changelog --first-release
.PHONY: changelog
## Create archive
archive: release/$(EXECUTABLE)
echo "Creating release/$(ARCHIVE) archive..."
tar czf release/$(ARCHIVE) README.md LICENSE CHANGELOG.md -C release/ $(EXECUTABLE)
rm release/$(EXECUTABLE)
.PHONY: archive
2018-02-12 20:18:33 +00:00
## Create distribution binaries
distribution:
GOARCH=amd64 make build archive
GOARCH=arm64 make build archive
GOARCH=arm make build archive
GOOS=darwin make build archive
2018-02-12 20:18:33 +00:00
.PHONY: distribution