From fe6e3c5252b2effe3d4ac6eadf4766017a43e312 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 27 Apr 2016 16:59:08 +0300 Subject: [PATCH] Build scripts improved, QtCreator build fixed. qmake and travis builds use -j4 for make. --- .gitignore | 2 +- .travis/build.sh | 36 ++++----- Telegram/build/build.sh | 6 +- Telegram/build/deploy.sh | 100 ++++++++++++----------- Telegram/build/makefile_static.sh | 28 +++---- Telegram/build/set_version.bat | 41 +++++----- Telegram/build/set_version.sh | 127 ++++++++++++++++++++++++++++++ 7 files changed, 238 insertions(+), 102 deletions(-) mode change 100644 => 100755 Telegram/build/build.sh mode change 100644 => 100755 Telegram/build/deploy.sh mode change 100644 => 100755 Telegram/build/makefile_static.sh create mode 100755 Telegram/build/set_version.sh diff --git a/.gitignore b/.gitignore index c43eeb70b..f2db043b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/Telegram/Target +/Telegram/build/target /Telegram/GeneratedFiles/ /Telegram/SourceFiles/art/grid.png /Telegram/SourceFiles/art/grid_125x.png diff --git a/.travis/build.sh b/.travis/build.sh index 260e16dc1..eea05c509 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -102,8 +102,8 @@ build() { ./configure -prefix "$srcdir/qt" -release -opensource -confirm-license -qt-zlib \ -qt-libpng -qt-libjpeg -qt-freetype -qt-harfbuzz -qt-pcre -qt-xcb \ -qt-xkbcommon-x11 -no-opengl -static -nomake examples -nomake tests - make --silent -j - make --silent -j install + make --silent -j4 + make --silent -j4 install export PATH="$srcdir/qt/bin:$PATH" @@ -111,28 +111,28 @@ build() { # Build breakpad cd "$srcdir/Libraries/breakpad" ./configure - make --silent -j + make --silent -j4 - info_msg "Build codegen_style" - # Build codegen_style - mkdir -p "$srcdir/tdesktop/Linux/obj/codegen_style/Debug" - cd "$srcdir/tdesktop/Linux/obj/codegen_style/Debug" - qmake CONFIG+=debug "../../../../Telegram/build/qmake/codegen_style/codegen_style.pro" - make --silent -j + info_msg "Build codegen_style" + # Build codegen_style + mkdir -p "$srcdir/tdesktop/Linux/obj/codegen_style/Debug" + cd "$srcdir/tdesktop/Linux/obj/codegen_style/Debug" + qmake CONFIG+=debug "../../../../Telegram/build/qmake/codegen_style/codegen_style.pro" + make --silent -j4 - info_msg "Build codegen_numbers" - # Build codegen_numbers - mkdir -p "$srcdir/tdesktop/Linux/obj/codegen_numbers/Debug" - cd "$srcdir/tdesktop/Linux/obj/codegen_numbers/Debug" - qmake CONFIG+=debug "../../../../Telegram/build/qmake/codegen_numbers/codegen_numbers.pro" - make --silent -j + info_msg "Build codegen_numbers" + # Build codegen_numbers + mkdir -p "$srcdir/tdesktop/Linux/obj/codegen_numbers/Debug" + cd "$srcdir/tdesktop/Linux/obj/codegen_numbers/Debug" + qmake CONFIG+=debug "../../../../Telegram/build/qmake/codegen_numbers/codegen_numbers.pro" + make --silent -j4 info_msg "Build MetaLang" # Build MetaLang mkdir -p "$srcdir/tdesktop/Linux/DebugIntermediateLang" cd "$srcdir/tdesktop/Linux/DebugIntermediateLang" qmake CONFIG+=debug "../../Telegram/MetaLang.pro" - make --silent -j + make --silent -j4 info_msg "Build Telegram Desktop" # Build Telegram Desktop @@ -141,9 +141,9 @@ build() { ./../codegen/Debug/codegen_style "-I./../../Telegram/Resources" "-I./../../Telegram/SourceFiles" "-o./GeneratedFiles/styles" all_files.style --rebuild ./../codegen/Debug/codegen_numbers "-o./GeneratedFiles" "./../../Telegram/Resources/numbers.txt" - ./../DebugLang/MetaLang -lang_in ./../../Telegram/Resources/lang.strings -lang_out ./GeneratedFiles/lang_auto + ./../DebugLang/MetaLang -lang_in ./../../Telegram/Resources/langs/lang.strings -lang_out ./GeneratedFiles/lang_auto qmake CONFIG+=debug "../../Telegram/Telegram.pro" - make -j + make -j4 } check() { diff --git a/Telegram/build/build.sh b/Telegram/build/build.sh old mode 100644 new mode 100755 index 281938622..0834e63c3 --- a/Telegram/build/build.sh +++ b/Telegram/build/build.sh @@ -134,8 +134,12 @@ if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ]; then mkdir -p "$WorkPath/ReleaseIntermediate" cd "$WorkPath/ReleaseIntermediate" "$QMakePath" "$HomePath/Telegram.pro" -r -spec linux-g++ + eval "$HomePath/build/makefile_static.sh" - make + ./../codegen/Debug/codegen_style "-I./../../Telegram/Resources" "-I./../../Telegram/SourceFiles" "-o./GeneratedFiles/styles" all_files.style --rebuild + ./../codegen/Debug/codegen_numbers "-o./GeneratedFiles" "./../../Telegram/Resources/numbers.txt" + ./../DebugLang/MetaLang -lang_in ./../../Telegram/Resources/langs/lang.strings -lang_out ./GeneratedFiles/lang_auto + make -j4 echo "$BinaryName build complete!" if [ ! -f "$ReleasePath/$BinaryName" ]; then diff --git a/Telegram/build/deploy.sh b/Telegram/build/deploy.sh old mode 100644 new mode 100755 index 245960fce..1e9195b3b --- a/Telegram/build/deploy.sh +++ b/Telegram/build/deploy.sh @@ -4,47 +4,59 @@ pushd `dirname $0` > /dev/null FullScriptPath=`pwd` popd > /dev/null -DeployTarget="$1" - -while IFS='' read -r line || [[ -n "$line" ]]; do - set $line - eval $1="$2" -done < Version - -if [ "$BetaVersion" != "0" ]; then - AppVersion="$BetaVersion" - AppVersionStrFull="${AppVersionStr}_${BetaVersion}" - DevParam="-beta $BetaVersion" - BetaKeyFile="tbeta_${AppVersion}_key" -elif [ "$DevChannel" == "0" ]; then - AppVersionStrFull="$AppVersionStr" - DevParam='' -else - AppVersionStrFull="$AppVersionStr.dev" - DevParam='-dev' +if [ ! -d "$FullScriptPath/../../../TelegramPrivate" ]; then + echo "" + echo "This script is for building the production version of Telegram Desktop." + echo "" + echo "For building custom versions please visit the build instructions page at:" + echo "https://github.com/telegramdesktop/tdesktop/#build-instructions" + exit fi -if [ ! -f "Target" ]; then - echo "Deploy target not found!" +Error () { + cd $FullExecPath + echo "$1" exit 1 +} + +DeployTarget="$1" + +if [ ! -f "$FullScriptPath/target" ]; then + Error "Build target not found!" fi while IFS='' read -r line || [[ -n "$line" ]]; do BuildTarget="$line" -done < Target +done < "$FullScriptPath/target" + +while IFS='' read -r line || [[ -n "$line" ]]; do + set $line + eval $1="$2" +done < "$FullScriptPath/version" + +if [ "$BetaVersion" != "0" ]; then + AppVersion="$BetaVersion" + AppVersionStrFull="${AppVersionStr}_${BetaVersion}" + BetaKeyFile="tbeta_${AppVersion}_key" +elif [ "$AlphaChannel" == "0" ]; then + AppVersionStrFull="$AppVersionStr" +else + AppVersionStrFull="$AppVersionStr.alpha" +fi echo "" +HomePath="$FullScriptPath/.." if [ "$BuildTarget" == "linux" ]; then echo "Deploying version $AppVersionStrFull for Linux 64bit.." UpdateFile="tlinuxupd$AppVersion" SetupFile="tsetup.$AppVersionStrFull.tar.xz" - ReleasePath="./../Linux/Release" + ReleasePath="$HomePath/../Linux/Release" RemoteFolder="tlinux" elif [ "$BuildTarget" == "linux32" ]; then echo "Deploying version $AppVersionStrFull for Linux 32bit.." UpdateFile="tlinux32upd$AppVersion" SetupFile="tsetup32.$AppVersionStrFull.tar.xz" - ReleasePath="./../Linux/Release" + ReleasePath="$HomePath/../Linux/Release" RemoteFolder="tlinux32" elif [ "$BuildTarget" == "mac" ]; then DeployMac="0" @@ -71,27 +83,25 @@ elif [ "$BuildTarget" == "mac" ]; then fi UpdateFile="tmacupd$AppVersion" SetupFile="tsetup.$AppVersionStrFull.dmg" - ReleasePath="./../Mac/Release" + ReleasePath="$HomePath/../Mac/Release" RemoteFolder="tmac" - Mac32DeployPath="./../../tother/tmac32/$AppVersionStrMajor/$AppVersionStrFull" + Mac32DeployPath="$HomePath/../../tother/tmac32/$AppVersionStrMajor/$AppVersionStrFull" Mac32UpdateFile="tmac32upd$AppVersion" Mac32SetupFile="tsetup32.$AppVersionStrFull.dmg" Mac32RemoteFolder="tmac32" - WinDeployPath="./../../tother/tsetup/$AppVersionStrMajor/$AppVersionStrFull" + WinDeployPath="$HomePath/../../tother/tsetup/$AppVersionStrMajor/$AppVersionStrFull" WinUpdateFile="tupdate$AppVersion" WinSetupFile="tsetup.$AppVersionStrFull.exe" WinPortableFile="tportable.$AppVersionStrFull.zip" WinRemoteFolder="tsetup" - DropboxPath="./../../../Dropbox/Telegram/deploy/$AppVersionStrMajor" + DropboxPath="/Volumes/Storage/Dropbox/Telegram/deploy/$AppVersionStrMajor" DropboxDeployPath="$DropboxPath/$AppVersionStrFull" DropboxSetupFile="$SetupFile" DropboxMac32SetupFile="$Mac32SetupFile" elif [ "$BuildTarget" == "mac32" ] || [ "$BuildTarget" = "macstore" ]; then - echo "No need to deploy this target." - exit + Error "No need to deploy this target." else - echo "Invalid target!" - exit 1 + Error "Invalid target!" fi DeployPath="$ReleasePath/deploy/$AppVersionStrMajor/$AppVersionStrFull" @@ -105,8 +115,7 @@ if [ "$BetaVersion" != "0" ]; then BetaFilePath="$DeployPath/$BetaKeyFile" fi if [ ! -f "$BetaFilePath" ]; then - echo "Beta key file for $AppVersionStrFull not found :(" - exit 1 + Error "Beta key file for $AppVersionStrFull not found :(" fi while IFS='' read -r line || [[ -n "$line" ]]; do @@ -131,45 +140,38 @@ fi if [ "$BuildTarget" != "mac" ] || [ "$DeployMac" == "1" ]; then if [ ! -f "$DeployPath/$UpdateFile" ]; then - echo "$UpdateFile not found!"; - exit 1 + Error "$UpdateFile not found!"; fi if [ ! -f "$DeployPath/$SetupFile" ]; then - echo "$SetupFile not found!" - exit 1 + Error "$SetupFile not found!" fi fi if [ "$BuildTarget" == "mac" ]; then if [ "$DeployMac32" == "1" ]; then if [ ! -f "$Mac32DeployPath/$Mac32UpdateFile" ]; then - echo "$Mac32UpdateFile not found!" - exit 1 + Error "$Mac32UpdateFile not found!" fi if [ ! -f "$Mac32DeployPath/$Mac32SetupFile" ]; then - echo "$Mac32SetupFile not found!" - exit 1 + Error "$Mac32SetupFile not found!" fi fi if [ "$DeployWin" == "1" ]; then if [ ! -f "$WinDeployPath/$WinUpdateFile" ]; then - echo "$WinUpdateFile not found!" - exit 1 + Error "$WinUpdateFile not found!" fi if [ "$BetaVersion" == "0" ]; then if [ ! -f "$WinDeployPath/$WinSetupFile" ]; then - echo "$WinSetupFile not found!" - exit 1 + Error "$WinSetupFile not found!" fi fi if [ ! -f "$WinDeployPath/$WinPortableFile" ]; then - echo "$WinPortableFile not found!" - exit 1 + Error "$WinPortableFile not found!" fi fi @@ -221,4 +223,6 @@ if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ] || [ "$Build fi fi -echo "Version $AppVersionStrFull was deployed!"; +echo "Version $AppVersionStrFull was deployed!" +cd $FullExecPath + diff --git a/Telegram/build/makefile_static.sh b/Telegram/build/makefile_static.sh old mode 100644 new mode 100755 index f0a4c93c5..12329f9ef --- a/Telegram/build/makefile_static.sh +++ b/Telegram/build/makefile_static.sh @@ -49,17 +49,17 @@ Replace () { } Replace '\-llzma' "$ArchDirPath\/liblzma\.a" -Replace '\-lXi' '$ArchDirPath\/libXi\.a $ArchDirPath\/libXext\.a' -Replace '\-lSM' '$ArchDirPath\/libSM\.a' -Replace '\-lICE' '$ArchDirPath\/libICE\.a' -Replace '\-lfontconfig' '$ArchDirPath\/libfontconfig\.a $ArchDirPath\/libexpat\.a' -Replace '\-lfreetype' '$ArchDirPath\/libfreetype\.a' -Replace '\-lXext' '$ArchDirPath\/libXext\.a' -Replace '\-lopus' '$LocalDirPath\/libopus\.a' -Replace '\-lopenal' '$LocalDirPath\/libopenal\.a' -Replace '\-lavformat' '$LocalDirPath\/libavformat\.a' -Replace '\-lavcodec' '$LocalDirPath\/libavcodec\.a' -Replace '\-lswresample' '$LocalDirPath\/libswresample\.a' -Replace '\-lswscale' '$LocalDirPath\/libswscale\.a' -Replace '\-lavutil' '$LocalDirPath\/libavutil\.a' -Replace '\-lva' '$LocalDirPath\/libva\.a' +Replace '\-lXi' "$ArchDirPath\/libXi\.a $ArchDirPath\/libXext\.a" +Replace '\-lSM' "$ArchDirPath\/libSM\.a" +Replace '\-lICE' "$ArchDirPath\/libICE\.a" +Replace '\-lfontconfig' "$ArchDirPath\/libfontconfig\.a $ArchDirPath\/libexpat\.a" +Replace '\-lfreetype' "$ArchDirPath\/libfreetype\.a" +Replace '\-lXext' "$ArchDirPath\/libXext\.a" +Replace '\-lopus' "$LocalDirPath\/libopus\.a" +Replace '\-lopenal' "$LocalDirPath\/libopenal\.a" +Replace '\-lavformat' "$LocalDirPath\/libavformat\.a" +Replace '\-lavcodec' "$LocalDirPath\/libavcodec\.a" +Replace '\-lswresample' "$LocalDirPath\/libswresample\.a" +Replace '\-lswscale' "$LocalDirPath\/libswscale\.a" +Replace '\-lavutil' "$LocalDirPath\/libavutil\.a" +Replace '\-lva' "$LocalDirPath\/libva\.a" diff --git a/Telegram/build/set_version.bat b/Telegram/build/set_version.bat index e5e69cdd8..7fd78f8d9 100644 --- a/Telegram/build/set_version.bat +++ b/Telegram/build/set_version.bat @@ -7,7 +7,7 @@ set "InputVersion=%1" for /F "tokens=1,2,3,4 delims=. " %%a in ("%InputVersion%") do ( set "VersionMajor=%%a" set "VersionMinor=%%b" - set "VersionMicro=%%c" + set "VersionPatch=%%c" if "%%d" == "" ( set "VersionBeta=0" set "VersionAlpha=0" @@ -30,9 +30,9 @@ if "%VersionMinorCleared%" neq "%VersionMinor%" ( echo Bad minor version! exit /b 1 ) -set /a "VersionMicroCleared=%VersionMicro% %% 1000" -if "%VersionMicroCleared%" neq "%VersionMicro%" ( - echo Bad micro version! +set /a "VersionPatchCleared=%VersionPatch% %% 1000" +if "%VersionPatchCleared%" neq "%VersionPatch%" ( + echo Bad patch version! exit /b 1 ) if "%VersionAlpha%" neq "0" ( @@ -45,7 +45,7 @@ if "%VersionAlpha%" neq "0" ( set "VersionAlphaBool=false" ) -set /a "VersionFull=%VersionMajor% * 1000000 + %VersionMinor% * 1000 + %VersionMicro%" +set /a "VersionFull=%VersionMajor% * 1000000 + %VersionMinor% * 1000 + %VersionPatch%" if "%VersionBeta%" neq "0" ( set /a "VersionBetaCleared=%VersionBeta% %% 1000" if "!VersionBetaCleared!" neq "%VersionBeta%" ( @@ -58,18 +58,19 @@ if "%VersionBeta%" neq "0" ( set "VersionFullBeta=0" ) -set "VersionStr=%VersionMajor%.%VersionMinor%.%VersionMicro%" -set "VersionStrSmall=%VersionMajor%.%VersionMinor%" -if "%VersionMicro%" neq "0" ( - set "VersionStrSmall=%VersionStrSmall%.%VersionMicro%" +set "VersionStr=%VersionMajor%.%VersionMinor%.%VersionPatch%" +if "%VersionPatch%" neq "0" ( + set "VersionStrSmall=%VersionStr%" +) else ( + set "VersionStrSmall=%VersionMajor%.%VersionMinor%" ) if "%VersionAlpha%" neq "0" ( - echo Setting version: %VersionMajor%.%VersionMinor%.%VersionMicro% alpha + echo Setting version: %VersionStr% alpha ) else if "%VersionBeta%" neq "0" ( - echo Setting version: %VersionMajor%.%VersionMinor%.%VersionMicro%.%VersionBeta% closed beta + echo Setting version: %VersionStr%.%VersionBeta% closed beta ) else ( - echo Setting version: %VersionMajor%.%VersionMinor%.%VersionMicro% stable + echo Setting version: %VersionStr% stable ) echo Patching build/version... @@ -95,17 +96,17 @@ call :repl "Replace=(TDESKTOP_VERSION\s+=) (\s*)[&hat;;]+/$1$2 %VersionStrSmall% echo Patching Telegram.rc... set "ResourcePath=%FullScriptPath%..\Resources\winrc\Telegram.rc" -call :repl "Replace=(FILEVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionMicro%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error -call :repl "Replace=(PRODUCTVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionMicro%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error -call :repl "Replace=("FileVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionMicro%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error -call :repl "Replace=("ProductVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionMicro%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=(FILEVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=(PRODUCTVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=("FileVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=("ProductVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error echo Patching Updater.rc... set "ResourcePath=%FullScriptPath%..\Resources\winrc\Updater.rc" -call :repl "Replace=(FILEVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionMicro%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error -call :repl "Replace=(PRODUCTVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionMicro%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error -call :repl "Replace=("FileVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionMicro%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error -call :repl "Replace=("ProductVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionMicro%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=(FILEVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=(PRODUCTVERSION) (\s*)\d+,\d+,\d+,\d+/$1$2 %VersionMajor%,%VersionMinor%,%VersionPatch%,%VersionBeta%" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=("FileVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error +call :repl "Replace=("ProductVersion",) (\s*)"\d+.\d+.\d+.\d+"/$1$2 "%VersionMajor%.%VersionMinor%.%VersionPatch%.%VersionBeta%"" "Filename=%ResourcePath%" || goto :error exit /b diff --git a/Telegram/build/set_version.sh b/Telegram/build/set_version.sh new file mode 100755 index 000000000..175f03cea --- /dev/null +++ b/Telegram/build/set_version.sh @@ -0,0 +1,127 @@ +set -e +pushd `dirname $0` > /dev/null +FullScriptPath=`pwd` +popd > /dev/null + +Error () { + echo "$1" + exit 1 +} + +InputVersion="$1" + +IFS='.' read -ra VersionParts <<< "$InputVersion" +VersionMajor="${VersionParts[0]}" +VersionMinor="${VersionParts[1]}" +VersionPatch="${VersionParts[2]}" +if [ "${VersionParts[3]}" == "" ]; then + VersionBeta=0 + VersionAlpha=0 +elif [ "${VersionParts[3]}" == "alpha" ]; then + VersionBeta=0 + VersionAlpha=1 +else + VersionBeta="${VersionParts[3]}" + VersionAlpha=0 +fi + +VersionMajorCleared=`echo "$VersionMajor % 1000" | bc` +if [ "$VersionMajorCleared" != "$VersionMajor" ]; then + Error "Bad major version!" +fi +VersionMinorCleared=`echo "$VersionMinor % 1000" | bc` +if [ "$VersionMinorCleared" != "$VersionMinor" ]; then + Error "Bad minor version!" +fi +VersionPatchCleared=`echo "$VersionPatch % 1000" | bc` +if [ "$VersionPatchCleared" != "$VersionPatch" ]; then + Error "Bad patch version!" +fi +if [ "$VersionAlpha" != "0" ]; then + if [ "$VersionAlpha" != "1" ]; then + Error "Bad alpha version!" + fi + VersionAlphaBool=true +else + VersionAlphaBool=false +fi + +VersionFull=`echo "$VersionMajor * 1000000 + $VersionMinor * 1000 + $VersionPatch" | bc` +if [ "$VersionBeta" != "0" ]; then + VersionBetaCleared=`echo "$VersionBeta % 1000" | bc` + if [ "$VersionBetaCleared" != "$VersionBeta" ]; then + Error "Bad beta version!" + fi + VersionBetaMul=`echo "$VersionBeta + 1000" | bc` + VersionFullBeta="$VersionFull${VersionBetaMul:1}" +else + VersionFullBeta=0 +fi + +VersionStr="$VersionMajor.$VersionMinor.$VersionPatch" +if [ "$VersionPatch" != "0" ]; then + VersionStrSmall="$VersionStr" +else + VersionStrSmall="$VersionMajor.$VersionMinor" +fi + +if [ "$VersionAlpha" != "0" ]; then + echo "Setting version: $VersionStr alpha" +elif [ "$VersionBeta" != "0" ]; then + echo "Setting version: $VersionStr.$VersionBeta closed beta" +else + echo "Setting version: $VersionStr stable" +fi + +repl () { + Pattern="$1" + Replacement="$2" + File="$3" + CheckCommand="grep -sc '$Pattern' $File" + set +e + CheckCount=`eval $CheckCommand` + set -e + if [ "$CheckCount" -gt 0 ]; then + ReplaceCommand="sed -i 's/$Pattern/$Replacement/g' $File" + eval $ReplaceCommand + else + echo "Not found $Pattern" + Error "While processing $File" + fi +} + +echo "Patching build/version..." +VersionFilePath="$FullScriptPath/version" +repl "\(AppVersion\) \(\s*\)[0-9][0-9]*" "\1\2 $VersionFull" "$VersionFilePath" +repl "\(AppVersionStrMajor\) \(\s*\)[0-9][0-9\.]*" "\1\2 $VersionMajor.$VersionMinor" "$VersionFilePath" +repl "\(AppVersionStrSmall\) \(\s*\)[0-9][0-9\.]*" "\1\2 $VersionStrSmall" "$VersionFilePath" +repl "\(AppVersionStr\) \(\s*\)[0-9][0-9\.]*" "\1\2 $VersionStr" "$VersionFilePath" +repl "\(AlphaChannel\) \(\s*\)[0-9][0-9]*" "\1\2 $VersionAlpha" "$VersionFilePath" +repl "\(BetaVersion\) \(\s*\)[0-9][0-9]*" "\1\2 $VersionFullBeta" "$VersionFilePath" + +echo "Patching core/version.h..." +VersionHeaderPath="$FullScriptPath/../SourceFiles/core/version.h" +repl "\(BETA_VERSION_MACRO\s\s*\)([0-9][0-9]*ULL)" "\1(${VersionFullBeta}ULL)" "$VersionHeaderPath" +repl "\(AppVersion\s\s*=\) \(\s*\)[0-9][0-9]*" "\1\2 $VersionFull" "$VersionHeaderPath" +repl "\(AppVersionStr\s\s*=\) \(\s*\)[^;][^;]*" "\1\2 \"$VersionStrSmall\"" "$VersionHeaderPath" +repl "\(AppAlphaVersion\s\s*=\) \(\s*\)[a-z][a-z]*" "\1\2 $VersionAlphaBool" "$VersionHeaderPath" + +echo "Patching project.pbxproj..." +TelegramProjectPath="$FullScriptPath/../Telegram.xcodeproj/project.pbxproj" +repl "\(TDESKTOP_MAJOR_VERSION\s\s*=\) \(\s*\)[^;][^;]*" "\1\2 $VersionMajor.$VersionMinor" "$TelegramProjectPath" +repl "\(TDESKTOP_VERSION\s\s*=\) \(\s*\)[^;][^;]*" "\1\2 $VersionStrSmall" "$TelegramProjectPath" + +echo "Patching Telegram.rc..." +ResourcePath="$FullScriptPath/../Resources/winrc/Telegram.rc" +repl "\(FILEVERSION\) \(\s*\)[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*" "\1\2 $VersionMajor,$VersionMinor,$VersionPatch,$VersionBeta" "$ResourcePath" +repl "\(PRODUCTVERSION\) \(\s*\)[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*" "\1\2 $VersionMajor,$VersionMinor,$VersionPatch,$VersionBeta" "$ResourcePath" +repl "\(\"FileVersion\",\) \(\s*\)\"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"" "\1\2 \"$VersionMajor.$VersionMinor.$VersionPatch.$VersionBeta\"" "$ResourcePath" +repl "\(\"ProductVersion\",\) \(\s*\)\"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"" "\1\2 \"$VersionMajor.$VersionMinor.$VersionPatch.$VersionBeta\"" "$ResourcePath" + +echo "Patching Updater.rc..." +ResourcePath="$FullScriptPath/../Resources/winrc/Updater.rc" +repl "\(FILEVERSION\) \(\s*\)[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*" "\1\2 $VersionMajor,$VersionMinor,$VersionPatch,$VersionBeta" "$ResourcePath" +repl "\(PRODUCTVERSION\) \(\s*\)[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*,[0-9][0-9]*" "\1\2 $VersionMajor,$VersionMinor,$VersionPatch,$VersionBeta" "$ResourcePath" +repl "\(\"FileVersion\",\) \(\s*\)\"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"" "\1\2 \"$VersionMajor.$VersionMinor.$VersionPatch.$VersionBeta\"" "$ResourcePath" +repl "\(\"ProductVersion\",\) \(\s*\)\"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\"" "\1\2 \"$VersionMajor.$VersionMinor.$VersionPatch.$VersionBeta\"" "$ResourcePath" +