From 8eecae65bb077d6e89935066ec5d4fbb060168cc Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 28 Dec 2023 15:34:37 +0100 Subject: Last version component is now generated fully automatically --- Makefile | 19 ++++++------------- version | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 13 deletions(-) create mode 100755 version diff --git a/Makefile b/Makefile index 25e2cda..d45757c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -TODAY=1 PREFIX?=/usr/local BINDIR?=$(PREFIX)/bin DATADIR?=$(PREFIX)/share @@ -11,28 +10,22 @@ USERSDIR?=$(LIBDIR)/sysusers.d all: mirror %: %.sh - sed s/@VERSION@/`git rev-list -1 --date=format:%Y%m%d --pretty=%ad --no-commit-header HEAD`.$(TODAY)/g <$< >$@ + sed s/@VERSION@/`./version`/g <$< >$@ chmod +x $@ clean: rm -f mirror install: all - mkdir -p $(DESTDIR)$(BINDIR) - mkdir -p $(DESTDIR)$(MANDIR) - mkdir -p $(DESTDIR)$(SYSDDIR) - mkdir -p $(DESTDIR)$(USERSDIR) - cp -f mirror $(DESTDIR)$(BINDIR)/mirror - cp -f mirror.1 $(DESTDIR)$(MAN1DIR)/mirror.1 - cp -f mirror.timer $(DESTDIR)$(SYSDDIR)/mirror.timer - cp -f mirror.service $(DESTDIR)$(SYSDDIR)/mirror.service - cp -f mirror.conf $(DESTDIR)$(USERSDIR)/mirror.conf + install -m755 -Dt $(DESTDIR)$(BINDIR) mirror + install -m644 -Dt $(DESTDIR)$(MAN1DIR) mirror.1 + install -m644 -Dt $(DESTDIR)$(SYSDDIR) mirror.{timer,service} + install -m644 -Dt $(DESTDIR)$(USERSDIR) mirror.conf uninstall: rm -f $(DESTDIR)$(BINDIR)/mirror rm -f $(DESTDIR)$(MAN1DIR)/mirror.1 - rm -f $(DESTDIR)$(SYSDDIR)/mirror.timer - rm -f $(DESTDIR)$(SYSDDIR)/mirror.service + rm -f $(DESTDIR)$(SYSDDIR)/mirror.{timer,service} rm -f $(DESTDIR)$(USERSDIR)/mirror.conf .PHONY: all clean install uninstall diff --git a/version b/version new file mode 100755 index 0000000..b967060 --- /dev/null +++ b/version @@ -0,0 +1,27 @@ +#!/bin/sh +# TODO: Think of a way to generate version without git repository for source tarballs. Making the script overwrite +# itself with a static version sounds good enough, really. +try_tag() { + local tag + if tag=$(git describe --exact-match --tags --dirty=-dirty 2>/dev/null); then + case "${tag}" in + *-dirty) return 1;; + *) echo "${tag}"; return 0;; + esac + fi + return 1 +} + + +if ! version=$(try_tag); then + fmt=%Y%m%d + set -- $(git rev-list --date=format:${fmt} --pretty=%ad --no-commit-header --since=yesterday HEAD) + if [ $# -gt 0 ]; then + suffix=$# + git diff-index --quiet HEAD -- || suffix=$(( $# + 1 )) + version="$1.${suffix}" + else + version="$(date +${fmt}).1" + fi +fi +echo "${version}" -- cgit v1.1