-
Notifications
You must be signed in to change notification settings - Fork 70
/
1Stop.cmd
343 lines (275 loc) · 10.4 KB
/
1Stop.cmd
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
@echo off
:: Create default Hyperion build directory, if it does not exist.
:: Then configure using the arguments.
:: Your current working directory MUST be the one where this file resides
SETLOCAL EnableDelayedExpansion
:: We check for PLATFORM because Windows is not very clear about whether
:: we are building for amd64 or just running on amd64. If PLATFORM
:: exists, then this is a cross-platform build x86 on amd64. Otherwise
:: we will use the PROCESSOR_ARCHITECTURE value. (Need to check
:: what the variables look like for a cross-platform build amd64 on
:: x86). The result is available to the remaining scripts.
:: These default commands match those that would be issued when doing an
:: interactive build on Visual Studio (any version). We will presume
:: the moment that should someone wish to build with other than these
:: defaults, they will re-issue the makefile.bat command with their
:: own parameters.
if DEFINED PLATFORM (
set "build_arch=%PLATFORM%"
) else (
if DEFINED PROCESSOR_ARCHITEW6432 (
set "build_arch=%PROCESSOR_ARCHITEW6432%"
) else (
set "build_arch=%PROCESSOR_ARCHITECTURE%"
)
)
:: PLATFORM is either x86 or x64, PROCESSORS_ARCHITECTURE is either
:: x86 or AMD64. Conform x64 to AMD64.
If /I "%build_arch%"=="x64" (
set "build_arch=AMD64"
)
:: Visual Studio 2012 and higher command prompts can be identified by
:: checking the environment variable VisualStudioVersion. Older than
:: 2012, we can parse the PATH variable, but that will fail if the
:: builder installed Visual Studio in a non-default directory. There
:: is no help for that beyond understanding the difficulty and
:: documenting it.
:: If Visual Studio 9.0 2008 is identified as the the newest version
:: installed, it is assumed to be the Express Edition. VS2008EE is
:: limited to building 32-bit applications out of the box, and 1Stop
:: will therefore only build a 32-bit Hercules when VS2008EE is in use.
:: Otherwise the bitness will be determined by the hardware architecture.
:: (Yes, there are VS2008EE hacks to enable 64-bit builds, and a builder
:: who uses those hacks will need to use the more flexible build tools
:: like makefile.bat.)
:: If there are multiple versions of Visual Studio installed, well,
:: 1Stop will end badly if someone wishes to use an older VS version to
:: build. In that case, we will expect the builder to use more flexible
:: build tools.
if "%VisualStudioVersion%" == "15.0" (
set "build_arch=%build_arch%"
) else if "%VisualStudioVersion%" == "14.0" (
set "build_arch=%build_arch%"
) else if "%VisualStudioVersion%" == "12.0" (
set "build_arch=%build_arch%"
) else if "%VisualStudioVersion%" == "11.0" (
set "build_arch=%build_arch%"
) else if "%VisualStudioVersion%" == "10.0" (
set "build_arch=%build_arch%"
) else if "%VisualStudioVersion%" == "9.0" (
set "build_arch=x86"
) else if NOT "%PATH:Visual Studio 10.0=%"=="%PATH%" (
set "build_arch=%build_arch%"
) else if NOT "%PATH:Visual Studio 9.0=%"=="%PATH%" (
echo Visual Studio 9 ^(2008^) identified as build tool. Assuming Express Edition.
echo Building 32-bit executables and shared libraries.
set "build_arch=x86"
) else (
echo Unable to determine Visual Studio version.
echo Unable to match VisualStudioVersion "%VisualStudioVersion%" to a valid version.
echo Unable to to determine version from PATH environment variable.
echo Terminating.
exit /b 12
)
if /i "%build_arch%"=="X86" (
set "build_cmd=makefile.bat RETAIL makefile.msvc 32 %*"
) else (
set "build_cmd=makefile.bat RETAIL-X64 makefile.msvc 64 %*"
)
echo Hercules will be built with command/parameters '%build_cmd%'
set "gitconf=.git\config"
set "sfdir=SoftFloat-3a"
:: if a SoftFloat 3a library path override exists in the environment
:: variable SFLIB_DIR, use it as default build directory for SoftFloat
:: 3a. Else use the Hercules default. If a non-default library was
:: specified and SoftFloat-3a is not there, it will be built in the
:: default location and copied to the specified location.
set "def_obj=..\%build_arch%\s3fh"
set "obj=%def_obj%"
if not "%SFLIB_DIR%" == "" (
set "obj=%SFLIB_DIR%"
)
:: Set up directory where Hyperion will be built. Because Hyperion
:: is always built in a set of subdirectories inside the source
:: directory, an in-source build is always done. The comments below
:: when uncommented would create a separate build directory under
:: the processor architecture directory using the same name as the
:: source directory.
:: set "build=%~p0"
:: set "build=%build:~0,-1%
:: for %%a in (%build%) do set "build=..\%build_arch%\%%~nxa
goto :StartDoConfigure %= Skip past function definitions =%
:: Create a directory if it does not exist. Report success, already
:: exists, or failure.
:: Note: routine is only needed when Hercules Windows build is changed
:: to build out of source. Until then, just comments.
:: :dodir
:: if not exist %1 (
:: mkdir %1
:: if not "%errorlevel%" == "0" (
:: echo Cannot create directory '%1'. Terminating.
:: exit /b 12
:: )
:: echo Created '%1'. >&2
:: ) else (
:: echo '%1' exists. >&2
:: )
::
:: exit /b 0
:: Look for SoftFloat; clone if not present
:: Decode the git configure url statement. The tokenized url =
:: line from the .git\config file is expected as parameters 1-3.
:: Because Windows batch does not have the same parsing tools as
:: open source systems, by the time :testurl is called, we know
:: that parameters 1 and 2 are "url" and "=", so we skip that
:: test. Note also that :: causes wierd errors inside if statements
:: and other multi-line constructs, hence 'rem' belowe.
:: Note also that variables are expanded at parse time, not at
:: run time; this breaks many things. Variables bracketed with "!"
:: (exclamation point) are expanded at run time.
:testurl
if not exist %gitconf% (
echo Hyperion git configuration file '%gitconf%' not found. >&2
exit /b 12
)
:: parse the .git\config file looking for a url = in a
:: [remote "origin"] section. when found, extract the url (https or
:: ssh) into %url% (!url!)
set "sectionfound="
for /f "tokens=*" %%z in (%gitconf%) do (
set "work=%%z"
if "!work:~0,1!" == "[" (
set "insection=0"
for /f "tokens=1-2" %%x in ("!work!") do (
if "%%x%%y" == "[remote"origin"]" ( %= [remote "origin"] section found =%
set "insection=1"
set "sectionfound=!work!"
)
)
) else (
if "!insection!" == "1" (
for /f "tokens=1-3" %%m in ("!work!") do (
if "%%m" == "url" if "%%n%" == "=" (
set "url=%%o"
)
)
)
)
)
:: Diagnose missing .git/config information; abort if needed
if "%sectionfound%" == "" (
echo Did not find '[remote "origin"] in %gitconf% >&2
exit /b 18
) else if "%url%" == "" (
echo Did not find remote origin url in %gitconf% >&2
exit /b 19
)
echo Hercules cloned from %sectionfound% url = %url%
for /f "tokens=1 delims=." %%a in ("%url%") do set "pfx=%%a"
if "!pfx!" == "git@github" (
set "[email protected]:hercules-390/%sfdir%.git"
) else (
if "!pfx!" == "https://github" (
set "clone=https://github.com/hercules-390/%sfdir%.git"
) else (
echo Git url '%url%' does not seem to be in the correct format. >&2
echo It should start 'git@github' or 'https://github', found '%pfx%'. >&2
exit /b 15
)
)
pushd ..
set "rv=%errorlevel%"
if "!rv!" neq "0" (
echo Change to parent of Hercules source dir failed rv=!rv!. >&2
exit /b 16
)
git clone !clone!
if "!rv!" neq "0" (
echo Git clone of %sfdir% failed rv=!rv!. >&2
exit /b 16
)
popd
exit /b 0
:: Look for Softfloat 3a public headers and library. Build them if they
:: do not exist.
:testSoftFloat
:: if Softfloat-3a public headers and library exist in the appropriate
:: directory, return to caller.
if exist %obj%\include\softfloat.h if exist %obj%\include\softfloat_types.h if exist %obj%\lib\softfloat.lib (
echo %sfdir% runntime and headers already in %obj%
exit /b 0
)
:: if the Softfloat-3a library and headers do not exist in the desired
:: directory but do exist in the default directory, copy from default
:: to desired directory and return to caller.
if not "%def_obj%" == "%obj%" (
if exist %def_obj%\include\softfloat.h if exist %def_obj%\include\softfloat_types.h if exist %def_obj%\lib\softfloat.lib (
xcopy /e /y /i /q %def_obj% %obj% > nul
set "rv=%errorlevel%"
if "!rv!" == "0" (
echo %sfdir% already built in '%def_obj%' and copied to '%obj%'
) else (
echo %sfdir% already built in '%def_obj%', unable to copy to '%obj%', xcopy rv=!rv! >&2
exit /b 17
)
exit /b 0
)
)
:: public header does not exist. See if a clone of the repository is
:: available to do a build. If not, clone using the same manner as
:: was used for the Hercules clone.
if exist ..\%sfdir% (
echo %sfdir% already installed and will be built.
) else (
call :testurl
set "rv=%errorlevel%"
if not "!rv!" == "0" (
echo unable to locate or clone %sfdir% >&2
exit /b %rv%
)
)
:: local clone of SoftFloat 3a already exists or has been cloned.
:: Build it using its 1Stop.
pushd ..\%sfdir%
set "rv=%errorlevel%"
if "!rv!" neq "0" (
echo Change to %sfdir% build dir '%obj%' failed rv=!rv!. >&2
exit /b 16
)
call 1Stop
set "rv=%errorlevel%"
popd
if not "%rv%" == "0" (
echo Could not build %sfdir%, %sfdir% 1Stop rv=%rv%. >&2
exit /b 17
)
:: If a non-default SoftFloat-3a directory was specified via environment
:: variable, copy the just-built SoftFloat-3a to the specified directory.
if "%def_obj%" == "%obj%" (
echo %sfdir% built in '%def_obj%'
) else (
xcopy /e /y /i /q %def_obj% %obj% > nul
set "rv=%errorlevel%"
if "%rv%" == "0" (
echo %sfdir% built in '%def_obj%' and copied to '%obj%'
) else (
echo %sfdir% built in '%def_obj%', unable to copy to '%obj%', xcopy rv=%rv% >&2
exit /b 17
)
)
exit /b 0
:: main routine...
:startDoConfigure
:: make certain Softfloat 3a library and headers are available at the
:: expected location.
call :testSoftFloat
set "rv=%errorlevel%"
if not "%rv%" == "0" exit /b %rv%
:: if/when Hercules is built for Windows out of source, the following
:: two calls will need to be uncommented.
:: call :dodir ..\%build_arch%
:: call :dodir %build%
:: Build Hercules
call %build_cmd%
ENDLOCAL
exit /b 0