ソースをダウンロードしてビルド、アーカイブを作成するバッチファイルです。
必要
Visual Studio
2019以降でビルドできます。
こちらの記事を参考にインストールしてください。
2022で動作確認しています。
Git for Windows
公式サイトの「Download」をクリックします。
インストールで特に変更するところはありません。
7-Zip
公式サイトからダウンロードしてインストールします。
バッチファイル
拡張子を.batにして保存します。
@echo off
setlocal
cd /d %~dp0
rem デフォルト設定
set ARCH=x86
set RUNTIME=dynamic
set TARGET=Build
set CONFIG=Release
set REPO_DEL=False
set CLONE_DIR=
set OUT_DIR=package
rem 引数の取得
for %%i in (%*) do (
if /i "%%i" == "help" goto Help
if /i "%%i" == "x86" set ARCH=x86
if /i "%%i" == "x64" set ARCH=x64
if /i "%%i" == "Both" set ARCH=Both
if /i "%%i" == "dynamic" set RUNTIME=dynamic
if /i "%%i" == "MD" set RUNTIME=dynamic
if /i "%%i" == "static" set RUNTIME=static
if /i "%%i" == "MT" set RUNTIME=static
if /i "%%i" == "Build" set TARGET=Build
if /i "%%i" == "Rebuild" set TARGET=Rebuild
if /i "%%i" == "Clean" set TARGET=Clean
if /i "%%i" == "Debug" set CONFIG=Debug
if /i "%%i" == "Release" set CONFIG=Release
if /i "%%i" == "del" set REPO_DEL=True
)
if defined CLONE_DIR (
if not exist "%CLONE_DIR%" md "%CLONE_DIR%"
cd /d "%CLONE_DIR%"
)
if /i "%REPO_DEL%" == "True" (
if exist BonDriver_BDA rd /s /q BonDriver_BDA
if exist BDASpecial-PlexPX rd /s /q BDASpecial-PlexPX
if exist Rijndael4plex rd /s /q Rijndael4plex
if exist BDASpecial-IT35 rd /s /q BDASpecial-IT35
if exist BDASpecial-DD rd /s /q BDASpecial-DD
if exist BDASpecial-LWire rd /s /q BDASpecial-LWire
)
rem ソースのダウンロード
if not exist BonDriver_BDA git clone --recursive https://github.com/radi-sh/BonDriver_BDA.git
if not exist BDASpecial-PlexPX git clone https://github.com/radi-sh/BDASpecial-PlexPX.git
if not exist Rijndael4plex git clone https://github.com/radi-sh/Rijndael4plex.git
if not exist BDASpecial-IT35 git clone https://github.com/radi-sh/BDASpecial-IT35.git
if not exist BDASpecial-DD git clone https://github.com/radi-sh/BDASpecial-DD.git
if not exist BDASpecial-LWire git clone https://github.com/radi-sh/BDASpecial-LWire.git
echo .gitmodules> exclude.txt
echo README.md>> exclude.txt
rem BDASpecialプラグインの配置
xcopy /e /v /y /exclude:exclude.txt BDASpecial-PlexPX BonDriver_BDA >nul
xcopy /e /v /y /exclude:exclude.txt Rijndael4plex BonDriver_BDA >nul
xcopy /e /v /y /exclude:exclude.txt BDASpecial-IT35 BonDriver_BDA >nul
xcopy /e /v /y /exclude:exclude.txt BDASpecial-DD BonDriver_BDA >nul
xcopy /e /v /y /exclude:exclude.txt BDASpecial-LWire BonDriver_BDA >nul
del exclude.txt
cd BonDriver_BDA
rem Visual Studioのインストールフォルダの検索
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
set VS_INSTALL_DIR=%%i
)
rem 開発者コマンドプロンプトの起動
call "%VS_INSTALL_DIR%\Common7\Tools\VsDevCmd.bat" -no_logo
if /i "%ARCH%" == "Both" (
call :Build x86
if errorlevel 1 exit /b 1
call :Build x64
if errorlevel 1 exit /b 1
) else (
call :Build %ARCH%
if errorlevel 1 exit /b 1
)
exit /b 0
:Build
set ARCH=%1
if /i "%ARCH%" == "x86" (
set PLATFORM=Win32
) else (
set PLATFORM=%ARCH%
)
set TOOLSET=v142
if "%VisualStudioVersion%" == "17.0" set TOOLSET=v143
if /i "%CONFIG%" == "Debug" set RUNTIME=
set BUILD_CONFIG=%CONFIG%
if /i "%RUNTIME%" == "static" set BUILD_CONFIG=%BUILD_CONFIG%_Static
rem ビルド
MSBuild BonDriver_BDA.sln /nologo /m /t:%TARGET% /p:Configuration=%BUILD_CONFIG%;Platform=%PLATFORM%;PlatformToolset=%TOOLSET%
if errorlevel 1 exit /b 1
if /i "%TARGET%" == "Clean" exit /b 0
set SRC_DIR=%PLATFORM%\%BUILD_CONFIG%
set DST_DIR=%OUT_DIR%\%ARCH%\%CONFIG%
rem フォルダの準備
if exist "%DST_DIR%" rd /s /q "%DST_DIR%"
md "%DST_DIR%\bin"
md "%DST_DIR%\doc"
rem ファイルの配置
copy /v %SRC_DIR%\*.dll "%DST_DIR%\bin" >nul
copy /v %SRC_DIR%\x3U4Remocon.tvtp "%DST_DIR%\bin" >nul
copy /v doc "%DST_DIR%\doc" >nul
copy /v doc\WinSCard-x3U4 "%DST_DIR%\doc" >nul
copy /v doc\x3U4Remocon "%DST_DIR%\doc" >nul
if /i "%CONFIG%" == "Release" ren "%DST_DIR%\bin\WinSCard-x3U4.dll" WinSCard.dll
rem コミットハッシュの取得
for /f "usebackq tokens=*" %%i in (`git rev-parse --short HEAD`) do set GIT_HASH=%%i
set ARCHIVE_NAME=%OUT_DIR%\BonDriver_BDA_%GIT_HASH%_%ARCH%
rem 7-Zipのインストールフォルダの検索
for /f "usebackq tokens=1,2*" %%i in (`reg query HKLM\Software\7-Zip /v Path`) do if "%%i" == "Path" set PATH=%%k;%PATH%
if exist "%ARCHIVE_NAME%.7z" del "%ARCHIVE_NAME%.7z"
rem アーカイブの作成
7z a "%ARCHIVE_NAME%.7z" ".\%DST_DIR%\*" -mx=9 -ms=on -myx=9
exit /b
:Help
echo %~nx0 [x86^|x64^|Both] [dynamic^|static] [Build^|Rebuild^|Clean] [Debug^|Release] [del]
exit /b
使い方
コマンドプロンプトでバッチファイルを実行するときに引数を指定します。
BonDriver.bat [x86|x64|Both] [dynamic|static] [Build|Rebuild|Clean] [Debug|Release] [del]
上記はhelpを指定すると表示されます。
引数のデフォルト値は以下です。
BonDriver.bat x86 dynamic Build Release
x86は32bit版、x64は64bit版、Bothは32bit版と64bit版の両方です。
dynamicは動的リンク、staticは静的リンクです。
dynamicの代わりにMD、staticの代わりにMTを指定することもできます。
delはソースを削除します。ダウンロードし直す場合に指定します。
バッチファイルと同じフォルダにある BonDriver_BDA\package に出力されます。
ソースのダウンロード先を変更する場合は「set CLONE_DIR=」にフォルダパスを書きます。
アーカイブの出力先を変更する場合は「set OUT_DIR=」にフォルダパスを書きます。


コメント