bt-template/build.bat
2021-02-15 15:45:22 +02:00

108 lines
3 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
@setlocal EnableDelayedExpansion enableextensions
@cls
@cd %~dp0
@SET PROGRAM_NAME=%~dp0
@for /D %%a in ("%PROGRAM_NAME:~0,-1%.txt") do @SET PROGRAM_NAME=%%~na
@SET EABI=arm-none-eabi
@SET LIB_BIP_PATH="..\libbip"
@SET LIB_BIP="%LIB_BIP_PATH%\libbip.a"
@SET GCC_OPT=-mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fno-math-errno -I "%LIB_BIP_PATH%" -c -Os -Wa,-R -Wall -fpie -pie -fpic -mthumb -mlittle-endian -ffunction-sections -fdata-sections
@SET LD_OPT=-lm -lc -EL -N -Os --cref -pie --gc-sections
@SET AS=%EABI%-as
@SET LD=%EABI%-ld
@SET OBJCOPY=%EABI%-objcopy
@SET GCC=%EABI%-gcc
@SET NM=%EABI%-nm
if exist label.txt (
set /p LABEL=< label.txt
) else (
SET LABEL = %PROGRAM_NAME%
)
@call :echoColor 0F "====================================" 1
@call :echoColor 0F "<EFBFBD>足平恥<EFBFBD>言 能恭芬<E681AD>: "
@echo %PROGRAM_NAME%
@call :echoColor 0F "㿺炫走檺桌: "
@echo %COMPILER%
@call :echoColor 0F "====================================" 1
@echo.
@call :echoColor 0F "<EFBFBD><EFBFBD>布 寣桌芥..." 1
@SET PARTNAME=%PROGRAM_NAME%
@call :echoColor 0B "㿺炫走檴剁 "
@call :echoColor 0E "%PARTNAME%" 1
@SET n=1
@for %%f in (*.c) do (
@ SET FILES_TO_COMPILE=!FILES_TO_COMPILE! %%~nf.o
@call :EchoN "%n%. %%~nf.c"
!GCC! !GCC_OPT! -o %%~nf.o %%~nf.c
@if errorlevel 1 goto :error
@call :echoColor 0A "...OK" 1
@SET /a n=n+1)
@SET /a n=n-1
@call :echoColor 0B "<EFBFBD><EFBFBD>: "
@call :echoColor 0E "%n%" 1
@call :echoColor 0B "鷄桌<EFBFBD>..."
%LD% -Map %PARTNAME%.map -o %PROGRAM_NAME%.elf %FILES_TO_COMPILE% %LD_OPT% %LIB_BIP%
@if errorlevel 1 goto :error
if exist label.txt (
%OBJCOPY% %PROGRAM_NAME%.elf --add-section .elf.label=label.txt
)
@call :EchoN "%PROGRAM_NAME%" > name.txt
%OBJCOPY% %PROGRAM_NAME%.elf --add-section .elf.name=name.txt
if exist name.txt del name.txt
@if errorlevel 1 goto :error
@call :echoColor 0A "OK" 1
@call :echoColor 0B "鷄桌<EFBFBD> 悚悌蟡<E6828C>." 1
:done_
@call :echoColor 0A "<EFBFBD>." 1
pause
@goto :EOF
:error
@call :echoColor 4e <20><><EFBFBD>! 1
@endlocal & @SET ERROR=ERROR
@pause
@goto :EOF
::===========================================================
:: A function prints text in first parameter without CRLF
:EchoN
@ <nul set /p strTemp=%~1
@ exit /b 0
::===========================================================
:: <09><EFBFBD> <20><>限悟 摵鉈爸 <20><>限諡 璇乒悔
:: 3 <20><>洛瘔 丟咧 郊 胯摵悟 <20><>乒 砲鄍<E9848D> 摵鉈爸
:: 0 = 𠯫酯諰 8 = 𡤻鳪<F0A1A4BB>
:: 1 = 𪂹郃<F0AA82B9> 9 = 𢅛乒垣-嶁郃<E5B681>
:: 2 = 𤅡咱卿<E592B1> A = 𢅛乒垣-坏咱卿<E592B1>
:: 3 = <20><E68092> B = 𢅛乒垣-ㄝ怒<E68092>
:: 4 = 𢺋<><EFBFBD> C = 𢅛乒垣-芹<><EFBFBD>
:: 5 = 𡆀垣<E59EA3> D = 𢅛乒垣-咧垣<E59EA3>
:: 6 = <20>徉諰 E = 𢅛乒垣-戎徉諰
:: 7 = <20><EFBFBD> F = 颴狙-<E28098>
:echoColor [Color] [Text] [\n]
@ if not defined BS for /F "tokens=1 delims=#" %%i in ('"prompt #$H#& echo on& for %%j in (.) do rem"') do set "BS=%%i"
@ if not exist foo set /p .=.<nul>foo
@ set "regex=%~2" !
@ set "regex=%regex:"="%"
@ findstr /a:%1 /prc:"\." "%regex%\..\foo" nul
@ set /p .=%BS%%BS%%BS%%BS%%BS%%BS%%BS%%BS%%BS%<nul
@ if "%3" neq "" echo.
@exit /b 0
::===========================================================
====================================================