Last active
February 8, 2021 04:52
-
-
Save kolumb/4d61d9a2c44fcddcd238b6b4b3567776 to your computer and use it in GitHub Desktop.
Build.bat that recompiles only changed source files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem Find and launch x64 Native Tools Command Prompt if needed | |
if not defined DevEnvDir ( | |
if "%VSWHERE%"=="" set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" | |
) | |
if not defined DevEnvDir ( | |
for /f "usebackq tokens=*" %%i in (`call "%VSWHERE%" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do ( | |
set InstallDir=%%i | |
) | |
) | |
if not defined DevEnvDir ( | |
if exist "%InstallDir%\VC\Auxiliary\Build\vcvars64.bat" ( | |
call "%InstallDir%\VC\Auxiliary\Build\vcvars64.bat" | |
) | |
) | |
rem Example for https://github.com/GPUOpen-LibrariesAndSDKs/HelloVulkan | |
set SRC=.\hellovulkan\src | |
set BIN=.\hellovulkan\bin | |
if not exist %BIN% mkdir %BIN% | |
for /f "tokens=* usebackq" %%t in (`time /t`) do ( | |
set BUILD_LAUNCH_START=%DATE% %%t | |
) | |
rem If changes were made to headers or shaders we need to recompile everything | |
if "%1" equ "-B" goto :cond | |
for /F %%a in ('dir /b %SRC%\*.h %SRC%\*.vert %SRC%\*.frag') do ( | |
if "%LAST_BUILD_TIME%" leq "%%~ta" goto :cond | |
) | |
goto :skip | |
:cond | |
echo Rebuiding everything... | |
%VULKAN_SDK%\bin\glslc %SRC%\basic.frag -o %SRC%\basic.spv | |
%VULKAN_SDK%\bin\glslc %SRC%\textured.frag -o %SRC%\textured.spv | |
%VULKAN_SDK%\bin\glslc %SRC%\tri.vert -o %SRC%\tri.spv | |
set CPP_FILES= | |
for /r %%F in (%SRC%\*.cpp) do call set CPP_FILES=%CPP_FILES% "%%F" | |
cl.exe /nologo /EHsc /Fo%BIN%\ /Fe%BIN%\ ^ | |
/I %VULKAN_SDK%\Include ^ | |
%CPP_FILES% ^ | |
%VULKAN_SDK%\Lib\vulkan-1.lib | |
set LAST_BUILD_TIME=%BUILD_LAUNCH_START% | |
exit /B | |
:skip | |
rem recompiling only recently changed sources | |
set LINKING_IS_NEEDED= | |
for %%a in (%SRC%\*.cpp) do ( | |
if "%LAST_BUILD_TIME%" leq "%%~ta" ( | |
echo|set /p="Compiling " | |
cl.exe /c /nologo /EHsc /Fo%BIN%\ /Fe%BIN%\ /I %VULKAN_SDK%\Include %%a | |
set LINKING_IS_NEEDED=yes | |
) | |
) | |
set LAST_BUILD_TIME=%BUILD_LAUNCH_START% | |
rem Only linking if one of the sources was recompiled | |
if defined LINKING_IS_NEEDED ( | |
set OBJ_FILES= | |
for /r %%F in (%BIN%\*.obj) do call set OBJ_FILES=%OBJ_FILES% "%%F" | |
link.exe /nologo ^ | |
%OBJ_FILES% ^ | |
%VULKAN_SDK%\Lib\vulkan-1.lib | |
) else echo Everythins is up-to-date. | |
if defined LINKING_IS_NEEDED ( | |
if %errorlevel% equ 0 echo Linked succesfully! | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment