OSDN Git Service

Code cleanup.
[mhash384/mhash384.git] / Make.cmd
1 @echo off
2 setlocal enabledelayedexpansion
3 cd /d "%~dp0"
4
5 REM ///////////////////////////////////////////////////////////////////////////
6 REM // Setup environment
7 REM ///////////////////////////////////////////////////////////////////////////
8
9 REM Build Tool-Chain
10 set "MSVC_PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
11 set "GIT2_PATH=C:\Program Files\Git\bin"
12 set "JAVA_HOME=C:\Program Files\Java\jdk1.8.0_131"
13 set "DELPHI_PATH=C:\Program Files (x86)\Borland\Delphi7"
14
15 REM Prerequisites
16 set "PDOC_PATH=%~dp0\..\Prerequisites\Pandoc"
17 set "ANT_HOME=%~dp0\..\Prerequisites\Ant"
18 set "PYTHON_HOME_INC=%~dp0\..\Prerequisites\Python3\include"
19 set "PYTHON_HOME_LIB32=%~dp0\..\Prerequisites\Python3\lib\Win32"
20 set "PYTHON_HOME_LIB64=%~dp0\..\Prerequisites\Python3\lib\x64"
21
22
23 REM ///////////////////////////////////////////////////////////////////////////
24 REM // Check paths
25 REM ///////////////////////////////////////////////////////////////////////////
26
27 if not exist "%MSVC_PATH%\vcvarsall.bat" (
28         "%~dp0\tools\cecho.exe" RED "\nMSVC not found.\n%MSVC_PATH:\=\\%\\vcvarsall.bat\n"
29         pause & goto:eof
30 )
31
32 if not exist "%PDOC_PATH%\pandoc.exe" (
33         "%~dp0\tools\cecho.exe" RED "\nPandoc not found.\n%PDOC_PATH:\=\\%\\pandoc.exe\n"
34         pause & goto:eof
35 )
36
37 if not exist "%GIT2_PATH%\git.exe" (
38         "%~dp0\tools\cecho.exe" RED "\nGIT not found.\n%GIT2_PATH:\=\\%\\git.exe\n"
39         pause & goto:eof
40 )
41
42 if not exist "%JAVA_HOME%\lib\tools.jar" (
43         "%~dp0\tools\cecho.exe" RED "\nJava not found.\n%JAVA_HOME:\=\\%\\lib\\tools.jar\n"
44         pause & goto:eof
45 )
46
47 if not exist "%JAVA_HOME%\bin\javac.exe" (
48         "%~dp0\tools\cecho.exe" RED "\nJava not found.\n%JAVA_HOME:\=\\%\\bin\\javac.exe\n"
49         pause & goto:eof
50 )
51
52 if not exist "%ANT_HOME%\bin\ant.bat" (
53         "%~dp0\tools\cecho.exe" RED "\nAnt not found.\n%ANT_HOME:\=\\%\\bin\\ant.cmd\n"
54         pause & goto:eof
55 )
56
57 if not exist "%ANT_HOME%\lib\ant.jar" (
58         "%~dp0\tools\cecho.exe" RED "\nAnt not found.\n%ANT_HOME:\=\\%\\lib\\ant.jar\n"
59         pause & goto:eof
60 )
61
62 if not exist "%PYTHON_HOME_INC%\Python.h" (
63         "%~dp0\tools\cecho.exe" RED "\nPython includes not found.\n%PYTHON_HOME_INC:\=\\%\\Python.h\n"
64         pause & goto:eof
65 )
66
67 if not exist "%PYTHON_HOME_LIB32%\python3.lib" (
68         "%~dp0\tools\cecho.exe" RED "\nPython-x86 not found.\n%PYTHON_HOME_LIB32:\=\\%\\python3.lib\n"
69         pause & goto:eof
70 )
71
72 if not exist "%PYTHON_HOME_LIB64%\python3.lib" (
73         "%~dp0\tools\cecho.exe" RED "\nPython-x64 not found.\n%PYTHON_HOME_LIB64:\=\\%\\python3.lib\n"
74         pause & goto:eof
75 )
76
77 if not exist "%DELPHI_PATH%\bin\dcc32.exe" (
78         "%~dp0\tools\cecho.exe" RED "\nDelphi not found.\n%DELPHI_PATH:\=\\%\\bin\\dcc32.exe\n"
79         pause & goto:eof
80 )
81
82 REM ///////////////////////////////////////////////////////////////////////////
83 REM // Get current date and time (in ISO format)
84 REM ///////////////////////////////////////////////////////////////////////////
85
86 set "ISO_DATE="
87 set "ISO_TIME="
88 for /F "tokens=1,2 delims=:" %%a in ('"%~dp0\tools\date.exe" +ISODATE:%%Y-%%m-%%d') do (
89         if "%%a"=="ISODATE" set "ISO_DATE=%%b"
90 )
91 for /F "tokens=1,2,3,4 delims=:" %%a in ('"%~dp0\tools\date.exe" +ISOTIME:%%T') do (
92         if "%%a"=="ISOTIME" set "ISO_TIME=%%b:%%c:%%d"
93 )
94
95
96 REM ///////////////////////////////////////////////////////////////////////////
97 REM // Clean up temp files
98 REM ///////////////////////////////////////////////////////////////////////////
99
100 "%~dp0\tools\cecho.exe" YELLOW "\n========[ CLEAN UP ]========\n"
101
102 for %%i in (bin,obj) do (
103         del /Q /S /F "%~dp0\%%i\*.*"  2> NUL
104 )
105
106 for %%i in (Microsoft.NET,Java,Delphi,Python) do (
107         for %%j in (native,library,wrapper,example) do (
108                 for %%k in (bin,obj,out) do (
109                         del /Q /S /F "%~dp0\bindings\%%i\%%j\%%k\*.*" 2> NUL
110                 )
111         )
112 )
113
114 for %%i in (exe,dcu) do (
115         del /Q /S /F "%~dp0\bindings\Delphi\*.%%i" 2> NUL
116 )
117
118
119 REM ///////////////////////////////////////////////////////////////////////////
120 REM // Build the binaries
121 REM ///////////////////////////////////////////////////////////////////////////
122
123 "%~dp0\tools\cecho.exe" YELLOW "\n========[ COMPILE ]========"
124
125 call "%MSVC_PATH%\vcvarsall.bat"
126
127 set "MSVC_PROJECTS=MHashLib.sln"
128 set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Python\native\MHashPy384_Native.sln"
129 set "MSVC_PROJECTS=%MSVC_PROJECTS%,bindings\Delphi\native\MHashDelphi384.sln"
130 for %%q in (%MSVC_PROJECTS%) do (
131         for %%p in (x86,x64) do (
132                 "%~dp0\tools\cecho.exe" CYAN "\n----[ %%~nq (%%~p) ]----\n"
133                 MSBuild.exe /property:Platform=%%p /property:Configuration=Release /target:Clean   "%~dp0\%%~q"
134                 if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
135                 MSBuild.exe /property:Platform=%%p /property:Configuration=Release /target:Rebuild "%~dp0\%%~q"
136                 if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
137         )
138 )
139
140 set "DOTNET_PROJECTS=bindings\Microsoft.NET\MHashDotNet384.sln"
141 for %%q in (%DOTNET_PROJECTS%) do (
142         "%~dp0\tools\cecho.exe" CYAN "\n----[ %%~nq (%%~p) ]----\n"
143         MSBuild.exe /property:Platform="Any CPU" /property:Configuration=Release /target:Clean   "%~dp0\%%~q"
144         if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
145         MSBuild.exe /property:Platform="Any CPU" /property:Configuration=Release /target:Rebuild "%~dp0\%%~q"
146         if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
147 )
148
149 for %%q in (example) do (
150         echo pushd "%~dp0\bindings\Delphi\%%~q"
151         pushd "%~dp0\bindings\Delphi\%%~q"
152         for %%p in (*.dpr) do (
153                 "%~dp0\tools\cecho.exe" CYAN "\n----[ %%~np ]----\n"
154                 "%DELPHI_PATH%\bin\dcc32.exe" -B -CG -$O+ -E"bin" -N"obj" "%%~nxp"
155                 if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
156         )
157         popd
158 )
159
160 for %%q in (library,example) do (
161         "%~dp0\tools\cecho.exe" CYAN "\n----[ %%~nq ]----\n"
162         pushd "%~dp0\bindings\Java\%%~q"
163         call "%ANT_HOME%\bin\ant.bat" clean jar
164         if not "!ERRORLEVEL!"=="0" goto BuildHasFailed
165         popd
166 )
167
168
169 REM ///////////////////////////////////////////////////////////////////////////
170 REM // Generate Docs
171 REM ///////////////////////////////////////////////////////////////////////////
172
173 "%PDOC_PATH%\pandoc.exe" --from markdown --to html5 --toc -N --standalone -H "%~dp0\etc\css\style.inc" --output "%~dp0\README.html" "%~dp0\README.md"
174 if not "%ERRORLEVEL%"=="0" goto BuildHasFailed
175
176
177 REM ///////////////////////////////////////////////////////////////////////////
178 REM // Generate output name
179 REM ///////////////////////////////////////////////////////////////////////////
180
181 mkdir "%~dp0\out" 2> NUL
182
183 set COUNTER=
184 set REVISON=
185
186 :GenerateOutfileNameNext
187 set "OUT_PATH_BIN_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-msvc-x86.zip"
188 set "OUT_PATH_BIN_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-msvc-x64.zip"
189 set "OUT_PATH_NET_GEN=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-dotnet.zip"
190 set "OUT_PATH_JNI_GEN=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.bin-java.zip"
191 set "OUT_PATH_PYC_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.python-win-x86.zip"
192 set "OUT_PATH_PYC_X64=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.python-win-x64.zip"
193 set "OUT_PATH_PAS_X86=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.delphi-win-x86.zip"
194 set "OUT_PATH_SRC_GEN=%~dp0\out\mhash_384.%ISO_DATE%%REVISON%.sources.tar.gz"
195
196 set /a COUNTER=COUNTER+1
197 set REVISON=.update-%COUNTER%
198
199 if exist "%OUT_PATH_BIN_X86%" goto GenerateOutfileNameNext
200 if exist "%OUT_PATH_BIN_X64%" goto GenerateOutfileNameNext
201 if exist "%OUT_PATH_NET_GEN%" goto GenerateOutfileNameNext
202 if exist "%OUT_PATH_JNI_GEN%" goto GenerateOutfileNameNext
203 if exist "%OUT_PATH_PYC_X86%" goto GenerateOutfileNameNext
204 if exist "%OUT_PATH_PYC_X64%" goto GenerateOutfileNameNext
205 if exist "%OUT_PATH_PAS_X86%" goto GenerateOutfileNameNext
206 if exist "%OUT_PATH_SRC_GEN%" goto GenerateOutfileNameNext
207
208
209 REM ///////////////////////////////////////////////////////////////////////////
210 REM // Build ZIP package
211 REM ///////////////////////////////////////////////////////////////////////////
212
213 "%~dp0\tools\cecho.exe" YELLOW "\n========[ PACKAGING ]========\n"
214
215 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X86%" "%~dp0\bin\Win32\Release\mhash_384.x86.exe" "%~dp0\include\mhash_384.h" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
216 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_BIN_X64%" "%~dp0\bin\x64\.\Release\mhash_384.x64.exe" "%~dp0\include\mhash_384.h" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
217
218 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_NET_GEN%" "%~dp0\bindings\Microsoft.NET\library\bin\Release\MHashDotNet384.dll" "%~dp0\bindings\Microsoft.NET\example\bin\Release\MHashDotNet384.Example.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
219
220 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_JNI_GEN%" "%~dp0\bindings\Java\library\out\MHashJava384.jar" "%~dp0\bindings\Java\example\out\MHashJava384-Example.jar" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
221
222 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X86%" "%~dp0\bindings\Python\native\bin\x86\Release\MHashPy384_Native.x86.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\MHashPy384_Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
223 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PYC_X64%" "%~dp0\bindings\Python\native\bin\x64\Release\MHashPy384_Native.x64.pyd" "%~dp0\bindings\Python\wrapper\MHashPy384_Wrapper.py" "%~dp0\bindings\Python\wrapper\mhash.pth" "%~dp0\bindings\Python\example\MHashPy384_Example.py" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
224
225 "%~dp0\tools\zip.exe" -j -9 -z "%OUT_PATH_PAS_X86%" "%~dp0\bindings\Delphi\native\bin\x86\Release\MHashDelphi384.x86.dll" "%~dp0\bindings\Delphi\wrapper\MHash384.pas" "%~dp0\bindings\Delphi\example\bin\Example.exe" "%~dp0\README.html" "%~dp0\COPYING.txt" < "%~dp0\COPYING.txt"
226
227 "%GIT2_PATH%\git.exe" archive --format tar.gz -9 --verbose --output "%OUT_PATH_SRC_GEN%" HEAD
228
229
230 REM ///////////////////////////////////////////////////////////////////////////
231 REM // Completed
232 REM ///////////////////////////////////////////////////////////////////////////
233
234 "%~dp0\tools\cecho.exe" GREEN "\nBUILD COMPLETED.\n"
235 pause
236 goto:eof
237
238
239 REM ///////////////////////////////////////////////////////////////////////////
240 REM // Failed
241 REM ///////////////////////////////////////////////////////////////////////////
242
243 :BuildHasFailed
244 "%~dp0\tools\cecho.exe" RED "\nBUILD HAS FAILED.\n"
245 pause
246 goto:eof