User:Dart Raiden/Build Miranda: Difference between revisions

From Miranda NG
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 5: Line 5:
@echo off
@echo off


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


:SetVariables
:: Whether to compile TDLib or not
set "BuildTDLib=1"
 
set "Configuration=Release"
set "Configuration=Release"
set "Miranda=%ProgramFiles%\Miranda NG"
set "Miranda=%ProgramFiles%\Miranda NG"
set "Vs=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community"
set "VS=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community"
set "Msbuild=%Vs%\MSBuild\15.0\Bin\MSBuild.exe"
set "MSBuild=%VS%\MSBuild\15.0\Bin\MSBuild.exe"
set "Openssl=D:\dev\openssl"
set "OpenSSLSources=D:\dev\openssl"
set "Path=%ProgramFiles%\NASM;%Path%"
set "Path=%ProgramFiles%\NASM;%Path%"
set "Solution=bin15"
set "Solution=bin15"
set "Sources=D:\dev\miranda-ng"
set "MirandaSources=D:\dev\miranda-ng"


:CleanSources
:: Clean Miranda sources
if exist "%Sources%\%Solution%\%Configuration%64" rd /s /q "%Sources%\%Solution%\%Configuration%64"
if exist "%MirandaSources%\%Solution%\%Configuration%64" (
cd /d "%Sources%"
    rd /s /q "%MirandaSources%\%Solution%\%Configuration%64"
)
cd /d "%MirandaSources%"
call cleaner.bat
call cleaner.bat


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


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


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


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


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


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


:SortCompiledFiles
:: Sort compiled files
cd /d "%Sources%\%Solution%\%Configuration%64"
cd /d "%MirandaSources%\%Solution%\%Configuration%64"
rd /q /s Obj
rd /q /s Obj
for /r %%i in (*.ilk,*.iobj,*.ipdb) do del /q /s %%i
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 %%j in (Icons\*.pdb) do del /q /s %%j
for /r %%k in (*.pdb) do move %%k "%Sources%\%Solution%\%Configuration%64"
for /r %%k in (*.pdb) do move %%k "%MirandaSources%\%Solution%\%Configuration%64"


:KillMiranda
:: Kill Miranda
Taskkill /f /im Miranda64.exe
Taskkill /f /im Miranda64.exe 2>nul


:BackupOldMiranda
:: Backup old Miranda
if exist "%Temp%\Miranda_backup" rd /q /s "%Temp%\Miranda_backup"
if exist "%Temp%\Miranda_backup" (
    rd /q /s "%Temp%\Miranda_backup"
)
xcopy /i /s /y "%Miranda%" "%Temp%\Miranda_backup"
xcopy /i /s /y "%Miranda%" "%Temp%\Miranda_backup"


:UpdateMiranda
:: Update Miranda
xcopy /i /s /y "%Sources%\%Solution%\%Configuration%64" "%Miranda%"
xcopy /i /s /y "%MirandaSources%\%Solution%\%Configuration%64" "%Miranda%"


:BuildOpenssl
:: Build OpenSSL
if exist "%Temp%\OpenSSL" (
    rd /s /q "%Temp%\OpenSSL"
)
xcopy /i /s "%OpenSSLSources%" "%Temp%\OpenSSL"
title Building OpenSSL...
title Building OpenSSL...
cd /d "%Openssl%"
cd /d "%Temp%\OpenSSL"
git apply "%Sources%\tools\openssl\openssl-mir-changes.patch"
git apply "%MirandaSources%\tools\openssl\openssl-mir-changes.patch"
perl "%Openssl%\Configure" shared VC-WIN64A
perl "%Temp%\OpenSSL\Configure" shared VC-WIN64A
nmake
nmake
for %%n in (libcrypto-3.mir,libssl-3.mir) do xcopy /y %%n "%Miranda%\Libs"
if %ErrorLevel% neq 0 (
for %%n in (libcrypto-3.pdb,libssl-3.pdb) do xcopy /y %%n "%Miranda%"
    echo ********** OpenSSL build failed **********
    pause
    exit /b 1
)
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"


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



Latest revision as of 18:59, 9 March 2025

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 "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=%Configuration%
    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=%Configuration%
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=%Configuration%
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 2>nul

:: 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
if exist "%Temp%\OpenSSL" (
    rd /s /q "%Temp%\OpenSSL"
)
xcopy /i /s "%OpenSSLSources%" "%Temp%\OpenSSL"
title Building OpenSSL...
cd /d "%Temp%\OpenSSL"
git apply "%MirandaSources%\tools\openssl\openssl-mir-changes.patch"
perl "%Temp%\OpenSSL\Configure" shared VC-WIN64A
nmake
if %ErrorLevel% neq 0 (
    echo ********** OpenSSL build failed **********
    pause
    exit /b 1
)
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.