build.makefile 572 B

12345678910111213141516171819
  1. BINARIES=$(patsubst cmd/%/main.go,bin/%,$(wildcard cmd/*/main.go))
  2. STATIC_BINARIES=$(patsubst cmd/%/main.go,bin/%-static,$(wildcard cmd/*/main.go))
  3. all: $(BINARIES)
  4. static: $(STATIC_BINARIES)
  5. .PHONY: all static
  6. GO_SOURCES=
  7. GO_SOURCES+=$(shell find . -name '*.go' -not -path '*vendor*' -not -path '*.pb.go')
  8. GO_SOURCES+=$(wildcard go.*)
  9. bin/%: cmd/%/main.go $(GO_SOURCES)
  10. @mkdir -p $(dir $@)
  11. go build -o $@ $<
  12. bin/%-static: cmd/%/main.go $(GO_SOURCES)
  13. @mkdir -p $(dir $@)
  14. CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -ldflags '-extldflags "-static"' -o $@ $<