xref: /freebsd/contrib/ntp/scripts/build/genver (revision 4232f826683298e85d469c0ef17259cecd13b2c7)
1#! /bin/sh
2
3# possible usage: $0 [-f] [version.m4] [version.def]
4#
5# -f would be 'force the update'
6
7force=0
8outputs=
9for i in $*
10do
11    case "$i" in
12     -f)
13	force=1
14	;;
15     *version.m4)
16	outputs="m4/version.m4 $outputs"
17	;;
18     *version.def)
19	outputs="include/version.def $outputs"
20	;;
21     *version.texi)
22	outputs="include/version.texi $outputs"
23	;;
24     *) echo "Unrecognized option: $i"
25	exit 1
26	;;
27    esac
28done
29
30case "$outputs" in
31 '') outputs="m4/version.m4 include/version.def include/version.texi" ;;
32esac
33
34set -e
35
36. ../packageinfo.sh
37
38dversion=`../scripts/build/VersionName -p ../packageinfo.sh`
39
40set +e
41
42# Create intermediate files in $TEMPDIR defaulting it to /tmp
43# if not set.  This avoids races when multiple builds run in
44# parallel on shared source.
45
46TEMPDIR=${TEMPDIR=/tmp}
47
48case "$outputs" in
49 *version.m4*)
50    echo "m4_define([VERSION_NUMBER],[${dversion}])" > "${TEMPDIR}/version.m4+"
51    cmp -s "${TEMPDIR}/version.m4+" m4/version.m4
52    rc=$?
53    case "$force$rc" in
54     00)
55	rm -f "${TEMPDIR}/version.m4+"
56	;;
57     *)
58	mv "${TEMPDIR}/version.m4+" m4/version.m4
59	;;
60    esac
61    ;;
62esac
63
64case "$outputs" in
65 *version.def*)
66    echo "version = '${dversion}';" > "${TEMPDIR}/version.def+"
67    cmp -s "${TEMPDIR}/version.def+" include/version.def
68    rc=$?
69    case "$force$rc" in
70     00)
71	rm -f "${TEMPDIR}/version.def+"
72	;;
73     *)
74	mv "${TEMPDIR}/version.def+" include/version.def
75	;;
76    esac
77    ;;
78esac
79
80case "$outputs" in
81 *version.texi*)
82    echo "@set UPDATED `date +'%d %B %Y'`"	>  "${TEMPDIR}/version.texi+"
83    echo "@set EDITION $dversion"		>> "${TEMPDIR}/version.texi+"
84    echo "@set VERSION $dversion"		>> "${TEMPDIR}/version.texi+"
85    cmp -s "${TEMPDIR}/version.texi+" include/version.texi
86    rc=$?
87    case "$force$rc" in
88     00)
89	rm -f "${TEMPDIR}/version.texi+"
90	;;
91     *)
92	mv "${TEMPDIR}/version.texi+" include/version.texi
93	;;
94    esac
95    ;;
96esac
97