чување 66d4f5d149add8793a4d5fefba3c0d130990cefd
родитељ 7b14d26738376b692729275c6ca274652bcf8846
Аутор: Страхиња Радић <contact@strahinja.org>
Датум: Mon, 11 Mar 2024 12:38:32 +0100
Rebuild when the date or version change
Signed-off-by: Страхиња Радић <contact@strahinja.org>
Diffstat:
измењених датотека: 4, додавања: 41(+), брисања: 15(-)
diff --git a/Makefile b/Makefile
@@ -3,12 +3,12 @@ include config.mk
.SUFFIXES: .1.in .1 .def.h .h.in .h .c .o
.1.in.1:
- sh -x lib/replacepat $< > $@
+ sh -x lib/replacepat $< $@
.h.in.h:
- sh -x lib/replacepat $< > $@
+ sh -x lib/replacepat $< $@
-all: $(PROG) $(MANPAGE)
+all: $(PROG) $(MANPAGE) makedate makeversion
config.h: config.def.h
[ ! -r config.h ] && cp config.def.h config.h || true
@@ -19,11 +19,17 @@ date:
version:
sh lib/makeversion
+makedate:
+ sh lib/makedate
+
+makeversion:
+ sh lib/makeversion
+
poe.o: poe.c config.h draw.h po.h termbox.h util.h version.h
-$(MANPAGE): $(MANPAGE).in version date
+$(MANPAGE): $(MANPAGE).in date version
-version.h: version.h.in version date
+version.h: version.h.in date version
draw.o: draw.c config.h draw.h po.h termbox.h util.h version.h
@@ -51,7 +57,7 @@ uninstall:
rm -f $(PROG) $(BINDIR)/$(PROG)
rmdir $(BINDIR) 2>/dev/null || true
-pack: all version
+pack: all
sh -x lib/mkpack
-.PHONY: all clean install uninstall pack
+.PHONY: clean install makedate makeversion pack uninstall
diff --git a/lib/makedate b/lib/makedate
@@ -9,12 +9,22 @@ e_user=$(id -un)
if [ -d .git ] && command -v git >/dev/null 2>&1; then
if [ "$e_user" = "$user" ]; then
git log --format=format:%cd \
- --date=format:"%B %d, %Y" -1 @ >date
+ --date=format:"%B %d, %Y" -1 @ >date.new
else
su "${user}" -c 'env LC_ALL=C git log --format=format:%cd \
- --date=format:"%B %d, %Y" -1 @' >date
+ --date=format:"%B %d, %Y" -1 @' >date.new
fi
- echo >>date
+ echo >>date.new
else
- printf "%s\n" "$FALLBACKDATE" >date
+ printf "%s\n" "$FALLBACKDATE" >date.new
+fi
+
+if [ -f date ]; then
+ if diff date date.new >/dev/null; then
+ rm date.new
+ else
+ mv date.new date
+ fi
+else
+ mv date.new date
fi
diff --git a/lib/makeversion b/lib/makeversion
@@ -8,11 +8,21 @@ user=$(unalias ls >/dev/null 2>&1 || true; \
e_user=$(id -un)
if [ -d .git ] && command -v git >/dev/null 2>&1; then
if [ "$e_user" = "$user" ]; then
- git describe 2>/dev/null | sed 's/^v//' >version
+ git describe 2>/dev/null | sed 's/^v//' >version.new
else
su "${user}" -c 'git describe' 2>/dev/null |
- sed 's/^v//' >version
+ sed 's/^v//' >version.new
fi
else
- printf "%s\n" "$FALLBACKVER" >version
+ printf "%s\n" "$FALLBACKVER" >version.new
+fi
+
+if [ -f version ]; then
+ if diff version version.new >/dev/null; then
+ rm version.new
+ else
+ mv version.new version
+ fi
+else
+ mv version.new version
fi
diff --git a/lib/replacepat b/lib/replacepat
@@ -2,4 +2,4 @@
# vim: set ft=bash:
DATE=$(cat date)
VERSION=$(cat version)
-sed -e 's|%VERSION%|'"$VERSION"'|g' -e 's|%DATE%|'"$DATE"'|g' $1
+sed -e 's|%VERSION%|'"$VERSION"'|g' -e 's|%DATE%|'"$DATE"'|g' "$1" > "$2"