Skip to content

Instantly share code, notes, and snippets.

@robbles
Created December 22, 2015 01:54
Show Gist options
  • Save robbles/67baa3c755e2919e4a5d to your computer and use it in GitHub Desktop.
Save robbles/67baa3c755e2919e4a5d to your computer and use it in GitHub Desktop.
Simple Makefile example for reference
# Find all files matching "src/*.go" and replace "src/%.go" with "bin/%"
OUTPUTS := $(patsubst src/%.go,bin/%,$(wildcard src/*.go))
# Reference all files to be built in a single rule
all: $(OUTPUTS)
# Rule for compiling a single output file in bin/
bin/%: src/%.go
# $* is replaced with the value of the wildcard in the rule (%)
go build -o bin/$* src/$*.go
# Treat "all" rule as phony, meaning make will not look for a file named "all" when running it
.PHONY: all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment