A makefile for Golang CLI tools

380 views
Skip to first unread message

Ariejan de Vroom

unread,
Oct 3, 2015, 1:26:15 PM10/3/15
to golang-nuts
Hey everyone,

I was busy figuring out compile time variables and Makefiles for Golang, I did a write up at https://ariejan.net/2015/10/03/a-makefile-for-golang-cli-tools/

Let me know if you have any questions of suggestions.

–Ariejan

Giulio Iotti

unread,
Oct 4, 2015, 4:00:26 AM10/4/15
to golang-nuts
I only have an issue with buildTime: it makes the build not reproducible.

-- 
Giulio Iotti 

andrewc...@gmail.com

unread,
Oct 4, 2015, 6:47:04 AM10/4/15
to golang-nuts
To me it seems like you took something simple and cross platform "go generate" + "go install/build" and turned it into something more complicated and less portable.

Peter Kleiweg

unread,
Oct 4, 2015, 11:05:55 AM10/4/15
to golang-nuts
Instead of using find to list source files, just use a wildcard:

prog: *.go
go build .

Ariejan de Vroom

unread,
Oct 12, 2015, 7:59:18 AM10/12/15
to golang-nuts
Hey everyone,

Thanks for your feedback. I've written an update on my previous post.


–Ariejan

Jakob Borg

unread,
Oct 14, 2015, 11:14:09 AM10/14/15
to Ariejan de Vroom, golang-nuts
I see you went with a build.sh instead of a Makefile. The next step in that progression is a build.go, which actually works on Windows too. 

(I still have some build.sh things around because it's less to type than go run build.go, but with the former delegating to the latter where it makes sense.)

//jb
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastien Binet

unread,
Oct 14, 2015, 2:58:03 PM10/14/15
to Jakob Borg, Ariejan de Vroom, golang-nuts
hi,

On Wed, Oct 14, 2015 at 5:13 PM, Jakob Borg <ja...@nym.se> wrote:
> I see you went with a build.sh instead of a Makefile. The next step in that
> progression is a build.go, which actually works on Windows too.
>
> (I still have some build.sh things around because it's less to type than go
> run build.go, but with the former delegating to the latter where it makes
> sense.)

my personal preference has been to automatically on-the-fly generate a
temporary Makefile:
https://github.com/sbinet/mk

it handles -race, -bench, tests, go-generate, gogcc/llgo and of course
build/install.
(if a Makefile already exists, it's used instead of the auto-generated one)

-s

Harry B

unread,
Oct 14, 2015, 3:10:28 PM10/14/15
to golang-nuts, ari...@ariejan.net
afaik "go install" already takes care of checking if the source file has changed and build if necessary. This also means you don't have the take the trouble with inserting git-hash (instead of the simple timestamp). Yes, you will still have a different binary if you force rebuild.
Reply all
Reply to author
Forward
0 new messages