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  if cmp "$1" "$2" > /dev/null 2>&1; then
7    rm -f "$1"
8  else
9    mv -f "$1" "$2"
10  fi
11}
12
13echo "creating libtransmission/version.h"
14
15user_agent_prefix=$(grep m4_define configure.ac | sed "s/[][)(]/,/g" | grep user_agent_prefix | cut -d , -f 6)
16
17peer_id_prefix=$(grep m4_define configure.ac | sed "s/[][)(]/,/g" | grep peer_id_prefix | cut -d , -f 6)
18
19major_version=$(echo "${user_agent_prefix}" | awk -F . '{print $1}')
20minor_version=$(echo "${user_agent_prefix}" | awk -F . '{print $2 + 0}')
21
22vcs_revision=
23vcs_revision_file=REVISION
24
25if [ -n "$JENKINS_URL" ] && [ -n "$GIT_COMMIT" ]; then
26  vcs_revision=$GIT_COMMIT
27elif [ -n "$TEAMCITY_PROJECT_NAME" ] && [ -n "$BUILD_VCS_NUMBER" ]; then
28  vcs_revision=$BUILD_VCS_NUMBER
29elif [ -d ".git" ] && type git > /dev/null 2>&1; then
30  vcs_revision=$(git rev-list --max-count=1 HEAD)
31elif [ -f "$vcs_revision_file" ]; then
32  vcs_revision=$(cat "$vcs_revision_file")
33fi
34
35if [ -n "$vcs_revision" ]; then
36  [ -f "$vcs_revision_file" ] && [ "$(cat "$vcs_revision_file")" = "$vcs_revision" ] || echo "$vcs_revision" > "$vcs_revision_file"
37else
38  vcs_revision=0
39  rm -f "$vcs_revision_file"
40fi
41
42vcs_revision=$(echo $vcs_revision | head -c10)
43
44cat > libtransmission/version.h.new << EOF
45#pragma once
46
47#define PEERID_PREFIX             "${peer_id_prefix}"
48#define USERAGENT_PREFIX          "${user_agent_prefix}"
49#define VCS_REVISION              "${vcs_revision}"
50#define VCS_REVISION_NUM          ${vcs_revision}
51#define SHORT_VERSION_STRING      "${user_agent_prefix}"
52#define LONG_VERSION_STRING       "${user_agent_prefix} (${vcs_revision})"
53#define VERSION_STRING_INFOPLIST  ${user_agent_prefix}
54#define BUILD_STRING_INFOPLIST    14714.${major_version}.${minor_version}
55#define MAJOR_VERSION             ${major_version}
56#define MINOR_VERSION             ${minor_version}
57EOF
58
59# Add a release definition
60case "${peer_id_prefix}" in
61  *X-) echo '#define TR_BETA_RELEASE           1' ;;
62  *Z-) echo '#define TR_NIGHTLY_RELEASE        1' ;;
63  *)   echo '#define TR_STABLE_RELEASE         1' ;;
64esac >> "libtransmission/version.h.new"
65
66replace_if_differs libtransmission/version.h.new libtransmission/version.h
67