PUD: only update version.h when needed
[olsrd.git] / lib / pud / scripts / makeVersionH
1 #!/bin/bash
2
3 set -e
4 set -u
5
6 if [[ ${#} -ne 2 ]]; then
7   echo "Need 2 arguments: outfile version"
8   exit 1
9 fi
10
11 outfile="${1}"
12 version="${2}"
13
14
15 outfileDir="$(dirname "${outfile}")"
16 outfileName="$(basename "${outfile}")"
17 tmpFile="$(mktemp --tmpdir="${outfileDir}" "${outfileName}.XXXXXXXXXX")"
18
19
20 set +e
21 sha="$(git describe 2> /dev/null)"
22 set -e
23
24
25 cat > "${tmpFile}" << EOF
26 #ifndef _PUD_VERSION_H_
27 #define _PUD_VERSION_H_
28
29 #define PLUGIN_VER "${version}"
30 EOF
31
32 if [[ -z "${sha:-}" ]]; then
33   sha="OLSRD_Unknown-g0000000"
34 fi
35
36 cat >> "${tmpFile}" << EOF
37 #define GIT_SHA    "${sha}"
38 EOF
39
40 cat >> "${tmpFile}" << EOF
41
42 #endif /* _PUD_VERSION_H_ */
43 EOF
44
45
46 set +e
47 diff "${outfile}" "${tmpFile}" &> /dev/null
48 declare -i diffResult=$?
49 set -e
50
51 if [[ ${diffResult} -eq 0 ]]; then
52   rm -f "${tmpFile}"
53 else
54   echo "[${outfile}]"
55   mv "${tmpFile}" "${outfile}"
56 fi
57