-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure.vbs
2240 lines (1998 loc) · 85.1 KB
/
configure.vbs
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
' $Id$
'' @file
' The purpose of this script is to check for all external tools, headers, and
' libraries VBox OSE depends on.
'
' The script generates the build configuration file 'AutoConfig.kmk' and the
' environment setup script 'env.bat'. A log of what has been done is
' written to 'configure.log'.
'
'
' Copyright (C) 2006-2023 Oracle and/or its affiliates.
'
' This file is part of VirtualBox base platform packages, as
' available from https://www.virtualbox.org.
'
' This program is free software; you can redistribute it and/or
' modify it under the terms of the GNU General Public License
' as published by the Free Software Foundation, in version 3 of the
' License.
'
' This program is distributed in the hope that it will be useful, but
' WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
' General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program; if not, see <https://www.gnu.org/licenses>.
'
' SPDX-License-Identifier: GPL-3.0-only
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Header Files
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
' Includes a vbscript file relative to the script.
sub IncludeFile(strFilename)
dim objFile, objFileSys
set objFileSys = WScript.CreateObject("Scripting.FileSystemObject")
dim strPath : strPath = objFileSys.BuildPath(objFileSys.GetParentFolderName(Wscript.ScriptFullName), strFilename)
set objFile = objFileSys.openTextFile(strPath)
executeglobal objFile.readAll()
objFile.close
set objFileSys = nothing
end sub
IncludeFile "tools\win\vbscript\helpers.vbs"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Global Variables '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
dim g_strPath, g_strEnvFile, g_strLogFile, g_strCfgFile
g_strPath = Left(Wscript.ScriptFullName, Len(Wscript.ScriptFullName) - Len("\configure.vbs"))
g_strEnvFile = g_strPath & "\env.bat"
g_strCfgFile = g_strPath & "\AutoConfig.kmk"
g_strLogFile = g_strPath & "\configure.log"
'g_strTmpFile = g_strPath & "\configure.tmp"
' kBuild stuff.
dim g_strPathkBuild, g_strPathkBuildBin, g_strPathDev, g_arrPathDev
g_strPathkBuild = ""
g_strPathkBuildBin = ""
g_strPathDev = ""
g_arrPathDev = Array(":placeholder:")
dim g_strTargetArch, g_StrTargetArchWin
g_strTargetArch = ""
g_StrTargetArchWin = ""
dim g_strHostArch, g_strHostArchWin
g_strHostArch = ""
g_strHostArchWin = ""
' Visual C++ info.
dim g_strPathVCC, g_strVCCVersion
g_strPathVCC = ""
g_strVCCVersion = ""
' SDK and DDK.
dim g_strPathSDK10, g_strPathPSDK, g_strVerPSDK, g_strPathDDK
g_strPathSDK10 = ""
g_strPathPSDK = ""
g_strVerPSDK = ""
g_strPathDDK = ""
' COM disabling.
dim g_blnDisableCOM, g_strDisableCOM
g_blnDisableCOM = False
g_strDisableCOM = ""
' Whether to try the internal stuff first or last.
dim g_blnInternalFirst
g_blnInternalFirst = True
' List of program files locations.
dim g_arrProgramFiles
if EnvGet("ProgramFiles(x86)") <> "" then
g_arrProgramFiles = Array(EnvGet("ProgramFiles"), EnvGet("ProgramFiles(x86)"))
else
g_arrProgramFiles = Array(EnvGet("ProgramFiles"))
end if
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Helpers: Logging and Logged operations '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
' Write a log header with some basic info.
sub LogInit
FileDelete g_strLogFile
LogPrint "# Log file generated by " & Wscript.ScriptFullName
for i = 1 to WScript.Arguments.Count
LogPrint "# Arg #" & i & ": " & WScript.Arguments.Item(i - 1)
next
if Wscript.Arguments.Count = 0 then
LogPrint "# No arguments given"
end if
LogPrint "# Reconstructed command line: " & GetCommandline()
' some Wscript stuff
LogPrint "# Wscript properties:"
LogPrint "# ScriptName: " & Wscript.ScriptName
LogPrint "# Version: " & Wscript.Version
LogPrint "# Build: " & Wscript.BuildVersion
LogPrint "# Name: " & Wscript.Name
LogPrint "# Full Name: " & Wscript.FullName
LogPrint "# Path: " & Wscript.Path
LogPrint "#"
' the environment
LogPrint "# Environment:"
dim objEnv
for each strVar in g_objShell.Environment("PROCESS")
LogPrint "# " & strVar
next
LogPrint "#"
end sub
''
' Append text to the log file.
sub LogPrint(str)
FileAppendLine g_strLogFile, str
'Wscript.Echo "dbg: " & str
end sub
''
' Debug output.
sub DbgPrint(str)
'FileAppendLine g_strLogFile, str
'Wscript.Echo "dbg: " & str
end sub
''
' Checks if the file exists and logs failures.
function LogFileExists(strPath, strFilename)
LogFileExists = FileExists(strPath & "/" & strFilename)
if LogFileExists = False then
LogPrint "Testing '" & strPath & "': " & strFilename & " not found"
end if
end function
''
' Checks if the file exists and logs failures.
function LogFileExists1(strPath)
LogFileExists1 = FileExists(strPath)
if LogFileExists1 = False then
LogPrint "Testing '" & strPath & "': file not found"
end if
end function
''
' Checks if the directory exists and logs failures.
function LogDirExists(strPath)
LogDirExists = DirExists(strPath)
if LogDirExists = False then
LogPrint "Testing '" & strPath & "': not found (or not dir)"
end if
end function
''
' Finds the first file matching the pattern.
' If no file is found, log the failure.
function LogFindFile(strPath, strPattern)
dim str, strOutput
'
' Yes, there are some facy database kinda interface to the filesystem
' however, breaking down the path and constructing a usable query is
' too much hassle. So, we'll do it the unix way...
'
if Shell("dir /B """ & DosSlashes(strPath) & "\" & DosSlashes(strPattern) & """", True, strOutput) = 0 _
And InStr(1, strOutput, Chr(13)) > 1 _
then
' return the first word.
LogFindFile = Left(strOutput, InStr(1, strOutput, Chr(13)) - 1)
else
LogPrint "Testing '" & strPath & "': " & strPattern & " not found"
LogFindFile = ""
end if
end function
''
' Finds the first directory matching the pattern.
' If no directory is found, log the failure,
' else return the complete path to the found directory.
function LogFindDir(strPath, strPattern)
dim str, strOutput
'
' Yes, there are some facy database kinda interface to the filesystem
' however, breaking down the path and constructing a usable query is
' too much hassle. So, we'll do it the unix way...
'
' List the alphabetically last names as first entries (with /O-N).
if Shell("dir /B /AD /O-N """ & DosSlashes(strPath) & "\" & DosSlashes(strPattern) & """", True, strOutput) = 0 _
And InStr(1, strOutput, Chr(13)) > 1 _
then
' return the first word.
LogFindDir = strPath & "/" & Left(strOutput, InStr(1, strOutput, Chr(13)) - 1)
else
LogPrint "Testing '" & strPath & "': " & strPattern & " not found"
LogFindDir = ""
end if
end function
''
' Wrapper around RegGetString that logs successes.
function LogRegGetString(strName)
LogRegGetString = RegGetString(strName)
if LogRegGetString <> "" then LogPrint "RegGetString(" & strName & ") -> " & LogRegGetString
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Helpers: Configuration and Batch Script Writers '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
' Initializes the config file.
sub CfgInit
FileDelete g_strCfgFile
CfgPrint "# -*- Makefile -*-"
CfgPrint "#"
CfgPrint "# Build configuration generated by " & GetCommandline()
CfgPrint "#"
CfgPrintAssign "VBOX_OSE", "1"
CfgPrintAssignRecursive "VBOX_VCC_WERR", "$(NO_SUCH_VARIABLE)"
end sub
''
' Prints a string to the config file.
sub CfgPrint(str)
FileAppendLine g_strCfgFile, str
end sub
''
' Prints a simple assignment to the config file.
sub CfgPrintAssign(strVar, strValue)
if strValue = "" then
FileAppendLine g_strCfgFile, RightPad(strVar, 23) & " :="
else
FileAppendLine g_strCfgFile, RightPad(strVar, 23) & " := " & strValue
end if
end sub
''
' Prints a recursive assignment to the config file.
sub CfgPrintAssignRecursive(strVar, strValue)
FileAppendLine g_strCfgFile, RightPad(strVar, 23) & " = " & strValue
end sub
''
' Initializes the environment batch script.
sub EnvInit
FileDelete g_strEnvFile
EnvPrint "@echo off"
EnvPrint "rem"
EnvPrint "rem Environment setup script generated by " & GetCommandline()
EnvPrint "rem"
end sub
''
' Prints a string to the environment batch script.
sub EnvPrint(str)
FileAppendLine g_strEnvFile, str
end sub
''
' Helper for EnvPrintPrepend and EnvPrintAppend.
sub EnvPrintCleanup(strEnv, strValue, strSep)
dim cchValueAndSep
FileAppendLine g_strEnvFile, "set " & strEnv & "=%" & strEnv & ":" & strSep & strValue & strSep & "=" & strSep & "%"
cchValueAndSep = Len(strValue) + Len(strSep)
FileAppendLine g_strEnvFile, "if ""%" & strEnv & "%""==""" & strValue & """ set " & strEnv & "="
FileAppendLine g_strEnvFile, "if ""%" & strEnv & ":~0," & cchValueAndSep & "%""==""" & strValue & strSep & """ set " & strEnv & "=%" & strEnv & ":~" & cchValueAndSep & "%"
FileAppendLine g_strEnvFile, "if ""%" & strEnv & ":~-" & cchValueAndSep & "%""==""" & strSep & strValue & """ set " & strEnv & "=%" & strEnv & ":~0,-" & cchValueAndSep & "%"
end sub
'' Use by EnvPrintPrepend to skip ';' stripping.
dim g_strPrependCleanEnvVars
''
' Print a statement prepending strValue to strEnv, removing duplicate values.
sub EnvPrintPrepend(strEnv, strValue, strSep)
' Remove old values and any leading separators.
EnvPrintCleanup strEnv, strValue, strSep
if InStr(1, g_strPrependCleanEnvVars, "|" & strEnv & "|") = 0 then
FileAppendLine g_strEnvFile, "if ""%" & strEnv & ":~0,1%""==""" & strSep & """ set " & strEnv & "=%" & strEnv & ":~1%"
FileAppendLine g_strEnvFile, "if ""%" & strEnv & ":~0,1%""==""" & strSep & """ set " & strEnv & "=%" & strEnv & ":~1%"
g_strPrependCleanEnvVars = g_strPrependCleanEnvVars & "|" & strEnv & "|"
end if
' Do the setting
FileAppendLine g_strEnvFile, "set " & strEnv & "=" & strValue & strSep & "%" & strEnv & "%"
end sub
'' Use by EnvPrintPrepend to skip ';' stripping.
dim g_strAppendCleanEnvVars
''
' Print a statement appending strValue to strEnv, removing duplicate values.
sub EnvPrintAppend(strEnv, strValue, strSep)
' Remove old values and any trailing separators.
EnvPrintCleanup strEnv, strValue, strSep
if InStr(1, g_strAppendCleanEnvVars, "|" & strEnv & "|") = 0 then
FileAppendLine g_strEnvFile, "if ""%" & strEnv & ":~-1%""==""" & strSep & """ set " & strEnv & "=%" & strEnv & ":~0,-1%"
FileAppendLine g_strEnvFile, "if ""%" & strEnv & ":~-1%""==""" & strSep & """ set " & strEnv & "=%" & strEnv & ":~0,-1%"
g_strAppendCleanEnvVars = g_strAppendCleanEnvVars & "|" & strEnv & "|"
end if
' Do the setting.
FileAppendLine g_strEnvFile, "set " & strEnv & "=%" & strEnv & "%" & strSep & strValue
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Feature disabling '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
' No COM
sub DisableCOM(strReason)
if g_blnDisableCOM = False then
LogPrint "Disabled COM components: " & strReason
g_blnDisableCOM = True
g_strDisableCOM = strReason
CfgPrintAssign "VBOX_WITH_MAIN", ""
CfgPrintAssign "VBOX_WITH_QTGUI", ""
CfgPrintAssign "VBOX_WITH_VBOXSDL", ""
CfgPrintAssign "VBOX_WITH_DEBUGGER_GUI", ""
end if
end sub
''
' No UDPTunnel
sub DisableUDPTunnel(strReason)
if g_blnDisableUDPTunnel = False then
LogPrint "Disabled UDPTunnel network transport: " & strReason
g_blnDisableUDPTunnel = True
g_strDisableUDPTunnel = strReason
CfgPrintAssign "VBOX_WITH_UDPTUNNEL", ""
end if
end sub
''
' No SDL
sub DisableSDL(strReason)
if g_blnDisableSDL = False then
LogPrint "Disabled SDL frontend: " & strReason
g_blnDisableSDL = True
g_strDisableSDL = strReason
CfgPrintAssign "VBOX_WITH_VBOXSDL", ""
end if
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Tool/Library Locating and Checking '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
' Generic helper for looking for a tools under g_strPathDev.
'
' The callback function takes the '.../tools/win.arch/tool/version' dir and
' varUser as arguments, returning an non-empty string if it was found suitable.
'
function SearchToolsEx(strTool, strVerPrefix, ByRef fnCallback, ByRef varUser, ByRef arrToolsDirs)
dim strToolsDir, arrDirs, strDir
SearchToolsEx = ""
for each strToolsDir in arrToolsDirs
arrDirs = GetSubdirsStartingWithRVerSorted(strToolsDir, strVerPrefix)
for each strDir in arrDirs
SearchToolsEx = fnCallback(strToolsDir & "/" & strDir, varUser)
if SearchToolsEx <> "" then
exit function
end if
next
next
end function
'' Search under g_strPathDev for a tool, target arch only.
function SearchTargetTools(strTool, strVerPrefix, ByRef fnCallback, ByRef varUser)
dim i
redim arrToolsDirs(ArraySize(g_arrPathDev) - 1)
for i = 0 to UBound(g_arrPathDev)
arrToolsDirs(i) = g_arrPathDev(i) & "/win." & g_strTargetArch & "/" & strTool
next
SearchTargetTools = SearchToolsEx(strTool, strVerPrefix, fnCallback, varUser, arrToolsDirs)
end function
'' Search under g_strPathDev for a tool, target arch and alternative arches.
function SearchTargetPlusTools(strTool, strVerPrefix, ByRef fnCallback, ByRef varUser)
dim i
redim arrToolsDirs(ArraySize(g_arrPathDev)*3 - 1)
for i = 0 to UBound(g_arrPathDev)
arrToolsDirs(i*3 + 0) = g_arrPathDev(i) & "/win." & g_strTargetArch & "/" & strTool
arrToolsDirs(i*3 + 1) = g_arrPathDev(i) & "/win.x86/" & strTool
arrToolsDirs(i*3 + 2) = g_arrPathDev(i) & "/win.amd64/" & strTool
next
SearchTargetPlusTools = SearchToolsEx(strTool, strVerPrefix, fnCallback, varUser, arrToolsDirs)
end function
'' Search under g_strPathDev for a tool, host arch first.
function SearchHostTools(strTool, strVerPrefix, ByRef fnCallback, ByRef varUser)
dim i
redim arrToolsDirs(ArraySize(g_arrPathDev) * 3 - 1)
for i = 0 to UBound(g_arrPathDev)
arrToolsDirs(i*3 + 0) = g_arrPathDev(i) & "/win." & g_strHostArch & "/" & strTool
arrToolsDirs(i*3 + 1) = g_arrPathDev(i) & "/win.x86/" & strTool
arrToolsDirs(i*3 + 2) = g_arrPathDev(i) & "/win.amd64/" & strTool
next
SearchHostTools = SearchToolsEx(strTool, strVerPrefix, fnCallback, varUser, arrToolsDirs)
end function
'' Search under g_strPathDev for a tool, common dir first.
function SearchCommonTools(strTool, strVerPrefix, ByRef fnCallback, ByRef varUser)
dim i
redim arrToolsDirs(ArraySize(g_arrPathDev) * 4 - 1)
for i = 0 to UBound(g_arrPathDev)
arrToolsDirs(i*4 + 0) = g_arrPathDev(i) & "/win.common/" & strTool
arrToolsDirs(i*4 + 1) = g_arrPathDev(i) & "/win." & g_strTargetArch & "/" & strTool
arrToolsDirs(i*4 + 2) = g_arrPathDev(i) & "/win.x86/" & strTool
arrToolsDirs(i*4 + 3) = g_arrPathDev(i) & "/win.amd64/" & strTool
next
SearchCommonTools = SearchToolsEx(strTool, strVerPrefix, fnCallback, varUser, arrToolsDirs)
end function
''
' Checks the the path doesn't contain characters the tools cannot deal with.
'
sub CheckSourcePath
dim sPwd
sPwd = PathAbsLong(g_strPath) ' Must check the long version.
if InStr(1, sPwd, " ") > 0 then
MsgError "Source path contains spaces! Please move it. (" & sPwd & ")"
end if
if InStr(1, sPwd, "$") > 0 then
MsgError "Source path contains the '$' char! Please move it. (" & sPwd & ")"
end if
if InStr(1, sPwd, "%") > 0 then
MsgError "Source path contains the '%' char! Please move it. (" & sPwd & ")"
end if
if InStr(1, sPwd, Chr(10)) > 0 _
or InStr(1, sPwd, Chr(13)) > 0 _
or InStr(1, sPwd, Chr(9)) > 0 _
then
MsgError "Source path contains control characters! Please move it. (" & sPwd & ")"
end if
Print "Source path: OK"
end sub
''
' Checks for kBuild - very simple :)
'
sub CheckForkBuild(strOptkBuild)
dim blnNeedEnvVars, strOutput
PrintHdr "kBuild"
'
' Check if there is a 'kmk' in the path somewhere without
' any KBUILD_*PATH stuff around.
'
blnNeedEnvVars = True
g_strPathkBuild = strOptkBuild
g_strPathkBuildBin = ""
if (g_strPathkBuild = "") _
And (EnvGetFirst("KBUILD_PATH", "PATH_KBUILD") = "") _
And (EnvGetFirst("KBUILD_BIN_PATH", "PATH_KBUILD_BIN") = "") _
And (Shell("kmk.exe --version", True, strOutput) = 0) _
And (InStr(1,strOutput, "kBuild Make 0.1") > 0) _
And (InStr(1,strOutput, "KBUILD_PATH") > 0) _
And (InStr(1,strOutput, "KBUILD_BIN_PATH") > 0) then
'' @todo Need to parse out the KBUILD_PATH and KBUILD_BIN_PATH values to complete the other tests.
'blnNeedEnvVars = False
MsgWarning "You've installed kBuild it seems. configure.vbs hasn't been updated to " _
& "deal with that yet and will use the one it ships with. Sorry."
end if
'
' Check for the KBUILD_PATH env.var. and fall back on root/kBuild otherwise.
'
if g_strPathkBuild = "" then
g_strPathkBuild = EnvGetFirst("KBUILD_PATH", "PATH_KBUILD")
if (g_strPathkBuild <> "") and (FileExists(g_strPathkBuild & "/footer.kmk") = False) then
MsgWarning "Ignoring incorrect kBuild path (KBUILD_PATH=" & g_strPathkBuild & ")"
g_strPathkBuild = ""
end if
if g_strPathkBuild = "" then
g_strPathkBuild = g_strPath & "/kBuild"
end if
end if
g_strPathkBuild = UnixSlashes(PathAbs(g_strPathkBuild))
'
' Check for env.vars that kBuild uses (do this early to set g_strTargetArch).
'
str = EnvGetFirst("KBUILD_TYPE", "BUILD_TYPE")
if (str <> "") _
And (InStr(1, "|release|debug|profile|kprofile", str) <= 0) then
EnvPrint "set KBUILD_TYPE=release"
EnvSet "KBUILD_TYPE", "release"
MsgWarning "Found unknown KBUILD_TYPE value '" & str &"' in your environment. Setting it to 'release'."
end if
str = EnvGetFirst("KBUILD_TARGET", "BUILD_TARGET")
if (str <> "") _
And (InStr(1, "win|win32|win64", str) <= 0) then '' @todo later only 'win' will be valid. remember to fix this check!
EnvPrint "set KBUILD_TARGET=win"
EnvSet "KBUILD_TARGET", "win"
MsgWarning "Found unknown KBUILD_TARGET value '" & str &"' in your environment. Setting it to 'win32'."
end if
str = EnvGetFirst("KBUILD_TARGET_ARCH", "BUILD_TARGET_ARCH")
if (str <> "") _
And (InStr(1, "x86|amd64", str) <= 0) then
EnvPrint "set KBUILD_TARGET_ARCH=x86"
EnvSet "KBUILD_TARGET_ARCH", "x86"
MsgWarning "Found unknown KBUILD_TARGET_ARCH value '" & str &"' in your environment. Setting it to 'x86'."
str = "x86"
end if
if g_strTargetArch = "" then '' command line parameter --target-arch=x86|amd64 has priority
if str <> "" then
g_strTargetArch = str
elseif (EnvGet("PROCESSOR_ARCHITEW6432") = "AMD64" ) _
Or (EnvGet("PROCESSOR_ARCHITECTURE") = "AMD64" ) then
g_strTargetArch = "amd64"
else
g_strTargetArch = "x86"
end if
else
if InStr(1, "x86|amd64", g_strTargetArch) <= 0 then
EnvPrint "set KBUILD_TARGET_ARCH=x86"
EnvSet "KBUILD_TARGET_ARCH", "x86"
MsgWarning "Unknown --target-arch=" & str &". Setting it to 'x86'."
end if
end if
LogPrint " Target architecture: " & g_strTargetArch & "."
Wscript.Echo " Target architecture: " & g_strTargetArch & "."
EnvPrint "set KBUILD_TARGET_ARCH=" & g_strTargetArch
' Windows variant of the arch name.
g_strTargetArchWin = g_strTargetArch
if g_strTargetArchWin = "amd64" then g_strTargetArchWin = "x64"
str = EnvGetFirst("KBUILD_TARGET_CPU", "BUILD_TARGET_CPU")
' perhaps a bit pedantic this since this isn't clearly define nor used much...
if (str <> "") _
And (InStr(1, "i386|i486|i686|i786|i868|k5|k6|k7|k8", str) <= 0) then
EnvPrint "set BUILD_TARGET_CPU=i386"
EnvSet "KBUILD_TARGET_CPU", "i386"
MsgWarning "Found unknown KBUILD_TARGET_CPU value '" & str &"' in your environment. Setting it to 'i386'."
end if
str = EnvGetFirst("KBUILD_HOST", "BUILD_PLATFORM")
if (str <> "") _
And (InStr(1, "win|win32|win64", str) <= 0) then '' @todo later only 'win' will be valid. remember to fix this check!
EnvPrint "set KBUILD_HOST=win"
EnvSet "KBUILD_HOST", "win"
MsgWarning "Found unknown KBUILD_HOST value '" & str &"' in your environment. Setting it to 'win32'."
end if
str = EnvGetFirst("KBUILD_HOST_ARCH", "BUILD_PLATFORM_ARCH")
if str <> "" then
if InStr(1, "x86|amd64", str) <= 0 then
str = "x86"
MsgWarning "Found unknown KBUILD_HOST_ARCH value '" & str &"' in your environment. Setting it to 'x86'."
end if
elseif (EnvGet("PROCESSOR_ARCHITEW6432") = "AMD64" ) _
Or (EnvGet("PROCESSOR_ARCHITECTURE") = "AMD64" ) then
str = "amd64"
else
str = "x86"
end if
LogPrint " Host architecture: " & str & "."
Wscript.Echo " Host architecture: " & str & "."
EnvPrint "set KBUILD_HOST_ARCH=" & str
g_strHostArch = str
' Windows variant of the arch name.
g_strHostArchWin = g_strHostArch
if g_strHostArchWin = "amd64" then g_strHostArchWin = "x64"
str = EnvGetFirst("KBUILD_HOST_CPU", "BUILD_PLATFORM_CPU")
' perhaps a bit pedantic this since this isn't clearly define nor used much...
if (str <> "") _
And (InStr(1, "i386|i486|i686|i786|i868|k5|k6|k7|k8", str) <= 0) then
EnvPrint "set KBUILD_HOST_CPU=i386"
EnvSet "KBUILD_HOST_CPU", "i386"
MsgWarning "Found unknown KBUILD_HOST_CPU value '" & str &"' in your environment. Setting it to 'i386'."
end if
'
' Determin the location of the kBuild binaries.
'
if g_strPathkBuildBin = "" then
g_strPathkBuildBin = g_strPathkBuild & "/bin/win." & g_strHostArch
if FileExists(g_strPathkBuildBin & "/kmk.exe") = False then
g_strPathkBuildBin = g_strPathkBuild & "/bin/win.x86"
end if
end if
g_strPathkBuildBin = UnixSlashes(PathAbs(g_strPathkBuildBin))
'
' Perform basic validations of the kBuild installation.
'
if (FileExists(g_strPathkBuild & "/footer.kmk") = False) _
Or (FileExists(g_strPathkBuild & "/header.kmk") = False) _
Or (FileExists(g_strPathkBuild & "/rules.kmk") = False) then
MsgFatal "Can't find valid kBuild at '" & g_strPathkBuild & "'. Either there is an " _
& "incorrect KBUILD_PATH in the environment or the checkout didn't succeed."
exit sub
end if
if (FileExists(g_strPathkBuildBin & "/kmk.exe") = False) _
Or (FileExists(g_strPathkBuildBin & "/kmk_ash.exe") = False) then
MsgFatal "Can't find valid kBuild binaries at '" & g_strPathkBuildBin & "'. Either there is an " _
& "incorrect KBUILD_PATH in the environment or the checkout didn't succeed."
exit sub
end if
if (Shell(DosSlashes(g_strPathkBuildBin & "/kmk.exe") & " --version", True, strOutput) <> 0) then
MsgFatal "Can't execute '" & g_strPathkBuildBin & "/kmk.exe --version'. check configure.log for the out."
exit sub
end if
'
' If KBUILD_DEVTOOLS is set, check that it's pointing to something useful.
'
str = UnixSlashes(EnvGet("KBUILD_DEVTOOLS"))
g_strPathDev = str
if str <> "" _
and LogDirExists(str & "/bin") _
and LogDirExists(str & "/win.amd64/bin") _
and LogDirExists(str & "/win.x86/bin") _
then
LogPrint "Found KBUILD_DEVTOOLS='" & str & "'."
elseif str <> "" then
MsgWarning "Ignoring bogus KBUILD_DEVTOOLS='" & str &"' in your environment!"
g_strPathDev = strNew
end if
if g_strPathDev = "" then
g_strPathDev = UnixSlashes(g_strPath & "/tools")
LogPrint "Using KBUILD_DEVTOOLS='" & g_strPathDev & "'."
if str <> "" then
EnvPrint "set KBUILD_DEVTOOLS=" & g_strPathDev
EnvSet "KBUILD_DEVTOOLS", g_strPathDev
end if
end if
g_arrPathDev(ArrayFindString(g_arrPathDev, ":placeholder:")) = g_strPathDev
'
' Write KBUILD_PATH and updated PATH to the environment script if necessary.
'
if blnNeedEnvVars = True then
EnvPrint "set KBUILD_PATH=" & g_strPathkBuild
EnvSet "KBUILD_PATH", g_strPathkBuild
if Right(g_strPathkBuildBin, 7) = "win.x86" then
EnvPrintCleanup "PATH", DosSlashes(Left(g_strPathkBuildBin, Len(g_strPathkBuildBin) - 7) & "win.amd64"), ";"
end if
if Right(g_strPathkBuildBin, 9) = "win.amd64" then
EnvPrintCleanup "PATH", DosSlashes(Left(g_strPathkBuildBin, Len(g_strPathkBuildBin) - 9) & "win.x86"), ";"
end if
EnvPrintPrepend "PATH", DosSlashes(g_strPathkBuildBin), ";"
EnvPrependPathItem "PATH", g_strPathkBuildBin, ";"
end if
PrintResult "kBuild", g_strPathkBuild
PrintResult "kBuild binaries", g_strPathkBuildBin
end sub
''
' Checks for Visual C++ version 16 (2019), 15 (2017), 14 (2015), 12 (2013), 11 (2012) or 10 (2010).
'
sub CheckForVisualCPP(strOptVC, strOptVCCommon)
PrintHdr "Visual C++"
'
' Try find it...
'
dim objState, strProgFiles
set objState = new VisualCPPState
objState.check strOptVC, strOptVCCommon
if g_blnInternalFirst = True then objState.checkInternal
objState.checkProgItems "2019"
objState.checkProgFiles "Microsoft Visual Studio\2019\BuildTools\VC"
objState.checkProgFiles "Microsoft Visual Studio\2019\Professional\VC"
objState.checkProgFiles "Microsoft Visual Studio\2019\Community\VC"
objState.checkRegistry "Microsoft\VisualStudio\SxS\VS7\16.0", "VC", "" ' doesn't work.
objState.checkProgItems "2017"
objState.checkProgFiles "Microsoft Visual Studio\2017\BuildTools\VC"
objState.checkProgFiles "Microsoft Visual Studio\2017\Professional\VC"
objState.checkProgFiles "Microsoft Visual Studio\2017\Community\VC"
objState.checkProgFiles "Microsoft Visual Studio\2017\Express\VC"
objState.checkRegistry "Microsoft\VisualStudio\SxS\VS7\15.0", "VC", ""
objState.checkRegistry "Microsoft\VisualStudio\SxS\VS7\14.0", "VC", "Common7"
objState.checkRegistry "Microsoft\VisualStudio\SxS\VS7\12.0", "VC", "Common7" '?
objState.checkRegistry "Microsoft\VisualStudio\SxS\VS7\11.0", "VC", "Common7" '?
objState.checkProg "cl.exe"
objState.checkRegistry "Microsoft\VisualStudio\10.0\Setup\VS\ProductDir", "VC", "Common7"
if g_blnInternalFirst = False then objState.checkInternal
if objState.m_blnFound = False then
MsgError "Cannot find cl.exe (Visual C++) anywhere on your system. Check the build requirements."
exit sub
end if
g_strPathVCC = objState.m_strPathVC
g_strVCCVersion = objState.m_strVersion
'
' Ok, emit build config variables.
'
CfgPrintAssign "VBOX_VCC_TOOL_STEM", objState.m_strVersion
CfgPrintAssign "PATH_TOOL_" & objState.m_strVersion, g_strPathVCC
CfgPrintAssign "PATH_TOOL_" & objState.m_strVersion & "X86", "$(PATH_TOOL_" & objState.m_strVersion & ")"
CfgPrintAssign "PATH_TOOL_" & objState.m_strVersion & "AMD64", "$(PATH_TOOL_" & objState.m_strVersion & ")"
if objState.m_strVersion = "VCC100" _
or objState.m_strVersion = "VCC110" _
or objState.m_strVersion = "VCC120" _
or objState.m_strVersion = "VCC140" _
then
CfgPrintAssign "VBOX_WITH_NEW_VCC", "" '?? for VCC110+
else
CfgPrintAssign "VBOX_WITH_NEW_VCC", "1"
end if
PrintResult "Visual C++ " & objState.m_strVersion, g_strPathVCC
' And the env.bat path fix.
if objState.m_strPathVCCommon <> "" then
EnvPrintAppend "PATH", DosSlashes(objState.m_strPathVCCommon) & "\IDE", ";"
end if
end sub
'' Class we use for detecting Visual C++
class VisualCPPState
public m_blnFound
public m_strPathVC
public m_strPathVCCommon
public m_strVersion
public m_strClVersion
public m_blnNewLayout
private sub Class_Initialize
m_blnFound = False
m_strPathVC = ""
m_strPathVCCommon = ""
m_strVersion = ""
m_strClVersion = ""
m_blnNewLayout = false
end sub
public function checkClExe(strClExe)
' We'll have to make sure mspdbXX.dll is somewhere in the PATH.
dim strSavedPath, rcExit, strOutput
strSavedPath = EnvGet("PATH")
if (m_strPathVCCommon <> "") then
EnvAppendPathItem "PATH", m_strPathVCCommon & "/IDE", ";"
end if
rcExit = Shell(DosSlashes(strClExe), True, strOutput)
EnvSet "PATH", strSavedPath
checkClExe = False
if rcExit = 0 then
' Extract the ' Version xx.yy.build.zz for arch' bit.
dim offVer, offEol, strVer
strVer = ""
offVer = InStr(1, strOutput, " Version ")
if offVer > 0 then
offVer = offVer + Len(" Version ")
offEol = InStr(offVer, strOutput, Chr(13))
if offEol > 0 then
strVer = Trim(Mid(strOutput, offVer, offEol - offVer))
end if
end if
' Check that it's a supported version
checkClExe = True
if InStr(1, strVer, "16.") = 1 then
m_strVersion = "VCC100"
elseif InStr(1, strVer, "17.") = 1 then
m_strVersion = "VCC110"
LogPrint "The Visual C++ compiler ('" & strClExe & "') version isn't really supported, but may work: " & strVer
elseif InStr(1, strVer, "18.") = 1 then
m_strVersion = "VCC120"
LogPrint "The Visual C++ compiler ('" & strClExe & "') version isn't really supported, but may work: " & strVer
elseif InStr(1, strVer, "19.0") = 1 then
m_strVersion = "VCC140"
LogPrint "The Visual C++ compiler ('" & strClExe & "') version isn't really supported, but may work: " & strVer
elseif InStr(1, strVer, "19.1") = 1 then
m_strVersion = "VCC141"
LogPrint "The Visual C++ compiler ('" & strClExe & "') version isn't really supported, but may work: " & strVer
elseif InStr(1, strVer, "19.2") = 1 then
m_strVersion = "VCC142"
else
LogPrint "The Visual C++ compiler we found ('" & strClExe & "') isn't in the 10.0-19.2x range (" & strVer & ")."
LogPrint "Check the build requirements and select the appropriate compiler version."
checkClExe = False
exit function
end if
LogPrint "'" & strClExe & "' = " & m_strVersion & " (" & strVer & ")"
else
LogPrint "Executing '" & strClExe & "' (which we believe to be the Visual C++ compiler driver) failed (rcExit=" & rcExit & ")."
end if
end function
public function checkInner(strPathVC) ' For the new layout only
if m_blnFound = False then
if LogDirExists(strPathVC & "/bin") _
and LogDirExists(strPathVC & "/lib") _
and LogDirExists(strPathVC & "/include") _
and LogFileExists(strPathVC, "include/stdarg.h") _
and LogFileExists(strPathVC, "lib/x64/libcpmt.lib") _
and LogFileExists(strPathVC, "lib/x86/libcpmt.lib") _
and LogFileExists(strPathVC, "bin/Host" & g_strHostArchWin & "/" & g_strTargetArchWin & "/cl.exe") _
and LogFileExists(strPathVC, "bin/Host" & g_strHostArchWin & "/" & g_strHostArchWin & "/cl.exe") _
then
LogPrint " => seems okay. new layout."
m_blnFound = checkClExe(strPathVC & "/bin/Host" & g_strHostArchWin & "/" & g_strTargetArchWin & "/cl.exe")
if m_blnFound then
m_strPathVC = strPathVC
end if
end if
end if
checkInner = m_blnFound
end function
public function check(strPathVC, strPathVCommon)
if (m_blnFound = False) and (strPathVC <> "") then
m_strPathVC = UnixSlashes(PathAbs(strPathVC))
m_strPathVCCommon = strPathVCCommon
m_strVersion = ""
LogPrint "Trying: strPathVC=" & m_strPathVC & " strPathVCCommon=" & m_strPathVCCommon
if LogDirExists(m_strPathVC) then
' 15.0+ layout? This is fun because of the multiple CL versions (/tools/msvc/xx.yy.bbbbb/).
' OTOH, the user may have pointed us directly to one of them.
if LogDirExists(m_strPathVC & "/Tools/MSVC") then
m_blnNewLayout = True
LogPrint " => seems okay. new layout."
dim arrFolders, i
arrFolders = GetSubdirsStartingWithVerSorted(m_strPathVC & "/Tools/MSVC", "14.2")
if UBound(arrFolders) < 0 then arrFolders = GetSubdirsStartingWithVerSorted(m_strPathVC & "/Tools/MSVC", "14.1")
if UBound(arrFolders) < 0 then arrFolders = GetSubdirsStartingWithVerSorted(m_strPathVC & "/Tools/MSVC", "1")
for i = UBound(arrFolders) to LBound(arrFolders) step -1
if checkInner(m_strPathVC & "/Tools/MSVC/" & arrFolders(i)) then exit for ' modifies m_strPathVC on success
next
elseif LogDirExists(m_strPathVC & "/bin/HostX64") _
or LogDirExists(m_strPathVC & "/bin/HostX86") then
checkInner(m_strPathVC)
' 14.0 and older layout?
elseif LogFileExists(m_strPathVC, "/bin/cl.exe") then
m_blnNewLayout = False
if LogFileExists(m_strPathVC, "bin/link.exe") _
and LogFileExists(m_strPathVC, "include/string.h") _
and LogFileExists(m_strPathVC, "lib/libcmt.lib") _
and LogFileExists(m_strPathVC, "lib/msvcrt.lib") _
then
LogPrint " => seems okay. old layout."
m_blnFound = checkClExe(m_strPathVC & "/bin/cl.exe")
end if
end if
end if
end if
check = m_bldFound
end function
public function checkProg(strProg)
if m_blnFound = False then
dim str, i, offNewLayout
str = Which(strProg)
if str <> "" then
LogPrint "checkProg: '" & strProg & "' -> '" & str & "'"
if FileExists(PathStripFilename(str) & "/build.exe") then
Warning "Ignoring DDK cl.exe (" & str & ")." ' don't know how to deal with this cl.
else
' Assume we've got cl.exe from somewhere under the 'bin' directory..
m_strPathVC = PathParent(PathStripFilename(str))
for i = 1 To 5
if LogDirExists(m_strPathVC & "/include") then
m_strPathVCCommon = PathParent(m_strPathVC) & "/Common7"
if DirExists(m_strPathVCCommon) = False then
m_strPathVCCommon = ""
' New layout?
offNewLayout = InStr(1, LCase(DosSlashes(m_strPathVC)), "\tools\msvc\")
if offNewLayout > 0 then m_strPathVC = Left(m_strPathVC, offNewLayout)
end if
check m_strPathVC, m_strPathVCCommon
exit for
end if
m_strPathVC = PathParent(m_strPathVC)
next
end if
end if
end if
checkProg = m_bldFound
end function
public function checkProgFiles(strSubdir)
if m_blnFound = False then
dim strProgFiles
for each strProgFiles in g_arrProgramFiles
check strProgFiles & "/" & strSubdir, ""
next
end if
checkProgFiles = m_blnFound
end function
public function checkRegistry(strValueNm, strVCSubdir, strVCommonSubdir)
if m_blnFound = False then
dim str, strPrefix, arrPrefixes
arrPrefixes = Array("HKLM\SOFTWARE\Wow6432Node\", "HKLM\SOFTWARE\", "HKCU\SOFTWARE\Wow6432Node\", "HKCU\SOFTWARE\")
for each strPrefix in arrPrefixes
str = LogRegGetString(strPrefix & strValueNm)
if str <> "" then
LogPrint "checkRegistry: '" & strPrefix & strValueNm & "' -> '" & str & "'"
if check(str & strVCSubdir, str & strVCommonSubdir) = True then
exit for
end if
end if
next
end if
checkRegistry = m_bldFound
end function
public function checkProgItems(strVersionYear)
if m_blnFound = False then
dim strCandidate
for each strCandidate in CollectFromProgramItemLinks(GetRef("VisualCPPCallback"), strVersionYear)
check strCandidate, ""
next
end if
checkProgItems = m_blnFound
end function
public function checkInternal
dim strPathDev
for each strPathDev in g_arrPathDev : check strPathDev & "/win.amd64/vcc/v14.2", "" : next
for each strPathDev in g_arrPathDev : check strPathDev & "/win.amd64/vcc/v14.2", "" : next
for each strPathDev in g_arrPathDev : check strPathDev & "/win.amd64/vcc/v14.1", "" : next
for each strPathDev in g_arrPathDev : check strPathDev & "/win.amd64/vcc/v14.0", "" : next
for each strPathDev in g_arrPathDev : check strPathDev & "/win.amd64/vcc/v10sp1", "" : next
for each strPathDev in g_arrPathDev : check strPathDev & "/win.x86/vcc/v10sp1", "" : next
checkInternal = m_blnFound
end function
end class
' See checkProgItems()
function VisualCPPCallback(ByRef arrStrings, cStrings, ByRef strVersionYear)
VisualCPPCallback = ""
' We're looking for items with three strings like this:
' C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\VC\x64 Native Tools Command Prompt for VS 2019.lnk