Skip to content

Instantly share code, notes, and snippets.

@imshvc
Last active August 2, 2024 05:59
Show Gist options
  • Save imshvc/f6c982fe9a549109558cff929bb31af4 to your computer and use it in GitHub Desktop.
Save imshvc/f6c982fe9a549109558cff929bb31af4 to your computer and use it in GitHub Desktop.
'make' cmd template for 'tcc'
@echo off
rem -------------------------------------------------------
rem Author: Nurudin Imsirovic
rem Abstract: Simple 'make' wrapper for 'tcc' under Windows
rem Created: 2024-08-01 06:35 PM
rem Updated: 2024-08-02 07:59 AM
rem -------------------------------------------------------
setlocal
pushd "%CD%"
set INPUT=sysenv_list.c
set OUTPUT=sysenv_list.exe
set COMPILER_FLAGS=%INPUT% -o %OUTPUT%
set OP=%1
set NEXT_LABEL=Main
if [%OP%] equ [] goto Main
if [%OP%] equ [clean] goto Clean
if [%OP%] equ [run] goto Run
if [%OP%] equ [help] goto Help
if [%OP%] equ [-h] goto Help
if [%OP%] equ [--help] goto Help
if [%OP%] equ [/h] goto Help
if [%OP%] equ [/help] goto Help
if [%OP%] equ [/?] goto Help
goto %NEXT_LABEL%
:Internal_Clean
del /f /q %OUTPUT% >nul 2>&1
del /f /q tcc_stdout.log >nul 2>&1
del /f /q tcc_stderr.log >nul 2>&1
goto %NEXT_LABEL%
:Main
tcc %COMPILER_FLAGS%
echo.OK
goto Terminate
:Help
echo.Usage: make ^<operation^>
echo.
echo. where ^<operation^> consists of:
echo.
echo. help - Print this help
echo. clean - Delete executable
echo. run - clean, build, run
echo.
echo. If ^<operation^> is unspecified,
echo. the following command is run,
echo. and the script terminates:
echo.
echo. tcc %COMPILER_FLAGS%
set ERRORLEVEL=1
goto Terminate
:Clean
set NEXT_LABEL=Clean2
goto Internal_Clean
:Clean2
echo.OK
goto Terminate
:Run
del /f /q %OUTPUT% >nul 2>&1
tcc %COMPILER_FLAGS% >tcc_stdout.log 2>tcc_stderr.log
if [%ERRORLEVEL%] neq [0] (
echo.[tcc stdout]
type tcc_stdout.log
echo.
echo.[tcc stderr]
type tcc_stderr.log
echo.
del /f /q tcc_stdout.log >nul 2>&1
del /f /q tcc_stderr.log >nul 2>&1
goto Terminate
)
call %OUTPUT%
goto Terminate
:Terminate
popd
endlocal
exit /B %ERRORLEVEL%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment