@echo off
:: Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
:: SPDX-License-Identifier: Apache-2.0 OR ISC
:: Dynamically generated compiler wrapper script
:: This file is generated by CMake from compiler_wrapper_template.bat.in
::
:: Real compiler: @REAL_COMPILER@
:: Generated on: @CURRENT_TIMESTAMP@
::
:: Purpose: Filter out conflicting -c flags when -S flag is present.
:: CMake always emits -c for static library targets, but the bcm_c_generated_asm
:: target uses -S to produce textual assembly. The two flags are contradictory;
:: this wrapper ensures -S wins regardless of compiler.
setlocal enabledelayedexpansion
:: The real compiler path (filled in by CMake)
set "REAL_COMPILER=@REAL_COMPILER@"
:: Verify the compiler exists
if not exist "!REAL_COMPILER!" (
echo Error: Compiler not found: !REAL_COMPILER! >&2
exit /b 1
)
:: Check if we have any arguments
if "%~1"=="" (
echo Error: No arguments provided to compiler wrapper >&2
echo Usage: %~n0 ^<compiler_args^> >&2
exit /b 1
)
:: Initialize variables
set "has_s_flag=false"
set "has_c_flag=false"
set "filtered_args="
:: First pass: check for conflicting flags
for %%i in (%*) do (
if "%%i"=="-S" set "has_s_flag=true"
if "%%i"=="-c" set "has_c_flag=true"
)
:: Second pass: build filtered arguments
for %%i in (%*) do (
set "include_arg=true"
:: If we have -S flag and current arg is -c, exclude it
if "!has_s_flag!"=="true" (
if "%%i"=="-c" set "include_arg=false"
)
:: Add argument to filtered list if we should include it
if "!include_arg!"=="true" (
if "!filtered_args!"=="" (
set "filtered_args=%%i"
) else (
set "filtered_args=!filtered_args! %%i"
)
)
)
:: Debug output if requested
if not "%COMPILER_WRAPPER_DEBUG%"=="" (
echo WRAPPER DEBUG: Real compiler: !REAL_COMPILER! >&2
if "!has_s_flag!"=="true" (
if "!has_c_flag!"=="true" (
echo WRAPPER DEBUG: Filtered out conflicting -c flag ^(keeping -S^) >&2
)
)
echo WRAPPER DEBUG: Executing: !REAL_COMPILER! !filtered_args! >&2
)
:: Execute the real compiler
"!REAL_COMPILER!" !filtered_args!
exit /b %errorlevel%