PKGBUILD/Makefile

214 lines
6.9 KiB
Makefile
Raw Normal View History

# VERSION/RELEASE
2019-04-18 14:59:55 +00:00
# If no version is specified as a parameter of make, the last git hash
# value is taken.
VERSION?=$(shell git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g')
RELEASE?=1
# CONTAINER_IMAGE_VERSION
# Defines the version of the container image which has included the executable
# binary. This is somethimes different to the variable VERSION, because the
# container image version should be latest instead contains the latest git tag
# and hash sum.
CONTAINER_IMAGE_VERSION:=latest
# CONTAINER_RUNTIME/BUILD_IMAGE
# The CONTAINER_RUNTIME variable will be used to specified the path to a
# container runtime. This is needed to start and run a container image defined
# by the BUILD_IMAGE variable. The BUILD_IMAGE container serve as build
# environment to execute the different make steps inside. Therefore, the bulid
# environment requires all necessary dependancies to build this project.
CONTAINER_RUNTIME?=$(shell which docker)
BUILD_IMAGE:=volkerraschek/build-image:latest
# EXECUTABLE
# Executable binary which should be compiled for different architecures
EXECUTABLE:=flucky
# DARWIN_EXECUTABLES AND TARGETS
DARWIN_EXECUTABLES:=\
darwin/386/${EXECUTABLE} \
darwin/amd64/${EXECUTABLE}
DARWIN_EXECUTABLE_TARGETS:=\
${DARWIN_EXECUTABLES:%=bin/%}
# FREEBSD_EXECUTABLES AND TARGETS
FREEBSD_EXECUTABLES:=\
freebsd/amd64/${EXECUTABLE}
FREEBSD_EXECUTABLE_TARGETS:=\
${FREEBSD_EXECUTABLES:%=bin/%}
# LINUX_EXECUTABLES AND TARGETS
LINUX_EXECUTABLES:=\
linux/amd64/${EXECUTABLE} \
linux/386/${EXECUTABLE} \
linux/arm/5/${EXECUTABLE} \
linux/arm/7/${EXECUTABLE}
LINUX_EXECUTABLE_TARGETS:=\
${LINUX_EXECUTABLES:%=bin/%}
# UNIX_EXECUTABLES AND TARGETS
# Define all executables for different architectures and operation systems
UNIX_EXECUTABLES:= \
${DARWIN_EXECUTABLES} \
${FREEBSD_EXECUTABLES} \
${LINUX_EXECUTABLES}
UNIX_EXECUTABLE_TARGETS:= \
${DARWIN_EXECUTABLE_TARGETS} \
${FREEBSD_EXECUTABLE_TARGETS} \
${LINUX_EXECUTABLE_TARGETS}
# EXECUTABLES AND TARGETS
# Include all UNIX and Windows targets.
EXECUTABLES:=\
${UNIX_EXECUTABLES}
EXECUTABLE_TARGETS:= \
${UNIX_EXECUTABLE_TARGETS}
# BINARIES
# ==============================================================================
# current os
${EXECUTABLE}: bindata
CGO_ENABLED=0 go build -ldflags "-X main.version=${VERSION}" -o ${@}
# build all binaries
PHONY:=all
2019-08-26 13:12:32 +00:00
all: ${EXECUTABLE_TARGETS}
# darwin os
bin/darwin/386/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=386 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o ${@}
bin/darwin/amd64/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=amd64 GOOS=darwin go build -ldflags "-X main.version=${VERSION}" -o ${@}
# freebsd os
bin/freebsd/amd64/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=amd64 GOOS=freebsd go build -ldflags "-X main.version=${VERSION}" -o ${@}
# linux os
bin/linux/386/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=386 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
bin/linux/amd64/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
2019-08-26 13:12:32 +00:00
bin/linux/arm/5/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARM=5 GOARCH=arm GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
2019-08-26 13:12:32 +00:00
bin/linux/arm/7/${EXECUTABLE}: bindata
CGO_ENABLED=0 GOARM=7 GOARCH=arm GOOS=linux go build -ldflags "-X main.version=${VERSION}" -o ${@}
2019-08-26 13:12:32 +00:00
# GO-BINDATA
# ==============================================================================
bindata:
go-bindata -pkg db -o ./pkg/storage/db/bindataSQL.go ./pkg/storage/db/sql/*** ./pkg/storage/db/sql/psql/schema/***
go-bindata -pkg goldenfiles -ignore ".*\.go" -o ./test/goldenfiles/bindata.go ./test/goldenfiles/***
# TEST
# ==============================================================================
PHONY+=test test-update-all
test: ${EXECUTABLE}
go test -v ./...
test-update-all: ${EXECUTABLE}
go test -v ./pkg/... -update all
# PACKAGES
# ==============================================================================
%.rpm: %
rpm-builder \
--exec-file "$<:/usr/bin/${EXECUTABLE}" \
--dir "systemd:/usr/lib/systemd/system" \
--license "Apache 2.0" \
--version ${VERSION} \
--release ${RELEASE} \
--out ${@} \
${EXECUTABLE}
# OTHER STUFF
# ==============================================================================
PHONY+=clean
clean:
rm ${EXECUTABLE} || true
rm ${EXECUTABLE}.* || true
rm --recursive --force bin/ || true
2019-08-26 13:12:32 +00:00
# CONTAINER IMAGE STEPS
# ==============================================================================
PHONY+=container-image/build/amd64
container-image/build/amd64: bin/linux/amd64/${EXECUTABLE}
${CONTAINER_RUNTIME} build \
--tag volkerraschek/${EXECUTABLE}:${IMAGE_VERSION} \
.
PHONY+=container-image/push/amd64
container-image/push/amd64: container-image/build/amd64
${CONTAINER_RUNTIME} push volkerraschek/${EXECUTABLE}:${IMAGE_VERSION}
# CONTAINER STEPS - BINARY
# ==============================================================================
# current os
PHONY+=container-run/${EXECUTABLE}
container-run/${EXECUTABLE}:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
# build all binaries for any operating system
PHONY+=container-run/all
container-run/all:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
PHONY+=${UNIX_EXECUTABLE_TARGETS:%=container-run/%}
${UNIX_EXECUTABLE_TARGETS:%=container-run/%}:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
# CONTAINER STEPS - GO-BINDATA
# ==============================================================================
PHONY+=container-run/bindata
container-run/bindata:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
# CONTAINER STEPS - TEST
# ==============================================================================
PHONY+=container-run/test
container-run/test:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
PHONY+=container-run/test-update-all
container-run/test-update-all:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
# CONTAINER STEPS - OTHER STUF
# ==============================================================================
PHONY+=container-run/clean
container-run/clean:
$(MAKE) container-run COMMAND=${@:container-run/%=%}
# GENERAL CONTAINER COMMAND
# ==============================================================================
PHONY+=container-run
container-run:
${CONTAINER_RUNTIME} run \
--rm \
--volume ${PWD}:/workspace \
${BUILD_IMAGE} \
make ${COMMAND} \
VERSION=${VERSION} \
RELEASE=${RELEASE}
# REMOTE
# ==============================================================================
PHONY+=${FLUCKY_REMOTE:%=remote/%}
remote/${FLUCKY_REMOTE}: bin/linux/arm/7/${EXECUTABLE}
scp bin/linux/arm/7/${EXECUTABLE} root@${FLUCKY_REMOTE}:/usr/local/bin/${EXECUTABLE}
ssh root@${FLUCKY_REMOTE} 'chmod +x /usr/local/bin/${EXECUTABLE}'
2019-06-11 18:07:55 +00:00
# PHONY
# ==============================================================================
# Declare the contents of the PHONY variable as phony. We keep that information
# in a variable so we can use it in if_changed.
.PHONY: ${PHONY}