source: trunk/update-version-h.sh

Last change on this file was 14515, checked in by mikedld, 3 years ago

#5934: Generate REVISION file and use it in case of missing reliable source

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/bin/sh
2
3# Generate files to be included: only overwrite them if changed so make
4# won't rebuild everything unless necessary
5replace_if_differs ()
6{
7    if cmp $1 $2 > /dev/null 2>&1; then
8      rm -f $1
9    else
10      mv -f $1 $2
11    fi
12}
13
14echo "creating libtransmission/version.h"
15
16user_agent_prefix=`grep m4_define configure.ac | sed "s/[][)(]/,/g" | grep user_agent_prefix  | cut -d , -f 6`
17
18peer_id_prefix=`grep m4_define configure.ac | sed "s/[][)(]/,/g" | grep peer_id_prefix  | cut -d , -f 6`
19
20major_version=`echo ${user_agent_prefix} | awk -F . '{print $1}'`
21minor_version=`echo ${user_agent_prefix} | awk -F . '{print $2 + 0}'`
22
23svn_revision_file=REVISION
24svn_revision_reliable=true
25
26if [ -n "$JENKINS_URL" -a -n "$SVN_REVISION" ]; then
27    # Jenkins automated build, use the set environment variables to avoid
28    # version mismatches between java's svn and command line's svn
29    svn_revision=$SVN_REVISION
30elif [ -d ".svn" ] && type svnversion >/dev/null 2>&1; then
31    # If this is a svn tree, and svnversion is available in PATH, use it to
32    # grab the version.
33    svn_revision=`svnversion -n . | cut -d: -f1 | cut -dM -f1 | cut -dS -f1`
34elif [ -f "$svn_revision_file" ]; then
35    svn_revision=`cat "$svn_revision_file"`
36else
37    # Give up and check the source files
38    svn_revision=`awk '/\\$Id: /{ if ($4>i) i=$4 } END {print i}' */*.cc */*.[chm] */*.po`
39    svn_revision_reliable=false
40fi
41
42if $svn_revision_reliable; then
43    [ -f "$svn_revision_file" ] && [ "`cat "$svn_revision_file"`" -eq "$svn_revision" ] || echo "$svn_revision" > "$svn_revision_file"
44else
45    rm -f "$svn_revision_file"
46fi
47
48cat > libtransmission/version.h.new << EOF
49#define PEERID_PREFIX             "${peer_id_prefix}"
50#define USERAGENT_PREFIX          "${user_agent_prefix}"
51#define SVN_REVISION              "${svn_revision}"
52#define SVN_REVISION_NUM          ${svn_revision}
53#define SHORT_VERSION_STRING      "${user_agent_prefix}"
54#define LONG_VERSION_STRING       "${user_agent_prefix} (${svn_revision})"
55#define VERSION_STRING_INFOPLIST  ${user_agent_prefix}
56#define MAJOR_VERSION             ${major_version}
57#define MINOR_VERSION             ${minor_version}
58EOF
59
60# Add a release definition
61case "${peer_id_prefix}" in
62    *X-) echo '#define TR_BETA_RELEASE           1' ;;
63    *Z-) echo '#define TR_NIGHTLY_RELEASE        1' ;;
64    *)   echo '#define TR_STABLE_RELEASE         1' ;;
65esac >> "libtransmission/version.h.new"
66
67replace_if_differs libtransmission/version.h.new libtransmission/version.h
Note: See TracBrowser for help on using the repository browser.