Skip to content

Instantly share code, notes, and snippets.

@WilliamBundy
Created November 6, 2017 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WilliamBundy/51f83810e16bac8ceadec2e08df9f217 to your computer and use it in GitHub Desktop.
Save WilliamBundy/51f83810e16bac8ceadec2e08df9f217 to your computer and use it in GitHub Desktop.
A short example of a make.bat file for windows or a make.sh file for linux
rem Windows Batch is bad.
@echo off
rem Save line space
set msvcdir="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\"
rem get compiler in our current path
if not defined DevEnvDir call %msvcdir%vcvars64.bat >nul
rem Note: you can also use the "visual studio command prompt" that comes
rem installed with visual studio; this part is so that you can use a
rem make.bat file with vim's :make -> nnoremap <leader><Space> :silent make
rem invoke the compiler w/ cl-style arguments
cl.exe /nologo ^
/Iusr/include ^
/Zi ^
main.c ^
/Febin\MyProgram.exe ^
/Fdbin\MyProgram.pdb ^
/link /nologo ^
/LIBPATH:usr/lib ^
SDL2.lib ^
SDL2main.lib ^
/INCREMENTAL:NO ^
/SUBSYSTEM:CONSOLE
REM cl explanation:
REM nologo: disables "Microsoft Optimizing Compiler..."
REM TC: globally use C language -- /TP for global C++
REM W3: enable warning level 3
REM Gd: use cdecl calling convention. Gr is fastcall, Gz is stdcall, Gv is vectorcall
REM GS-: disable buffer security checks
REM Gs****: set maximum size of local variables before there's a stack probe
REM Gm-: disables minimal rebuild
REM fp:fast: use fast floating point
REM EHsc: Only catch C++ exceptions, extern "C" will never throw a C++ execption
REM MTd: statically link against CRT (debug), MD is dynamic link. LD creates a dll
REM wd****: warning disable
REM D****: define ****. Use /Dname#value for numeric values
REM Fe: rename executable (File executable)
REM Fd: rename pdb (File database)
REM link explanation:
REM ****.lib: library to link against
REM SUBSYSTEM:****: use WINDOWS or CONSOLE
REM nologo: same as above
REM INCREMENTAL:NO: don't do incremental linking or generate ikl files
#pretend we're in a make.sh file now
# clang or gcc
clang \
-x c \
--std==c11 \
-Iusr/include \
-g \
main.c \
-o bin\MyProgram.exe \
-Lusr/lib \
-lm \
-lSDL2 \
-lSDL2main \
# -x specify language, c or c++
# -g enable debugging
# -lm is link to math library
# -o is output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment