Skip to content

Instantly share code, notes, and snippets.

@heewa heewa/Makefile
Last active Jun 18, 2016

What would you like to do?
gomake - sharable golang makefile
# Makefile to build Golang projects that can be used without putting the
# makefile in the project directory. Using make to build & run go projects
# allows you to reuse build output when files haven't changed, considering
# building go can be slow.
# Based On:
# By default it builds main.go from the directory you're in, to a binary
# called main. To amke it easier to use, set bash aliases & functions:
# alias gomake='make -f /path/to/Makefile'
# gorun() { gomake RUN_ARGS="$*" run ;}
# Then you can use like `gomake clean all` or `gorun args to your program`
# Project vars - You can override these with the below vars directly when
# calling make `BINARY=myproject make`, or `make BINARY=myproject`, or modify
# this file. But it's probably best to set them using aliases.
SOURCEDIR ?= $(shell pwd)
MAIN ?= main.go
BINARY ?= /tmp/gorun--$(notdir $(basename $(MAIN)))
# Auto vars - you shouldn't need to modify these
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')
all: $(BINARY)
go build ${BUILD_FLAGS} -o $@ ${MAIN}
.PHONY: clean list
@echo MAIN:${MAIN}
if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.