Skip to content

Instantly share code, notes, and snippets.

@Yanrishatum
Created August 4, 2018 01:06
Show Gist options
  • Save Yanrishatum/5cfe6b7dfe66f6eb5befc67caf44cfd3 to your computer and use it in GitHub Desktop.
Save Yanrishatum/5cfe6b7dfe66f6eb5befc67caf44cfd3 to your computer and use it in GitHub Desktop.
HashLink: HLC compiler for windows.
@echo OFF
REM Somewhat stable hlc compiler.
REM Usage notes:
REM %HASHLINK% should point to hl/include folder
REM %HASHLINK_BIN% should point to hl folder
REM vcvarsall.bat should be available in path OR cl.exe should be available beforehand.
REM Use -h for instructions
set srcPath=.
set mainCl=main.c
set mainExe=main.exe
if "%1"=="--help" goto help
if "%1"=="-h" goto help
if not [%1]==[] goto args
goto build
:args
if [%1]==[] goto build
if "%1"=="-o" goto setExe
if "%1"=="--output" goto setExe
if "%1"=="-i" goto setInput
if "%1"=="--input" goto setInput
if "%1"=="-m" goto setMain
if "%1"=="--main" goto setMain
SHIFT
goto args
:setExe
set mainExe=%2
echo Set executable name to: %2
SHIFT
SHIFT
goto args
:setInput
set srcPath=%2
echo Set source path to: %2
SHIFT
SHIFT
goto args
:setMain
set mainCl=%2
echo Set main class to: %2
SHIFT
SHIFT
goto args
:help
echo compile_hlc.bat [options]
echo Options:
echo -h / --help : Print this text
echo -o / --output ^<exe^> : Set output executable (defaults to 'main.exe')
echo -i / --input ^<path^> : Set C sources path (defaults to '.')
echo -m / --main ^<file^> : Set main class file (defaults to 'main.c')
goto :eof
:build
where /q cl.exe
if ERRORLEVEL 1 (
call "vcvarsall.bat"
)
echo Running cl...
cl /Ox /F%mainExe% -I %HASHLINK% -I %srcPath% %srcPath%/%mainCl% %HASHLINK_BIN%/libhl.lib %HASHLINK_BIN%/fmt.lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment