Little tool to generate a Makefile
for your project.
Use it to get a minimal boilerplate with a Makefile
for your project.
Two kinds of Makefiles could be generated by this tool:
- package
- application
Each of them will contain rules for corresponding entity.
Application Makefile
will contain everything the package needs but not vice versa.
Kinds could be simplified until they are not ambiguous, for example:
application -> app -> a
package -> pack -> p
$ cd $GOPATH/src/github.com/corpix/some-package
$ go-makefile --write-config .go-makefile.json > Makefile
This will write code to the Makefile
in current directory:
.DEFAULT_GOAL = all
version := $(shell git rev-list --count HEAD).$(shell git rev-parse --short HEAD)
name := some-package
package := github.com/corpix/$(name)
packages := $(shell go list ./... | grep -v /vendor/)
.PHONY: all
all:: dependencies
all:: build
.PHONY: dependencies
dependencies::
dep ensure
.PHONY: test
test::
go test -v $(packages)
.PHONY: bench
bench::
go test -bench=. -v $(packages)
.PHONY: lint
lint::
go vet -v $(packages)
.PHONY: check
check:: lint test
.PHONY: clean
clean::
git clean -xddff
If you need additional includes(or other kind
, or specify github username and project) you could pass --include
parameter in this manner:
go-makefile \
--kind app \
--user your-name \
--name project-name \
--include \
build.mk \
ci.mk
Includes could be used to extend the builtin Makefile targets, all targets are «(double-colon)[#goals]».
All of them will be appended to the list of the includes which will be appended to the end of the Makefile
.
You could save parameters which was used to generate Makefile
.
There are --read-config
and --write-config
arguments.
To write your config while generating Makefile
you could use:
go-makefile --kind app --user your-name --name project-name --write-config go-makefile.json
To read previously stored config and use them to generate Makefile
:
go-makefile --read-config go-makefile.json
Each goal is a double-colon rule so
you could define your custom logic for any Makefile
rule using includes.
Available for
--kind package
and--kind application
.
For --kind package
:
- install all dependencies
For --kind application
:
- install all dependencies
- build an application
Available for
--kind package
and--kind application
.
Run go build
against project sources. For project name test
entrypoint should be in test/main.go
.
Available for
--kind package
and--kind application
.
Will reach dependencies
target after that will run tests for project package.
Available for
--kind package
and--kind application
.
Will reach dependencies
target after that will run tests and benchmarks for project package.
Available for
--kind package
and--kind application
.
Install dependencies with dep
.
Available only for
--kind application
.
Name of this target depends on the--name
flag which you should specify to generate aMakefile
.
It will build a binary release for the project.
Name of the project.
It depends on the --name
flag which you should specify to generate a Makefile
.
Package of the project.
This is an absolute package name which should be used to import your project like any other go project would do.
It depends on the --project
flag which you should specify to generate a Makefile
.
Version number retrieved from the git version control.
It could be customized with
--version-generator
argument.
It will look like 100.abcdef
where:
100
is a commit count from the first commit toHEAD
abcdef
is a shortHEAD
sha1 sum
Build id which usually written to the binary file and helps identify the build.
It will be derived from the version.
It could be customized with
--build-id-generator
argument.
Linker flags.
It passes this variables to go build tools:
version
build_id
Our example project name is
github.com/corpix/hello
.
~/go/src/github.com/corpix/hello
├── cli
│ └── cli.go
└── hello
└── main.go
Where:
hello/main.go
is an entrypointcli/cli.go
is a part of the packagecli
It should have version
variable to allow linker automatically tag a build with version.
package cli
var version string
func Run() { ... }
MIT