Skip to content

Commit 639e574

Browse files
authored
Makefile fixes, target help and more atomic / idiomatic implementation
Merge pull request #436 from alissa-huskey/makefile
2 parents 5d2727f + 1a938c7 commit 639e574

File tree

2 files changed

+60
-33
lines changed

2 files changed

+60
-33
lines changed

GEN-VERSION-FILE

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22
# Based on git's GIT-VERSION-GEN.
33

44
VF=VERSION-FILE
5-
DEF_VER=v2.2
6-
7-
LF='
8-
'
5+
DEF_VER=v0.0
96

107
if test -d .git -o -f .git &&
11-
VN=$(git describe --abbrev=0 --tags 2>/dev/null) &&
12-
case "$VN" in
13-
*$LF*) (exit 1) ;;
14-
v[0-9]*)
15-
git update-index -q --refresh
16-
test -z "$(git diff-index --name-only HEAD --)" ||
17-
VN="$VN-dirty" ;;
18-
esac
8+
VN=$(git describe --dirty --tags 2>/dev/null)
199
then
20-
VN=$(echo "$VN" | sed -e 's/-/./g');
10+
VN=${VN//-/.}
2111
else
2212
VN="$DEF_VER"
2313
fi

Makefile

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,49 +33,84 @@ else
3333
datarootdir = $(prefix)/share/bash_completion.d
3434
endif
3535

36+
# generate list of targets from this Makefile
37+
# looks for any lowercase target with a double hash mark (##) on the same line
38+
# and uses the inline comment as the target description
39+
.PHONY: help
40+
.DEFAULT: help
41+
help: ## list public targets
42+
@echo
43+
@echo todo.txt Makefile
44+
@echo
45+
@sed -ne '/^[a-z%-]\+:.*##/ s/:.*##/\t/p' $(word 1, $(MAKEFILE_LIST)) \
46+
| column -t -s ' '
47+
@echo
48+
3649
# Dynamically detect/generate version file as necessary
37-
# This file will define a variable called VERSION.
38-
.PHONY: .FORCE-VERSION-FILE
39-
VERSION-FILE: .FORCE-VERSION-FILE
50+
# This file will define a variable called VERSION used in
51+
# both todo.sh and this Makefile.
52+
VERSION-FILE:
4053
@./GEN-VERSION-FILE
4154
-include VERSION-FILE
4255

43-
# Maybe this will include the version in it.
44-
todo.sh: VERSION-FILE
56+
# dist/build directory name
57+
DISTNAME=todo.txt_cli-$(VERSION)
4558

46-
# For packaging
47-
DISTFILES := todo.cfg todo_completion
59+
# files to copy unmodified into the dist directory
60+
SRC_FILES := todo.cfg todo_completion
4861

49-
DISTNAME=todo.txt_cli-$(VERSION)
50-
dist: $(DISTFILES) todo.sh
62+
# path of SRC_FILES in the dist directory
63+
OUTPUT_FILES := $(patsubst %, $(DISTNAME)/%, $(SRC_FILES))
64+
65+
# all dist files
66+
DISTFILES := $(OUTPUT_FILES) $(DISTNAME)/todo.sh
67+
68+
# create the dist directory
69+
$(DISTNAME): VERSION-FILE
5170
mkdir -p $(DISTNAME)
52-
cp -f $(DISTFILES) $(DISTNAME)/
71+
72+
# copy SRC_FILES to the dist directory
73+
$(OUTPUT_FILES): $(DISTNAME)/%: %
74+
cp -f $(*) $(DISTNAME)/
75+
76+
# generate todo.sh
77+
$(DISTNAME)/todo.sh: VERSION-FILE
5378
sed -e 's/@DEV_VERSION@/'$(VERSION)'/' todo.sh > $(DISTNAME)/todo.sh
5479
chmod +x $(DISTNAME)/todo.sh
80+
81+
.PHONY: build
82+
build: $(DISTNAME) $(DISTFILES) ## create the dist directory and files
83+
84+
.PHONY: dist
85+
dist: build ## create the compressed release files
5586
tar cf $(DISTNAME).tar $(DISTNAME)
5687
gzip -f -9 $(DISTNAME).tar
5788
zip -r -9 $(DISTNAME).zip $(DISTNAME)
5889
rm -r $(DISTNAME)
5990

6091
.PHONY: clean
61-
clean: test-pre-clean
92+
clean: test-pre-clean VERSION-FILE ## remove dist directory and all release files
93+
rm -rf $(DISTNAME)
6294
rm -f $(DISTNAME).tar.gz $(DISTNAME).zip
63-
rm VERSION-FILE
6495

65-
install: installdirs
66-
$(INSTALL_PROGRAM) todo.sh $(DESTDIR)$(bindir)/todo.sh
67-
$(INSTALL_DATA) todo_completion $(DESTDIR)$(datarootdir)/todo.sh
96+
.PHONY: install
97+
install: build installdirs ## local package install
98+
$(INSTALL_PROGRAM) $(DISTNAME)/todo.sh $(DESTDIR)$(bindir)/todo.sh
99+
$(INSTALL_DATA) $(DISTNAME)/todo_completion $(DESTDIR)$(datarootdir)/todo.sh
68100
[ -e $(DESTDIR)$(sysconfdir)/todo/config ] || \
69-
sed "s/^\(export[ \t]*TODO_DIR=\).*/\1~\/.todo/" todo.cfg > $(DESTDIR)$(sysconfdir)/todo/config
101+
sed "s/^\(export[ \t]*TODO_DIR=\).*/\1~\/.todo/" $(DISTNAME)/todo.cfg > $(DESTDIR)$(sysconfdir)/todo/config
70102

71-
uninstall:
103+
.PHONY: uninstall
104+
uninstall: ## uninstall package
72105
rm -f $(DESTDIR)$(bindir)/todo.sh
73106
rm -f $(DESTDIR)$(datarootdir)/todo
74107
rm -f $(DESTDIR)$(sysconfdir)/todo/config
75108

76109
rmdir $(DESTDIR)$(datarootdir)
77110
rmdir $(DESTDIR)$(sysconfdir)/todo
78111

112+
# create local installation directories
113+
.PHONY: installdirs
79114
installdirs:
80115
mkdir -p $(DESTDIR)$(bindir) \
81116
$(DESTDIR)$(sysconfdir)/todo \
@@ -87,18 +122,20 @@ installdirs:
87122
TESTS = $(wildcard tests/t[0-9][0-9][0-9][0-9]-*.sh)
88123
#TEST_OPTIONS=--verbose
89124

125+
# remove test detritus
90126
test-pre-clean:
91127
rm -rf tests/test-results "tests/trash directory"*
92128

129+
# run tests and generate test result files
93130
aggregate-results: $(TESTS)
94131

95132
$(TESTS): test-pre-clean
96133
cd tests && ./$(notdir $@) $(TEST_OPTIONS)
97134

98-
test: aggregate-results
135+
# run tests, print a test result summary, and remove generated test results
136+
test: aggregate-results ## run tests
99137
tests/aggregate-results.sh tests/test-results/t*-*
100138
rm -rf tests/test-results
101139

102140
# Force tests to get run every time
103141
.PHONY: test test-pre-clean aggregate-results $(TESTS)
104-

0 commit comments

Comments
 (0)