3333 datarootdir = $(prefix)/share/bash_completion.d
3434endif
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
79114installdirs :
80115 mkdir -p $(DESTDIR )$(bindir ) \
81116 $(DESTDIR )$(sysconfdir ) /todo \
@@ -87,18 +122,20 @@ installdirs:
87122TESTS = $(wildcard tests/t[0-9][0-9][0-9][0-9]-* .sh)
88123# TEST_OPTIONS=--verbose
89124
125+ # remove test detritus
90126test-pre-clean :
91127 rm -rf tests/test-results " tests/trash directory" *
92128
129+ # run tests and generate test result files
93130aggregate-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