xref: /freebsd/contrib/unifdef/scripts/reversion.sh (revision e1e636193db45630c7881246d25902e57c43d24e)
1#!/bin/sh
2
3if [ ! -f version.sh ] && [ ! -d .git ]
4then
5	echo Your copy of unifdef is incomplete 1>&2
6	exit 1
7fi
8
9[ -f version.sh ] && . ./version.sh
10
11if [ -d .git ]
12then
13	GV=$(git describe | sed 's|-g*|.|g;s|[.]|-|')
14	git update-index -q --refresh
15	if git diff-index --quiet HEAD
16	then
17		GD="$(git show --pretty=format:%ai -s HEAD)"
18	else
19		GD="$(date +'%Y-%m-%d %H:%M:%S %z')"
20		GV=$GV.XX
21	fi
22	[ unifdef -nt unifdef.c ] &&
23	[ unifdef -nt unifdef.h ] &&
24		GD="$D"
25	if [ "$GV $GD" != "$V $D" ]
26	then
27		echo "version $V $D"   1>&2
28		echo "     -> $GV $GD" 1>&2
29		V="$GV"
30		D="$GD"
31		echo "V=\"$V\""  >version.sh
32		echo "D=\"$D\"" >>version.sh
33		rm -f version.h
34	fi
35fi
36
37if [ ! -f version.h ]
38then
39	printf '"@(#) $Version: %s $\\n"\n' "$V" >version.h
40	printf '"@(#) $Date: %s $\\n"\n'   "$D" >>version.h
41fi
42