PKGBUILD/Makefile

174 lines
4.9 KiB
Makefile
Raw Normal View History

2019-04-18 14:59:55 +00:00
# UID/GID
# UID or GID is the UNIX user ID or group ID of the user who executes
# make. If the UID or GID is not passed as a make variable, an attempt
# is made to determine it.
2019-05-12 09:57:53 +00:00
UID?=$(shell id --user)
GID?=$(shell id --group)
2019-04-18 14:59:55 +00:00
# VERSION
# If no version is specified as a parameter of make, the last git hash
# value is taken.
2019-08-20 19:37:45 +00:00
VERSION:=$(or ${TRAVIS_TAG}, $(shell git rev-parse --short HEAD)-git)
2018-11-07 19:07:15 +00:00
# CONTAINER_RUNTIME
CONTAINER_RUNTIME?=$(shell which docker)
# BUILD_IMAGE
BUILD_IMAGE:=volkerraschek/build-image:latest
# GH_USER/GITHUB_TOKEN
# It's the user name from github.com and his token. This token and the username
# can be set over encrypted environment variables in the ci/cd pipeline
GITHUB_USER=volker-raschek
GITHUB_TOKEN?=""
# EXECUTABLE
# Executable binary which should be compiled for different architecures
EXECUTABLE:=flucky
# UNIX_EXECUTABLES
# Define all executables for different architectures and operation systems
UNIX_EXECUTABLES := \
2019-08-26 13:12:32 +00:00
darwin/386/$(EXECUTABLE) \
darwin/amd64/$(EXECUTABLE) \
freebsd/amd64/$(EXECUTABLE) \
2019-08-26 13:12:32 +00:00
linux/386/$(EXECUTABLE) \
linux/amd64/$(EXECUTABLE) \
linux/arm/5/$(EXECUTABLE) \
linux/arm/7/$(EXECUTABLE) \
# EXECUTABLE_TARGETS
# Include the relative paths to all executables
EXECUTABLE_TARGETS=$(UNIX_EXECUTABLES:%=bin/%)
# COMPRSSED_EXECUTABLES
# Append to all defined executables the compression extentions to detect the
# different make steps which compress the binary
COMPRESSED_EXECUTABLES=$(UNIX_EXECUTABLES:%=%.tar.bz2) $(UNIX_EXECUTABLES:%=%.tar.gz) $(UNIX_EXECUTABLES:%=%.tar.xz)
COMPRESSED_EXECUTABLE_TARGETS=$(COMPRESSED_EXECUTABLES:%=bin/%)
# PHONY
# To avoid a conflict with an existing file and a defined make step
.PHONY: clean container/${EXECUTABLE_TARGETS} container/test release remote test
$(EXECUTABLE): bindata
go build -ldflags "-X main.version=${VERSION}" -o "$@"
2019-08-26 13:12:32 +00:00
all: ${EXECUTABLE_TARGETS}
2019-08-26 13:12:32 +00:00
container/bin/tmp/${EXECUTABLE}:
$(MAKE) container-run COMMAND=$(subst container/,,$@)
# 386
bin/darwin/386/$(EXECUTABLE): bindata
GOARCH=386 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o "$@"
bin/linux/386/$(EXECUTABLE): bindata
GOARCH=386 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
# amd64
bin/freebsd/amd64/$(EXECUTABLE): bindata
GOARCH=amd64 GOOS=freebsd go build -ldflags "-X main.version=${VERSION}" -o "$@"
bin/darwin/amd64/$(EXECUTABLE): bindata
GOARCH=amd64 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o "$@"
bin/linux/amd64/$(EXECUTABLE): bindata
GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o "$@"
2019-08-26 13:12:32 +00:00
# arm
bin/linux/arm/5/${EXECUTABLE}: bindata
GOARM=5 GOARCH=arm go build -ldflags "-X main.version=${VERSION}" -o "$@"
bin/linux/arm/7/${EXECUTABLE}: bindata
GOARM=7 GOARCH=arm go build -ldflags "-X main.version=${VERSION}" -o "$@"
bindata:
2019-08-20 19:37:45 +00:00
go-bindata -pkg db -o ./pkg/db/bindataSQL.go ./pkg/db/sql/***
go-bindata -pkg goldenfiles -o ./test/goldenfiles/bindata.go ./test/goldenfiles/json/***
2019-08-26 13:12:32 +00:00
%.tar.bz2: %
tar --create --bzip2 --file "$@" "$<"
%.tar.gz: %
tar --create --gunzip --file "$@" "$<"
%.tar.xz: %
tar --create --xz --file "$@" "$<"
test: ${EXECUTABLE}
go test -v ./pkg/...
release: clean
$(MAKE) $(COMPRESSED_EXECUTABLE_TARGETS)
github-release release \
--user ${GITHUB_USER} \
--repo ${EXECUTABLE} \
--tag ${VERSION}
$(foreach FILE,$(COMPRESSED_EXECUTABLES),github-release upload --user ${GITHUB_USER} --repo ${EXECUTABLE} --tag ${VERSION} --name $(subst /,-,$(FILE)) --file bin/$(FILE) --replace;)
clean:
rm ${EXECUTABLE} || true
rm --recursive --force bin/ || true
2019-08-26 13:12:32 +00:00
# container
container/${EXECUTABLE}:
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container/all:
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container/test:
2019-08-26 13:12:32 +00:00
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container/release:
2019-08-26 13:12:32 +00:00
$(MAKE) container-run COMMAND=$(subst container/,,$@)
# container - 386
container/bin/darwin/386/$(EXECUTABLE):
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container/bin/linux/386/$(EXECUTABLE):
$(MAKE) container-run COMMAND=$(subst container/,,$@)
# container - amd
container/bin/freebsd/amd64/$(EXECUTABLE):
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container/bin/darwin/amd64/$(EXECUTABLE):
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container/bin/linux/amd64/$(EXECUTABLE):
$(MAKE) container-run COMMAND=$(subst container/,,$@)
# container - arm
container/bin/linux/arm/7/${EXECUTABLE}:
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container/bin/linux/arm/5/${EXECUTABLE}:
$(MAKE) container-run COMMAND=$(subst container/,,$@)
container-run:
${CONTAINER_RUNTIME} run \
--rm \
--volume ${PWD}:/workspace \
${BUILD_IMAGE} \
make ${COMMAND} \
UID=${UID} \
GID=${GID} \
VERSION=${VERSION} \
GITHUB_TOKEN=${GITHUB_TOKEN}
2019-06-11 18:07:55 +00:00
remote: bin/linux/arm/7/${EXECUTABLE}
scp bin/linux/arm/7/${EXECUTABLE} ${FLUCKY_REMOTE}:/usr/local/bin
ssh ${FLUCKY_REMOTE} "chmod +x /usr/local/bin/flucky"