2022-10-05 21:53:10 +00:00
|
|
|
#!/bin/bash
|
2009-07-11 23:45:51 +00:00
|
|
|
|
2009-07-07 00:32:40 +00:00
|
|
|
# Generate files to be included: only overwrite them if changed so make
|
|
|
|
# won't rebuild everything unless necessary
|
2019-01-15 19:22:29 +00:00
|
|
|
replace_if_differs() {
|
|
|
|
if cmp "$1" "$2" > /dev/null 2>&1; then
|
|
|
|
rm -f "$1"
|
|
|
|
else
|
|
|
|
mv -f "$1" "$2"
|
|
|
|
fi
|
2009-07-07 00:32:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 00:43:01 +00:00
|
|
|
echo "creating libtransmission/version.h"
|
|
|
|
|
2022-10-05 21:53:10 +00:00
|
|
|
major_version=$(grep 'set[(]TR_VERSION_MAJOR' CMakeLists.txt | cut -d \" -f 2)
|
|
|
|
minor_version=$(grep 'set[(]TR_VERSION_MINOR' CMakeLists.txt | cut -d \" -f 2)
|
|
|
|
patch_version=$(grep 'set[(]TR_VERSION_PATCH' CMakeLists.txt | cut -d \" -f 2)
|
|
|
|
beta_number=$(grep 'set[(]TR_VERSION_BETA_NUMBER' CMakeLists.txt | cut -d \" -f 2)
|
|
|
|
if grep -q 'set[(]TR_VERSION_DEV TRUE)' CMakeLists.txt; then
|
|
|
|
is_dev=true
|
|
|
|
else
|
|
|
|
is_dev=false
|
|
|
|
fi
|
2009-05-31 20:22:47 +00:00
|
|
|
|
2022-10-05 21:53:10 +00:00
|
|
|
# derived from above: semver version string. https://semver.org/
|
|
|
|
# '4.0.0-beta.1'
|
|
|
|
# '4.0.0-beta.1.dev' (a dev release between beta 1 and 2)
|
|
|
|
# '4.0.0-beta.2'
|
|
|
|
# '4.0.0'
|
|
|
|
user_agent_prefix="${major_version}.${minor_version}.${patch_version}"
|
|
|
|
if [ "$is_dev" = true ] || [ -n "${beta_number}" ]; then
|
|
|
|
user_agent_prefix="${user_agent_prefix}-"
|
|
|
|
if [ -n "${beta_number}" ]; then
|
|
|
|
user_agent_prefix="${user_agent_prefix}beta.${beta_number}"
|
|
|
|
fi
|
|
|
|
if [ "$is_dev" = true ] && [ -n "${beta_number}" ]; then
|
|
|
|
user_agent_prefix="${user_agent_prefix}."
|
|
|
|
fi
|
|
|
|
if [ "$is_dev" = true ]; then
|
|
|
|
user_agent_prefix="${user_agent_prefix}dev";
|
|
|
|
fi
|
|
|
|
fi
|
2009-05-31 20:22:47 +00:00
|
|
|
|
2022-10-05 21:53:10 +00:00
|
|
|
# derived from above: peer-id prefix. https://www.bittorrent.org/beps/bep_0020.html
|
|
|
|
# chars 4, 5, 6 are major, minor, patch in https://en.wikipedia.org/wiki/Base62
|
|
|
|
# char 7 is '0' for a stable release, 'B' for a beta release, or 'Z' for a dev build
|
|
|
|
# '-TR400B-' (4.0.0 Beta)
|
|
|
|
# '-TR400Z-' (4.0.0 Dev)
|
|
|
|
# '-TR4000-' (4.0.0)
|
|
|
|
BASE62=($(echo {0..9} {A..A} {a..z}))
|
|
|
|
peer_id_prefix="-TR${BASE62[$(( 10#$major_version ))]}${BASE62[$(( 10#$minor_version ))]}${BASE62[$(( 10#$patch_version ))]}"
|
|
|
|
if [ "$is_dev" = true ]; then
|
|
|
|
peer_id_prefix="${peer_id_prefix}Z"
|
|
|
|
elif [ -n "${beta_number}" ]; then
|
|
|
|
peer_id_prefix="${peer_id_prefix}B"
|
|
|
|
else
|
|
|
|
peer_id_prefix="${peer_id_prefix}0"
|
|
|
|
fi
|
|
|
|
peer_id_prefix="${peer_id_prefix}-"
|
2010-10-13 17:09:05 +00:00
|
|
|
|
2016-09-02 19:45:03 +00:00
|
|
|
vcs_revision=
|
2016-09-02 19:02:51 +00:00
|
|
|
vcs_revision_file=REVISION
|
2015-04-24 19:14:56 +00:00
|
|
|
|
2019-01-15 19:22:29 +00:00
|
|
|
if [ -n "$JENKINS_URL" ] && [ -n "$GIT_COMMIT" ]; then
|
|
|
|
vcs_revision=$GIT_COMMIT
|
|
|
|
elif [ -n "$TEAMCITY_PROJECT_NAME" ] && [ -n "$BUILD_VCS_NUMBER" ]; then
|
|
|
|
vcs_revision=$BUILD_VCS_NUMBER
|
2020-10-13 00:15:19 +00:00
|
|
|
elif [ -e ".git" ] && type git > /dev/null 2>&1; then
|
2019-01-15 19:22:29 +00:00
|
|
|
vcs_revision=$(git rev-list --max-count=1 HEAD)
|
2016-09-02 19:02:51 +00:00
|
|
|
elif [ -f "$vcs_revision_file" ]; then
|
2019-01-15 19:22:29 +00:00
|
|
|
vcs_revision=$(cat "$vcs_revision_file")
|
2015-04-24 19:14:56 +00:00
|
|
|
fi
|
|
|
|
|
2016-09-02 19:45:03 +00:00
|
|
|
if [ -n "$vcs_revision" ]; then
|
2019-01-15 19:22:29 +00:00
|
|
|
[ -f "$vcs_revision_file" ] && [ "$(cat "$vcs_revision_file")" = "$vcs_revision" ] || echo "$vcs_revision" > "$vcs_revision_file"
|
2015-04-24 19:14:56 +00:00
|
|
|
else
|
2019-01-15 19:22:29 +00:00
|
|
|
vcs_revision=0
|
|
|
|
rm -f "$vcs_revision_file"
|
2009-05-31 20:22:47 +00:00
|
|
|
fi
|
|
|
|
|
2019-01-15 19:22:29 +00:00
|
|
|
vcs_revision=$(echo $vcs_revision | head -c10)
|
2017-01-14 21:54:56 +00:00
|
|
|
|
2009-07-07 00:32:40 +00:00
|
|
|
cat > libtransmission/version.h.new << EOF
|
2017-01-14 21:54:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2009-07-11 23:45:51 +00:00
|
|
|
#define PEERID_PREFIX "${peer_id_prefix}"
|
|
|
|
#define USERAGENT_PREFIX "${user_agent_prefix}"
|
2016-09-02 19:02:51 +00:00
|
|
|
#define VCS_REVISION "${vcs_revision}"
|
|
|
|
#define VCS_REVISION_NUM ${vcs_revision}
|
2009-07-11 23:45:51 +00:00
|
|
|
#define SHORT_VERSION_STRING "${user_agent_prefix}"
|
2016-09-02 19:02:51 +00:00
|
|
|
#define LONG_VERSION_STRING "${user_agent_prefix} (${vcs_revision})"
|
2009-07-07 00:32:40 +00:00
|
|
|
#define VERSION_STRING_INFOPLIST ${user_agent_prefix}
|
2022-10-05 21:53:10 +00:00
|
|
|
#define BUILD_STRING_INFOPLIST 14714.${major_version}.${minor_version}.${patch_version}
|
2010-10-13 17:09:05 +00:00
|
|
|
#define MAJOR_VERSION ${major_version}
|
|
|
|
#define MINOR_VERSION ${minor_version}
|
2022-10-05 21:53:10 +00:00
|
|
|
#define PATCH_VERSION ${patch_version}
|
2009-05-31 20:22:47 +00:00
|
|
|
EOF
|
2009-07-07 00:32:40 +00:00
|
|
|
|
|
|
|
# Add a release definition
|
|
|
|
case "${peer_id_prefix}" in
|
2019-01-15 19:22:29 +00:00
|
|
|
*X-) echo '#define TR_BETA_RELEASE 1' ;;
|
|
|
|
*Z-) echo '#define TR_NIGHTLY_RELEASE 1' ;;
|
|
|
|
*) echo '#define TR_STABLE_RELEASE 1' ;;
|
2009-07-07 00:32:40 +00:00
|
|
|
esac >> "libtransmission/version.h.new"
|
|
|
|
|
|
|
|
replace_if_differs libtransmission/version.h.new libtransmission/version.h
|