Merge pull request #592 from sosedoff/default-build-flags

Set LDFLAGS for make build/release commands
This commit is contained in:
Dan Sosedoff 2022-12-02 12:21:37 -06:00 committed by GitHub
commit f493d0d04d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,15 @@
GIT_COMMIT = $(shell git rev-parse HEAD) PKG = github.com/sosedoff/pgweb
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n') GIT_COMMIT ?= $(shell git rev-parse HEAD)
GO_VERSION = $(shell go version | awk {'print $$3'}) BUILD_TIME ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
GO_VERSION ?= $(shell go version | awk {'print $$3'})
DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')" DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')"
DOCKER_LATEST_TAG = "sosedoff/pgweb:latest" DOCKER_LATEST_TAG = "sosedoff/pgweb:latest"
LDFLAGS = -s -w LDFLAGS = -s -w
PKG = github.com/sosedoff/pgweb LDFLAGS += -X $(PKG)/pkg/command.GitCommit=$(GIT_COMMIT)
LDFLAGS += -X $(PKG)/pkg/command.BuildTime=$(BUILD_TIME)
LDFLAGS += -X $(PKG)/pkg/command.GoVersion=$(GO_VERSION)
usage: usage:
@echo "" @echo ""
@ -37,16 +42,13 @@ dev:
@echo "You can now execute ./pgweb" @echo "You can now execute ./pgweb"
build: build:
go build go build -ldflags '${LDFLAGS}'
@echo "You can now execute ./pgweb" @echo "You can now execute ./pgweb"
install: install:
go install go install
@echo "You can now execute pgweb" @echo "You can now execute pgweb"
release: LDFLAGS += -X $(PKG)/pkg/command.GitCommit=$(GIT_COMMIT)
release: LDFLAGS += -X $(PKG)/pkg/command.BuildTime=$(BUILD_TIME)
release: LDFLAGS += -X $(PKG)/pkg/command.GoVersion=$(GO_VERSION)
release: clean release: clean
@echo "Building binaries..." @echo "Building binaries..."
@LDFLAGS='${LDFLAGS}' ./script/build_all.sh @LDFLAGS='${LDFLAGS}' ./script/build_all.sh