# 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. UID?=$(shell id --user) GID?=$(shell id --group) # VERSION # If no version is specified as a parameter of make, the last git hash # value is taken. VERSION:=$(or ${TRAVIS_TAG}, $(shell git rev-parse --short HEAD)-git) # 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 := \ darwin/amd64/$(EXECUTABLE) \ freebsd/amd64/$(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 all: ${EXECUTABLE} $(EXECUTABLE): bindata go build -ldflags "-X main.version=${VERSION}" -o "$@" bin/tmp/${EXECUTABLE}: bindata go build -ldflags "-X main.version=${VERSION}" -o "$@" # 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 "$@" # 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 "$@" bindata: go-bindata -pkg db -o ./pkg/db/bindataSQL.go ./pkg/db/sql/*** go-bindata -pkg goldenfiles -o ./test/goldenfiles/bindata.go ./test/goldenfiles/json/*** %.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 container/all: $(MAKE) container-run COMMAND=all container/test: $(MAKE) container-run COMMAND=test container/release: $(MAKE) container-run COMMAND=release container-run: ${CONTAINER_RUNTIME} run \ --rm \ --volume ${PWD}:/workspace \ ${BUILD_IMAGE} \ make ${COMMAND} \ UID=${UID} \ GID=${GID} \ VERSION=${VERSION} \ GITHUB_TOKEN=${GITHUB_TOKEN} 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"