-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.bat
More file actions
75 lines (66 loc) · 1.82 KB
/
Copy pathcompile.bat
File metadata and controls
75 lines (66 loc) · 1.82 KB
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
@echo off
REM Expected input: FULL_PATH\MAIN_CPP_FILE OR FULL_LIBRARY_PATH
REM - Split the path given to directory and main file
REM - Determine the library path
set dir=%~dp1
set main="%~nx1"
set library=%~dp0%Library
REM If main file given check it exists
if not %main% == "" (
if not exist %1 (
echo usage:
echo compile.bat ^<main_file_path^>
echo.
echo example:
echo - compile the library itself:
echo .\compile.bat .\Library\
echo.
echo - compile user code:
echo .\compile.bat .\SomeCodeDir\main.cpp
echo.
exit
)
)
REM Require cl
echo [*] Initializing...
set vs17comntools=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\
call "%vs17comntools%vcvars32.bat" > nul
echo [+] Ready
REM Cd to the code directory
cd "%dir%"
REM Create directory for obj files
if not exist OBJECT mkdir OBJECT
REM Compile the library itself
if "%dir%" == "%library%\" (
echo [*] Compiling library files...
for /r "%dir%" %%F in (*.cpp) do (
echo | set /p prefix="[*] "
call cl /c /nologo /EHsc /O2 /Oi "%%F" /FoOBJECT\ 2> nul
)
echo [+] Done
pause
exit
)
echo [*] Compiling files...
REM Create obj files
for /r "%dir%" %%F in (*.cpp) do (
echo | set /p prefix="[*] "
call cl /c /nologo /EHsc /O2 /Oi "%%F" /FoOBJECT\ /I "%library%" 2> nul
)
echo [+] Done
REM List all obj files
for /r "%dir%OBJECT\" %%F in (*.obj) do (
call set "list=%%list%% "%%F""
)
for /r "%library%\OBJECT\" %%F in (*.obj) do (
call set "list=%%list%% "%%F""
)
echo [*] Linking...
REM Choose name for exe file based on main file
call set out=%%main%:cpp=exe%%
REM Link all the obj file to an exe file
link /NOLOGO %list% user32.lib gdi32.lib msimg32.lib /OUT:%out% 2> nul
echo [+] Done
pause
REM Run the code
start /MAX "" %out%