Created
October 6, 2016 19:41
-
-
Save TheHackerDev/c717dde57345343662dcdec012883499 to your computer and use it in GitHub Desktop.
Golang Makefile for easy builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use git tags for versioning most of my binaries. You can also use git commit hashes for more granular builds.