-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.bat
105 lines (89 loc) · 3.3 KB
/
build.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
@echo off
setlocal
cd /d "%~dp0"
chcp 65001 > nul
rem unpack arguments
for %%a in (%*) do (
for /f "tokens=1,2 delims=:" %%b IN ("%%a") do (
if [%%c] == [] (set %%b=true) else (set %%b=%%c)
)
)
rem prepare flags
if [%toolset%] == [] set toolset=clang
if [%CRT%] == [] set CRT=static
if [%type%] == [] set type=windows
if [%optimize%] == [] set optimize=release
if [%arch%] == [] set arch=64
if [%WAE%] == [] set WAE=false
set root=%cd%
set code=%root%/code
rem prepare directories
if not exist "build" mkdir "build"
pushd "build"
if not exist "temp" mkdir "temp"
popd
if "%clean%" == "true" (
del "build\temp\*" /s /q > nul
)
rem build
call :build_%toolset%
endlocal
rem declare functions
goto :eof
:build_clang
rem refer to `code/_project.h` for additional info
where -q "clang.exe" || (
set "PATH=%PATH%;C:/Program Files/LLVM/bin/"
where -q "clang.exe" || (
echo.please, install "Clang", https://github.com/llvm/llvm-project/releases
exit /b 1
)
)
echo.[compile data]
pushd "build/temp"
set resource=-nologo
call llvm-rc %resource% "%root%/data/main.rc" -fo "main.res" || exit /b 1
popd
echo.[compile code]
pushd "build/temp"
rem https://clang.llvm.org/docs/CommandGuide/clang.html
rem https://gcc.gnu.org/onlinedocs/
set compiler=-std=c99 -fno-exceptions -fno-rtti
set compiler=%compiler% -ffp-contract=off
set compiler=%compiler% -flto=thin
set compiler=%compiler% ^
-I"%code%" ^
-I"%code%/third_party"
if "%type%" == "console" set compiler=%compiler% -DBUILD_TYPE=BUILD_TYPE_CONSOLE
if "%type%" == "windows" set compiler=%compiler% -DBUILD_TYPE=BUILD_TYPE_WINDOWS
if "%type%" == "dynamic" set compiler=%compiler% -DBUILD_TYPE=BUILD_TYPE_DYNAMIC
if "%optimize%" == "inspect" set compiler=%compiler% -O0 -g -DBUILD_OPT=BUILD_OPT_INSPECT
if "%optimize%" == "develop" set compiler=%compiler% -Og -g -DBUILD_OPT=BUILD_OPT_DEVELOP
if "%optimize%" == "release" set compiler=%compiler% -O2 -DBUILD_OPT=BUILD_OPT_RELEASE
if "%arch%" == "32" set compiler=%compiler% -m32
if "%arch%" == "64" set compiler=%compiler% -m64
if not "%WAE%" == "false" set compiler=%compiler% -Werror -Wall
call clang -c %compiler% "%code%/main.c" -o "main.o" || exit /b 1
popd
echo.[link objects]
pushd "build"
rem https://learn.microsoft.com/cpp/build/reference/linker-options
rem https://learn.microsoft.com/cpp/c-runtime-library/crt-library-features
set linker=-nologo -incremental:no -noimplib
if "%CRT%" == "static" set linker=%linker% -nodefaultlib libucrt.lib libvcruntime.lib libcmt.lib
if "%CRT%" == "dynamic" set linker=%linker% -nodefaultlib ucrt.lib vcruntime.lib msvcrt.lib
set linker=%linker% kernel32.lib user32.lib
if "%type%" == "console" set linker=%linker% -subsystem:console
if "%type%" == "windows" set linker=%linker% -subsystem:windows
if "%type%" == "dynamic" set linker=%linker% -dll
if "%optimize%" == "inspect" set linker=%linker% -debug:full
if "%optimize%" == "develop" set linker=%linker% -debug:full
if "%optimize%" == "release" set linker=%linker% -debug:none
if "%arch%" == "32" set linker=%linker% -machine:x86
if "%arch%" == "64" set linker=%linker% -machine:x64
if not "%WAE%" == "false" set linker=%linker% -WX
call lld-link %linker% ^
"temp/main.o" "temp/main.res" ^
-out:"main.exe" || exit /b 1
popd
goto :eof