compile.bat 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. :: This file is dedicated to the public domain.
  2. @echo off
  3. :: don't leak vars into the environment
  4. setlocal
  5. if not exist .build\ (
  6. md .build
  7. attrib +H .build
  8. )
  9. if not exist .build\include\ md .build\include
  10. if "%CC%"=="" set CC=clang --target=i686-pc-windows-msvc -fuse-ld=lld
  11. if "%HOSTCC%"=="" set HOSTCC=clang -fuse-ld=lld
  12. set warnings=-Wall -pedantic -Wno-parentheses -Wno-missing-braces ^
  13. -Wno-gnu-zero-variadic-macro-arguments
  14. set dbg=0
  15. :: XXX: -Og would be nice but apparently a bunch of stuff still gets inlined
  16. :: which can be somewhat annoying so -O0 it is. Still using -Og in the linux
  17. :: script; will need to investigate when linux is actually a thing later.
  18. if "%dbg%"=="1" (
  19. set cflags=-O0 -g3
  20. set ldflags=-O0 -g3
  21. ) else (
  22. set cflags=-O2
  23. set ldflags=-O2
  24. )
  25. set objs=
  26. goto :main
  27. :cc
  28. for /F %%b in ("%1") do set basename=%%~nb
  29. set dmodname= -DMODULE_NAME=%basename%
  30. :: ugly annoying special cases
  31. if "%dmodname%"==" -DMODULE_NAME=con_" set dmodname= -DMODULE_NAME=con
  32. if "%dmodname%"==" -DMODULE_NAME=sst" set dmodname=
  33. set objs=%objs% .build/%basename%.o
  34. :: note: we use a couple of C23 things now because otherwise we'd have to wait a
  35. :: year to get anything done. typeof=__typeof prevents pedantic warnings caused
  36. :: by typeof still technically being an extension, and stdbool gives us
  37. :: predefined bool/true/false before compilers start doing that by default
  38. %CC% -m32 -c -flto -mno-stack-arg-probe %cflags% %warnings% -I.build/include ^
  39. -D_CRT_SECURE_NO_WARNINGS -D_DLL -DWIN32_LEAN_AND_MEAN -DNOMINMAX%dmodname% ^
  40. -Dtypeof=__typeof -include stdbool.h -o .build/%basename%.o %1 || exit /b
  41. goto :eof
  42. :src
  43. goto :eof
  44. :main
  45. set src=
  46. :: funny hack to build a list conveniently, lol.
  47. setlocal EnableDelayedExpansion
  48. for /f "tokens=2" %%f in ('findstr /B /C:":+ " "%~nx0"') do set src=!src! src/%%f
  49. setlocal DisableDelayedExpansion
  50. :+ ac.c
  51. :+ alias.c
  52. :+ autojump.c
  53. :+ bind.c
  54. :+ con_.c
  55. :+ chunklets/fastspin.c
  56. :+ chunklets/msg.c
  57. :+ crypto.c
  58. :+ democustom.c
  59. :+ demorec.c
  60. :+ engineapi.c
  61. :+ ent.c
  62. :+ errmsg.c
  63. :+ extmalloc.c
  64. :+ fixes.c
  65. :+ fov.c
  66. :+ gamedata.c
  67. :+ gameinfo.c
  68. :+ hook.c
  69. :+ kv.c
  70. :+ kvsys.c
  71. :+ l4dmm.c
  72. :+ l4dreset.c
  73. :+ l4dwarp.c
  74. :+ nomute.c
  75. :+ nosleep.c
  76. :+ portalcolours.c
  77. :+ rinput.c
  78. :+ sst.c
  79. :+ x86.c
  80. :: just tack these on, whatever (repeated condition because of expansion memes)
  81. if "%dbg%"=="1" set src=%src% src/dbg.c
  82. if "%dbg%"=="1" set src=%src% src/udis86.c
  83. if "%dbg%"=="0" set src=%src% src/wincrt.c
  84. %HOSTCC% -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -include stdbool.h -ladvapi32 ^
  85. -o .build/codegen.exe src/build/codegen.c src/build/cmeta.c || exit /b
  86. %HOSTCC% -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -include stdbool.h ^
  87. -o .build/mkgamedata.exe src/build/mkgamedata.c src/kv.c || exit /b
  88. %HOSTCC% -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -include stdbool.h -ladvapi32 ^
  89. -o .build/mkentprops.exe src/build/mkentprops.c src/kv.c || exit /b
  90. .build\codegen.exe%src% || exit /b
  91. .build\mkgamedata.exe gamedata/engine.kv gamedata/gamelib.kv gamedata/inputsystem.kv gamedata/matchmaking.kv || exit /b
  92. .build\mkentprops.exe gamedata/entprops.kv || exit /b
  93. llvm-rc /FO .build\dll.res src\dll.rc || exit /b
  94. %CC% -shared -O0 -w -o .build/tier0.dll src/stubs/tier0.c
  95. %CC% -shared -O0 -w -o .build/vstdlib.dll src/stubs/vstdlib.c
  96. for %%b in (%src%) do ( call :cc %%b || exit /b )
  97. :: we need different library names for debugging because Microsoft...
  98. :: actually, it's different anyway because we don't use vcruntime for releases
  99. :: any more. see comment in wincrt.c
  100. if "%dbg%"=="1" (
  101. set clibs=-lmsvcrtd -lvcruntimed -lucrtd
  102. ) else (
  103. set clibs=-lucrt
  104. )
  105. %CC% -shared -flto %ldflags% -Wl,/IMPLIB:.build/sst.lib,/Brepro,/nodefaultlib ^
  106. -L.build %clibs% -lkernel32 -luser32 -ladvapi32 -lshlwapi -ld3d9 -ldsound ^
  107. -ltier0 -lvstdlib -lntdll -o sst.dll%objs% .build/dll.res || exit /b
  108. :: get rid of another useless file (can we just not create this???)
  109. del .build\sst.lib
  110. %HOSTCC% -O2 -g -include test/test.h -o .build/bitbuf.test.exe test/bitbuf.test.c || exit /b
  111. .build\bitbuf.test.exe || exit /b
  112. :: special case: test must be 32-bit
  113. %HOSTCC% -m32 -O2 -g -ladvapi32 -include test/test.h -o .build/hook.test.exe test/hook.test.c || exit /b
  114. .build\hook.test.exe || exit /b
  115. %HOSTCC% -O2 -g -include test/test.h -o .build/kv.test.exe test/kv.test.c || exit /b
  116. .build\kv.test.exe || exit /b
  117. %HOSTCC% -O2 -g -include test/test.h -o .build/x86.test.exe test/x86.test.c || exit /b
  118. .build\x86.test.exe || exit /b
  119. endlocal
  120. :: vi: sw=4 tw=4 noet tw=80 cc=80