> On Aug 22, 2021, at 10:11 PM, jlfo...@berkeley.edu <jlforr...@berkeley.edu>
> wrote:
>
>
> I've noticed that few, if any, Go programs use Makefiles. Is that because the
> overhead of using make is greater than the overhead of just always compiling
> and linking everything?
> One piece of evidence for this is that the Go compiler leaves no artifacts,
> like object files, so as is make wouldn't fit into the current build method.
>
I started using a Makefile for my Go project so that I could inject a version
string at build time without having to remember what to pass to go binaries.
I made a Discord bot to use in a server with my friends, and since I have some
automation in place to automatically deploy the tip of my main branch, I
thought it’d be convenient to be able to ask the bot what build it’s running so
we can see which commits are “live."
So while it’s not a “traditional” use of make, it certainly is convenient.
Connor
P.S., here’s the Makefile. The important bits are the lines that mention
“LD_FLAGS"
VERSION := v2.2.0+dev
BUILD := $(shell git describe --tags 2>/dev/null || echo "$(VERSION)")
LD_FLAGS := "-X 'main.Version=$(BUILD)'"
SOURCES := $(shell find . -type f -name '*.go')
SOURCES += go.mod go.sum
.PHONY: build clean test
all: popple
popple: build
build: $(SOURCES)
@go build -v -ldflags=$(LD_FLAGS) ./...
test: popple
@go test -v -ldflags=$(LD_FLAGS) ./...
clean:
@rm -rf popple
--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/06427CFB-1F08-43F3-8971-A095E8D47C30%40gmail.com.