Skip to content

Commit

Permalink
Add makefile (planetdecred#628)
Browse files Browse the repository at this point in the history
* Add makefile

Using a makefile would enable building a binary with build flags &
variables while targeting multiple os.

* Update readme
  • Loading branch information
beansgum authored Sep 16, 2021
1 parent 735323c commit ac2cb6d
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ A cross-platform desktop [SPV](https://docs.decred.org/wallets/spv/) wallet for

## Building

Note: You need to have [Go 1.13](https://golang.org/dl/) or above to build.
Note: You need to have [Go 1.16](https://golang.org/dl/) or above to build.

Follow the [installation](https://gioui.org/doc/install) instructions for gio.

Pkger is required to bundle static resources before building. Install Pkger globally by running
`go get github.com/markbates/pkger/cmd/pkger`

In the root directory, run
`pkger`. A pkged.go file should be silently created in your root directory.

Then `go build`.

## Profiling
Expand Down
22 changes: 17 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"os"
"time"

"gioui.org/app"

Expand All @@ -15,6 +16,12 @@ import (
"github.com/planetdecred/godcr/wallet"
)

var (
Version string = "0.0.0"
BuildDate string
BuildEnv = wallet.DevBuild
)

func main() {
cfg, err := loadConfig()
if err != nil {
Expand All @@ -31,13 +38,18 @@ func main() {

dcrlibwallet.SetLogLevels(cfg.DebugLevel)

var confirms int32 = dcrlibwallet.DefaultRequiredConfirmations

if cfg.SpendUnconfirmed {
confirms = 0
var buildDate time.Time
if BuildEnv == wallet.ProdBuild {
buildDate, err = time.Parse(time.RFC3339, BuildDate)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
} else {
buildDate = time.Now()
}

wal, err := wallet.NewWallet(cfg.HomeDir, cfg.Network, make(chan wallet.Response, 3), confirms)
wal, err := wallet.NewWallet(cfg.HomeDir, cfg.Network, Version, buildDate, make(chan wallet.Response, 3))
if err != nil {
log.Error(err)
return
Expand Down
28 changes: 28 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This how we want to name the binary output
BINARY=godcr

VERSION="0.0.1"
BUILD=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
# dev or prod
BuildEnv="prod"

LDFLAGS=-ldflags "-w -s -X main.Version=${VERSION} -X main.BuildDate=${BUILD} -X main.BuildEnv=${BuildEnv}"

export GOARCH=amd64

all: clean darwin windows

freebsd:
GOOS=freebsd go build -trimpath ${LDFLAGS} -o ${BINARY}-freebsd-${GOARCH}

darwin:
GOOS=darwin go build -trimpath ${LDFLAGS} -o ${BINARY}-darwin-${GOARCH}

windows:
GOOS=windows go build -trimpath ${LDFLAGS} -o ${BINARY}-windows-${GOARCH}.exe

# Cleans our project: deletes old binaries
clean:
-rm -f ${BINARY}-*

.PHONY: clean darwin windows
4 changes: 2 additions & 2 deletions ui/page/about_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func NewAboutPage(l *load.Load) *AboutPage {
card: l.Theme.Card(),
container: &layout.List{Axis: layout.Vertical},
version: l.Theme.Body1("Version"),
versionValue: l.Theme.Body1("v1.5.2"),
versionValue: l.Theme.Body1(l.WL.Wallet.Version()),
buildDate: l.Theme.Body1("Build date"),
buildDateValue: l.Theme.Body1("2020-09-10"),
buildDateValue: l.Theme.Body1(l.WL.Wallet.BuildDate().Format("2006-01-02 15:04:05")),
network: l.Theme.Body1("Network"),
networkValue: l.Theme.Body1(l.WL.Wallet.Net),
license: l.Theme.Body1("License"),
Expand Down
32 changes: 24 additions & 8 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,55 @@ import (
"fmt"
"net/http"
"sort"
"time"

"github.com/planetdecred/dcrlibwallet"
)

const syncID = "godcr"
const (
syncID = "godcr"
DevBuild = "dev"
ProdBuild = "prod"
)

// Wallet represents the wallet back end of the app
type Wallet struct {
multi *dcrlibwallet.MultiWallet
Root, Net string
buildDate time.Time
version string
Send chan Response
Sync chan SyncStatusUpdate
confirms int32
OverallBlockHeight int32
}

// NewWallet initializies an new Wallet instance.
// The Wallet is not loaded until LoadWallets is called.
func NewWallet(root string, net string, send chan Response, confirms int32) (*Wallet, error) {
func NewWallet(root, net, version string, buildDate time.Time, send chan Response) (*Wallet, error) {
if root == "" || net == "" { // This should really be handled by dcrlibwallet
return nil, fmt.Errorf(`root directory or network cannot be ""`)
}

wal := &Wallet{
Root: root,
Net: net,
Sync: make(chan SyncStatusUpdate, 2),
Send: send,
confirms: confirms,
Root: root,
Net: net,
buildDate: buildDate,
version: version,
Sync: make(chan SyncStatusUpdate, 2),
Send: send,
}

return wal, nil
}

func (wal *Wallet) BuildDate() time.Time {
return wal.buildDate
}

func (wal *Wallet) Version() string {
return wal.version
}

func (wal *Wallet) InitMultiWallet() error {
politeiaHost := dcrlibwallet.PoliteiaMainnetHost
if wal.Net == dcrlibwallet.Testnet3 {
Expand Down

0 comments on commit ac2cb6d

Please sign in to comment.