summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xcompile54
-rw-r--r--compile.bat49
2 files changed, 63 insertions, 40 deletions
diff --git a/compile b/compile
index f3af608..072a1eb 100755
--- a/compile
+++ b/compile
@@ -10,52 +10,64 @@ esac
mkdir -p .build/include
+: "${CC:=clang --target=-i686-pc-linux-gnu -fuse-ld=lld}"
+: "${HOSTCC:=clang -fuse-ld=lld}"
+
warnings="-Wall -pedantic -Wno-parentheses -Wno-missing-braces"
+dbg=0
+if [ "$dbg" = 1 ]; then
+ cflags="-Og -g3"
+ ldflags="-Og -g3"
+else
+ cflags="-O2"
+ ldflags="-O2 -s"
+fi
+
objs=
cc() {
objs="$objs .build/${1%%.c}.o"
- clang -m32 -c -O2 -flto -fpic $warnings -I.build/include \
+ $CC -m32 -c -flto -fpic $cflags $warnings -I.build/include \
-D_FILE_OFFSET_BITS=64 -DFILE_BASENAME="${1%%.c}" \
-o ".build/${1%%.c}.o" "src/$1"
}
ld() {
- clang -m32 -shared -O2 -flto -fpic -s -fuse-ld=lld -L.build -ldl -ltier0 \
- -lvstdlib -o sst.so$objs
+ $CC -m32 -shared -flto -fpic -fno-ident -fuse-ld=lld $ldflags \
+ -L.build -ldl -ltier0 -lvstdlib -o sst.so$objs
}
src="\
- autojump.c \
- con_.c \
- demorec.c \
- dbg.c \
- extmalloc.c \
- fixes.c \
- gamedata.c \
- gameinfo.c \
- hook.c \
- kv.c \
- sst.c \
+ autojump.c
+ con_.c
+ dbg.c
+ demorec.c
+ extmalloc.c
+ fixes.c
+ gamedata.c
+ gameinfo.c
+ hook.c
+ kv.c
+ sst.c
udis86.c"
-clang -O2 -fuse-ld=lld $warnings -D_FILE_OFFSET_BITS=64 -o .build/codegen \
+$HOSTCC -O2 -fuse-ld=lld $warnings -D_FILE_OFFSET_BITS=64 -o .build/codegen \
src/build/codegen.c src/build/cmeta.c
-clang -O2 -fuse-ld=lld $warnings -D_FILE_OFFSET_BITS=64 -o .build/mkgamedata \
+$HOSTCC -O2 -fuse-ld=lld $warnings -D_FILE_OFFSET_BITS=64 -o .build/mkgamedata \
src/build/mkgamedata.c src/kv.c
.build/codegen `for s in $src; do echo "src/$s"; done`
.build/mkgamedata gamedata/gamelib.kv gamedata/engine.kv
for s in $src; do cc "$s"; done
-clang -m32 -shared -fpic -fuse-ld=lld -O0 -w -o .build/libtier0.so src/stubs/tier0.c
-clang -m32 -shared -fpic -fuse-ld=lld -O0 -w -o .build/libvstdlib.so src/stubs/vstdlib.c
+$CC -shared -fpic -fuse-ld=lld -O0 -w -o .build/libtier0.so src/stubs/tier0.c
+$CC -shared -fpic -fuse-ld=lld -O0 -w -o .build/libvstdlib.so src/stubs/vstdlib.c
ld
-clang -fuse-ld=lld -O2 -g3 -include test/test.h -o .build/bitbuf.test test/bitbuf.test.c
+$HOSTCC -O2 -g3 -include test/test.h -o .build/bitbuf.test test/bitbuf.test.c
.build/bitbuf.test
# skipping this test on linux for now, since inline hooks aren't compiled in
-#clang -m32 -fuse-ld=lld -O2 -g3 -include test/test.h -o .build/hook.test test/hook.test.c
+#$HOSTCC -m32 -O2 -g3 -include test/test.h -o .build/hook.test test/hook.test.c
#.build/hook.test
-clang -fuse-ld=lld -O2 -g3 -include test/test.h -o .build/kv.test test/kv.test.c
+$HOSTCC -O2 -g3 -include test/test.h -o .build/kv.test test/kv.test.c
.build/kv.test
# vi: sw=4 tw=4 noet tw=80 cc=80
diff --git a/compile.bat b/compile.bat
index da1e2d2..f363eef 100644
--- a/compile.bat
+++ b/compile.bat
@@ -1,45 +1,54 @@
:: This file is dedicated to the public domain.
@echo off
+:: don't leak vars into the environment
+setlocal
+
if not exist .build\ (
md .build
attrib +H .build
)
if not exist .build\include\ md .build\include
+if "%CC%"=="" set CC=clang --target=i686-pc-windows-msvc -fuse-ld=lld
+if "%HOSTCC%"=="" set HOSTCC=clang -fuse-ld=lld
+
set warnings=-Wall -pedantic -Wno-parentheses -Wno-missing-braces
+set dbg=0
+if "%dbg%"=="1" (
+ set cflags=-Og -g
+ set ldflags=-Og -g
+) else (
+ set cflags=-O2
+ set ldflags=-O2
+)
+
set objs=
goto :main
:cc
for /F %%b in ("%1") do set basename=%%~nb
set objs=%objs% .build/%basename%.o
-clang -m32 -c -O2 -flto %warnings% -I.build/include -D_CRT_SECURE_NO_WARNINGS ^
+%CC% -m32 -c -flto %cflags% %warnings% -I.build/include -D_CRT_SECURE_NO_WARNINGS ^
-DFILE_BASENAME=%basename% -o .build/%basename%.o %1 || exit /b
goto :eof
:main
-clang -municode -O2 -fuse-ld=lld %warnings% -D_CRT_SECURE_NO_WARNINGS -ladvapi32 ^
+%HOSTCC% -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -ladvapi32 ^
-o .build/codegen.exe src/build/codegen.c src/build/cmeta.c || exit /b
-clang -municode -O2 -fuse-ld=lld %warnings% -D_CRT_SECURE_NO_WARNINGS -ladvapi32 ^
+%HOSTCC% -municode -O2 %warnings% -D_CRT_SECURE_NO_WARNINGS -ladvapi32 ^
-o .build/mkgamedata.exe src/build/mkgamedata.c src/kv.c || exit /b
-.build\codegen.exe src/autojump.c src/con_.c src/demorec.c src/dbg.c src/fixes.c ^
-src/gamedata.c src/gameinfo.c src/hook.c src/kv.c src/rinput.c src/sst.c src/udis86.c || exit /b
+.build\codegen.exe src/autojump.c src/con_.c src/dbg.c src/demorec.c src/extmalloc.c ^
+src/fixes.c src/gamedata.c src/gameinfo.c src/hook.c src/kv.c src/rinput.c src/sst.c src/udis86.c || exit /b
.build\mkgamedata.exe gamedata/engine.kv gamedata/gamelib.kv || exit /b
-:: llvm-rc doesn't preprocess, looks like it might later:
-:: https://reviews.llvm.org/D100755?id=339141
-:: in the meantime, manually run through clang -E
-clang -E -xc src/dll.rc>.build\dll.pp.rc || exit /b
-llvm-rc /FO .build\dll.res .build\dll.pp.rc || exit /b
-:: might as well remove the temp file afterwards
-del .build\dll.pp.rc
-clang -m32 -shared -fuse-ld=lld -O0 -w -o .build/tier0.dll src/stubs/tier0.c
-clang -m32 -shared -fuse-ld=lld -O0 -w -o .build/vstdlib.dll src/stubs/vstdlib.c
+llvm-rc /FO .build\dll.res src\dll.rc || exit /b
+%CC% -shared -O0 -w -o .build/tier0.dll src/stubs/tier0.c
+%CC% -shared -O0 -w -o .build/vstdlib.dll src/stubs/vstdlib.c
call :cc src/autojump.c || exit /b
call :cc src/con_.c || exit /b
-call :cc src/demorec.c || exit /b
call :cc src/dbg.c || exit /b
+call :cc src/demorec.c || exit /b
call :cc src/extmalloc.c || exit /b
call :cc src/fixes.c || exit /b
call :cc src/gamedata.c || exit /b
@@ -49,17 +58,19 @@ call :cc src/kv.c || exit /b
call :cc src/rinput.c || exit /b
call :cc src/sst.c || exit /b
call :cc src/udis86.c || exit /b
-clang -m32 -fuse-ld=lld -shared -O2 -flto -Wl,/IMPLIB:.build/sst.lib,/Brepro ^
+%CC% -shared -flto %ldflags% -Wl,/IMPLIB:.build/sst.lib,/Brepro ^
-L.build -luser32 -ladvapi32 -lshlwapi -ltier0 -lvstdlib -o sst.dll%objs% .build/dll.res || exit /b
:: get rid of another useless file (can we just not create this???)
del .build\sst.lib
-clang -fuse-ld=lld -O2 -g3 -include test/test.h -o .build/bitbuf.test.exe test/bitbuf.test.c || exit /b
+%HOSTCC% -O2 -g -include test/test.h -o .build/bitbuf.test.exe test/bitbuf.test.c || exit /b
.build\bitbuf.test.exe || exit /b
:: special case: test must be 32-bit
-clang -m32 -fuse-ld=lld -O2 -g3 -ladvapi32 -include test/test.h -o .build/hook.test.exe test/hook.test.c || exit /b
+%HOSTCC% -m32 -O2 -g -ladvapi32 -include test/test.h -o .build/hook.test.exe test/hook.test.c || exit /b
.build\hook.test.exe || exit /b
-clang -fuse-ld=lld -O2 -g3 -include test/test.h -o .build/kv.test.exe test/kv.test.c || exit /b
+%HOSTCC% -O2 -g -include test/test.h -o .build/kv.test.exe test/kv.test.c || exit /b
.build\kv.test.exe || exit /b
+endlocal
+
:: vi: sw=4 tw=4 noet tw=80 cc=80