-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.bat
508 lines (456 loc) · 16 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
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
@echo off
setlocal enabledelayedexpansion
@rem only for interactive debugging !
set _DEBUG=0
@rem #########################################################################
@rem ## Environment setup
set _EXITCODE=0
call :env
if not %_EXITCODE%==0 goto end
call :args %*
if not %_EXITCODE%==0 goto end
@rem #########################################################################
@rem ## Main
for %%i in (%_COMMANDS%) do (
call :%%i
if not !_EXITCODE!==0 goto end
)
goto end
@rem #########################################################################
@rem ## Subroutines
:env
set _BASENAME=%~n0
set "_ROOT_DIR=%~dp0"
call :env_colors
set _DEBUG_LABEL=%_NORMAL_BG_CYAN%[%_BASENAME%]%_RESET%
set _ERROR_LABEL=%_STRONG_FG_RED%Error%_RESET%:
set _WARNING_LABEL=%_STRONG_FG_YELLOW%Warning%_RESET%:
set "_SOURCE_DIR=%_ROOT_DIR%src"
set "_SOURCE_DEF_DIR=%_SOURCE_DIR%\main\def"
set "_SOURCE_MOD_DIR=%_SOURCE_DIR%\main\mod"
set "_TARGET_DIR=%_ROOT_DIR%target"
set "_TARGET_DEF_DIR=%_TARGET_DIR%\def"
set "_TARGET_MOD_DIR=%_TARGET_DIR%\mod"
@rem library dependencies
set "_TARGET_BIN_DIR=%_TARGET_DIR%\bin"
set "_TARGET_SYM_DIR=%_TARGET_DIR%\sym"
for /f "delims=" %%i in ("%~dp0.") do set "_APP_NAME=%%~ni"
set "_TARGET_FILE=%_TARGET_DIR%\%_APP_NAME%.exe"
@rem 2 choices: ASCII, Unicode
set "_ADWM2_HOME=%ADWM2_HOME%\ASCII"
if not exist "%_ADWM2_HOME%\m2amd64.exe" (
echo %_ERROR_LABEL% ADW Modula-2 installation not found 1>&2
set _EXITCODE=1
goto :eof
)
set "_M2C_CMD=%_ADWM2_HOME%\m2amd64.exe"
if not exist "%_ADWM2_HOME%\sblink.exe" (
echo %_ERROR_LABEL% ADW Modula-2 installation not found 1>&2
set _EXITCODE=1
goto :eof
)
set "_SBLINK_CMD=%_ADWM2_HOME%\sblink.exe"
if not exist "%XDSM2_HOME%\bin\xc.exe" (
echo %_ERROR_LABEL% XDS Modula-2 installation not found 1>&2
set _EXITCODE=1
goto :eof
)
set "_XC_CMD=%XDSM2_HOME%\bin\xc.exe"
@rem use newer PowerShell version if available
where /q pwsh.exe
if %ERRORLEVEL%==0 ( set _PWSH_CMD=pwsh.exe
) else ( set _PWSH_CMD=powershell.exe
)
goto :eof
:env_colors
@rem ANSI colors in standard Windows 10 shell
@rem see https://gist.github.com/mlocati/#file-win10colors-cmd
@rem normal foreground colors
set _NORMAL_FG_BLACK=[30m
set _NORMAL_FG_RED=[31m
set _NORMAL_FG_GREEN=[32m
set _NORMAL_FG_YELLOW=[33m
set _NORMAL_FG_BLUE=[34m
set _NORMAL_FG_MAGENTA=[35m
set _NORMAL_FG_CYAN=[36m
set _NORMAL_FG_WHITE=[37m
@rem normal background colors
set _NORMAL_BG_BLACK=[40m
set _NORMAL_BG_RED=[41m
set _NORMAL_BG_GREEN=[42m
set _NORMAL_BG_YELLOW=[43m
set _NORMAL_BG_BLUE=[44m
set _NORMAL_BG_MAGENTA=[45m
set _NORMAL_BG_CYAN=[46m
set _NORMAL_BG_WHITE=[47m
@rem strong foreground colors
set _STRONG_FG_BLACK=[90m
set _STRONG_FG_RED=[91m
set _STRONG_FG_GREEN=[92m
set _STRONG_FG_YELLOW=[93m
set _STRONG_FG_BLUE=[94m
set _STRONG_FG_MAGENTA=[95m
set _STRONG_FG_CYAN=[96m
set _STRONG_FG_WHITE=[97m
@rem strong background colors
set _STRONG_BG_BLACK=[100m
set _STRONG_BG_RED=[101m
set _STRONG_BG_GREEN=[102m
set _STRONG_BG_YELLOW=[103m
set _STRONG_BG_BLUE=[104m
@rem we define _RESET in last position to avoid crazy console output with type command
set _BOLD=[1m
set _UNDERSCORE=[4m
set _INVERSE=[7m
set _RESET=[0m
goto :eof
@rem input parameter: %*
:args
set _COMMANDS=
set _VERBOSE=0
set _TOOLSET=xds
set __N=0
:args_loop
set "__ARG=%~1"
if not defined __ARG (
if !__N!==0 set _COMMANDS=help
goto args_done
)
if "%__ARG:~0,1%"=="-" (
@rem option
if "%__ARG%"=="-adw" ( set _TOOLSET=adw
) else if "%__ARG%"=="-debug" ( set _DEBUG=1
) else if "%__ARG%"=="-gm2" ( set _TOOLSET=gm2
) else if "%__ARG%"=="-help" ( set _HELP=1
) else if "%__ARG%"=="-verbose" ( set _VERBOSE=1
) else if "%__ARG%"=="-xds" ( set _TOOLSET=xds
) else (
echo %_ERROR_LABEL% Unknown option "%__ARG%" 1>&2
set _EXITCODE=1
goto args_done
)
) else (
@rem subcommand
if "%__ARG%"=="clean" ( set _COMMANDS=!_COMMANDS! clean
) else if "%__ARG%"=="compile" ( set _COMMANDS=!_COMMANDS! compile
) else if "%__ARG%"=="help" ( set _COMMANDS=help
) else if "%__ARG%"=="run" ( set _COMMANDS=!_COMMANDS! compile run
) else (
echo %_ERROR_LABEL% Unknown subcommand "%__ARG%" 1>&2
set _EXITCODE=1
goto args_done
)
set /a __N+=1
)
shift
goto args_loop
:args_done
set _STDOUT_REDIRECT=1^>NUL
if %_DEBUG%==1 set _STDOUT_REDIRECT=
if exist "%_SOURCE_DIR%\main\mod-%_TOOLSET%" (
set "_SOURCE_MOD_DIR=%_SOURCE_DIR%\main\mod-%_TOOLSET%"
)
for /f "delims=" %%f in ("%~dp0.") do set "_LIB_DIR=%%~dpflib\%_TOOLSET%"
if %_DEBUG%==1 (
echo %_DEBUG_LABEL% Options : _TOOLSET=%_TOOLSET% _VERBOSE=%_VERBOSE% 1>&2
echo %_DEBUG_LABEL% Subcommands: %_COMMANDS% 1>&2
echo %_DEBUG_LABEL% Variables : "ADWM2_HOME=%ADWM2_HOME%" 1>&2
if defined GM2_HOME echo %_DEBUG_LABEL% Variables : "GM2_HOME=%GM2_HOME%" 1>&2
echo %_DEBUG_LABEL% Variables : "XDSM2_HOME=%XDSM2_HOME%" 1>&2
echo %_DEBUG_LABEL% Variables : _APP_NAME=%_APP_NAME% 1>&2
echo %_DEBUG_LABEL% Variables : "_LIB_DIR=%_LIB_DIR%" 1>&2
)
goto :eof
:help
if %_VERBOSE%==1 (
set __BEG_P=%_STRONG_FG_CYAN%
set __BEG_O=%_STRONG_FG_GREEN%
set __BEG_N=%_NORMAL_FG_YELLOW%
set __END=%_RESET%
) else (
set __BEG_P=
set __BEG_O=
set __BEG_N=
set __END=
)
echo Usage: %__BEG_O%%_BASENAME% { ^<option^> ^| ^<subcommand^> }%__END%
echo.
echo %__BEG_P%Options:%__END%
echo %__BEG_O%-adw%__END% select ADW Modula-2 toolset
echo %__BEG_O%-debug%__END% print commands executed by this script
echo %__BEG_O%-gm2%__END% select GNU Modula-2 toolset
echo %__BEG_O%-verbose%__END% print progress messages
echo %__BEG_O%-xds%__END% select XDS Modula-2 toolset ^(default^)
echo.
echo %__BEG_P%Subcommands:%__END%
echo %__BEG_O%clean%__END% delete generated object files
echo %__BEG_O%compile%__END% compile Modula-2 source files
echo %__BEG_O%run%__END% execute Modula-2 program "%__BEG_O%%_APP_NAME%%__END%"
goto :eof
:clean
call :rmdir "%_TARGET_DIR%"
if exist "%_ROOT_DIR%*.err" del "%_ROOT_DIR%*.err"
if exist "%_ROOT_DIR%errinfo.$$$" del "%_ROOT_DIR%errinfo.$$$"
goto :eof
@rem input parameter: %1=directory path
:rmdir
set "__DIR=%~1"
if not exist "%__DIR%\" goto :eof
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% rmdir /s /q "%__DIR%" 1>&2
) else if %_VERBOSE%==1 ( echo Delete directory "!__DIR:%_ROOT_DIR%=!" 1>&2
)
rmdir /s /q "%__DIR%"
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to delete directory "!__DIR:%_ROOT_DIR%=!" 1>&2
set _EXITCODE=1
goto :eof
)
goto :eof
:compile
if not exist "%_TARGET_DIR%" mkdir "%_TARGET_DIR%"
call :action_required "%_TARGET_FILE%" "%_SOURCE_DEF_DIR%\*.def"
set __ACTION_DEF=%_ACTION_REQUIRED%
call :action_required "%_TARGET_FILE%" "%_SOURCE_MOD_DIR%\*.mod"
if %_ACTION_REQUIRED%==0 if %__ACTION_DEF%==0 goto :eof
call :compile_%_TOOLSET% %__ACTION_DEF%
if not %_EXITCODE%==0 goto :eof
goto :eof
@rem input parameter: %1=.def files are out of date
:compile_adw
set __ACTION_DEF=%~1
if %_DEBUG%==1 echo %_DEBUG_LABEL% xcopy /i /q /y "%_ADWM2_HOME%\winamd64sym\*.sym" "%_TARGET_SYM_DIR%\" 1>&2
xcopy /i /q /y "%_ADWM2_HOME%\winamd64sym\*.sym" "%_TARGET_SYM_DIR%\" %_STDOUT_REDIRECT%
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to copy ADW Modula-2 symbol files 1>&2
set _EXITCODE=1
goto :eof
)
if exist "%_LIB_DIR%\*.sym" (
if %_DEBUG%==1 echo %_DEBUG_LABEL% xcopy /i /q /y "%_LIB_DIR%\*.sym" "%_TARGET_SYM_DIR%\" 1>&2
xcopy /i /q /y "%_LIB_DIR%\*.sym" "%_TARGET_SYM_DIR%\" %_STDOUT_REDIRECT%
)
if exist "%_LIB_DIR%\*.obj" (
if %_DEBUG%==1 echo %_DEBUG_LABEL% xcopy /i /q /y "%_LIB_DIR%\*.obj" "%_TARGET_MOD_DIR%\" 1>&2
xcopy /i /q /y "%_LIB_DIR%\*.obj" "%_TARGET_MOD_DIR%\" %_STDOUT_REDIRECT%
)
if exist "%_SOURCE_DEF_DIR%\*.def" (
if %_DEBUG%==1 echo %_DEBUG_LABEL% xcopy /i /q /y "%_SOURCE_DEF_DIR%\*.def" "%_TARGET_DEF_DIR%\" 1>&2
xcopy /i /q /y "%_SOURCE_DEF_DIR%\*.def" "%_TARGET_DEF_DIR%\" %_STDOUT_REDIRECT%
)
if exist "%_SOURCE_MOD_DIR%\*.mod" (
if %_DEBUG%==1 echo %_DEBUG_LABEL% xcopy /i /q /y "%_SOURCE_MOD_DIR%\*.mod" "%_TARGET_MOD_DIR%\" 1>&2
xcopy /i /q /y "%_SOURCE_MOD_DIR%\*.mod" "%_TARGET_MOD_DIR%\" %_STDOUT_REDIRECT%
) else (
echo %_WARNING_LABEL% No Modula-2 implementation module found 1>&2
goto :eof
)
@rem We must specify a relative path for the SYM directories
set __M2C_OPTS=-sym:"!_TARGET_SYM_DIR:%_ROOT_DIR%\=!"
if %_DEBUG%==0 set __M2C_OPTS=-quiet %__M2C_OPTS%
set __N=0
if %__ACTION_DEF%==0 goto compile_adw_mod
@rem we generate symbol files for definition modules
for /f "delims=" %%f in ('dir /s /b "%_TARGET_DEF_DIR%\*.def" 2^>NUL') do (
set "__DEF_FILE=%%f"
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_M2C_CMD%" %__M2C_OPTS% "!__DEF_FILE!" 1>&2
) else if %_VERBOSE%==1 ( echo Compile "!__DEF_FILE!" into directory "!_TARGET_DEF_DIR:%_ROOT_DIR%=!" 1>&2
)
call "%_M2C_CMD%" %__M2C_OPTS% "!__DEF_FILE!"
if not !ERRORLEVEL!==0 (
echo %_ERROR_LABEL% Failed to compile "!__DEF_FILE!" into directory "!_TARGET_DEF_DIR:%_ROOT_DIR%=!" 1>&2
set _EXITCODE=1
goto :eof
)
set /a __N+=1
)
:compile_adw_mod
for /f "delims=" %%f in ('dir /s /b "%_TARGET_MOD_DIR%\*.mod" 2^>NUL') do (
set "__MOD_FILE=%%f"
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_M2C_CMD%" %__M2C_OPTS% "!__MOD_FILE!" 1>&2
) else if %_VERBOSE%==1 ( echo Compile "!__MOD_FILE!" into directory "!_TARGET_MOD_DIR:%_ROOT_DIR%=!" 1>&2
)
call "%_M2C_CMD%" %__M2C_OPTS% "!__MOD_FILE!" %_STDOUT_REDIRECT%
if not !ERRORLEVEL!==0 (
echo %_ERROR_LABEL% Failed to compile "!__MOD_FILE!" into directory "!_TARGET_MOD_DIR:%_ROOT_DIR%=!" 1>&2
set _EXITCODE=1
goto :eof
)
set /a __N+=1
)
set "__LINKER_OPTS_FILE=%_TARGET_DIR%\linker_opts.txt"
(
@rem echo -EXETYPE:exe
echo -MACHINE:X86_64
echo -SUBSYSTEM:WINDOWS
echo -MAP:%_TARGET_DIR%\%_APP_NAME%
echo -OUT:%_TARGET_FILE%
echo -LARGEADDRESSAWARE
) > "%__LINKER_OPTS_FILE%"
@rem object files of current program
for /f "delims=" %%f in ('dir /b "%_TARGET_MOD_DIR%\*.obj" 2^>NUL') do (
echo !_TARGET_MOD_DIR:%_ROOT_DIR%=!\%%f >> "%__LINKER_OPTS_FILE%"
)
@rem object files of library depencencies
for /f "delims=" %%f in ('dir /b "%_TARGET_BIN_DIR%\*.obj" 2^>NUL') do (
echo !_TARGET_BIN_DIR:%_ROOT_DIR%=!\%%f >> "%__LINKER_OPTS_FILE%"
)
(
echo %_ADWM2_HOME%\rtl-win-amd64.lib
echo %_ADWM2_HOME%\win64api.lib
) >> "%__LINKER_OPTS_FILE%"
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_SBLINK_CMD%" @%__LINKER_OPTS_FILE% 1>&2
) else if %_VERBOSE%==1 ( echo Execute ADW linker 1>&2
)
@rem command sblink does NOT support quoted argument file
call "%_SBLINK_CMD%" @%__LINKER_OPTS_FILE% %_STDOUT_REDIRECT%
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to execute ADW linker 1>&2
if %_DEBUG%==1 ( if exist "%_ROOT_DIR%linker.err" type "%_ROOT_DIR%linker.err"
) else if %_VERBOSE%==1 ( if exist "%_ROOT_DIR%linker.err" type "%_ROOT_DIR%linker.err"
)
set _EXITCODE=1
goto :eof
)
goto :eof
:compile_gm2
echo %_WARNING_LABEL% Not yet implemented
goto :eof
@rem input parameter: %1=.def files are out of date
:compile_xds
set __ACTION_DEF=%~1
if exist "%_SOURCE_DEF_DIR%\*.def" (
if %_DEBUG%==1 echo %_DEBUG_LABEL% xcopy /i /q /y "%_SOURCE_DEF_DIR%\*.def" "%_TARGET_DEF_DIR%\" 1>&2
xcopy /i /q /y "%_SOURCE_DEF_DIR%\*.def" "%_TARGET_DEF_DIR%\" %_STDOUT_REDIRECT%
)
if exist "%_SOURCE_MOD_DIR%\*.mod" (
if %_DEBUG%==1 echo %_DEBUG_LABEL% xcopy /i /q /y "%_SOURCE_MOD_DIR%\*.mod" "%_TARGET_MOD_DIR%\" 1>&2
xcopy /i /q /y "%_SOURCE_MOD_DIR%\*.mod" "%_TARGET_MOD_DIR%\" %_STDOUT_REDIRECT%
) else (
echo %_WARNING_LABEL% No Modula-2 implementation module found 1>&2
goto :eof
)
set "__PRJ_FILE=%_TARGET_DIR%\%_APP_NAME%.prj"
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% @rem Create XDS project file "!__PRJ_FILE:%_ROOT_DIR%=!" 1>&2
) else if %_VERBOSE%==1 ( echo Create XDS project file "!__PRJ_FILE:%_ROOT_DIR%=!" 1>&2
)
(
if %_DEBUG%==1 (
echo %% debug ON
echo -gendebug+
echo -genhistory+
echo -lineno+
)
echo -cpu = 486
echo -lookup = *.sym = sym;%XDSM2_HOME%\sym
echo -lookup = *.dll^|*.lib = bin;%XDSM2_HOME%\bin
echo -m2
echo %% recognize types SHORTINT, LONGINT, SHORTCARD and LONGCARD
echo %% -m2addtypes
echo %% -verbose
echo -werr
echo %% disable warning 301 ^(parameter "xxx" is never used^)
echo -woff301+
echo %% disable warning 303 ^(procedure "xxx" declared but never used^)
echo -woff303+
echo %% disable warning 306 ^(import of "xxx.yyy" is never used^)
echo -woff306+
) > "%__PRJ_FILE%"
set __N=0
for /f "delims=" %%f in ('dir /b "%_TARGET_MOD_DIR%\*.mod" 2^>NUL') do (
@rem source file path is either absolute or relative to project file
echo ^^!module !_TARGET_MOD_DIR:%_TARGET_DIR%\=!\%%f
set /a __N+=1
) >> "%__PRJ_FILE%"
if %__N%==0 (
echo %_WARNING_LABEL% No Modula-2 implementation module found 1>&2
goto :eof
) else if %__N%==1 ( set __N_FILES=%__N% Modula-2 implementation module
) else ( set __N_FILES=%__N% Modula-2 implementation modules
)
@rem add library dependencies to project file
for /f "delims=" %%f in ('dir /s /b "%_TARGET_BIN_DIR%\*.lib" 2^>NUL') do (
set "__LIB_FILE=%%f"
echo ^^!module !__LIB_FILE!
) >> "%__PRJ_FILE%"
pushd "%_TARGET_DIR%"
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_XC_CMD%" =p "%__PRJ_FILE%" 1>&2
) else if %_VERBOSE%==1 ( echo Compile %__N_FILES% into directory "!_TARGET_DIR:%_ROOT_DIR%=!" 1>&2
)
call "%_XC_CMD%" =p "%__PRJ_FILE%"
if not %ERRORLEVEL%==0 (
popd
echo %_ERROR_LABEL% Failed to compile %__N_FILES% into directory "!_TARGET_DIR:%_ROOT_DIR%=!" 1>&2
set _EXITCODE=1
goto :eof
)
popd
goto :eof
@rem input parameter: 1=target file 2,3,..=path (wildcards accepted)
@rem output parameter: _ACTION_REQUIRED
:action_required
set "__TARGET_FILE=%~1"
set __PATH_ARRAY=
set __PATH_ARRAY1=
:action_path
shift
set __PATH=%~1
if not defined __PATH goto action_next
set __PATH_ARRAY=%__PATH_ARRAY%,'%__PATH%'
set __PATH_ARRAY1=%__PATH_ARRAY1%,'!__PATH:%_ROOT_DIR%=!'
goto action_path
:action_next
set __TARGET_TIMESTAMP=00000000000000
for /f "usebackq" %%i in (`call "%_PWSH_CMD%" -c "gci -path '%__TARGET_FILE%' -ea Stop | select -last 1 -expandProperty LastWriteTime | Get-Date -uformat %%Y%%m%%d%%H%%M%%S" 2^>NUL`) do (
set __TARGET_TIMESTAMP=%%i
)
set __SOURCE_TIMESTAMP=00000000000000
for /f "usebackq" %%i in (`call "%_PWSH_CMD%" -c "gci -recurse -path %__PATH_ARRAY:~1% -ea Stop | sort LastWriteTime | select -last 1 -expandProperty LastWriteTime | Get-Date -uformat %%Y%%m%%d%%H%%M%%S" 2^>NUL`) do (
set __SOURCE_TIMESTAMP=%%i
)
call :newer %__SOURCE_TIMESTAMP% %__TARGET_TIMESTAMP%
set _ACTION_REQUIRED=%_NEWER%
if %_DEBUG%==1 (
echo %_DEBUG_LABEL% %__TARGET_TIMESTAMP% Target : '%__TARGET_FILE%' 1>&2
echo %_DEBUG_LABEL% %__SOURCE_TIMESTAMP% Sources: %__PATH_ARRAY:~1% 1>&2
echo %_DEBUG_LABEL% _ACTION_REQUIRED=%_ACTION_REQUIRED% 1>&2
) else if %_VERBOSE%==1 if %_ACTION_REQUIRED%==0 if %__SOURCE_TIMESTAMP% gtr 0 (
echo No action required ^(%__PATH_ARRAY1:~1%^) 1>&2
)
goto :eof
@rem input parameters: %1=source timestamp, %2=target timestamp
@rem output parameter: _NEWER
:newer
set __TIMESTAMP1=%~1
set __TIMESTAMP2=%~2
set __DATE1=%__TIMESTAMP1:~0,8%
set __TIME1=%__TIMESTAMP1:~-6%
set __DATE2=%__TIMESTAMP2:~0,8%
set __TIME2=%__TIMESTAMP2:~-6%
if %__DATE1% gtr %__DATE2% ( set _NEWER=1
) else if %__DATE1% lss %__DATE2% ( set _NEWER=0
) else if %__TIME1% gtr %__TIME2% ( set _NEWER=1
) else ( set _NEWER=0
)
goto :eof
:run
if not exist "%_TARGET_FILE%" (
echo %_ERROR_LABEL% Program "!_TARGET_FILE:%_ROOT_DIR%=!" not found 1>&2
set _EXITCODE=1
goto :eof
)
if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_TARGET_FILE%" 1>&2
) else if %_VERBOSE%==1 ( echo Execute program "!_TARGET_FILE:%_ROOT_DIR%=!" 1>&2
)
"%_TARGET_FILE%"
if not %ERRORLEVEL%==0 (
echo %_ERROR_LABEL% Failed to execute program "!_TARGET_FILE:%_ROOT_DIR%=!" 1>&2
set _EXITCODE=1
goto :eof
)
goto :eof
@rem #########################################################################
@rem ## Cleanups
:end
if %_DEBUG%==1 echo %_DEBUG_LABEL%_EXITCODE=%_EXITCODE% 1>&2
exit /b %_EXITCODE%
endlocal