Skip to content

Instantly share code, notes, and snippets.

@pjvds
Created August 31, 2013 19:09
Show Gist options
  • Save pjvds/6400026 to your computer and use it in GitHub Desktop.
Save pjvds/6400026 to your computer and use it in GitHub Desktop.
Make file for Golang projects
# Targets:
# all: Builds the code
# build: Builds the code
# clean: cleans the code
# install: Installs the code to the GOPATH
# iref: Installs referenced projects
# test: Runs the tests
# Go commands
GOCMD=go
GOGET=$(GOCMD) get
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOINSTALL=$(GOCMD) install
GOTEST=$(GOCMD) test
GODEP=$(GOTEST) -i
# Package lists
TOPLEVEL_PKG := github.com/pjvds/eventdb
JOURNAL_LIST := journal/page journal
# List building
ALL_LIST = $(JOURNAL_LIST)
GET_LIST = $(foreach int, $(ALL_LIST), $(int)_get)
BUILD_LIST = $(foreach int, $(ALL_LIST), $(int)_build)
CLEAN_LIST = $(foreach int, $(ALL_LIST), $(int)_clean)
INSTALL_LIST = $(foreach int, $(ALL_LIST), $(int)_install)
IREF_LIST = $(foreach int, $(ALL_LIST), $(int)_iref)
TEST_LIST = $(foreach int, $(ALL_LIST), $(int)_test)
all: get build test
get: $(GET_LIST)
build: get $(BUILD_LIST)
clean: $(CLEAN_LIST)
install: $(INSTALL_LIST)
test: iref $(TEST_LIST)
iref: build $(IREF_LIST)
$(GET_LIST): %_get:
$(GOGET) $(TOPLEVEL_PKG)/$*
$(BUILD_LIST): %_build:
$(GOBUILD) $(TOPLEVEL_PKG)/$*
$(CLEAN_LIST): %_clean:
$(GOCLEAN) $(TOPLEVEL_PKG)/$*
$(INSTALL_LIST): %_install:
$(GOINSTALL) $(TOPLEVEL_PKG)/$*
$(IREF_LIST): %_iref: %_build
$(GODEP) $(TOPLEVEL_PKG)/$*
$(TEST_LIST): %_test:
$(GOTEST) $(TOPLEVEL_PKG)/$*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment