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