User:Dart Raiden/Build Miranda

From Miranda NG
Jump to navigation Jump to search

It is assumed that you have 7-Zip, NASM, Strawberry Perl, and Visual Studion 2017 installed.

build.bat:

@echo off

:: check admin rights
reg query "HKU\S-1-5-19\Environment" >nul 2>&1
if not %ErrorLevel% == 0 (
	echo Please run as administrator^^!
	pause
	exit /b 1
)

:: whether to compile tdlib or not
set "BuildTdlib=1"

set "Configuration=Release"
set "Miranda=%ProgramFiles%\Miranda NG"
set "Vs=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community"
set "Msbuild=%Vs%\MSBuild\15.0\Bin\MSBuild.exe"
set "OpensslSources=D:\dev\openssl"
set "OpensslBuild=%Temp%\OpenSSL"
set "Path=%ProgramFiles%\NASM;%Path%"
set "Solution=bin15"
set "MirandaSources=D:\dev\miranda-ng"

:: clean Miranda sources
if exist "%MirandaSources%\%Solution%\%Configuration%64" rd /s /q "%MirandaSources%\%Solution%\%Configuration%64"
cd /d "%MirandaSources%"
call cleaner.bat

:: update Miranda sources
git --work-tree="%MirandaSources%" --git-dir="%MirandaSources%/.git" pull
:: or you can use something like tortoisegitproc /command:pull /path:"%MirandaSources%"

:: set VS environment variables
call "%Vs%\VC\Auxiliary\Build\vcvarsall.bat" x64

if "%BuildTdlib%"=="1" (
	:: build TDLib
	title Building TDLib...
	"%Msbuild%" "%MirandaSources%\%Solution%\tdlib.sln" /m /t:Rebuild /p:Configuration=Release
	if %ErrorLevel% neq 0 (
		echo ********** TDLib build failed **********
		pause
		exit /b 1
	)
)

:: build Miranda
title Building Miranda...
"%Msbuild%" "%MirandaSources%\%Solution%\my.sln" /m /t:Rebuild /p:Configuration=Release
if %ErrorLevel% neq 0 (
	echo ********** Miranda build failed **********
	pause
	exit /b 1
)

:: build icons
title Building icons...
"%Msbuild%" "%MirandaSources%\%Solution%\my_icons.sln" /m /t:Rebuild /p:Configuration=Release
if %ErrorLevel% neq 0 (
	echo ********** Icons build failed **********
	pause
	exit /b 1
)

:: build langpack
mkdir "%MirandaSources%\%Solution%\%Configuration%64\Languages"
cscript /nologo "%MirandaSources%\tools\lpgen\translate.js" /sourcelang:"russian" /release:"%MirandaSources%\%Solution%\%Configuration%64\Languages\langpack_russian.txt"

:: sort compiled files
cd /d "%MirandaSources%\%Solution%\%Configuration%64"
rd /q /s Obj
for /r %%i in (*.ilk,*.iobj,*.ipdb) do del /q /s %%i
for /r %%j in (Icons\*.pdb) do del /q /s %%j
for /r %%k in (*.pdb) do move %%k "%MirandaSources%\%Solution%\%Configuration%64"

:: kill Miranda
Taskkill /f /im Miranda64.exe

:: backup old Miranda
if exist "%Temp%\Miranda_backup" rd /q /s "%Temp%\Miranda_backup"
xcopy /i /s /y "%Miranda%" "%Temp%\Miranda_backup"

:: update Miranda
xcopy /i /s /y "%MirandaSources%\%Solution%\%Configuration%64" "%Miranda%"

:: build OpenSSL
rd /s /q "%OpensslBuild%"
xcopy /i /s "%OpensslSources%" "%OpensslBuild%"
title Building OpenSSL...
cd /d "%OpensslBuild%"
git apply "%MirandaSources%\tools\openssl\openssl-mir-changes.patch"
perl "%OpensslBuild%\Configure" shared VC-WIN64A
nmake
copy /y libcrypto-3.dll "%Miranda%\Libs\libcrypto-3.mir"
copy /y libssl-3.dll "%Miranda%\Libs\libssl-3.mir"
copy /y libcrypto-3.pdb "%Miranda%\Libs\libcrypto-3.pdb"
copy /y libssl-3.pdb "%Miranda%\Libs\libssl-3.pdb"

:: run Miranda (dirty hack to prevent the app from inheriting elevated permissions)
explorer "%Miranda%\Miranda64.exe"

exit /b 0

my.sln and my_icons.sln are my custom solutions.