-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBUILD.bat
136 lines (122 loc) · 4.81 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@echo off
:: Copyright 2019 Michael Thomas Greer
:: Distributed under the Boost Software License, Version 1.0.
:: (See accompanying file LICENSE_1_0.txt
:: or copy at https://www.boost.org/LICENSE_1_0.txt )
if "%1"=="msvc" goto :MSVC
if "%1"=="mingw" goto :MINGW
if "%1"=="clang" goto :CLANG
if "%1"=="clean" goto :CLEAN
if "%1"=="" goto :SEARCH
::----------------------------------------------------------------------------
:USAGE
echo.usage:
echo. BUILD.bat [COMPILER [ARCH]]
echo.
echo.where COMPILER is one of:
echo. msvc -- Make sure you are running at a Native C++ Visual Studio prompt
echo. (either x86 or x64)
echo. clang -- Make sure that Clang is in the path
echo. mingw -- Make sure that MinGW is in the path
echo. clean -- Removes all generated obj and exe files.
echo.
echo.and where ARCH is one of:
echo. -m32
echo. -m64
echo.
echo.If you do not specify a compiler, then the first one found in the %%PATH%%
echo.will be used, preferring Clang over MinGW.
echo.
echo.If you do not specify an architecture, the compiler default is used.
echo.Valid only for Clang and MinGW targets. (If supported. For example,
echo.Clang-CL supports it, but MSYS2's Clang-w64 does not.)
echo.
goto :EOF
::----------------------------------------------------------------------------
:SEARCH
for %%A in ("%PATH:;=";"%") do (
if exist "%%~A\cl.exe" goto :MSVC
if exist "%%~A\clang++.exe" goto :CLANG
if exist "%%~A\g++.exe" goto :MINGW
)
goto :USAGE
::----------------------------------------------------------------------------
:MSVC
:: MSVC must have been initialized properly at the command line, either by
:: running one of the "Native Tools Command Prompt for Visual Studio" shortcuts
:: or by executing "vcvarsall.bat" with a x86 or x64 argument.
echo.MSVC
cl /nologo /EHsc /std:c++17 /Ox /W3 /utf-8 /c utf8_console.cpp /Fo:utf8_console.obj
if ERRORLEVEL 1 goto :ERROR
cl /nologo /EHsc /std:c++14 /Ox /W3 /utf-8 example.cpp utf8_console.obj /Fe:example.ms.no-argv.exe
cl /nologo /EHsc /std:c++14 /Ox /W3 /utf-8 example.cpp utf8_console.obj /Fe:example.ms.argv.exe /DUSE_ARGV
goto :DONE
::----------------------------------------------------------------------------
:MINGW
:: MinGW must be in the %PATH%.
for /F %%I in ('g++ -dumpmachine') do set M=%%I
if "%M:w64=%"=="%M%" goto :MINGW2
:MINGW1
echo.MinGW-w64
echo.utf8_console.cpp
g++ %2 -std=c++17 -O3 -c utf8_console.cpp -o utf8_console.o -municode
if ERRORLEVEL 1 goto :ERROR
echo.example.cpp
g++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.mingw.no-argv.exe -municode -mconsole
echo.example.cpp
g++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.mingw.argv.exe -DUSE_ARGV -municode -mconsole
goto :DONE
:MINGW2
echo.MinGW
echo.utf8_console.cpp
g++ %2 -std=c++17 -O3 -c utf8_console.cpp -o utf8_console.o
if ERRORLEVEL 1 goto :ERROR
echo.example.cpp
g++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.mingw.no-argv.exe
echo.example.cpp
g++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.mingw.argv.exe -DUSE_ARGV
goto :DONE
::----------------------------------------------------------------------------
:CLANG
:: Clang++ must be in the %PATH%.
for /F "delims=" %%I in ('clang++ -dumpmachine') do set M=%%I
if not "%M:msvc=%"=="%M%" goto :CLANG1
if "%M:w64=%"=="%M%" goto :CLANG2
:CLANG1
echo.Clang-CL / Clang-w64
echo.utf8_console.cpp
clang++ %2 -std=c++17 -O3 -c utf8_console.cpp -o utf8_console.o -municode
if ERRORLEVEL 1 goto :ERROR
echo.example.cpp
clang++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.clang.no-argv.exe -municode -mconsole
echo.example.cpp
clang++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.clang.argv.exe -DUSE_ARGV -municode -mconsole
goto :DONE
:CLANG2
echo.Clang
echo.utf8_console.cpp
clang++ %2 -std=c++17 -O3 -c utf8_console.cpp -o utf8_console.o
if ERRORLEVEL 1 goto :ERROR
echo.example.cpp
clang++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.clang.no-argv.exe
echo.example.cpp
clang++ %2 -std=c++14 -O3 -Wall -pedantic-errors example.cpp utf8_console.o -o example.clang.argv.exe -DUSE_ARGV
goto :DONE
::----------------------------------------------------------------------------
:CLEAN
if exist *.o del /F/Q *.o
if exist *.obj del /F/Q *.obj
if exist *.exe del /F/Q *.exe
goto :EOF
::----------------------------------------------------------------------------
:ERROR
echo.Failure to build the utf8_console object file!
goto :EOF
::----------------------------------------------------------------------------
:DONE
if ERRORLEVEL 1 (
echo.Failure to build the example
) else (
echo.Success
)
goto :EOF