Files
Juliet/new_generate.bat
T
2026-10-17 23:21:16 -04:00

67 lines
2.0 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
cd /D "%~dp0"
:: --- Usage Notes -------------------------------------------------------------
::
:: Generates clangd compile_commands.json and Visual Studio project/solution files.
::
:: Examples:
:: new_generate (generates compile_commands.json and VS files)
:: new_generate compile_commands (generates only compile_commands.json)
:: new_generate vs (generates only vs/new_Juliet.sln and projects)
::
set GEN_TOOL=misc\new_project_gen.exe
set GEN_SRC=tools\new_project_gen.c
:: Auto-detect compiler for building the generator tool
set COMPILER=
where clang.exe >nul 2>nul
if not errorlevel 1 (
set COMPILER=clang
) else (
where cl.exe >nul 2>nul
if not errorlevel 1 (
set COMPILER=cl
) else (
if exist "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" (
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 >nul 2>&1
)
where cl.exe >nul 2>nul
if not errorlevel 1 (
set COMPILER=cl
)
)
)
if "%COMPILER%"=="" (
echo [ERROR] Neither clang nor cl found in PATH.
exit /b 1
)
:: Recompile generator tool if needed
set RECOMPILE=0
if not exist "%GEN_TOOL%" set RECOMPILE=1
if exist "Intermediate\new_project_gen.stamp" (
set /p CACHED_STAMP=<"Intermediate\new_project_gen.stamp"
for %%I in ("%GEN_SRC%") do (
if "%%~tI_%%~zI" neq "!CACHED_STAMP!" set RECOMPILE=1
)
) else set RECOMPILE=1
if "!RECOMPILE!"=="1" (
echo [GENERATE] Compiling %GEN_SRC% -^> %GEN_TOOL%...
if not exist misc mkdir misc
if not exist Intermediate mkdir Intermediate
if "%COMPILER%"=="clang" (
call clang -O2 -Wall -Wextra -Werror "%GEN_SRC%" -o "%GEN_TOOL%" || exit /b 1
) else (
call cl /nologo /O2 /W4 /WX "%GEN_SRC%" /Fe"%GEN_TOOL%" || exit /b 1
)
for %%I in ("%GEN_SRC%") do (echo %%~tI_%%~zI)>"Intermediate\new_project_gen.stamp"
)
"%GEN_TOOL%" %*
exit /b %ERRORLEVEL%