initial import
[vuplus_webkit] / Tools / Scripts / build-webkit
1 #!/usr/bin/perl -w
2
3 # Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 # Copyright (C) 2009 Google Inc. All rights reserved.
5 # Copyright (C) 2010 moiji-mobile.com All rights reserved.
6 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # 1.  Redistributions of source code must retain the above copyright
13 #     notice, this list of conditions and the following disclaimer. 
14 # 2.  Redistributions in binary form must reproduce the above copyright
15 #     notice, this list of conditions and the following disclaimer in the
16 #     documentation and/or other materials provided with the distribution. 
17 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
18 #     its contributors may be used to endorse or promote products derived
19 #     from this software without specific prior written permission. 
20 #
21 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
22 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
25 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32 # Build script wrapper for the WebKit Open Source Project.
33
34 use strict;
35 use File::Basename;
36 use File::Find;
37 use File::Spec;
38 use FindBin;
39 use Getopt::Long qw(:config pass_through);
40 use lib $FindBin::Bin;
41 use webkitdirs;
42 use webkitperl::features;
43 use POSIX;
44
45 sub cMakeArgsFromFeatures();
46 sub checkForJavaSDK();
47 sub formatBuildTime($);
48 sub writeCongrats();
49
50 my $originalWorkingDirectory = getcwd();
51 chdirWebKit();
52
53 my $showHelp = 0;
54 my $clean = 0;
55 my $useGYP = 0;
56 my $minimal = 0;
57 my $v8 = 0;
58 my $installHeaders;
59 my $installLibs;
60 my $prefixPath;
61 my $makeArgs = "";
62 my $onlyWebKitProject = 0;
63 my $noWebKit2 = 0;
64 my $startTime = time();
65
66 my (
67     $requestAnimationFrameSupport,
68     $threeDCanvasSupport,
69     $threeDRenderingSupport,
70     $accelerated2dCanvasSupport,
71     $animationAPISupport,
72     $blobSupport,
73     $channelMessagingSupport,
74     $clientBasedGeolocationSupport,
75     $coverageSupport,
76     $css3FlexboxSupport,
77     $databaseSupport,
78     $datalistSupport,
79     $dataTransferItemsSupport,
80     $detailsSupport,
81     $deviceOrientationSupport,
82     $directoryUploadSupport,
83     $domStorageSupport,
84     $eventsourceSupport,
85     $fileSystemSupport,
86     $filtersSupport,
87     $fullscreenAPISupport,
88     $geolocationSupport,
89     $iconDatabaseSupport,
90     $imageResizerSupport,
91     $indexedDatabaseSupport,
92     $inputColorSupport,
93     $inputSpeechSupport,
94     $javaScriptDebuggerSupport,
95     $linkPrefetchSupport,
96     $mathmlSupport,
97     $mediaSourceSupport,
98     $mediaStatisticsSupport,
99     $mediaStreamSupport,
100     $meterTagSupport,
101     $mhtmlSupport,
102     $netscapePluginSupport,
103     $notificationsSupport,
104     $offlineWebApplicationSupport,
105     $orientationEventsSupport,
106     $pageVisibilityApiSupport,
107     $progressTagSupport,
108     $quotaSupport,
109     $registerProtocolHandlerSupport,
110     $sharedWorkersSupport,
111     $svgSupport,
112     $svgAnimationSupport,
113     $svgAsImageSupport,
114     $svgDOMObjCBindingsSupport,
115     $svgFontsSupport,
116     $systemMallocSupport,
117     $tiledBackingStoreSupport,
118     $touchEventsSupport,
119     $touchIconLoadingSupport,
120     $videoSupport,
121     $wcssSupport,
122     $webAudioSupport,
123     $webInspectorSupport,
124     $webSocketsSupport,
125     $webTimingSupport,
126     $workersSupport,
127     $xhtmlmpSupport,
128     $xpathSupport,
129     $xsltSupport,
130 );
131
132 my @features = (
133     { option => "request-animation-frame", desc => "Toggle requestAnimationFrame support",
134       define => "ENABLE_REQUEST_ANIMATION_FRAME", default => (isAppleMacWebKit()), value => \$requestAnimationFrameSupport },
135
136     { option => "3d-canvas", desc => "Toggle 3D canvas (WebGL) support",
137       define => "ENABLE_WEBGL", default => (isAppleMacWebKit() && !isLeopard()), value => \$threeDCanvasSupport },
138
139     { option => "3d-rendering", desc => "Toggle 3D rendering support",
140       define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() || isQt()), value => \$threeDRenderingSupport },
141
142     { option => "accelerated-2d-canvas", desc => "Toggle accelerated 2D canvas support",
143       define => "ENABLE_ACCELERATED_2D_CANVAS", default => 0, value => \$accelerated2dCanvasSupport },
144
145     { option => "animation-api", desc => "Toggle animation API support",
146       define => "ENABLE_ANIMATION_API", default => 0, value => \$animationAPISupport },
147
148     { option => "blob", desc => "Toggle Blob support",
149       define => "ENABLE_BLOB", default => (isAppleMacWebKit() || isGtk()), value => \$blobSupport },
150
151     { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
152       define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
153
154     { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
155       define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport },
156
157     { option => "css3-flexbox", desc => "Toggle CSS3 Flexbox support",
158       define => "ENABLE_CSS3_FLEXBOX", default => 0, value => \$css3FlexboxSupport },
159
160     { option => "coverage", desc => "Toggle code coverage support",
161       define => "", default => 0, value => \$coverageSupport },
162
163     { option => "database", desc => "Toggle Database Support",
164       define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport },
165
166     { option => "datalist", desc => "Toggle HTML5 datalist support",
167       define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
168
169     { option => "data-transfer-items", desc => "Toggle HTML5 data transfer items support",
170       define => "ENABLE_DATA_TRANSFER_ITEMS", default => 0, value => \$dataTransferItemsSupport },
171
172     { option => "details", desc => "Toggle HTML5 details support",
173       define => "ENABLE_DETAILS", default => 1, value => \$detailsSupport },
174
175     { option => "device-orientation", desc => "Toggle DeviceOrientation support",
176       define => "ENABLE_DEVICE_ORIENTATION", default => 0, value => \$deviceOrientationSupport },
177
178     { option => "directory-upload", desc => "Toogle Directory upload support",
179       define => "ENABLE_DIRECTORY_UPLOAD", default => 0, value => \$directoryUploadSupport },
180
181     { option => "dom-storage", desc => "Toggle DOM Storage Support",
182       define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport },
183
184     { option => "eventsource", desc => "Toggle server-sent events support",
185       define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport },
186
187     { option => "file-system", desc => "Toggle FileSystem support",
188       define => "ENABLE_FILE_SYSTEM", default => 0, value => \$fileSystemSupport },
189
190     { option => "filters", desc => "Toggle Filters support",
191       define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt() || isEfl()), value => \$filtersSupport },
192
193     { option => "fullscreen-api", desc => "Toggle Fullscreen API support",
194       define => "ENABLE_FULLSCREEN_API", default => (isAppleMacWebKit() || isGtk()), value => \$fullscreenAPISupport },
195
196     { option => "geolocation", desc => "Toggle Geolocation support",
197       define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport },
198
199     { option => "icon-database", desc => "Toggle Icon database support",
200       define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
201
202     { option => "indexed-database", desc => "Toggle Indexed Database API support",
203       define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
204
205     { option => "input-color", desc => "Color Input support",
206       define => "ENABLE_INPUT_COLOR", default => 0, value => \$inputColorSupport },
207
208     { option => "input-speech", desc => "Speech Input API support",
209       define => "ENABLE_INPUT_SPEECH", default => 0, value => \$inputSpeechSupport },
210
211     { option => "inspector", desc => "Toggle Web Inspector support",
212       define => "ENABLE_INSPECTOR", default => 1, value => \$webInspectorSupport },
213
214     { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
215       define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
216
217     { option => "link-prefetch", desc => "Toggle pre fetching support",
218       define => "ENABLE_LINK_PREFETCH", default => 0, value => \$linkPrefetchSupport },
219
220     { option => "mathml", desc => "Toggle MathML support",
221       define => "ENABLE_MATHML", default => 1, value => \$mathmlSupport },
222
223     { option => "media-source", desc => "Toggle Media Source support",
224       define => "ENABLE_MEDIA_SOURCE", default => 0, value => \$mediaSourceSupport },
225
226     { option => "media-statistics", desc => "Toggle Media Statistics support",
227       define => "ENABLE_MEDIA_STATISTICS", default => 0, value => \$mediaStatisticsSupport },
228
229     { option => "media-stream", desc => "Toggle Media Stream API support (implies Blob support, currently Chromium and GTK only)",
230       define => "ENABLE_MEDIA_STREAM", default => (isChromium() || isGtk()), value => \$mediaStreamSupport },
231
232     { option => "meter-tag", desc => "Meter Tag support",
233       define => "ENABLE_METER_TAG", default => !isAppleWinWebKit(), value => \$meterTagSupport },
234
235     { option => "mhtml", desc => "Toggle MHTML support",
236       define => "ENABLE_MHTML", default => 0, value => \$mhtmlSupport },
237
238     { option => "netscape-plugin", desc => "Netscape Plugin support",
239       define => "ENABLE_NETSCAPE_PLUGIN_API", default => !isEfl(), value => \$netscapePluginSupport },
240
241     { option => "notifications", desc => "Toggle Desktop Notifications Support",
242       define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
243
244     { option => "offline-web-applications", desc => "Toggle Offline Web Application Support",
245       define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport },
246
247     { option => "orientation-events", desc => "Toggle Orientation Events support",
248       define => "ENABLE_ORIENTATION_EVENTS", default => 0, value => \$orientationEventsSupport },
249
250     { option => "page-visibility-api", desc => "Page Visibility API support",
251       define => "ENABLE_PAGE_VISIBILITY_API", default => 0, value => \$pageVisibilityApiSupport },
252
253     { option => "progress-tag", desc => "Progress Tag support",
254       define => "ENABLE_PROGRESS_TAG", default => 1, value => \$progressTagSupport },
255
256     { option => "quota", desc => "Toggle Quota support",
257       define => "ENABLE_QUOTA", default => 0, value => \$quotaSupport },
258
259     { option => "register-protocol-handler", desc => "Register Protocol Handler support",
260       define => "ENABLE_REGISTER_PROTOCOL_HANDLER", default => 0, value => \$registerProtocolHandlerSupport },
261
262     { option => "system-malloc", desc => "Toggle system allocator instead of TCmalloc",
263       define => "USE_SYSTEM_MALLOC", default => 0, value => \$systemMallocSupport },
264
265     { option => "shared-workers", desc => "Toggle SharedWorkers support",
266       define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport },
267
268     { option => "svg", desc => "Toggle SVG support",
269       define => "ENABLE_SVG", default => 1, value => \$svgSupport },
270
271     { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)",
272       define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport },
273
274     { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)",
275       define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport },
276
277     { option => "svg-dom-objc-bindings", desc => "Toggle SVG DOM Objective-C bindings support (implies SVG support)",
278       define => "ENABLE_SVG_DOM_OBJC_BINDINGS", default => isAppleMacWebKit(), value => \$svgDOMObjCBindingsSupport },
279
280     { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
281       define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
282
283     { option => "tiled-backing-store", desc => "Toggle Tiled Backing Store support",
284       define => "ENABLE_TILED_BACKING_STORE", default => isQt(), value => \$tiledBackingStoreSupport },
285
286     { option => "touch-events", desc => "Toggle Touch Events support",
287       define => "ENABLE_TOUCH_EVENTS", default => isQt(), value => \$touchEventsSupport },
288
289     { option => "touch-icon-loading", desc => "Toggle Touch Icon Loading Support",
290       define => "ENABLE_TOUCH_ICON_LOADING", default => 0, value => \$touchIconLoadingSupport },
291
292     { option => "video", desc => "Toggle Video support",
293       define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport },
294
295     { option => "wcss", desc => "Toggle WCSS support",
296       define => "ENABLE_WCSS", default => 0, value => \$wcssSupport },
297
298     { option => "web-audio", desc => "Toggle Web Audio support",
299       define => "ENABLE_WEB_AUDIO", default => 0, value=> \$webAudioSupport },
300
301     { option => "web-sockets", desc => "Toggle Web Sockets support",
302       define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
303
304     { option => "web-timing", desc => "Toggle Web Timing support",
305       define => "ENABLE_WEB_TIMING", default => 0, value=> \$webTimingSupport },
306
307     { option => "workers", desc => "Toggle Web Workers support",
308       define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport },
309
310     { option => "xhtmlmp", desc => "Toggle XHTML-MP support",
311       define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport },
312
313     { option => "xpath", desc => "Toggle XPath support",
314       define => "ENABLE_XPATH", default => 1, value => \$xpathSupport },
315
316     { option => "xslt", desc => "Toggle XSLT support",
317       define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
318 );
319
320 # Update defaults from Qt's project file
321 if (isQt()) {
322     # Take a sneek peek at the arguments, since we will need the qmake binary early
323     # on to do profile parsing.
324     foreach (@ARGV) {
325         if (/^--qmake=(.*)/) {
326             setQmakeBinaryPath($1);
327         }
328     }
329     my %qtDefaults = qtFeatureDefaults();
330     foreach (@features) {
331         $_->{default} = $qtDefaults{$_->{define}} || 0;
332     }
333 }
334
335 # Additional environment parameters
336 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
337
338 # Initialize values from defaults
339 foreach (@ARGV) {
340     if ($_ eq '--minimal') {
341         $minimal = 1;
342     } elsif ($_ eq '--v8') {
343         $v8 = 1;
344     }
345 }
346
347 # Initialize values from defaults
348 foreach (@features) {
349     ${$_->{value}} = ($_->{default} && !$minimal) || 0;
350 }
351
352 $svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport
353     || $svgDOMObjCBindingsSupport || $svgFontsSupport;
354
355 $blobSupport = $blobSupport || $mediaStreamSupport;
356
357 my $programName = basename($0);
358 my $usage = <<EOF;
359 Usage: $programName [options] [options to pass to build system]
360   --help                            Show this help message
361   --clean                           Cleanup the build directory
362   --debug                           Compile in debug mode
363   --gyp                             Use GYP-generated project files
364   --dsym                            Change debugging format to dwarf-with-dsym (Mac only)
365
366   --chromium                        Build the Chromium port on Mac/Win/Linux
367   --chromium-android                Build the Chromium port on Android
368   --efl                             Build the EFL port
369   --gtk                             Build the GTK+ port
370   --qt                              Build the Qt port
371   --wincairo                        Build using Cairo (rather than CoreGraphics) on Windows
372   --wince                           Build the WinCE port
373
374   --inspector-frontend              Copy changes to the inspector front-end files to the build directory
375
376   --install-headers=<path>          Set installation path for the headers (Qt only)
377   --install-libs=<path>             Set installation path for the libraries (Qt only)
378   --v8                              Use V8 as JavaScript engine (Qt only)
379   -2                                build WebKit2 (Qt only)
380
381   --prefix=<path>                   Set installation prefix to the given path (Gtk/Efl only)
382   --makeargs=<arguments>            Optional Makefile flags
383   --qmakearg=<arguments>            Optional qmake flags (Qt only, e.g. --qmakearg="CONFIG+=webkit2" to build WebKit2)
384
385   --minimal                         No optional features, unless explicitly enabled
386
387   --only-webkit                     Build only the WebKit project
388   --no-webkit2                      Omit WebKit2 code from the build
389
390 EOF
391
392 my %options = (
393     'help' => \$showHelp,
394     'clean' => \$clean,
395     'gyp' => \$useGYP,
396     'install-headers=s' => \$installHeaders,
397     'install-libs=s' => \$installLibs,
398     'prefix=s' => \$prefixPath,
399     'makeargs=s' => \$makeArgs,
400     'minimal' => \$minimal,
401     'v8' => \$v8,
402     'only-webkit' => \$onlyWebKitProject,
403     'no-webkit2' => \$noWebKit2,
404 );
405
406 # Build usage text and options list from features
407 foreach (@features) {
408     my $opt = sprintf("%-35s", "  --[no-]$_->{option}");
409     $usage .= "$opt $_->{desc} (default: $_->{default})\n";
410     $options{"$_->{option}!"} = $_->{value};
411 }
412
413 GetOptions(%options);
414
415 if ($showHelp) {
416    print STDERR $usage;
417    exit 1;
418 }
419
420 checkRequiredSystemConfig();
421 setConfiguration();
422
423 my $productDir = productDir();
424
425 # Remove Qt makefiles from productDir.
426 # https://bugs.webkit.org/show_bug.cgi?id=54466
427 File::Find::find(sub {unlink $File::Find::name if $File::Find::name =~ m/Makefile/;}, $productDir) if (isQt() && !isSymbian() && -e $productDir);
428
429 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
430 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && !isSymbian() && -e $productDir);
431
432 sub unlinkZeroFiles()
433 {
434     my $file = $File::Find::name;
435     if (! -s $file) {
436         unlink $file;
437         print "0 byte sized file removed from build directory: $file\n";
438     }
439 }
440
441 # Check that all the project directories are there.
442 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
443
444 for my $dir (@projects) {
445     if (! -d $dir) {
446         die "Error: No $dir directory found. Please do a fresh checkout.\n";
447     }
448 }
449
450 if (!isQt() && !-d "WebKitLibraries") {
451     die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
452 }
453
454 # Generate the generate project files from .gyp files
455 if ($useGYP) {
456     system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
457 }
458
459 my @options = ();
460
461 # enable autotool options accordingly
462 if (isGtk()) {
463     @options = @ARGV;
464     foreach (@features) {
465         push @options, autotoolsFlag(${$_->{value}}, $_->{option});
466     }
467
468     push @options, "--prefix=" . $prefixPath if defined($prefixPath);
469     push @options, "--makeargs=" . $makeArgs if $makeArgs;
470 } elsif (isAppleMacWebKit()) {
471     checkForJavaSDK();
472     push @options, XcodeOptions();
473
474     sub option($$$)
475     {
476         my ($feature, $isEnabled, $defaultValue) = @_;
477         return "" if $defaultValue == $isEnabled;
478         return $feature . "=" . ($isEnabled ? $feature : "");
479     }
480
481     foreach (@features) {
482         if ($_->{option} ne "coverage") {
483             my $option = option($_->{define}, ${$_->{value}}, $_->{default});
484             push @options, $option unless $option eq "";
485         }
486     }
487
488     # Apple builds JavaScriptGlue, and only on the Mac.
489     splice @projects, 1, 0, "Source/JavaScriptGlue";
490
491     # ANGLE must come before WebCore
492     splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
493
494     # WebKit2 is only supported in SnowLeopard and later at present.
495     push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
496
497     # Copy library and header from WebKitLibraries to a findable place in the product directory.
498     my @librariesToCopy = (
499         "libWebKitSystemInterfaceLeopard.a",
500         "libWebKitSystemInterfaceSnowLeopard.a",
501         "libWebKitSystemInterfaceLion.a",
502         "libWebCoreSQLite3.a",
503     );
504     foreach my $libName (@librariesToCopy) {
505         my $srcLib = "WebKitLibraries/" . $libName;
506         my $lib = "$productDir/" . $libName;
507         if (!-e $lib || -M $lib > -M $srcLib) {
508             print "Updating $lib\n";
509             system "ditto", $srcLib, $lib;
510             system "ranlib", $lib;
511         }
512     }
513
514     # FIXME: This code should be abstracted to not be copy/paste.
515     my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h";
516     my $header = "$productDir/usr/local/include/WebKitSystemInterface.h";
517     if (!-e $header || -M $header > -M $srcHeader) {
518         print "Updating $header\n";
519         system "mkdir", "-p", "$productDir/usr/local/include";
520         system "ditto", $srcHeader, $header;
521     }
522
523     my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3";
524     my $headerDir = "$productDir/WebCoreSQLite3";
525     if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) {
526         print "Updating $headerDir\n";
527         system "ditto", $srcHeaderDir, $headerDir;
528     }
529 } elsif (isWinCairo()) {
530     (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
531 } elsif (isAppleWinWebKit()) {
532     # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
533     # Will fail if WebKitSupportLibrary.zip is not in source root.
534     (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
535 } elsif (isQt()) {
536     push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
537     push @options, "--install-libs=" . $installLibs if defined($installLibs);
538     push @options, "--makeargs=" . $makeArgs if $makeArgs;
539     push @options, "--qmakearg=CONFIG+=webkit2" if isWK2();
540     @options = (@ARGV, @options);
541
542     foreach (@features) {
543         push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default};
544     }
545
546     if ($minimal) {
547         push @options, "CONFIG+=minimal";
548     }
549
550     if ($v8) {
551         push @options, "CONFIG+=v8";
552     }
553 }
554
555 # If asked to build just the WebKit project, overwrite the projects
556 # list after all of the port specific tweaks have been made to
557 # build options, etc.
558 @projects = ("Source/WebKit") if $onlyWebKitProject;
559
560 # Force re-link of existing libraries if different than expected
561 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
562
563 if (isInspectorFrontend()) {
564     exit exitStatus(copyInspectorFrontendFiles());
565 }
566
567 if (isWx()) {
568     $makeArgs .= " --port=wx";
569
570     downloadWafIfNeeded();
571     @options = split(/ /, $makeArgs);
572     @projects = ();
573     my $result = buildWafProject('.', $clean, @options);
574     exit exitStatus($result) if exitStatus($result);
575 }
576
577 if (isChromium()) {
578     @options = @ARGV;
579     # Chromium doesn't build by project directories.
580     @projects = ();
581     push @options, "--makeargs=" . $makeArgs if $makeArgs;
582     my $result = buildChromium($clean, @options);
583     exit exitStatus($result) if exitStatus($result);
584 }
585
586 if (isEfl()) {
587     # By default we build using all of the available CPUs.
588     $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
589     buildCMakeProjectOrExit($clean, "Efl", $prefixPath, $makeArgs, cMakeArgsFromFeatures());
590 }
591
592 if (isWinCE()) {
593     buildCMakeProjectOrExit($clean, "WinCE", $prefixPath, $makeArgs, ("-DCMAKE_WINCE_SDK=\"STANDARDSDK_500 (ARMV4I)\"", cMakeArgsFromFeatures()));
594 }
595
596 # Build, and abort if the build fails.
597 for my $dir (@projects) {
598     chdir $dir or die;
599     my $result = 0;
600
601     # For Gtk and Qt the WebKit project builds all others
602     if ((isGtk() || isQt()) && $dir ne "Source/WebKit") {
603         chdirWebKit();
604         next;
605     }
606
607     my $project = basename($dir);
608     if (isGtk()) {
609         $result = buildGtkProject($project, $clean,  @options);
610     } elsif (isQt()) {
611         #FIXME: $dir should probably be $project.
612         $result = buildQMakeQtProject($dir, $clean, @options);
613     } elsif (isAppleMacWebKit()) {
614         my @local_options = @options;
615         push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $project ne "ANGLE";
616         my $useGYPProject = $useGYP && ($project =~ "WebCore|JavaScriptCore|JavaScriptGlue");
617         my $projectPath = $useGYPProject ? "gyp/$project" : $project;
618         $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
619     } elsif (isAppleWinWebKit()) {
620         if ($project eq "WebKit") {
621             $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
622         }
623     }
624     # Various build* calls above may change the CWD.
625     chdirWebKit();
626
627     if (exitStatus($result)) {
628         my $scriptDir = relativeScriptsDir();
629         if (usingVisualStudioExpress()) {
630             # Visual Studio Express is so lame it can't stdout build failures.
631             # So we find its logs and dump them to the console ourselves.
632             system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
633         }
634         if (isAppleWinWebKit()) {
635             print "\n\n===== BUILD FAILED ======\n\n";
636             print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
637             my $baseProductDir = baseProductDir();
638             print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
639         }
640         exit exitStatus($result);
641     }
642 }
643
644 # Don't report the "WebKit is now built" message after a clean operation.
645 exit if $clean;
646
647 # Write out congratulations message.
648 writeCongrats();
649
650 exit 0;
651
652 sub cMakeArgsFromFeatures()
653 {
654     my @args;
655     foreach (@features) {
656         my $featureName = $_->{define};
657         if ($featureName) {
658             my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
659             push @args, "-D$featureName=$featureEnabled";
660         }
661     }
662     return @args;
663 }
664
665 sub checkForJavaSDK()
666 {
667     my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
668     if (-e $jniHeader) {
669         return;
670     }
671     print "\nCan't find required $jniHeader, build will fail.\n\n";
672     print "After installing \"Java for Mac OS X 10.6 Update 3\", the Java Developer Package is required to build WebKit.\n";
673     print "Please install the package from http://connect.apple.com (found under Downloads > Java).\n\n";
674     print "For more information, see:\n";
675     print "https://lists.webkit.org/pipermail/webkit-dev/2010-October/014867.html\n";
676     print "https://webkit.org/building/tools.html\n\n";
677     exit 1;
678 }
679
680 sub formatBuildTime($)
681 {
682     my ($buildTime) = @_;
683
684     my $buildHours = int($buildTime / 3600);
685     my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
686     my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
687
688     if ($buildHours) {
689         return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
690     }
691     return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
692 }
693
694 sub writeCongrats()
695 {
696     my $launcherPath = launcherPath();
697     my $launcherName = launcherName();
698     my $endTime = time();
699     my $buildTime = formatBuildTime($endTime - $startTime);
700
701     print "\n";
702     print "===========================================================\n";
703     print " WebKit is now built ($buildTime). \n";
704     if (!isChromium()) {
705         print " To run $launcherName with this newly-built code, use the\n";
706         print " \"$launcherPath\" script.\n";
707     }
708     print "===========================================================\n";
709 }