Annotation of embedaddon/ntp/ports/winnt/scripts/mkver.bat, revision 1.1
1.1 ! misho 1: @echo off
! 2: GOTO PROG
! 3:
! 4: see notes/remarks directly below this header:
! 5: ######################################################################
! 6: #
! 7: # Revision: mkver.bat
! 8: # Author: Frederick Czajka
! 9: # Date: 02/10/2000
! 10: # Purpose: Provide a NT Shell script to replace the perl script
! 11: # that replaced the UNIX mkver shell script.
! 12: #
! 13: #
! 14: #
! 15: # Notes: I had two goals with this script one to only use native
! 16: # NT Shell commands and two was too emulate the PERL style
! 17: # output. This required some work for the DATE format as
! 18: # you will see and TIME was really tricky to get a format
! 19: # matching PERLs!
! 20: #
! 21: #
! 22: # Changes:
! 23: # 12/21/2009 Dave Hart
! 24: # - packageinfo.sh uses prerelease= now not
! 25: # releasecandidate=
! 26: # 08/28/2009 Dave Hart
! 27: # - support for building using per-compiler subdirs of winnt
! 28: # 08/08/2006 Heiko Gerstung
! 29: # - bugfixed point / rcpoint errors leading to a wrong
! 30: # version string
! 31: # - added a few cases for uppercase strings
! 32: # 03/09/2005 Heiko Gerstung
! 33: # - added UTC offset to version time information
! 34: # - bugfixed several issues preventing this script to be used on NT4
! 35: # - removed an obsolete warning
! 36: #
! 37: # 03/08/2005 Danny Mayer
! 38: # - bugfixed NOBK label position
! 39: #
! 40: # 03/08/2005 Heiko Gerstung
! 41: # - bugfixed BK detection and support for multiple ChangeSets
! 42: #
! 43: # 02/24/2005 Heiko Gerstung
! 44: # - check if BK is installed and do not try to call it if not
! 45: #
! 46: #
! 47: # 02/03/2005 Heiko Gerstung
! 48: # - now getting NTP version from version.m4 (not configure)
! 49: # - added BK ChangeSet revision and Openssl-Indicator (-o)
! 50: # to the version number
! 51: # - major rework of the time and date recognition routines
! 52: # in order to reflect international settings and OS-
! 53: # dependand formats
! 54: #
! 55: ######################################################################
! 56:
! 57: Notes/Howtos:
! 58:
! 59: If you spot an error stating that bk.exe could not be found or executed
! 60: although it is installed on your computer, you should try to add the path
! 61: to your BK binary in your IDE configuration (for VisualStudio see
! 62: Tools/Options/Directories/Executables).
! 63:
! 64: Alternatively you can create a file called 'version' in the root path of
! 65: your ntp source tree which holds a string that is added to the version number.
! 66:
! 67:
! 68: :PROG
! 69: IF {%1} == {} GOTO USAGE
! 70: IF {%1} == {-H} GOTO USAGE
! 71: IF {%2} == {} GOTO USAGE
! 72: IF {%1} == {-P} GOTO BEGIN
! 73:
! 74:
! 75:
! 76: REM *****************************************************************************************************************
! 77: REM For any other bizarre permutation...
! 78: REM *****************************************************************************************************************
! 79: GOTO USAGE
! 80:
! 81: :BEGIN
! 82:
! 83: SET GENERATED_PROGRAM=%2
! 84:
! 85: REM *****************************************************************************************************************
! 86: REM Reimplemented from orginal Unix Shell script
! 87: REM *****************************************************************************************************************
! 88: IF NOT EXIST .version ECHO 0 > .version
! 89: FOR /F %%i IN (.version) do @SET RUN=%%i
! 90: SET /A RUN=%RUN%+1
! 91: ECHO %RUN% > .version
! 92:
! 93: REM *****************************************************************************************************************
! 94: REM Resetting variables
! 95: REM *****************************************************************************************************************
! 96: SET VER=
! 97: SET CSET=
! 98: SET SSL=
! 99: SET MYDATE=
! 100: SET MYTIME=
! 101: SET DAY=99
! 102: SET NMM=99
! 103: SET YEAR=0
! 104: SET HOUR=
! 105: SET MIN=
! 106: SET MMIN=
! 107: SET SEC=
! 108: SET SUBSEC=
! 109: SET DATEDELIM=
! 110: SET TIMEDELIM=
! 111: SET DATEFORMAT=
! 112: SET TIMEFORMAT=
! 113: SET UTC=
! 114: SET ACTIVEBIAS=
! 115:
! 116: REM *****************************************************************************************************************
! 117: REM Check if DATE and TIME environment variables are available
! 118: REM *****************************************************************************************************************
! 119:
! 120: SET MYDATE=%DATE%
! 121: SET MYTIME=%TIME%
! 122:
! 123: REM ** Not available (huh? Are you older than NT4SP6A, grandpa?)
! 124: IF "%MYDATE%" == "" FOR /F "TOKENS=1 DELIMS=" %%a IN ('date/t') DO SET MYDATE=%%a
! 125: IF "%MYTIME%" == "" FOR /F "TOKENS=1 DELIMS=" %%a IN ('time/t') DO SET MYTIME=%%a
! 126:
! 127: REM *****************************************************************************************************************
! 128: REM Try to find out UTC offset
! 129: REM *****************************************************************************************************************
! 130:
! 131: REM *** Start with setting a dummy value which is used when we are not able to find out the real UTC offset
! 132: SET UTC=(LOCAL TIME)
! 133: SET UTC_HR=
! 134: SET UTC_MIN=
! 135: SET UTC_SIGN=
! 136:
! 137: REM *** Now get the timezone settings from the registry
! 138: regedit /e %TEMP%\TZ-%GENERATED_PROGRAM%.TMP "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
! 139: IF NOT EXIST %TEMP%\TZ-%GENERATED_PROGRAM%.TMP GOTO NOTZINFO
! 140:
! 141: for /f "Tokens=1* Delims==" %%a in ('type %TEMP%\TZ-%GENERATED_PROGRAM%.TMP') do if %%a == "ActiveTimeBias" SET ACTIVEBIAS=%%b
! 142: for /f "Tokens=1* Delims=:" %%a in ('echo %ACTIVEBIAS%') do ( SET ACTIVEBIAS=%%b & SET PARTYP=%%a )
! 143:
! 144: REM *** Clean up temporary file
! 145: IF EXIST %TEMP%\TZ-%GENERATED_PROGRAM%.TMP DEL %TEMP%\TZ-%GENERATED_PROGRAM%.TMP
! 146:
! 147: REM *** Check if we really got a dword value from the registry ...
! 148: IF NOT "%PARTYP%"=="dword " goto NOTZINFO
! 149:
! 150: REM *** Check if we are in UTC timezone, then we can avoid some stress...
! 151: if "%ACTIVEBIAS%" == "00000000" SET UTC=(UTC) & GOTO NOTZINFO
! 152:
! 153: SET HI=0x%ACTIVEBIAS:~0,4%
! 154: SET LO=0x%ACTIVEBIAS:~4,4%
! 155:
! 156: if "%HI%"=="0xffff" ( SET /A ACTIVEBIAS=%LO% - %HI% - 1 ) ELSE ( SET /A ACTIVEBIAS=%LO%)
! 157: SET /A UTC_HR="%ACTIVEBIAS%/60"
! 158: SET /A UTC_MIN="%ACTIVEBIAS% %% 60"
! 159: SET UTC_SIGN=%ACTIVEBIAS:~0,1%
! 160:
! 161: REM *** check the direction in which the local timezone alters UTC time
! 162: IF NOT "%UTC_SIGN%"=="-" SET UTC_SIGN=+
! 163: IF "%UTC_SIGN%"=="-" SET UTC_HR=%UTC_HR:~1,2%
! 164:
! 165: REM *** Now turn the direction, because we need to know it from the viewpoint of UTC
! 166: IF "%UTC_SIGN%"=="+" (SET UTC_SIGN=-) ELSE (SET UTC_SIGN=+)
! 167:
! 168: REM *** Put the values in a "00" format
! 169: IF %UTC_HR% LEQ 9 SET UTC_HR=0%UTC_HR%
! 170: IF %UTC_MIN% LEQ 9 SET UTC_MIN=0%UTC_MIN%
! 171:
! 172: REM *** Set up UTC offset string used in version string
! 173: SET UTC=(UTC%UTC_SIGN%%UTC_HR%:%UTC_MIN%)
! 174:
! 175:
! 176: :NOTZINFO
! 177: echo off
! 178:
! 179: REM *****************************************************************************************************************
! 180: REM Now grab the Version number out of the source code (using the packageinfo.sh file...)
! 181: REM *****************************************************************************************************************
! 182:
! 183: REM First, get the main NTP version number. In recent versions this must be extracted
! 184: REM from a packageinfo.sh file while in earlier versions the info was available from
! 185: REM a version.m4 file.
! 186: SET F_PACKAGEINFO_SH=..\..\..\..\packageinfo.sh
! 187: IF EXIST %F_PACKAGEINFO_SH% goto VER_FROM_PACKAGE_INFO
! 188: REM next two lines can go away when all windows compilers are building under
! 189: rem ports\winnt\<compiler dir>\<binary name dir> (ports\winnt\vs2008\ntpd)
! 190: rem rather than ports\winnt\<binary name dir> (ports\winnt\ntpd)
! 191: SET F_PACKAGEINFO_SH=..\..\..\packageinfo.sh
! 192: IF EXIST %F_PACKAGEINFO_SH% goto VER_FROM_PACKAGE_INFO
! 193: goto ERRNOVERF
! 194:
! 195: :VER_FROM_PACKAGE_INFO
! 196: REM Get version from packageinfo.sh file, which contains lines reading e.g.
! 197:
! 198: TYPE %F_PACKAGEINFO_SH% | FIND /V "rcpoint=" | FIND /V "betapoint=" | FIND "point=" > point.txt
! 199: SET F_POINT_SH=point.txt
! 200:
! 201: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "proto=" %%F_PACKAGEINFO_SH%%') DO SET PROTO=%%a
! 202: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "major=" %%F_PACKAGEINFO_SH%%') DO SET MAJOR=%%a
! 203: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "minor=" %%F_PACKAGEINFO_SH%%') DO SET MINOR=%%a
! 204:
! 205: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "point=" %%F_POINT_SH%%') DO SET POINT=%%a
! 206: IF "%POINT%"=="NEW" set POINT=
! 207: IF NOT "%POINT%"=="" set POINT=p%POINT%
! 208:
! 209: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "betapoint=" %%F_PACKAGEINFO_SH%%') DO SET BETAPOINT=%%a
! 210:
! 211: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "rcpoint=" %%F_PACKAGEINFO_SH%%') DO SET RCPOINT=%%a
! 212:
! 213: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "special=" %%F_PACKAGEINFO_SH%%') DO SET SPECIAL=%%a
! 214: IF NOT "%SPECIAL%"=="" set SPECIAL=-%SPECIAL%
! 215:
! 216: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "prerelease=" %%F_PACKAGEINFO_SH%%') DO SET PRERELEASE=%%a
! 217: IF /I "%PRERELEASE%"=="beta" set PR_SUF=-beta
! 218: IF /I "%PRERELEASE%"=="rc" set PR_SUF=-RC
! 219:
! 220: FOR /F "eol=# TOKENS=2 DELIMS==" %%a IN ('findstr "repotype=" %%F_PACKAGEINFO_SH%%') DO SET REPOTYPE=%%a
! 221: IF /I "%REPOTYPE%"=="stable" set REPOTYPE=STABLE
! 222:
! 223: IF NOT "%REPOTYPE%"=="STABLE" SET RCPOINT=
! 224: IF "%PR_SUF%"=="-RC" set PR_POINT=%RCPOINT%
! 225: IF "%PR_SUF%"=="-beta" set PR_POINT=%BETAPOINT%
! 226:
! 227: SET VER=%PROTO%.%MAJOR%.%MINOR%%POINT%%SPECIAL%%PR_SUF%%PR_POINT%
! 228:
! 229: REM Now we have the version info, try to add a BK ChangeSet version number
! 230:
! 231: REM ** Check if BK is installed ...
! 232: bk -R prs -hr+ -nd:I: ChangeSet 2> NUL > NUL
! 233: IF ERRORLEVEL 1 GOTO NOBK
! 234:
! 235: REM ** Try to get the CSet rev directly from BK
! 236: FOR /F "TOKENS=1 DELIMS==" %%a IN ('bk.exe -R prs -hr+ -nd:I: ChangeSet') DO @SET CSET=%%a
! 237:
! 238: :NOBK
! 239: REM ** If that was not successful, we'll take a look into a version file, if available
! 240: IF EXIST ..\..\..\..\version (
! 241: IF "%CSET%"=="" FOR /F "TOKENS=1" %%a IN ('type ..\..\..\..\version') DO @SET CSET=%%a
! 242: )
! 243: REM next if block can go away once all windows compilers are building in
! 244: REM ports\winnt\<compiler dir>\<binary name dir> (ports\winnt\vs2008\ntpd)
! 245: IF EXIST ..\..\..\version (
! 246: IF "%CSET%"=="" FOR /F "TOKENS=1" %%a IN ('type ..\..\..\version') DO @SET CSET=%%a
! 247: )
! 248:
! 249: REM ** Now, expand our version number with the CSet revision, if we managed to get one
! 250: IF NOT "%CSET%"=="" SET VER=%VER%@%CSET%
! 251:
! 252: REM We can add a "crypto" identifier (-o) if we see that Crypto support is included in our build
! 253: REM we always include openssl on windows...
! 254: SET VER=%VER%-o
! 255:
! 256:
! 257: REM *****************************************************************************************************************
! 258: REM Check for user settings regarding the time and date format, we use the registry to find out...
! 259: REM *****************************************************************************************************************
! 260:
! 261:
! 262: REM Any temporary files left from a previous run? Go where you belong...
! 263: IF exist userset.reg del userset.reg
! 264: IF exist userset.txt del userset.txt
! 265:
! 266: regedit /E userset.reg "HKEY_CURRENT_USER\Control Panel\International"
! 267: IF not exist userset.reg goto ERRNOREG
! 268:
! 269: rem *** convert from unicode to ascii if necessary
! 270: type userset.reg > userset.txt
! 271:
! 272:
! 273: FOR /F "TOKENS=1-9 DELIMS== " %%a IN ('findstr "iDate" userset.txt') DO SET DATEFORMAT=%%b
! 274: FOR /F "TOKENS=1-9 DELIMS== " %%a IN ('findstr "iTime" userset.txt') DO SET TIMEFORMAT=%%b
! 275:
! 276: FOR /F "TOKENS=1-9 DELIMS== " %%a IN ('findstr /R "sDate\>" userset.txt') DO SET DATEDELIM=%%b
! 277: FOR /F "TOKENS=1-9 DELIMS== " %%a IN ('findstr /R "sTime\>" userset.txt') DO SET TIMEDELIM=%%b
! 278:
! 279: IF "%TIMEFORMAT%"=="" GOTO ERRNOTIME
! 280: IF "%DATEFORMAT%"=="" GOTO ERRNODATE
! 281: IF "%TIMEDELIM%"=="" GOTO ERRNOTIME
! 282: IF "%DATEDELIM%"=="" GOTO ERRNODATE
! 283:
! 284: SET TIMEDELIM=%TIMEDELIM:~1,1%
! 285: SET DATEDELIM=%DATEDELIM:~1,1%
! 286: SET TIMEFORMAT=%TIMEFORMAT:~1,1%
! 287: SET DATEFORMAT=%DATEFORMAT:~1,1%
! 288:
! 289: REM *****************************************************************************************************************
! 290: REM Well, well. Its time to look at the time and format it in a standard way (if possible)
! 291: REM *****************************************************************************************************************
! 292:
! 293:
! 294: FOR /F "TOKENS=1-4 DELIMS=%TIMEDELIM% " %%a IN ('echo %MYTIME%') DO SET AA=%%a&SET BB=%%b&SET CC=%%c&SET DD=%%d
! 295:
! 296: REM 12H Format
! 297: IF "%TIMEFORMAT%" == "0" (
! 298: SET HOUR=%AA%
! 299: SET MIN=%BB%
! 300: FOR /F "USEBACKQ TOKENS=1 DELIMS=ap" %%a IN ('%BB%') DO SET MMIN=%%a
! 301: SET SEC=%CC%
! 302: SET SUBSEC=%DD%
! 303: )
! 304:
! 305: REM Get rid of the "a" or "p" if we have one of these in our minute string
! 306: IF NOT "%MMIN%"=="%MIN%" FOR /F "USEBACKQ TOKENS=1 DELIMS=ap " %%a IN ('%MIN%') DO SET MIN=%%a
! 307:
! 308: REM 24H Format
! 309: IF "%TIMEFORMAT%" == "1" (
! 310: SET HOUR=%AA%
! 311: SET MIN=%BB%
! 312: SET SEC=%CC%
! 313: SET SUBSEC=%DD%
! 314: )
! 315:
! 316: IF "%HOUR%"=="" GOTO ERRNOTIME
! 317: IF "%MIN%"=="" GOTO ERRNOTIME
! 318:
! 319: IF "%SEC%"=="" SET SEC=00
! 320: IF "%SUBSEC%"=="" SET SUBSEC=00
! 321:
! 322:
! 323: REM *****************************************************************************************************************
! 324: REM It's time to format the date :-)
! 325: REM *****************************************************************************************************************
! 326:
! 327:
! 328: FOR /F "TOKENS=1-4 DELIMS=./- " %%a IN ('ECHO %MYDATE%') DO SET AA=%%a&SET BB=%%b&SET CC=%%c&SET DD=%%d
! 329:
! 330: IF "%DD%" == "" (
! 331: REM No Day of Week in Date
! 332: ( IF "%DATEFORMAT%" == "0" SET DOW=_&SET DAY=%BB%&SET NMM=%AA%&SET YEAR=%CC% )
! 333: ( IF "%DATEFORMAT%" == "1" SET DOW=_&SET DAY=%AA%&SET NMM=%BB%&SET YEAR=%CC% )
! 334: ( IF "%DATEFORMAT%" == "2" SET DOW=_&SET DAY=%CC%&SET NMM=%BB%&SET YEAR=%AA% )
! 335: ) ELSE (
! 336: ( IF "%DATEFORMAT%" == "0" SET DOW=%AA%&SET DAY=%CC%&SET NMM=%BB%&SET YEAR=%DD% )
! 337: ( IF "%DATEFORMAT%" == "1" SET DOW=%AA%&SET DAY=%BB%&SET NMM=%CC%&SET YEAR=%DD% )
! 338: ( IF "%DATEFORMAT%" == "2" SET DOW=%AA%&SET DAY=%DD%&SET NMM=%CC%&SET YEAR=%BB% )
! 339: )
! 340:
! 341: REM Something went wrong, we weren't able to get a valid date
! 342: IF NOT "%YEAR%" == "0" GOTO DATEOK
! 343: goto ERRNODATE
! 344:
! 345: :DATEOK
! 346:
! 347: REM Clean up any temporary files we may have created...
! 348: REM IF exist userset.reg del userset.reg
! 349: REM IF exist userset.txt del userset.txt
! 350:
! 351: IF "%NMM%" == "01" SET MONTH=Jan
! 352: IF "%NMM%" == "02" SET MONTH=Feb
! 353: IF "%NMM%" == "03" SET MONTH=Mar
! 354: IF "%NMM%" == "04" SET MONTH=Apr
! 355: IF "%NMM%" == "05" SET MONTH=May
! 356: IF "%NMM%" == "06" SET MONTH=Jun
! 357: IF "%NMM%" == "07" SET MONTH=Jul
! 358: IF "%NMM%" == "08" SET MONTH=Aug
! 359: IF "%NMM%" == "09" SET MONTH=Sep
! 360: IF "%NMM%" == "10" SET MONTH=Oct
! 361: IF "%NMM%" == "11" SET MONTH=Nov
! 362: IF "%NMM%" == "12" SET MONTH=Dec
! 363:
! 364: IF NOT {%MONTH%} == {} GOTO DATE_OK
! 365:
! 366: REM *** Not US date format! Assume ISO: yyyy-mm-dd
! 367:
! 368: FOR /F "TOKENS=1-4 DELIMS=/- " %%a IN ('date/t') DO SET DAY=%%a&SET yyyy=%%b&SET nmm=%%c&SET dd=%%d
! 369:
! 370: echo a=%%a b=%%b c=%%c d=%%d
! 371: IF "%NMM%" == "01" SET MONTH=Jan
! 372: IF "%NMM%" == "02" SET MONTH=Feb
! 373: IF "%NMM%" == "03" SET MONTH=Mar
! 374: IF "%NMM%" == "04" SET MONTH=Apr
! 375: IF "%NMM%" == "05" SET MONTH=May
! 376: IF "%NMM%" == "06" SET MONTH=Jun
! 377: IF "%NMM%" == "07" SET MONTH=Jul
! 378: IF "%NMM%" == "08" SET MONTH=Aug
! 379: IF "%NMM%" == "09" SET MONTH=Sep
! 380: IF "%NMM%" == "10" SET MONTH=Oct
! 381: IF "%NMM%" == "11" SET MONTH=Nov
! 382: IF "%NMM%" == "12" SET MONTH=Dec
! 383:
! 384: :DATE_OK
! 385: IF "%SS" == "" SET SS="00"
! 386:
! 387:
! 388: REM *****************************************************************************************************************
! 389: REM Now create a valid version.c file ...
! 390: REM *****************************************************************************************************************
! 391:
! 392: ECHO Version %VER% Build %RUN% date %MONTH%/%DAY%/%YEAR% time %HOUR%:%MIN%:%SEC% %UTC%
! 393: ECHO char * Version = "%GENERATED_PROGRAM% %VER% %MONTH% %DAY% %HOUR%:%MIN%:%SEC% %UTC% %YEAR% (%RUN%)" ; > version.c
! 394: GOTO EOF
! 395:
! 396:
! 397: REM *****************************************************************************************************************
! 398: REM Here are the error messages I know
! 399: REM *****************************************************************************************************************
! 400: :ERRNOREG
! 401: ECHO "Error: Registry could not be read (check if regedit.exe is available and works as expected)"
! 402: GOTO EOF
! 403:
! 404:
! 405: :ERRNODATE
! 406: ECHO "Error: Dateformat unknown (check if contents of userset.txt are correctly, especially for iDate and sDate)"
! 407: GOTO EOF
! 408:
! 409: :ERRNOTIME
! 410: ECHO "Error: Timeformat unknown (check if contents of userset.txt are correctly, especially for iTime and sTime)"
! 411: GOTO EOF
! 412:
! 413: :ERRNOVERF
! 414: ECHO "Error: Version file not found (searching for ..\..\..\..\packageinfo.sh)"
! 415: GOTO EOF
! 416:
! 417:
! 418: REM *****************************************************************************************************************
! 419: REM Show'em how to run (me)
! 420: REM *****************************************************************************************************************
! 421: :USAGE
! 422:
! 423: ECHO Usage: mkver.bat [ -P <Program Name> -H ]
! 424: ECHO -P Database Name
! 425: ECHO -H Help on options
! 426:
! 427: REM *****************************************************************************************************************
! 428: REM All good things come to an end someday. Time to leave
! 429: REM *****************************************************************************************************************
! 430: :EOF
! 431:
! 432: REM *** Cleaning up
! 433: IF EXIST point.txt DEL point.txt
! 434: IF EXIST userset.txt DEL userset.txt
! 435: IF EXIST userset.reg DEL userset.reg
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>