From 465949b73c098698ff7a0a2b0686ece53c712d25 Mon Sep 17 00:00:00 2001 From: Alissa Huskey Date: Sun, 2 Jun 2024 18:40:31 -0600 Subject: [PATCH 1/6] Improved Makefile. --- Makefile | 73 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index d498004c..820415e5 100644 --- a/Makefile +++ b/Makefile @@ -34,41 +34,61 @@ else endif # Dynamically detect/generate version file as necessary -# This file will define a variable called VERSION. -.PHONY: .FORCE-VERSION-FILE -VERSION-FILE: .FORCE-VERSION-FILE +# This file will define a variable called VERSION used in +# both todo.sh and this Makefile. +VERSION-FILE: @./GEN-VERSION-FILE -include VERSION-FILE -# Maybe this will include the version in it. -todo.sh: VERSION-FILE +# dist/build directory name +DISTNAME=todo.txt_cli-$(VERSION) -# For packaging -DISTFILES := todo.cfg todo_completion +# files to copy unmodified into the dist directory +SRC_FILES := todo.cfg todo_completion -DISTNAME=todo.txt_cli-$(VERSION) -dist: $(DISTFILES) todo.sh +# path of SRC_FILES in the dist directory +OUTPUT_FILES := $(patsubst %, $(DISTNAME)/%, $(SRC_FILES)) + +# all dist files +DISTFILES := $(OUTPUT_FILES) $(DISTNAME)/todo.sh + +# create the dist directory +$(DISTNAME): VERSION-FILE mkdir -p $(DISTNAME) - cp -f $(DISTFILES) $(DISTNAME)/ + +# copy SRC_FILES to the dist directory +$(OUTPUT_FILES): $(DISTNAME)/%: % + cp -f $(*) $(DISTNAME)/ + +# generate todo.sh +$(DISTNAME)/todo.sh: VERSION-FILE sed -e 's/@DEV_VERSION@/'$(VERSION)'/' todo.sh > $(DISTNAME)/todo.sh chmod +x $(DISTNAME)/todo.sh + +.PHONY: build +build: $(DISTNAME) $(DISTFILES) ## create the dist directory and files + +.PHONY: dist +dist: build ## create the compressed release files tar cf $(DISTNAME).tar $(DISTNAME) gzip -f -9 $(DISTNAME).tar zip -r -9 $(DISTNAME).zip $(DISTNAME) rm -r $(DISTNAME) .PHONY: clean -clean: test-pre-clean +clean: test-pre-clean VERSION-FILE ## remove dist directory and all release files + rm -rf $(DISTNAME) rm -f $(DISTNAME).tar.gz $(DISTNAME).zip - rm VERSION-FILE -install: installdirs - $(INSTALL_PROGRAM) todo.sh $(DESTDIR)$(bindir)/todo.sh - $(INSTALL_DATA) todo_completion $(DESTDIR)$(datarootdir)/todo.sh +.PHONY: install +install: build installdirs ## local package install + $(INSTALL_PROGRAM) $(DISTNAME)/todo.sh $(DESTDIR)$(bindir)/todo.sh + $(INSTALL_DATA) $(DISTNAME)/todo_completion $(DESTDIR)$(datarootdir)/todo.sh [ -e $(DESTDIR)$(sysconfdir)/todo/config ] || \ - sed "s/^\(export[ \t]*TODO_DIR=\).*/\1~\/.todo/" todo.cfg > $(DESTDIR)$(sysconfdir)/todo/config + sed "s/^\(export[ \t]*TODO_DIR=\).*/\1~\/.todo/" $(DISTNAME)/todo.cfg > $(DESTDIR)$(sysconfdir)/todo/config -uninstall: +.PHONY: uninstall +uninstall: ## uninstall package rm -f $(DESTDIR)$(bindir)/todo.sh rm -f $(DESTDIR)$(datarootdir)/todo rm -f $(DESTDIR)$(sysconfdir)/todo/config @@ -76,6 +96,8 @@ uninstall: rmdir $(DESTDIR)$(datarootdir) rmdir $(DESTDIR)$(sysconfdir)/todo +# create local installation directories +.PHONY: installdirs installdirs: mkdir -p $(DESTDIR)$(bindir) \ $(DESTDIR)$(sysconfdir)/todo \ @@ -87,18 +109,33 @@ installdirs: TESTS = $(wildcard tests/t[0-9][0-9][0-9][0-9]-*.sh) #TEST_OPTIONS=--verbose +# remove test detritus test-pre-clean: rm -rf tests/test-results "tests/trash directory"* +# run tests and generate test result files aggregate-results: $(TESTS) $(TESTS): test-pre-clean cd tests && ./$(notdir $@) $(TEST_OPTIONS) -test: aggregate-results +# run tests, print a test result summary, and remove generated test results +test: aggregate-results ## run tests tests/aggregate-results.sh tests/test-results/t*-* rm -rf tests/test-results # Force tests to get run every time .PHONY: test test-pre-clean aggregate-results $(TESTS) +# generate list of targets from this Makefile +# looks for any lowercase target with a double hash mark (##) on the same line +# and uses the inline comment as the target description +.PHONY: help +.DEFAULT: help +help: ## list public targets + @echo + @echo todo.txt Makefile + @echo + @sed -ne '/^[a-z%-]\+:.*##/ s/:.*##/\t/p' $(word 1, $(MAKEFILE_LIST)) \ + | column -t -s $$'\t' + @echo From 98841b79e42c1f6bc390e7b6c2d99e837fcd590d Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 26 Dec 2024 11:12:25 +0100 Subject: [PATCH 2/6] FIX: Minor: Replace $'\t' with literal tab The default shell (/bin/sh) might not understand the Bash syntax. This happens on Ubuntu 20.04; column produces garbled output then. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 820415e5..69ea7af6 100644 --- a/Makefile +++ b/Makefile @@ -137,5 +137,5 @@ help: ## list public targets @echo todo.txt Makefile @echo @sed -ne '/^[a-z%-]\+:.*##/ s/:.*##/\t/p' $(word 1, $(MAKEFILE_LIST)) \ - | column -t -s $$'\t' + | column -t -s ' ' @echo From b4ab778e28edebc9924a375f8275f9b291619e28 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 26 Dec 2024 11:14:15 +0100 Subject: [PATCH 3/6] Make "help" the default target So far, the version file gets updated, which isn't a meaningful default action and rather incidental. Defaulting to help output that lists all available targets is a much better default. --- Makefile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 69ea7af6..e17e7735 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,19 @@ else datarootdir = $(prefix)/share/bash_completion.d endif +# generate list of targets from this Makefile +# looks for any lowercase target with a double hash mark (##) on the same line +# and uses the inline comment as the target description +.PHONY: help +.DEFAULT: help +help: ## list public targets + @echo + @echo todo.txt Makefile + @echo + @sed -ne '/^[a-z%-]\+:.*##/ s/:.*##/\t/p' $(word 1, $(MAKEFILE_LIST)) \ + | column -t -s ' ' + @echo + # Dynamically detect/generate version file as necessary # This file will define a variable called VERSION used in # both todo.sh and this Makefile. @@ -126,16 +139,3 @@ test: aggregate-results ## run tests # Force tests to get run every time .PHONY: test test-pre-clean aggregate-results $(TESTS) - -# generate list of targets from this Makefile -# looks for any lowercase target with a double hash mark (##) on the same line -# and uses the inline comment as the target description -.PHONY: help -.DEFAULT: help -help: ## list public targets - @echo - @echo todo.txt Makefile - @echo - @sed -ne '/^[a-z%-]\+:.*##/ s/:.*##/\t/p' $(word 1, $(MAKEFILE_LIST)) \ - | column -t -s ' ' - @echo From e9eaacb530ee9ebd977668fee9898f9e95eed5bb Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 26 Dec 2024 11:30:24 +0100 Subject: [PATCH 4/6] GEN-VERSION-FILE: Refactoring: Use "git describe --dirty", don't show closest tag only No need to emulate the dirty addition any longer; Git has this built-in. Use the full long version to avoid accidentally building packages that look like the released version, but contain further commits. The official build should be done after tagging, on the tagged version commit. --- GEN-VERSION-FILE | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/GEN-VERSION-FILE b/GEN-VERSION-FILE index 6308d3ef..9576b76d 100755 --- a/GEN-VERSION-FILE +++ b/GEN-VERSION-FILE @@ -4,18 +4,8 @@ VF=VERSION-FILE DEF_VER=v2.2 -LF=' -' - if test -d .git -o -f .git && - VN=$(git describe --abbrev=0 --tags 2>/dev/null) && - case "$VN" in - *$LF*) (exit 1) ;; - v[0-9]*) - git update-index -q --refresh - test -z "$(git diff-index --name-only HEAD --)" || - VN="$VN-dirty" ;; - esac + VN=$(git describe --dirty --tags 2>/dev/null) then VN=$(echo "$VN" | sed -e 's/-/./g'); else From fd6bab4b6d397d8e84e94ed568c66c239cfd6587 Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 26 Dec 2024 11:32:54 +0100 Subject: [PATCH 5/6] GEN-VERSION-FILE: Minor: Default to 0.0 version, not 2.2 This could be confusing, as there have been 2.1.0 and 2.3.0 releases. --- GEN-VERSION-FILE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GEN-VERSION-FILE b/GEN-VERSION-FILE index 9576b76d..9162b235 100755 --- a/GEN-VERSION-FILE +++ b/GEN-VERSION-FILE @@ -2,7 +2,7 @@ # Based on git's GIT-VERSION-GEN. VF=VERSION-FILE -DEF_VER=v2.2 +DEF_VER=v0.0 if test -d .git -o -f .git && VN=$(git describe --dirty --tags 2>/dev/null) From 1a938c7a0814574da72461a02693d02df94ea96c Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Thu, 26 Dec 2024 11:34:50 +0100 Subject: [PATCH 6/6] GEN-VERSION-FILE: Refactoring: Switch to Bash to use ${parameter//pattern/string} instead of sed --- GEN-VERSION-FILE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GEN-VERSION-FILE b/GEN-VERSION-FILE index 9162b235..aec88dfa 100755 --- a/GEN-VERSION-FILE +++ b/GEN-VERSION-FILE @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # Based on git's GIT-VERSION-GEN. VF=VERSION-FILE @@ -7,7 +7,7 @@ DEF_VER=v0.0 if test -d .git -o -f .git && VN=$(git describe --dirty --tags 2>/dev/null) then - VN=$(echo "$VN" | sed -e 's/-/./g'); + VN=${VN//-/.} else VN="$DEF_VER" fi