Skip to content

Instantly share code, notes, and snippets.

@TheHackerDev
Created October 6, 2016 19:41
Show Gist options
  • Save TheHackerDev/c717dde57345343662dcdec012883499 to your computer and use it in GitHub Desktop.
Save TheHackerDev/c717dde57345343662dcdec012883499 to your computer and use it in GitHub Desktop.
Golang Makefile for easy builds
# File name
DIR := bin
PREFIX := race-the-web
TAG := $(shell git describe --always --dirty --tags)
# Build command
CMD_BUILD := go build -o $(DIR)/$(PREFIX)_$(TAG)_
# Environment variables for build
ENV_OSX64 := GOOS=darwin GOARCH=amd64
ENV_OSX32 := GOOS=darwin GOARCH=386
ENV_LIN64 := GOOS=linux GOARCH=amd64
ENV_LIN32 := GOOS=linux GOARCH=386
ENV_WIN64 := GOOS=windows GOARCH=amd64
ENV_WIN32 := GOOS=windows GOARCH=386
# Runs all builds when "make" is run
all: windows linux osx
# Runs only a build for the local architecture in
# the local directory when "make build" is run
build:
@go build -o $(PREFIX)$(TAG) .
windows:
@$(ENV_WIN64) $(CMD_BUILD)win64.exe
@$(ENV_WIN32) $(CMD_BUILD)win32.exe
@echo "Windows complete."
linux:
@$(ENV_LIN64) $(CMD_BUILD)lin32.bin
@$(ENV_LIN32) $(CMD_BUILD)lin64.bin
@echo "Linux complete."
osx:
@$(ENV_OSX64) $(CMD_BUILD)osx64.app
@$(ENV_OSX32) $(CMD_BUILD)osx32.app
@echo "OSX complete."
@TheHackerDev
Copy link
Author

I use git tags for versioning most of my binaries. You can also use git commit hashes for more granular builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment