Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit a1a0802

Browse files
committed
Add makefile
1 parent 7e6f504 commit a1a0802

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
*.dylib
88
pcp$
99

10+
out/**
11+
1012
# Test binary, built with `go test -c`
1113
*.test
1214

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ########################################################## #
2+
# Makefile for Golang Project
3+
# Includes cross-compiling, installation, cleanup
4+
# ########################################################## #
5+
6+
ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
7+
8+
BINARY=pcp
9+
VERSION=0.1.0
10+
BUILD=`git rev-parse HEAD`
11+
PLATFORMS=darwin linux windows
12+
ARCHITECTURES=386 amd64 arm
13+
14+
# Setup linker flags option for build that interoperate with variable names in src code
15+
LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD}"
16+
17+
default: build
18+
19+
all: clean release install
20+
21+
build:
22+
go build ${LDFLAGS} -o ${BINARY} cmd/pcp/pcp.go
23+
24+
release:
25+
$(foreach GOOS, $(PLATFORMS),\
26+
$(foreach GOARCH, $(ARCHITECTURES), $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build -o out/$(BINARY)-$(GOOS)-$(GOARCH) cmd/pcp/pcp.go)))
27+
28+
install:
29+
go install ${LDFLAGS}
30+
31+
# Remove only what we've created
32+
clean:
33+
rm -r out
34+
35+
.PHONY: check clean install release all

cmd/pcp/pcp.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56

67
"github.com/urfave/cli/v2"
@@ -11,17 +12,18 @@ import (
1112
"github.com/dennis-tra/pcp/pkg/send"
1213
)
1314

14-
const (
15+
var (
1516
// Version of the PCP command line tool.
16-
Version = "0.0.1"
17+
Version = "compile-time"
18+
Build = "compile-time"
1719
)
1820

1921
func main() {
2022

2123
app := &cli.App{
2224
Name: "pcp",
2325
Usage: "Peer Copy, a peer-to-peer data transfer tool.",
24-
Version: Version,
26+
Version: fmt.Sprintf("%s+%s", Version, Build[:7]),
2527
EnableBashCompletion: true,
2628
Commands: []*cli.Command{
2729
receive.Command,

0 commit comments

Comments
 (0)