about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2024-01-22 08:07:58 -0800
committerFranck Cuny <franck@fcuny.net>2024-01-22 08:07:58 -0800
commitffd20492d19f547de3456249ed374ba752c2e1ab (patch)
tree90f587e26e77dfd28147e830fa0d87bf7ade28dd
parentdisable linter for yaml (diff)
downloadworld-ffd20492d19f547de3456249ed374ba752c2e1ab.tar.gz
build all the binaries using a Makefile
Add a Makefile to build the local binaries. Rename all the commands
without a dash.

We can build the commands with `make all` or by being explicit, for
example `make bin/x509-info`.

Add a common package to keep track of build information (commit and
build date) so we can reuse the same pattern across all the commands.
Diffstat (limited to '')
-rw-r--r--.gitignore1
-rw-r--r--Makefile24
-rw-r--r--cmd/flakeinfo/main.go (renamed from cmd/flake-info/main.go)0
-rw-r--r--cmd/x509info/README.md (renamed from cmd/x509-info/README.md)0
-rw-r--r--cmd/x509info/main.go (renamed from cmd/x509-info/main.go)11
-rw-r--r--internal/version/main.go12
6 files changed, 41 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 3eceeeb..14d4519 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@
 /.pre-commit-config.yaml
 **/target/
 /*.qcow2
+bin/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9e28dc2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,24 @@
+.PHONY: all build-binaries clean
+
+all: build-binaries
+
+BUILD_DIR=bin
+
+VERSION=$(shell git describe --tag --always --dirty)
+BUILD_DATE ?= $(shell TZ=UTC0 date +%Y-%m-%dT%H:%M:%SZ)
+
+PKG:=github.com/fcuny/world
+
+BINARIES = bin/x509-info bin/flake-info
+
+ALL_BINARIES = $(foreach binary, $(BINARIES), ./$(binary))
+
+bin/%:
+	go build -o $@ \
+		-ldflags "-X $(PKG)/internal/version.Version=${VERSION} -X $(PKG)/internal/version.BuildDate=${BUILD_DATE}" \
+		-trimpath ./cmd/$(subst -,,$*)
+
+build-binaries: $(ALL_BINARIES)
+
+clean:
+	rm -rf bin/
diff --git a/cmd/flake-info/main.go b/cmd/flakeinfo/main.go
index d41f321..d41f321 100644
--- a/cmd/flake-info/main.go
+++ b/cmd/flakeinfo/main.go
diff --git a/cmd/x509-info/README.md b/cmd/x509info/README.md
index 479771c..479771c 100644
--- a/cmd/x509-info/README.md
+++ b/cmd/x509info/README.md
diff --git a/cmd/x509-info/main.go b/cmd/x509info/main.go
index 65ac548..c425c45 100644
--- a/cmd/x509-info/main.go
+++ b/cmd/x509info/main.go
@@ -8,6 +8,8 @@ import (
 	"html/template"
 	"os"
 	"time"
+
+	"github.com/fcuny/world/internal/version"
 )
 
 const usage = `Usage:
@@ -22,8 +24,6 @@ Options:
     -h, --help        Print this message
 `
 
-var Version, BuildDate string
-
 func main() {
 	flag.Usage = func() { fmt.Fprintf(os.Stderr, "%s\n", usage) }
 
@@ -46,11 +46,8 @@ func main() {
 	flag.Parse()
 
 	if versionFlag {
-		if Version != "" {
-			fmt.Printf("version: %s, build on: %s\n", Version, BuildDate)
-			return
-		}
-		fmt.Println("(unknown)")
+		information := version.VersionAndBuildInfo()
+		fmt.Println(information)
 		return
 	}
 
diff --git a/internal/version/main.go b/internal/version/main.go
new file mode 100644
index 0000000..d8a745f
--- /dev/null
+++ b/internal/version/main.go
@@ -0,0 +1,12 @@
+package version
+
+import "fmt"
+
+var Version, BuildDate string
+
+func VersionAndBuildInfo() string {
+	if Version != "" {
+		return fmt.Sprintf("version: %s, build on: %s", Version, BuildDate)
+	}
+	return "(unknown)"
+}