Skip to content

Commit

Permalink
Update makefile to make nicer release binaries
Browse files Browse the repository at this point in the history
Fixes #46
  • Loading branch information
jacksontj committed Sep 25, 2018
1 parent 0163556 commit acf5e0c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cmd/promxy/promxy
build/*
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
BUILD := build
GO ?= go
GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*")
GOFMT ?= gofmt -s

.PHONY: clean
clean:
$(GO) clean -i ./...
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)

.PHONY: fmt
fmt:
$(GOFMT) -w $(GOFILES)

.PHONY: test
test:
$(GO) test ./...

.PHONY: release
release:
./build.bash github.com/jacksontj/promxy/cmd/promxy $(BUILD)
32 changes: 32 additions & 0 deletions build.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

VERSION=`git describe --tags`

package=$1
destination=$2
if [[ -z "$package" ]]; then
echo "usage: $0 <package-name> <destination>"
exit 1
fi
package_split=(${package//\// })
package_name=${package_split[-1]}

platforms=("linux/amd64" "linux/386" "darwin/amd64")

for platform in "${platforms[@]}"
do
platform_split=(${platform//\// })
GOOS=${platform_split[0]}
GOARCH=${platform_split[1]}
output_name=$package_name'-'$VERSION'-'$GOOS'-'$GOARCH
if [ $GOOS = "windows" ]; then
output_name+='.exe'
fi

env GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o $destination/$output_name $package
if [ $? -ne 0 ]; then
echo 'An error has occurred! Aborting the script execution...'
exit 1
fi
done

0 comments on commit acf5e0c

Please sign in to comment.