-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddkbuild.cmd
1275 lines (1183 loc) · 53.4 KB
/
ddkbuild.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
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
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@echo off
@set VERSION=V7.4
@set OSR_DEBUG=off
@if "%OS%"=="Windows_NT" goto :Prerequisites
@echo This script requires Windows NT 4.0 or later to run properly!
goto :EOF
:Prerequisites
:: Check whether FINDSTR is available. It's used to show warnings etc.
findstr /? > NUL 2>&1 || echo "FINDSTR is a prerequisite but wasn't found!" && goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: $Id: ddkbuild.cmd 60 2009-11-28 04:28:01Z oliver $
::
:: This software is supplied for instructional purposes only.
::
:: OSR Open Systems Resources, Inc. (OSR) expressly disclaims any warranty
:: for this software. THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY
:: OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION,
:: THE IMPLIED WARRANTIES OF MECHANTABILITY OR FITNESS FOR A PARTICULAR
:: PURPOSE. THE ENTIRE RISK ARISING FROM THE USE OF THIS SOFTWARE REMAINS
:: WITH YOU. OSR's entire liability and your exclusive remedy shall not
:: exceed the price paid for this material. In no event shall OSR or its
:: suppliers be liable for any damages whatsoever (including, without
:: limitation, damages for loss of business profit, business interruption,
:: loss of business information, or any other pecuniary loss) arising out
:: of the use or inability to use this software, even if OSR has been
:: advised of the possibility of such damages. Because some states/
:: jurisdictions do not allow the exclusion or limitation of liability for
:: consequential or incidental damages, the above limitation may not apply
:: to you.
::
:: OSR Open Systems Resources, Inc.
:: 105 Route 101A Suite 19
:: Amherst, NH 03031 (603) 595-6500 FAX: (603) 595-6503
:: report bugs to <bugs@osr.com>
:: alternatively report them via <http://assarbad.net/contact/>
::
::
:: MODULE:
::
:: ddkbuild.cmd
::
:: ABSTRACT:
::
:: This script allows drivers to be built with Visual Studio 2002 through
:: Visual Studio 2008 and possibly future versions. It will also work fine
:: from the command line.
:: If you are interested in a project wizard that makes use of this script,
:: try DDKWizard from <http://ddkwizard.assarbad.net>.
::
:: AUTHOR(S):
::
:: - OSR Open Systems Resources, Inc.
:: - Oliver Schneider (ddkwizard.assarbad.net)
::
:: REQUIREMENTS:
::
:: Environment variables that must be set.
:: %NT4BASE% - Set this up for "-NT4" builds (legacy, support not tested)
:: %W2KBASE% - Set this up for "-W2K*" builds (legacy, support not tested)
:: %WXPBASE% - Set this up for "-WXP*" builds
:: %WNETBASE% - Set this up for "-WNET*" builds
:: %WLHBASE% - Set this up for "-WLH*" builds
:: %W7BASE% - Set this up for "-W7*" builds
:: %WDF_ROOT% - Must be set if attempting to do a WDF Build.
::
:: Examples:
:: NT4BASE : could be "D:\NT4DDK"
:: W2KBASE : could be "D:\Nt50DDK"
:: WXPBASE : could be "D:\WINDDK\2600"
:: WNETBASE: could be "D:\WINDDK\3790.1830" or "C:\WINDDK\3790"
:: W7BASE : could be "C:\WINDDK\7600.16385.0"
::
:: COMMAND FORMAT:
::
:: Run the script without any parameters to get the whole help content!
:: Note: "-WDF" has been tested with the 01.00.5054 version of the framework
::
:: RETURN CODES AND THEIR MEANING:
::
:: 001 == Unknown type of build. Please recheck parameters.
:: 002 == WDF_ROOT is not defined, are you using 00.01.5054 or later?
:: 003 == To build using type <target> you need to set the <basedir>
:: environment variable to point to the <basediros> DDK base
:: directory!
:: 004 == NT4BASE, W2KBASE, WXPBASE, WNETBASE and/or W7BASE environment
:: variable(s) not set. Environment variable(s) must be set by user
:: according to DDK version(s) installed.
:: 005 == <build type> must be 'checked', 'free', 'chk' or 'fre'
:: (case-insensitive).
:: 006 == No DIR or SOURCES file found in the given target directory.
:: 007 == Target directory must have a SOURCES+MAKEFILE or DIRS file.
:: 008 == The <directory> parameter must be a valid directory.
:: 009 == The SETENV script failed.
:: 254 == BUILD or PREfast not found or not executable.
::
:: Note: If %OSR_ERRCODE% and %ERRORLEVEL% are equal, the return code stems
:: from one of the tools being called during the build process.
::
:: BROWSE FILES:
::
:: This procedure supports the building of BROWSE files to be used by
:: Visual Studio 6 and by Visual Studio.NET However, the BSCfiles created
:: by bscmake for the two are not compatible. When this command procedure
:: runs, it selects the first bscmake.exe found in the path. So, make sure
:: that the correct bscmake.exe is in the path ...
::
:: Note that if using Visual Studio.NET the .BSC must be added to the project
:: in order for the project to be browsed.
:: Another alternative is the VS addon named "Visual Assist X" which will
:: parse the header files - no more need for browse files.
::
:: COMPILERS:
::
:: If you are building NT4 you should really be using the VC6 compiler.
:: Later versions of the DDK now contain the compiler and the linker. This
:: procedure should use the correct compiler.
::
:: GENERAL COMMENTS:
::
:: This procedure has been cleaned up to be modular and easy to understand.
::
:: To modify the default behavior of this script with the newest WDKs,
:: set the variable SETTING_OACR in the ddkbldenv.cmd hook script to turn
:: OACR back on (NB: no OACR tools exist for Itanium in the WDK).
::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: / MAIN function of the script
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:MAIN
:: Building "stack frame"
setlocal ENABLEEXTENSIONS & pushd .
:: Check whether the REG utility is available
reg /? > NUL 2>&1 && set OSR_REGAVAILABLE=1
:: This is set by client-side keyword substitution
set SVN_REVISION=$Revision: 60 $
:: Extract the revision number from the revision keyword
set SVN_REVISION=%SVN_REVISION:~0,-2%
set SVN_REVISION=%SVN_REVISION:~11%
:: This is set by client-side keyword substitution
set SVN_REVDATE=$Date: 2009-11-28 04:28:01 +0000 (Sat, 28 Nov 2009) $
:: Extract the date from the Date keyword
set SVN_REVDATE=%SVN_REVDATE:~7,10%
set VERSION=%VERSION%/r%SVN_REVISION%
:: Init some special variables
set OSR_VERSTR=OSR DDKBUILD.CMD %VERSION% (%SVN_REVDATE%) - OSR, Open Systems Resources, Inc.
set OSR_PREBUILD_SCRIPT=ddkprebld.cmd
set OSR_POSTBUILD_SCRIPT=ddkpostbld.cmd
set OSR_SETENV_SCRIPT=ddkbldenv.cmd
set OSR_ECHO=@echo DDKBLD:
set OSR_RANDEXT=%RANDOM%%RANDOM%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Set error messages
:: Possible codes: 1
set ERR_UnknownBuildType=Unknown type of build. Please recheck parameters.
:: Possible codes: 2
set ERR_NoWdfRoot=WDF_ROOT is not defined, are you using 00.01.5054 or later?
:: Possible codes: 3
set ERR_BaseDirNotSet=To build using type %%OSR_TARGET%% you need to set the %%%%%%BASEDIRVAR%%%%%% environment variable to point to the %%BASEDIROS%% DDK base directory!
:: Possible codes: 4
set ERR_NoBASEDIR=NT4BASE, W2KBASE, WXPBASE, WNETBASE and/or W7BASE environment variable(s) not set. Environment variable(s) must be set by user according to DDK version(s) installed.
:: Possible codes: 5
set ERR_BadMode=^<build type^> must be 'checked', 'free', 'chk' or 'fre' (case-insensitive).
:: Possible codes: 6
set ERR_NoTarget=Target directory must have a SOURCES+MAKEFILE or DIRS file.
:: Possible codes: 7, 8
set ERR_NoDir=The ^<directory^> parameter must be a valid directory.
:: Possible codes: 9
set ERR_SetEnvFailed=The SETENV script failed.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Clear the error code variable
set OSR_ERRCODE=0
set PREFAST_BUILD=0
:: Turn on tracing, use %OSR_TRACE% instead of ECHO
if /i "%OSR_DEBUG%" == "on" (set OSR_TRACE=%OSR_ECHO% [TRACE]) else (set OSR_TRACE=rem)
:: Turn on echoing of current line if %OSR_DEBUG% is set to "on"
@echo %OSR_DEBUG%
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: If the user wants to suppress the header part ... or the info about hook scripts
if /i "%~1" == "/nologo" (shift & set OSR_NOLOGO=1)
if /i "%~1" == "/notquiet" (shift & set OSR_NOTQUIET=1)
:: The next line is *not* a mistake or bug ... it ensures that the order does not matter
if /i "%~1" == "/nologo" (shift & set OSR_NOLOGO=1)
:: Set the target platform variable
set OSR_TARGET=%~1
:: Remove any dashes in the target
if not "%OSR_TARGET%" == "" set OSR_TARGET=%OSR_TARGET:-=%
:: Output version string
@if not DEFINED OSR_NOLOGO echo %OSR_VERSTR%
%OSR_TRACE% ^(Current module: ^"%~f0^"^)
@if not DEFINED OSR_NOLOGO echo.
:: Show help if the target parameter is empty after removal of the dashes
if "%OSR_TARGET%" == "" goto :USAGE
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: In the build directory check for this script and call it if it exists.
:: This allows to override any global system variable setting, if desired.
:: It also checks whether a DIRS/SOURCES file exists ...
if not "%3" == "" call :GetCustomEnvironment "%~f3"
if DEFINED HOOK_ABORT goto :END
if %OSR_ERRCODE% neq 0 goto :USAGE
:: Additional error handling for better usability
:: These subroutines will also attempt to locate the requested DDK!!!
set OSR_ERRCODE=3
%OSR_TRACE% Checking whether the environment variable for the build type was set
:: Calling as a subroutine has 2 advantages:
:: 1. the script does not quit if the label was not found
:: 2. we return to the line after the call and can check variables there
call :%OSR_TARGET%Check > NUL 2>&1
:: If the BASEDIROS/BASEDIRVAR variable is not defined, it means the subroutine did not exist!
if not DEFINED BASEDIROS call :ShowErrorMsg 1 "%ERR_UnknownBuildType% (BASEDIROS)" & goto :USAGE
if not DEFINED BASEDIRVAR call :ShowErrorMsg 1 "%ERR_UnknownBuildType% (BASEDIRVAR)" & goto :USAGE
if %OSR_ERRCODE% neq 0 call :ShowErrorMsg %OSR_ERRCODE% "%ERR_BaseDirNotSet%" & goto :USAGE
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set BASEDIR=%%%BASEDIRVAR%%%
call :ResolveVar BASEDIR
call :MakeShort BASEDIR "%BASEDIR%"
:: Check for existing %BASEDIR%
if "%BASEDIR%" == "" call :ShowErrorMsg 4 "%ERR_NoBASEDIR%" & goto :USAGE
set PATH=%BASEDIR%\bin;%PATH%
%OSR_TRACE% Now jump to the initialization of the commandline
:: Calling as a subroutine has 2 advantages:
:: 1. the script does not quit if the label was not found
:: 2. we return to the line after the call and can check variables there
call :%OSR_TARGET%Build
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%OSR_TRACE% We returned from the variable initialization
if not DEFINED OSR_CMDLINE call :ShowErrorMsg 1 "%ERR_UnknownBuildType% (OSR_CMDLINE)" & goto :USAGE
%OSR_TRACE% Hurrah, all the variables have been initialized, continuing
:: Proceed with common build steps
goto :CommonBuild
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Check whether the parameter makes sense and try to
:: correct it if possible
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These labels are for compatibility with the respective
:: modes supported by another flavor of DDKBUILD.
:WIN7Check
:WIN764Check
:WIN7A64Check
:WIN7WLHCheck
:WIN7WLH64Check
:WIN7WLHA64Check
:WIN7NETCheck
:WIN7NET64Check
:WIN7NETA64Check
:WIN7XPCheck
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:W7Check
:W7I64Check
:W7X64Check
:W7LHCheck
:W7LHI64Check
:W7LHX64Check
:W7NETCheck
:W7NETI64Check
:W7NETX64Check
:W7XPCheck
set BASEDIROS=Windows 7/Windows 2008 Server R2
set BASEDIRVAR=W7BASE
:: The default for OACR is off ("no_oacr" appended)
if not DEFINED SETTING_OACR set SETTING_OACR=no_oacr
:: The default for "separate_object_root" is to not pass it to setenv.bat
if not DEFINED SETTING_SEP_OBJ_ROOT set SETTING_SEPARATE_OBJ_ROOT=
:: Other flavor of DDKBUILD
if not DEFINED W7BASE if DEFINED WIN7BASE set BASEDIRVAR=WIN7BASE
:: Compatibility between BUILD and VS ... prevent pipes from being used
%OSR_ECHO% Clearing %%VS_UNICODE_OUTPUT%% ...
set VS_UNICODE_OUTPUT=
:: Return to caller if the BASEDIR is already defined (either customized or global)
if DEFINED %BASEDIRVAR% goto :CommonCheckNoErrorWithReturn
call :DetectBaseDirTemp "7600.16385.0"
if DEFINED BASEDIRTEMP if exist "%BASEDIRTEMP%" goto :CommonCheckSetVarWithReturn
goto :CommonCheckErrorNotSupportedWithReturn
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These labels are for compatibility with the respective
:: modes supported by another flavor of DDKBUILD.
:WLH64Check
:WLHA64Check
:WLHXP64Check
:WLHNET64Check
:WLHNETA64Check
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:WLHCheck
:WLHX64Check
:WLHI64Check
:WLHNETX64Check
:WLHNETI64Check
:WLHXPCheck
:WLH2KCheck
:WLHNETCheck
set BASEDIROS=Windows Vista/Windows 2008 Server
set BASEDIRVAR=WLHBASE
:: Compatibility between BUILD and VS ... prevent pipes from being used
%OSR_ECHO% Clearing %%VS_UNICODE_OUTPUT%% ...
set VS_UNICODE_OUTPUT=
:: Return to caller if the BASEDIR is already defined (either customized or global)
if DEFINED %BASEDIRVAR% goto :CommonCheckNoErrorWithReturn
call :DetectBaseDirTemp "6001.18002 6001.18001 6001.18000 6000"
if DEFINED BASEDIRTEMP if exist "%BASEDIRTEMP%" goto :CommonCheckSetVarWithReturn
goto :CommonCheckErrorNotSupportedWithReturn
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These labels are for compatibility with the respective
:: modes supported by another flavor of DDKBUILD.
:WNETW2KCheck
:WNETA64Check
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:WNET2KCheck
:WNETXPCheck
:WNETXP64Check
:WNET64Check
:WNETI64Check
:WNETAMD64Check
:WNETX64Check
:WNETCheck
set BASEDIROS=Windows 2003 Server
set BASEDIRVAR=WNETBASE
:: Return to caller if the BASEDIR is already defined (either customized or global)
if DEFINED %BASEDIRVAR% goto :CommonCheckNoErrorWithReturn
call :DetectBaseDirTemp "3790.1830 3790.1218 3790"
if DEFINED BASEDIRTEMP if exist "%BASEDIRTEMP%" goto :CommonCheckSetVarWithReturn
goto :CommonCheckErrorNotDetectedWithReturn
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: These labels are for compatibility with the respective
:: modes supported by another flavor of DDKBUILD.
:XPCheck
:XP64Check
:XPW2KCheck
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:WXP64Check
:WXPI64Check
:WXPCheck
:WXP2KCheck
set BASEDIROS=Windows XP
set BASEDIRVAR=WXPBASE
:: Other flavor of DDKBUILD
if not DEFINED WXPBASE if DEFINED XPBASE set BASEDIRVAR=XPBASE
:: Return to caller if the BASEDIR is already defined (either customized or global)
if DEFINED %BASEDIRVAR% goto :CommonCheckNoErrorWithReturn
call :DetectBaseDirTemp "2600.1106 2600"
if DEFINED BASEDIRTEMP if exist "%BASEDIRTEMP%" goto :CommonCheckSetVarWithReturn
goto :CommonCheckErrorNotDetectedWithReturn
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:W2K64Check
:W2KI64Check
:W2KCheck
set BASEDIROS=Windows 2000
set BASEDIRVAR=W2KBASE
:: Return to caller
if DEFINED %BASEDIRVAR% goto :CommonCheckNoErrorWithReturn
call :CommonCheckMsg2
goto :CommonCheckErrorNotSupportedWithReturn
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:NT4Check
set BASEDIROS=Windows NT4
set BASEDIRVAR=NT4BASE
:: Return to caller
if DEFINED %BASEDIRVAR% goto :CommonCheckNoErrorWithReturn
call :CommonCheckMsg2
goto :CommonCheckErrorNotSupportedWithReturn
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CommonCheckMsg1
echo.
%OSR_ECHO% WARNING: %%%BASEDIRVAR%%% NOT SET!
%OSR_ECHO% Attempting to auto-detect the installation folder and set %%%BASEDIRVAR%%%.
%OSR_ECHO% (If this fails *you* will have to set it!)
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CommonCheckMsg2
echo.
%OSR_ECHO% WARNING:
%OSR_ECHO% Auto-detection of the folder settings is not supported for the requested DDK.
%OSR_ECHO% Please set %%%BASEDIRVAR%%% yourself!
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CommonCheckSetVarWithReturn
%OSR_ECHO% Found!
echo.
set %BASEDIRVAR%=%BASEDIRTEMP%
set BASEDIRTEMP=
:: Tell the caller it was successful
:CommonCheckNoErrorWithReturn
set OSR_ERRCODE=0
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CommonCheckErrorNotDetectedWithReturn
echo.
%OSR_ECHO% None of the usual default paths works. Set %%%BASEDIRVAR%%% manually!
:CommonCheckErrorNotSupportedWithReturn
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Initialize variables specific to the respective platform
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: Valid parameters for setenv in different DDKs/WDKs:
::
:: 2600 - "setenv <directory> [fre|chk] [64] [hal]"
:: 2600.1106 - "setenv <directory> [fre|chk] [64] [hal] [WXP|W2K]"
:: 3790 - "setenv <directory> [fre|chk] [64|AMD64] [hal] [WXP|WNET|W2K]"
:: 3790.1830 - "setenv <directory> [fre|chk] [64|AMD64] [hal] [WXP|WNET|W2K] [no_prefast] [bscmake]"
:: 6000 - "setenv <directory> [fre|chk] [64|AMD64] [hal] [WLH|WXP|WNET|W2K] [bscmake]"
:: 6001.18000 - "setenv <directory> [fre|chk] [64|x64] [hal] [WLH|WXP|WNET|W2K] [bscmake]"
:: 6001.18001 - "setenv <directory> [fre|chk] [64|x64] [hal] [WLH|WXP|WNET|W2K] [bscmake]"
:: 6001.18002 - "setenv <directory> [fre|chk] [64|x64] [hal] [WLH|WXP|WNET|W2K] [bscmake]"
:: 7600.16385 - "setenv <directory> [fre|chk] [64|x64] [WIN7|WLH|WXP|WNET] [bscmake] [no_oacr] [separate_object_root]"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: NT 4.0 build using NT4 DDK
:NT4Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% "%%MSDEVDIR%%"
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W2K build for 32bit using WXP DDK
:XPW2KBuild
:WXP2KBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\w2k\set2k.bat" %%BASEDIR%% %%BuildMode%%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W2K build for 64bit (Itanium) using W2K DDK
:W2K64Build
:W2KI64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv64.bat" %%BASEDIR%% %%BuildMode%%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W2K build for 32bit using W2K DDK
:W2KBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WXP build for 64bit (Itanium) using WXP DDK
:XP64Build
:WXP64Build
:WXPI64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% 64
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WXP build for 32bit using WXP DDK
:XPBuild
:WXPBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W2K build for 32bit using WNET DDK
:WNETW2KBuild
:WNET2KBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% W2K %%BuildMode%%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WXP build for 32bit using WNET DDK
:WNETXPBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% WXP
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WXP build for 64bit using WNET DDK
:WNETXP64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% 64 WXP
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 64bit (Itanium) using WNET DDK
:WNET64Build
:WNETI64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% 64 WNET
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 64bit (x64) using WNET DDK
:WNETA64Build
:WNETAMD64Build
:WNETX64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% AMD64 WNET
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 32bit using WNET DDK
:WNETBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WLH build for 32bit using WLH WDK
:WLHBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% WLH
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WLH build for 64bit (x64) using WLH WDK
:WLHA64Build
:WLHX64Build
call :DetectVistaWDK
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% %OSR_AMD64FLAG% WLH
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WLH build for 64bit (Itanium) using WLH WDK
:WLH64Build
:WLHI64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% 64 WLH
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 64bit (x64) using WLH WDK
:WLHNETA64Build
:WLHNETX64Build
call :DetectVistaWDK
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% %OSR_AMD64FLAG% WNET
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 64bit (Itanium) using WLH WDK
:WLHNET64Build
:WLHNETI64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% 64 WNET
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WXP build for 32bit using WLH WDK
:WLHXPBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% WXP
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WXP build for 64bit (Itanium) using WLH WDK
:WLHXP64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% 64 WXP
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W2K build for 32bit using WLH WDK
:WLH2KBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% W2K
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 32bit using WLH WDK
:WLHNETBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% WNET
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W7 build for 32bit using W7/2008 WDK
:W7Build
:WIN7Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% x86 WIN7 %SETTING_OACR% %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W7 build for 64bit (x64) using W7/2008 WDK
:W7X64Build
:WIN7A64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% x64 WIN7 %SETTING_OACR% %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: W7 build for 64bit (Itanium) using W7/2008 WDK
:W7I64Build
:WIN764Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% ia64 WIN7 no_oacr %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WLH build for 32bit using W7/2008 WDK
:W7LHBuild
:WIN7WLHBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% x86 WLH %SETTING_OACR% %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WLH build for 64bit (x64) using W7/2008 WDK
:W7LHX64Build
:WIN7WLHA64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% x64 WLH %SETTING_OACR% %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WLH build for 64bit (Itanium) using W7/2008 WDK
:W7LHI64Build
:WIN7WLH64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% ia64 WLH no_oacr %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 32bit using W7/2008 WDK
:W7NETBuild
:WIN7NETBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% x86 WNET %SETTING_OACR% %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 64bit (x64) using W7/2008 WDK
:W7NETX64Build
:WIN7NETA64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% x64 WNET %SETTING_OACR% %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WNET build for 64bit (Itanium) using W7/2008 WDK
:W7NETI64Build
:WIN7NET64Build
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% ia64 WNET no_oacr %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: WXP build for 32bit using W7/2008 WDK
:W7XPBuild
:WIN7XPBuild
set OSR_CMDLINE="%%BASEDIR%%\bin\setenv.bat" %%BASEDIR%% %%BuildMode%% x86 WXP %SETTING_OACR% %SETTING_SEPARATE_OBJ_ROOT%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: All builds go here for the rest of the procedure. Now,
:: we are getting ready to call build. The big problem
:: here is to figure our the name of the buildxxx files
:: being generated for the different platforms.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CommonBuild
:: Remove first command line arg
shift
call :SetMode %1
if %OSR_ERRCODE% neq 0 call :ShowErrorMsg %OSR_ERRCODE% "%ERR_BadMode%" & goto :USAGE
set OSR_BUILDNAME=%OSR_TARGET% (%BuildMode%) using the %BASEDIROS% DDK and %%%BASEDIRVAR%%%
call :CheckTargets %2
if %OSR_ERRCODE% equ 6 call :ShowErrorMsg %OSR_ERRCODE% "%ERR_NoTarget%" & goto :USAGE
if %OSR_ERRCODE% neq 0 call :ShowErrorMsg %OSR_ERRCODE% "%ERR_NoDir%" & goto :USAGE
:: Resolve any variables in the command line string
call :ResolveVar OSR_CMDLINE
pushd .
set ERRORLEVEL=0
:: This external script prepares the build environment (e.g. setenv.bat)
call %OSR_CMDLINE%
:: Will only work with newer SETENV.BAT versions, but will be helpful in this case.
if not "%ERRORLEVEL%" == "0" call :ShowErrorMsg 9 "%ERR_SetEnvFailed%" & goto :USAGE
popd
:: Check whether BUILD can be executed ...
build /? > NUL 2>&1
if %ERRORLEVEL% neq 0 ( call :ShowErrorMsg 254 "BUILD not found or not executable!" & goto :END )
:: ----------------------------------------------------------------------------
:: Setting global variables for the scope of this CMD session
set NO_BROWSER_FILE=
set NO_BINPLACE=
set buildDirectory=%~fs2
call :MakeShort buildDirectory "%buildDirectory%"
set buildDirectory_raw=%2
set buildDirectory_fname=%~n2
%OSR_TRACE% buildDirectory == %buildDirectory%
%OSR_TRACE% buildDirectory_raw == %buildDirectory_raw%
%OSR_TRACE% buildDirectory_fname == %buildDirectory_fname%
set mpFlag=-M
if "%BUILD_ALT_DIR%" == "" goto :NT4
:: W2K sets this!
set OSR_EXT=%BUILD_ALT_DIR%
set mpFlag=-MI
:NT4
if "%NUMBER_OF_PROCESSORS%" == "" set mpFlag=
if "%NUMBER_OF_PROCESSORS%" == "1" set mpFlag=
:: Set additional variables at this point or do whatever you please
@if exist "%buildDirectory%\%OSR_PREBUILD_SCRIPT%" @(
if DEFINED OSR_NOTQUIET %OSR_ECHO% ^>^> Performing pre-build steps [%OSR_PREBUILD_SCRIPT%] ...
pushd "%buildDirectory%"
call "%OSR_PREBUILD_SCRIPT%" > "%TEMP%\%OSR_PREBUILD_SCRIPT%_%OSR_RANDEXT%.tmp"
for /f "tokens=*" %%x in ('type "%TEMP%\%OSR_PREBUILD_SCRIPT%_%OSR_RANDEXT%.tmp"') do @(
%OSR_ECHO% %%x
)
if exist "%TEMP%\%OSR_PREBUILD_SCRIPT%_%OSR_RANDEXT%.tmp" del /f /q "%TEMP%\%OSR_PREBUILD_SCRIPT%_%OSR_RANDEXT%.tmp"
popd
if DEFINED OSR_NOTQUIET %OSR_ECHO% ^<^< Finished pre-build steps [%OSR_PREBUILD_SCRIPT%] ...
)
if %OSR_ERRCODE% neq 0 (echo %OSR_PREBUILD_SCRIPT% requested abort ^(%OSR_ERRCODE%^) & goto :END)
:: Save the current directory (before changing into the build directory!)
:: AFTERPREBUILD
pushd .
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Determine the settings of flags, WDF and PREFAST in
:: other words what was set for %3 and beyond....
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
%OSR_ECHO% %OSR_BUILDNAME%
set OSR_ARGS= + argument(s):
if not "%3" == "" set OSR_ARGS=%OSR_ARGS% %3
if not "%4" == "" set OSR_ARGS=%OSR_ARGS% %4
if not "%5" == "" set OSR_ARGS=%OSR_ARGS% %5
if /i "%OSR_ARGS%" == " + argument(s):" set OSR_ARGS=
%OSR_ECHO% Directory: %buildDirectory%%OSR_ARGS%
%OSR_ECHO% %BASEDIRVAR%: %BASEDIR%
cd /D %~s2
set bFlags=-Ze
set bscFlags=
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:ContinueParsing
if "%3" == "" goto :DONE
if "%3" == "/a" goto :RebuildallFound
if /i "%3" == "-WDF" goto :WDFFound
if /i "%3" == "-PREFAST" goto :PrefastFound
if /i "%3" == "-CUV" goto :CallUsageVerifier
set bscFlags=/n
set bFlags=%bFlags% %3
:: Remove next arg
shift
goto :ContinueParsing
:WDFFound
shift
:: Note, that the setwdf.bat is called from setenv.bat in the WDK,
:: therefore we skip it.
if /i "%BASEDIRVAR%" == "WLHBASE" goto :WDFOkay
if /i "%BASEDIRVAR%" == "W7BASE" goto :WDFOkay
if /i "%BASEDIRVAR%" == "WIN7BASE" goto :WDFOkay
if "%WDF_ROOT%" == "" call :ShowErrorMsg 2 "%ERR_NoWdfRoot%" & goto :USAGE
pushd .
if exist "%WDF_ROOT%\set_wdf_env.cmd" call "%WDF_ROOT%\set_wdf_env.cmd"
popd
:WDFOkay
goto :ContinueParsing
:PrefastFound
shift
set PREFAST_BUILD=1
goto :ContinueParsing
:CallUsageVerifier
shift
set VERIFIER_DDK_EXTENSIONS=1
set PREFAST_BUILD=1
goto :ContinueParsing
:RebuildallFound
shift
set bscFlags=/n
set bFlags=%bFlags:-Ze=-cfeZ%
set bFlags=%bFlags: -cZ=%
goto :ContinueParsing
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:DONE
:: Check whether PREfast can be executed (also pop one directory) ...
if %PREFAST_BUILD% neq 0 prefast /? > NUL 2>&1
if %ERRORLEVEL% neq 0 ( popd & call :ShowErrorMsg 254 "PREfast not found or not executable!" & goto :END )
:: Remove old warnings and logs ...
for %%x in (build%OSR_EXT%.err build%OSR_EXT%.wrn build%OSR_EXT%.log prefast%OSR_EXT%.log) do @(
if exist "%%x" del /f /q "%%x"
)
if not "%PREFAST_BUILD%" == "0" goto :RunPrefastBuild
%OSR_ECHO% Run build %mpFlag% %bFlags% for %BuildMode% version in %buildDirectory_raw%
pushd .
build %mpFlag% %bFlags%
popd
goto :BuildComplete
:RunPrefastBuild
%OSR_ECHO% Run prefast build %mpFlag% %bFlags% for %BuildMode% version in %buildDirectory_raw%
setlocal ENABLEEXTENSIONS & pushd .
set PREFASTLOG=PREfast_defects_%OSR_EXT%.xml
prefast /log=%PREFASTLOG% /reset build %mpFlag% %bFlags% > NUL 2>&1
if %ERRORLEVEL% neq 0 set OSR_ERRCODE=%ERRORLEVEL%
prefast /log=%PREFASTLOG% list > prefast%OSR_EXT%.log
%OSR_ECHO% The PREfast logfile is ^"%prefastlog%^"!
popd & endlocal
:BuildComplete
if %ERRORLEVEL% neq 0 set OSR_ERRCODE=%ERRORLEVEL%
@echo %OSR_DEBUG%
:: Assume that the onscreen errors are complete!
setlocal
set WARNING_FILE_COUNT=0
if exist "build%OSR_EXT%.log" for /f "tokens=*" %%x in ('findstr "warning[^.][CDMRU][0-9][0-9]* warning[^.][BRP][KCWG][0-9][0-9]* warning[^.][ACLPS][DNRTVX][JKLTX][0-9][0-9]* error[^.][CDMRU][0-9][0-9]* error[^.][BRP][KCWG][0-9][0-9]* error[^.][ACLPS][DNRTVX][JKLTX][0-9][0-9]*" "build%OSR_EXT%.log"') do @(
set /a WARNING_FILE_COUNT=%WARNING_FILE_COUNT%+1
)
if not "%WARNING_FILE_COUNT%" == "0" (
%OSR_ECHO% ================ Build warnings =======================
if exist "build%OSR_EXT%.log" for /f "tokens=*" %%x in ('findstr "warning[^.][CDMRU][0-9][0-9]* warning[^.][BRP][KCWG][0-9][0-9]* warning[^.][ACLPS][DNRTVX][JKLTX][0-9][0-9]* error[^.][CDMRU][0-9][0-9]* error[^.][BRP][KCWG][0-9][0-9]* error[^.][ACLPS][DNRTVX][JKLTX][0-9][0-9]*" "build%OSR_EXT%.log"') do @(
@echo %%x
)
)
set WARNING_FILE_COUNT_PRE=0
if exist "prefast%OSR_EXT%.log" for /f "tokens=*" %%x in ('findstr "warning[^.][CDMRU][0-9][0-9]* warning[^.][BRP][KCWG][0-9][0-9]* warning[^.][ACLPS][DNRTVX][JKLTX][0-9][0-9]*" "prefast%OSR_EXT%.log"') do @(
set /a WARNING_FILE_COUNT_PRE=%WARNING_FILE_COUNT_PRE%+1
)
:: Reset if this is no PREfast build
if "%PREFAST_BUILD%" == "0" set WARNING_FILE_COUNT_PRE=0
if not "%WARNING_FILE_COUNT_PRE%" == "0" (
%OSR_ECHO% =============== PREfast warnings ======================
if exist "prefast%OSR_EXT%.log" for /f "tokens=*" %%x in ('findstr "warning[^.][CDMRU][0-9][0-9]* warning[^.][BRP][KCWG][0-9][0-9]* warning[^.][ACLPS][DNRTVX][JKLTX][0-9][0-9]*" "prefast%OSR_EXT%.log"') do @(
@echo %%x
)
)
set /a WARNING_FILE_COUNT=%WARNING_FILE_COUNT%+%WARNING_FILE_COUNT_PRE%
if not "%WARNING_FILE_COUNT%" == "0" (
%OSR_ECHO% =======================================================
)
endlocal
@echo.
%OSR_ECHO% Build complete
%OSR_ECHO% Building browse information files
if exist "buildbrowse.cmd" call "buildbrowse.cmd" & goto :postBuildSteps
set sbrlist=sbrList.txt
if not exist sbrList%CPU%.txt goto :sbrDefault
set sbrlist=sbrList%CPU%.txt
:sbrDefault
if not exist %sbrlist% goto :postBuildSteps
:: Prepend blank space
if not "%bscFlags%" == "" set bscFlags= %bscFlags%
:: bscmake%bscFlags% prevents a double blank space ...
bscmake%bscFlags% @%sbrlist%
:: Perform whatever post-build steps
:postBuildSteps
:: Restore the current directory (after changing into the build directory!)
:: Search upwards for "AFTERPREBUILD" to find the corresponding PUSHD
popd
@if exist "%buildDirectory%\%OSR_POSTBUILD_SCRIPT%" @(
if DEFINED OSR_NOTQUIET %OSR_ECHO% ^>^> Performing post-build steps [%OSR_POSTBUILD_SCRIPT%] ...
pushd "%buildDirectory%"
call "%OSR_POSTBUILD_SCRIPT%" > "%TEMP%\%OSR_POSTBUILD_SCRIPT%_%OSR_RANDEXT%.tmp"
for /f "tokens=*" %%x in ('type "%TEMP%\%OSR_POSTBUILD_SCRIPT%_%OSR_RANDEXT%.tmp"') do @(
%OSR_ECHO% %%x
)
if exist "%TEMP%\%OSR_POSTBUILD_SCRIPT%_%OSR_RANDEXT%.tmp" del /f /q "%TEMP%\%OSR_POSTBUILD_SCRIPT%_%OSR_RANDEXT%.tmp"
popd
if DEFINED OSR_NOTQUIET %OSR_ECHO% ^<^< Finished post-build steps [%OSR_POSTBUILD_SCRIPT%] ...
)
if %OSR_ERRCODE% neq 0 (echo %OSR_POSTBUILD_SCRIPT% requested abort ^(%OSR_ERRCODE%^) & goto :END)
goto :END
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: \ MAIN function of the script
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: / GetCustomEnvironment
:: First parameter is the "directory" that supposedly contains the SOURCES
:: or DIRS file (and the build scripts)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:GetCustomEnvironment
pushd .
call :CheckTargets "%~f1"
@if %OSR_ERRCODE% neq 0 @(
echo.
%OSR_ECHO% The target directory seemed to not contain a DIRS or SOURCES file
%OSR_ECHO% when trying to set a custom environment! Quitting. ^(ERROR #%OSR_ERRCODE%^)
set buildDirectory=%~f1
if %OSR_ERRCODE% equ 6 call :ShowErrorMsg %OSR_ERRCODE% "%ERR_NoTarget%" & goto :GetCustomEnvironment_ret
call :ShowErrorMsg %OSR_ERRCODE% "%ERR_NoDir%" & goto :GetCustomEnvironment_ret
goto :GetCustomEnvironment_ret
)
:: If the user provided a script to customize the environment, execute it.
@if exist "%~f1\%OSR_SETENV_SCRIPT%" @(
if DEFINED OSR_NOTQUIET %OSR_ECHO% ^>^> Setting custom environment variables [%OSR_SETENV_SCRIPT%] ...
pushd "%~f1"
call "%OSR_SETENV_SCRIPT%" > "%TEMP%\%OSR_SETENV_SCRIPT%_%OSR_RANDEXT%.tmp"
for /f "tokens=*" %%x in ('type "%TEMP%\%OSR_SETENV_SCRIPT%_%OSR_RANDEXT%.tmp"') do @(
%OSR_ECHO% %%x
)
if exist "%TEMP%\%OSR_SETENV_SCRIPT%_%OSR_RANDEXT%.tmp" del /f /q "%TEMP%\%OSR_SETENV_SCRIPT%_%OSR_RANDEXT%.tmp"
popd
if DEFINED OSR_NOTQUIET %OSR_ECHO% ^<^< Finished setting custom environment variables [%OSR_SETENV_SCRIPT%] ...
)
if %OSR_ERRCODE% neq 0 (echo %OSR_SETENV_SCRIPT% requested abort ^(%OSR_ERRCODE%^) & set HOOK_ABORT=1)
:GetCustomEnvironment_ret
popd
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: \ GetCustomEnvironment
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: / SetMode
:: Subroutine to validate the mode of the build passed in. It must be free,
:: FREE, fre, FRE or checked, CHECKED, chk, CHK. Anything else is an error.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:SetMode
set BuildMode=
if /i "%OSR_TARGET%" == "WLH2K" goto :SetModeWLH2K
for %%f in (free fre) do if /i "%%f" == "%1" set BuildMode=free
for %%f in (checked chk) do if /i "%%f" == "%1" set BuildMode=checked
goto :SetModeCommonEnd
:SetModeWLH2K
for %%f in (free fre) do if /i "%%f" == "%1" set BuildMode=f
for %%f in (checked chk) do if /i "%%f" == "%1" set BuildMode=c
:SetModeCommonEnd
%OSR_TRACE% Mode set to ^"%BuildMode%^"
if "%BuildMode%" == "" set OSR_ERRCODE=5
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: \ SetMode
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: / CheckTargets subroutine
:: Subroutine to validate that the target directory exists and that there is
:: either a DIRS or SOURCES and MakeFile in it.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:CheckTargets
:: Building "stack frame"
setlocal & pushd . & set OSR_ERRCODE=0
set lTarget=%~1
if not "%lTarget%" == "" goto :CheckTargets1
set OSR_ERRCODE=7
goto :CheckTargets_ret
:CheckTargets1
if exist "%lTarget%" goto :CheckTargets2
set OSR_ERRCODE=8
goto :CheckTargets_ret
:CheckTargets2
if not exist "%lTarget%\DIRS" goto :CheckTargets3
set OSR_ERRCODE=0
goto :CheckTargets_ret
:CheckTargets3
if exist "%lTarget%\SOURCES" goto :CheckTargets4
set OSR_ERRCODE=6
goto :CheckTargets_ret
:CheckTargets4
if exist "%lTarget%\MAKEFILE" goto :CheckTargets5
set OSR_ERRCODE=6
goto :CheckTargets_ret
:CheckTargets5
set OSR_ERRCODE=0
:CheckTargets_ret
:: Cleaning "stack frame" and returning error code into global scope
popd & endlocal & set OSR_ERRCODE=%OSR_ERRCODE%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: \ CheckTargets subroutine
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: / ResolveVar subroutine
:: There is only one parameter, the name of the variable to be resolved!
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:ResolveVar
:: Get the name of the variable we are working with
setlocal ENABLEEXTENSIONS & set VAR_NAME=%1
set VAR_TEMPRET2=%%%VAR_NAME%%%
:ResolveVarLoop
set VAR_TEMPRET1=%VAR_TEMPRET2%
set VAR_TEMPRET2=%VAR_TEMPRET1%
for /f "tokens=*" %%i in ('echo %VAR_TEMPRET1%') do (
set VAR_TEMPRET2=%%i
)
if not "%VAR_TEMPRET1%" == "%VAR_TEMPRET2%" goto :ResolveVarLoop
:: Re-export the variable out of the local scope
endlocal & set %VAR_NAME%=%VAR_TEMPRET1%
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: \ ResolveVar subroutine
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: / MakeShort subroutine
:: Two parameters. First parameter is the variable name, second is the path
:: to convert into a short filename.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:MakeShort
setlocal ENABLEEXTENSIONS
:: Get the name of the variable we are working with and the path to convert
set VAR_NAME=%~1