Skip to content

Commit

Permalink
Updated Makefile and added support for embedding version.
Browse files Browse the repository at this point in the history
  • Loading branch information
dekobon committed Jul 21, 2017
1 parent e48c966 commit 8a45081
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

# Created by https://www.gitignore.io/api/go,intellij

### Go ###
# Binaries for programs and plugins
*.exe
Expand All @@ -10,6 +7,9 @@

/bin/

### Current Version Resource File ###
/.version

### Glide Go Vendor Directory ###
vendor/

Expand Down Expand Up @@ -86,5 +86,3 @@ modules.xml

# Sonarlint plugin
.idea/sonarlint

# End of https://www.gitignore.io/api/go,intellij
32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PACKAGE = github.com/dekobon/clamav-mirror
DATE ?= $(shell date -u +%FT%T%z)
VERSION ?= $(shell git describe --tags --always --dirty --match=v* 2> /dev/null || \
cat $(CURDIR)/.version 2> /dev/null || echo v0)
GITHASH ?= $(shell git rev-parse HEAD)

GOPATH = $(CURDIR)/.gopath~
BIN = $(GOPATH)/bin
BASE = $(GOPATH)/src/$(PACKAGE)
PKGS = $(or $(PKG),$(shell cd $(BASE) && env GOPATH=$(GOPATH) $(GO) list ./... | grep -v "^$(PACKAGE)/vendor/"))
TESTPKGS = $(shell env GOPATH=$(GOPATH) $(GO) list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))
PACKAGE_ROOT = github.com/dekobon
PACKAGE = $(PACKAGE_ROOT)/clamav-mirror
DATE ?= $(shell date -u +%FT%T%z)
VERSION ?= $(shell cat $(CURDIR)/.version 2> /dev/null || echo unknown)
GITHASH ?= $(shell git rev-parse HEAD)

GOPATH = $(CURDIR)/.gopath~
BIN = $(GOPATH)/bin
BASE = $(GOPATH)/src/$(PACKAGE)
PKGS = $(or $(PKG),$(shell cd $(BASE) && env GOPATH=$(GOPATH) $(GO) list ./... | grep -v "^$(PACKAGE)/vendor/"))
TESTPKGS = $(shell env GOPATH=$(GOPATH) $(GO) list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))

GO = go
GODOC = godoc
Expand All @@ -19,14 +19,14 @@ V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[34;1m▶\033[0m")

#export GOPATH:=$(GOPATH)
export GOPATH:=$(GOPATH)

.PHONY: all
all: fmt lint vendor | $(BASE) sigupdate sigserver

$(BASE): ; $(info $(M) setting GOPATH…)
@mkdir -p $(GOPATH)
@ln -sf $(CURDIR)/src $(GOPATH)/src
@mkdir -p $(GOPATH)/src/github.com
@ln -sf $(CURDIR)/src/$(PACKAGE_ROOT) $(GOPATH)/src/$(PACKAGE_ROOT)
@ln -sf $(CURDIR)/vendor $(GOPATH)/src/vendor

# Tools
Expand Down Expand Up @@ -105,15 +105,15 @@ sigserver:
$(info $(M) building sigserver…) @ ## Build sigupdate binary
$Q cd $(BASE) && $(GO) build \
-tags release \
-ldflags '-X main.githash=$(GITHASH) -X main.buildstamp=$(DATE)' \
-ldflags '-X main.githash=$(GITHASH) -X main.buildstamp=$(DATE) -X main.appversion=$(VERSION)' \
-o $(CURDIR)/bin/sigserver \
$(GOPATH)/src/$(PACKAGE)/sigserver/*.go

sigupdate:
$(info $(M) building sigupdate…) @ ## Build sigserver binary
$Q cd $(BASE) && $(GO) build \
-tags release \
-ldflags '-X main.githash=$(GITHASH) -X main.buildstamp=$(DATE)' \
-ldflags '-X main.githash=$(GITHASH) -X main.buildstamp=$(DATE) -X main.appversion=$(VERSION)' \
-o $(CURDIR)/bin/sigupdate \
$(GOPATH)/src/$(PACKAGE)/sigupdate/*.go

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

var githash = "unknown"
var buildstamp = "unknown"
var appversion = "unknown"

var logger *log.Logger
var logFatal *log.Logger
Expand Down
4 changes: 3 additions & 1 deletion src/github.com/dekobon/clamav-mirror/sigupdate/sigupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

var githash = "unknown"
var buildstamp = "unknown"
var appversion = "unknown"

var logger *log.Logger
var logFatal *log.Logger
Expand Down Expand Up @@ -125,9 +126,10 @@ func parseCliFlags() (bool, string, string, uint16) {
if *versionPart {
fmt.Println("sigupdate")
fmt.Println("")
fmt.Printf("License : MPLv2\n")
fmt.Printf("Version : %v\n", appversion)
fmt.Printf("Git Commit Hash: %v\n", githash)
fmt.Printf("UTC Build Time : %v\n", buildstamp)
fmt.Printf("License : MPLv2\n")

os.Exit(0)
}
Expand Down

0 comments on commit 8a45081

Please sign in to comment.