From 1f5af9b941ac429d485ebcc80c17b5a6862f5a64 Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sun, 16 Jun 2024 10:32:23 -0400 Subject: Add versioning --- Makefile | 27 ++++++++++++++++++++------- sixkcd.go | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index ff38c26..8c1db33 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,37 @@ # sixkcd - Fetch XKCD comics from the command line # See LICENSE file for copyright and license details. +COMMIT := $(shell git rev-parse --short HEAD) +VERSION := $(or $(SIXKCD_VERSION),dev-$(COMMIT)) + +SRC := $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}} {{end}}' ./...) + +CMD := sixkcd PREFIX=/usr/local MANPREFIX=$(PREFIX)/share/man -all: +sixkcd: $(SRC) go mod download - go build -o sixkcd ./sixkcd.go + go mod verify + go build -ldflags "-X main.version=$(VERSION)" -o $(CMD) ./$(CMD).go install: all mkdir -p $(PREFIX)/bin mkdir -p $(MANPREFIX)/man1 - cp -f sixkcd $(PREFIX)/bin - cp -f sixkcd.1 $(MANPREFIX)/man1 + cp -f $(CMD) $(PREFIX)/bin + cp -f $(CMD).1 $(MANPREFIX)/man1 clean: - rm -f ./sixkcd + rm -f ./$(CMD) uninstall: - rm -f $(PREFIX)/bin/sixkcd - rm -f $(MANPREFIX)/man1/sixkcd.1 + rm -f $(PREFIX)/bin/$(CMD) + rm -f $(MANPREFIX)/man1/$(CMD).1 + +info: + @echo "$(CMD)" + @echo "Version: $(VERSION)" + +all: info sixkcd .PHONY: all install clean uninstall help diff --git a/sixkcd.go b/sixkcd.go index b9c13d7..9fdfdc9 100644 --- a/sixkcd.go +++ b/sixkcd.go @@ -22,6 +22,8 @@ const ( target = "info.0.json" ) +var version string + type Comic struct { Month string Num int @@ -40,6 +42,7 @@ func main() { app := &cli.App{ Name: "siXKCD", Usage: "Sixel viewer/fetcher for XKCD Comics", + Version: version, Authors: []*cli.Author{ { Name: "Benjamin Chausse", -- cgit v1.2.3