tizen beta release
[framework/web/webkit-efl.git] / 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 $cmakeArgs;
63 my $onlyWebKitProject = 0;
64 my $noWebKit2 = 0;
65 my $startTime = time();
66
67 my (
68     $requestAnimationFrameSupport,
69     $threeDCanvasSupport,
70     $threeDRenderingSupport,
71     $accelerated2dCanvasSupport,
72     $animationAPISupport,
73     $blobSupport,
74     $channelMessagingSupport,
75     $clientBasedGeolocationSupport,
76     $coverageSupport,
77     $cssFiltersSupport,
78     $cssGridLayoutSupport,
79     $cssShadersSupport,
80     $sqlDatabaseSupport,
81     $datalistSupport,
82     $dataTransferItemsSupport,
83     $detailsSupport,
84     $deviceOrientationSupport,
85     $directoryUploadSupport,
86     $fileSystemSupport,
87     $filtersSupport,
88     $fullscreenAPISupport,
89     $gamepadSupport,
90     $geolocationSupport,
91     $iconDatabaseSupport,
92     $imageResizerSupport,
93     $indexedDatabaseSupport,
94     $inputColorSupport,
95     $inputSpeechSupport,
96     $inputTypeDateSupport,
97     $inputTypeDatetimeSupport,
98     $inputTypeDatetimelocalSupport,
99     $inputTypeMonthSupport,
100     $inputTypeTimeSupport,
101     $inputTypeWeekSupport,
102     $javaScriptDebuggerSupport,
103     $linkPrefetchSupport,
104     $mathmlSupport,
105     $mediaSourceSupport,
106     $mediaStatisticsSupport,
107     $mediaStreamSupport,
108     $meterTagSupport,
109     $mhtmlSupport,
110     $microdataSupport,
111     $mutationObserversSupport,
112     $netscapePluginSupport,
113     $notificationsSupport,
114     $orientationEventsSupport,
115     $pageVisibilityApiSupport,
116     $progressTagSupport,
117     $quotaSupport,
118     $registerProtocolHandlerSupport,
119     $sharedWorkersSupport,
120     $styleScopedSupport,
121     $svgSupport,
122     $svgDOMObjCBindingsSupport,
123     $svgFontsSupport,
124     $systemMallocSupport,
125     $tiledBackingStoreSupport,
126     $touchEventsSupport,
127     $touchIconLoadingSupport,
128     $videoSupport,
129     $webAudioSupport,
130     $webInspectorSupport,
131     $webSocketsSupport,
132     $webTimingSupport,
133     $workersSupport,
134     $xsltSupport,
135 );
136
137 my @features = (
138     { option => "request-animation-frame", desc => "Toggle requestAnimationFrame support",
139       define => "ENABLE_REQUEST_ANIMATION_FRAME", default => (isAppleMacWebKit()), value => \$requestAnimationFrameSupport },
140
141     { option => "3d-canvas", desc => "Toggle 3D canvas (WebGL) support",
142       define => "ENABLE_WEBGL", default => (isAppleMacWebKit() && !isLeopard()), value => \$threeDCanvasSupport },
143
144     { option => "3d-rendering", desc => "Toggle 3D rendering support",
145       define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() || isQt()), value => \$threeDRenderingSupport },
146
147     { option => "accelerated-2d-canvas", desc => "Toggle accelerated 2D canvas support",
148       define => "ENABLE_ACCELERATED_2D_CANVAS", default => 0, value => \$accelerated2dCanvasSupport },
149
150     { option => "animation-api", desc => "Toggle animation API support",
151       define => "ENABLE_ANIMATION_API", default => isBlackBerry(), value => \$animationAPISupport },
152
153     { option => "blob", desc => "Toggle Blob support",
154       define => "ENABLE_BLOB", default => (isAppleMacWebKit() || isGtk() || isChromium()), value => \$blobSupport },
155
156     { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
157       define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
158
159     { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
160       define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => (isAppleWebKit() || isGtk() || isBlackBerry()), value => \$clientBasedGeolocationSupport },
161
162     { option => "css-filters", desc => "Toggle CSS Filters support",
163       define => "ENABLE_CSS_FILTERS", default => isAppleWebKit(), value => \$cssFiltersSupport },
164
165     { option => "css-grid-layout", desc => "Toggle CSS Grid Layout support",
166       define => "ENABLE_CSS_GRID_LAYOUT", default => 0, value => \$cssGridLayoutSupport },
167
168     { option => "css-shaders", desc => "Toggle CSS Shaders (within CSS Filters) support",
169       define => "ENABLE_CSS_SHADERS", default => isAppleWebKit(), value => \$cssShadersSupport },
170
171     { option => "coverage", desc => "Toggle code coverage support",
172       define => "", default => 0, value => \$coverageSupport },
173
174     { option => "sql-database", desc => "Toggle SQL Database Support",
175       define => "ENABLE_SQL_DATABASE", default => 1, value => \$sqlDatabaseSupport },
176
177     { option => "datalist", desc => "Toggle HTML5 datalist support",
178       define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
179
180     { option => "data-transfer-items", desc => "Toggle HTML5 data transfer items support",
181       define => "ENABLE_DATA_TRANSFER_ITEMS", default => 0, value => \$dataTransferItemsSupport },
182
183     { option => "details", desc => "Toggle HTML5 details support",
184       define => "ENABLE_DETAILS", default => 1, value => \$detailsSupport },
185
186     { option => "device-orientation", desc => "Toggle DeviceOrientation support",
187       define => "ENABLE_DEVICE_ORIENTATION", default => isBlackBerry(), value => \$deviceOrientationSupport },
188
189     { option => "directory-upload", desc => "Toogle Directory upload support",
190       define => "ENABLE_DIRECTORY_UPLOAD", default => 0, value => \$directoryUploadSupport },
191
192     { option => "mutation-observers", desc => "Toggle DOM mutation observer support",
193       define => "ENABLE_MUTATION_OBSERVERS", default => 0, value => \$mutationObserversSupport },
194
195     { option => "file-system", desc => "Toggle FileSystem support",
196       define => "ENABLE_FILE_SYSTEM", default => 0, value => \$fileSystemSupport },
197
198     { option => "filters", desc => "Toggle SVG Filters support",
199       define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt() || isEfl() || isBlackBerry()), value => \$filtersSupport },
200
201     { option => "fullscreen-api", desc => "Toggle Fullscreen API support",
202       define => "ENABLE_FULLSCREEN_API", default => (isAppleMacWebKit() || isGtk()), value => \$fullscreenAPISupport },
203
204     { option => "gamepad", desc => "Toggle Gamepad support",
205       define => "ENABLE_GAMEPAD", default => 0, value => \$gamepadSupport },
206
207     { option => "geolocation", desc => "Toggle Geolocation support",
208       define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk() || isBlackBerry()), value => \$geolocationSupport },
209
210     { option => "icon-database", desc => "Toggle Icon database support",
211       define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
212
213     { option => "indexed-database", desc => "Toggle Indexed Database API support",
214       define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
215
216     { option => "input-color", desc => "Color Input support",
217       define => "ENABLE_INPUT_COLOR", default => isBlackBerry(), value => \$inputColorSupport },
218
219     { option => "input-speech", desc => "Speech Input API support",
220       define => "ENABLE_INPUT_SPEECH", default => 0, value => \$inputSpeechSupport },
221
222     { option => "input-type-date", desc => "Toggle date type <input> support",
223       define => "ENABLE_INPUT_TYPE_DATE", default => 0, value => \$inputTypeDateSupport },
224
225     { option => "input-type-datetime", desc => "Toggle datetime type <input> support",
226       define => "ENABLE_INPUT_TYPE_DATETIME", default => 0, value => \$inputTypeDatetimeSupport },
227
228     { option => "input-type-datetimelocal", desc => "Toggle datetime-local type <input> support",
229       define => "ENABLE_INPUT_TYPE_DATETIMELOCAL", default => 0, value => \$inputTypeDatetimelocalSupport },
230
231     { option => "input-type-month", desc => "Toggle month type <input> support",
232       define => "ENABLE_INPUT_TYPE_MONTH", default => 0, value => \$inputTypeMonthSupport },
233
234     { option => "input-type-time", desc => "Toggle time type <input> support",
235       define => "ENABLE_INPUT_TYPE_TIME", default => 0, value => \$inputTypeTimeSupport },
236
237     { option => "input-type-week", desc => "Toggle week type <input> support",
238       define => "ENABLE_INPUT_TYPE_WEEK", default => 0, value => \$inputTypeWeekSupport },
239
240     { option => "inspector", desc => "Toggle Web Inspector support",
241       define => "ENABLE_INSPECTOR", default => 1, value => \$webInspectorSupport },
242
243     { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
244       define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
245
246     { option => "link-prefetch", desc => "Toggle pre fetching support",
247       define => "ENABLE_LINK_PREFETCH", default => 0, value => \$linkPrefetchSupport },
248
249     { option => "mathml", desc => "Toggle MathML support",
250       define => "ENABLE_MATHML", default => 1, value => \$mathmlSupport },
251
252     { option => "media-source", desc => "Toggle Media Source support",
253       define => "ENABLE_MEDIA_SOURCE", default => 0, value => \$mediaSourceSupport },
254
255     { option => "media-statistics", desc => "Toggle Media Statistics support",
256       define => "ENABLE_MEDIA_STATISTICS", default => 0, value => \$mediaStatisticsSupport },
257
258     { option => "media-stream", desc => "Toggle Media Stream API support (implies Blob support, currently Chromium and GTK only)",
259       define => "ENABLE_MEDIA_STREAM", default => (isChromium() || isGtk()), value => \$mediaStreamSupport },
260
261     { option => "meter-tag", desc => "Meter Tag support",
262       define => "ENABLE_METER_TAG", default => !isAppleWinWebKit(), value => \$meterTagSupport },
263
264     { option => "mhtml", desc => "Toggle MHTML support",
265       define => "ENABLE_MHTML", default => 0, value => \$mhtmlSupport },
266
267     { option => "microdata", desc => "Toggle Microdata support",
268       define => "ENABLE_MICRODATA", default => 0, value => \$microdataSupport },
269
270     { option => "netscape-plugin", desc => "Netscape Plugin support",
271       define => "ENABLE_NETSCAPE_PLUGIN_API", default => !isEfl(), value => \$netscapePluginSupport },
272
273     { option => "notifications", desc => "Toggle Desktop Notifications Support",
274       define => "ENABLE_NOTIFICATIONS", default => isEfl(), value => \$notificationsSupport },
275
276     { option => "orientation-events", desc => "Toggle Orientation Events support",
277       define => "ENABLE_ORIENTATION_EVENTS", default => isBlackBerry(), value => \$orientationEventsSupport },
278
279     { option => "page-visibility-api", desc => "Page Visibility API support",
280       define => "ENABLE_PAGE_VISIBILITY_API", default => 0, value => \$pageVisibilityApiSupport },
281
282     { option => "progress-tag", desc => "Progress Tag support",
283       define => "ENABLE_PROGRESS_TAG", default => 1, value => \$progressTagSupport },
284
285     { option => "quota", desc => "Toggle Quota support",
286       define => "ENABLE_QUOTA", default => 0, value => \$quotaSupport },
287
288     { option => "register-protocol-handler", desc => "Register Protocol Handler support",
289       define => "ENABLE_REGISTER_PROTOCOL_HANDLER", default => 0, value => \$registerProtocolHandlerSupport },
290
291     { option => "system-malloc", desc => "Toggle system allocator instead of TCmalloc",
292       define => "USE_SYSTEM_MALLOC", default => 0, value => \$systemMallocSupport },
293
294     { option => "shared-workers", desc => "Toggle SharedWorkers support",
295       define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk() || isBlackBerry()), value => \$sharedWorkersSupport },
296
297     { option => "style-scoped", desc => "Toggle <style scoped> support",
298       define => "ENABLE_STYLE_SCOPED", default => 0, value => \$styleScopedSupport },
299
300     { option => "svg", desc => "Toggle SVG support",
301       define => "ENABLE_SVG", default => 1, value => \$svgSupport },
302
303     { option => "svg-dom-objc-bindings", desc => "Toggle SVG DOM Objective-C bindings support (implies SVG support)",
304       define => "ENABLE_SVG_DOM_OBJC_BINDINGS", default => isAppleMacWebKit(), value => \$svgDOMObjCBindingsSupport },
305
306     { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
307       define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
308
309     { option => "tiled-backing-store", desc => "Toggle Tiled Backing Store support",
310       define => "WTF_USE_TILED_BACKING_STORE", default => isQt(), value => \$tiledBackingStoreSupport },
311
312     { option => "touch-events", desc => "Toggle Touch Events support",
313       define => "ENABLE_TOUCH_EVENTS", default => (isQt() || isBlackBerry()), value => \$touchEventsSupport },
314
315     { option => "touch-icon-loading", desc => "Toggle Touch Icon Loading Support",
316       define => "ENABLE_TOUCH_ICON_LOADING", default => 0, value => \$touchIconLoadingSupport },
317
318     { option => "video", desc => "Toggle Video support",
319       define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk() || isBlackBerry()), value => \$videoSupport },
320
321     { option => "web-audio", desc => "Toggle Web Audio support",
322       define => "ENABLE_WEB_AUDIO", default => 0, value=> \$webAudioSupport },
323
324     { option => "web-sockets", desc => "Toggle Web Sockets support",
325       define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
326
327     { option => "web-timing", desc => "Toggle Web Timing support",
328       define => "ENABLE_WEB_TIMING", default => 0, value=> \$webTimingSupport },
329
330     { option => "workers", desc => "Toggle Web Workers support",
331       define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk() || isBlackBerry()), value => \$workersSupport },
332
333     { option => "xslt", desc => "Toggle XSLT support",
334       define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
335 );
336
337 # Update defaults from Qt's project file
338 if (isQt()) {
339     # Take a sneek peek at the arguments, since we will need the qmake binary early
340     # on to do profile parsing. We also need to know if we're showing the help-text.
341     foreach (@ARGV) {
342         if (/^--qmake=(.*)/) {
343             setQmakeBinaryPath($1);
344         } elsif (/^--help$/) {
345             $showHelp = 1;
346         }
347     }
348
349     my %qtDefaults;
350     if ($showHelp) {
351         %qtDefaults = qtFeatureDefaults();
352     }
353
354     foreach (@features) {
355         $_->{default} = (%qtDefaults ? $qtDefaults{$_->{define}} || 0 : -1);
356     }
357 }
358
359 # Additional environment parameters
360 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
361
362 # Initialize values from defaults
363 foreach (@ARGV) {
364     if ($_ eq '--minimal') {
365         $minimal = 1;
366     } elsif ($_ eq '--v8') {
367         $v8 = 1;
368     }
369 }
370
371 # Initialize values from defaults
372 foreach (@features) {
373     ${$_->{value}} = ($minimal ? 0 : $_->{default});
374 }
375
376 $svgSupport = $svgSupport || $svgDOMObjCBindingsSupport || $svgFontsSupport;
377
378 $blobSupport = $blobSupport || $mediaStreamSupport;
379
380 my $programName = basename($0);
381 my $usage = <<EOF;
382 Usage: $programName [options] [options to pass to build system]
383   --help                            Show this help message
384   --clean                           Cleanup the build directory
385   --debug                           Compile in debug mode
386   --gyp                             Use GYP-generated project files
387   --dsym                            Change debugging format to dwarf-with-dsym (Mac only)
388
389   --blackberry                      Build the BlackBerry port on Mac/Linux
390   --chromium                        Build the Chromium port on Mac/Win/Linux
391   --chromium-android                Build the Chromium port on Android
392   --efl                             Build the EFL port
393   --gtk                             Build the GTK+ port
394   --qt                              Build the Qt port
395   --wincairo                        Build using Cairo (rather than CoreGraphics) on Windows
396   --wince                           Build the WinCE port
397
398   --inspector-frontend              Copy changes to the inspector front-end files to the build directory
399
400   --install-headers=<path>          Set installation path for the headers (Qt only)
401   --install-libs=<path>             Set installation path for the libraries (Qt only)
402   --v8                              Use V8 as JavaScript engine (Qt only)
403
404   --prefix=<path>                   Set installation prefix to the given path (Gtk/Efl/BlackBerry only)
405   --makeargs=<arguments>            Optional Makefile flags
406   --qmakearg=<arguments>            Optional qmake flags (Qt only, e.g. --qmakearg="CONFIG+=webkit2" to build WebKit2)
407   --cmakearg=<arguments>            Optional CMake flags (e.g. --cmakearg="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
408
409   --minimal                         No optional features, unless explicitly enabled
410
411   --only-webkit                     Build only the WebKit project
412   --no-webkit2                      Omit WebKit2 code from the build
413
414 EOF
415
416 my %options = (
417     'help' => \$showHelp,
418     'clean' => \$clean,
419     'gyp' => \$useGYP,
420     'install-headers=s' => \$installHeaders,
421     'install-libs=s' => \$installLibs,
422     'prefix=s' => \$prefixPath,
423     'makeargs=s' => \$makeArgs,
424     'cmakeargs=s' => \$cmakeArgs,
425     'minimal' => \$minimal,
426     'v8' => \$v8,
427     'only-webkit' => \$onlyWebKitProject,
428     'no-webkit2' => \$noWebKit2,
429 );
430
431 # Build usage text and options list from features
432 foreach (@features) {
433     my $opt = sprintf("%-35s", "  --[no-]$_->{option}");
434     $usage .= "$opt $_->{desc} (default: $_->{default})\n";
435     $options{"$_->{option}!"} = $_->{value};
436 }
437
438 GetOptions(%options);
439
440 if ($showHelp) {
441    print STDERR $usage;
442    exit 1;
443 }
444
445 checkRequiredSystemConfig();
446 setConfiguration();
447
448 my $productDir = productDir();
449
450 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
451 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && -e $productDir);
452
453 sub unlinkZeroFiles()
454 {
455     my $file = $File::Find::name;
456     # Remove 0 size files, except .d files used for dependency tracking
457     if (! -s $file && $file !~ m/\.d$/) {
458         unlink $file;
459         print "0 byte sized file removed from build directory: $file\n";
460     }
461 }
462
463 # Check that all the project directories are there.
464 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
465
466 for my $dir (@projects) {
467     if (! -d $dir) {
468         die "Error: No $dir directory found. Please do a fresh checkout.\n";
469     }
470 }
471
472 if (!isQt() && !-d "WebKitLibraries") {
473     die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
474 }
475
476 # Generate the generate project files from .gyp files
477 if ($useGYP) {
478     system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
479 }
480
481 my @options = ();
482
483 # enable autotool options accordingly
484 if (isGtk()) {
485     @options = @ARGV;
486     foreach (@features) {
487         push @options, autotoolsFlag(${$_->{value}}, $_->{option});
488     }
489
490     push @options, "--prefix=" . $prefixPath if defined($prefixPath);
491     push @options, "--makeargs=" . $makeArgs if $makeArgs;
492 } elsif (isAppleMacWebKit()) {
493     checkForJavaSDK();
494     push @options, XcodeOptions();
495
496     sub option($$$)
497     {
498         my ($feature, $isEnabled, $defaultValue) = @_;
499         return "" if $defaultValue == $isEnabled;
500         return $feature . "=" . ($isEnabled ? $feature : "");
501     }
502
503     foreach (@features) {
504         if ($_->{option} ne "coverage") {
505             my $option = option($_->{define}, ${$_->{value}}, $_->{default});
506             push @options, $option unless $option eq "";
507         }
508     }
509
510     # Apple builds JavaScriptGlue, and only on the Mac.
511     splice @projects, 1, 0, "Source/JavaScriptGlue";
512
513     # ANGLE must come before WebCore
514     splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
515
516     # WebKit2 is only supported in SnowLeopard and later at present.
517     push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
518
519     # Copy library and header from WebKitLibraries to a findable place in the product directory.
520     my @librariesToCopy = (
521         "libWebKitSystemInterfaceLeopard.a",
522         "libWebKitSystemInterfaceSnowLeopard.a",
523         "libWebKitSystemInterfaceLion.a",
524         "libWebCoreSQLite3.a",
525     );
526     foreach my $libName (@librariesToCopy) {
527         my $srcLib = "WebKitLibraries/" . $libName;
528         my $lib = "$productDir/" . $libName;
529         if (!-e $lib || -M $lib > -M $srcLib) {
530             print "Updating $lib\n";
531             system "ditto", $srcLib, $lib;
532             system "ranlib", $lib;
533         }
534     }
535
536     # FIXME: This code should be abstracted to not be copy/paste.
537     my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h";
538     my $header = "$productDir/usr/local/include/WebKitSystemInterface.h";
539     if (!-e $header || -M $header > -M $srcHeader) {
540         print "Updating $header\n";
541         system "mkdir", "-p", "$productDir/usr/local/include";
542         system "ditto", $srcHeader, $header;
543     }
544
545     my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3";
546     my $headerDir = "$productDir/WebCoreSQLite3";
547     if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) {
548         print "Updating $headerDir\n";
549         system "ditto", $srcHeaderDir, $headerDir;
550     }
551 } elsif (isWinCairo()) {
552     (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
553 } elsif (isAppleWinWebKit()) {
554     # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
555     # Will fail if WebKitSupportLibrary.zip is not in source root.
556     (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
557 } elsif (isQt()) {
558     push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
559     push @options, "--install-libs=" . $installLibs if defined($installLibs);
560     push @options, "--makeargs=" . $makeArgs if $makeArgs;
561     push @options, "--qmakearg=CONFIG+=no_webkit2" if $noWebKit2;
562
563     if (checkForArgumentAndRemoveFromARGV("-2")) {
564         print "Note: WebKit2 is now built by default, you don't need to passs -2. Disable using --no-webkit2\n";
565     }
566
567     @options = (@ARGV, @options);
568
569     foreach (@features) {
570         push @options, "DEFINES+=$_->{define}=${$_->{value}}" if $_->{define} && ${$_->{value}} != $_->{default};
571     }
572
573     if ($minimal) {
574         push @options, "CONFIG+=minimal";
575     }
576
577     if ($v8) {
578         push @options, "CONFIG+=v8";
579     }
580 }
581
582 # If asked to build just the WebKit project, overwrite the projects
583 # list after all of the port specific tweaks have been made to
584 # build options, etc.
585 @projects = ("Source/WebKit") if $onlyWebKitProject;
586
587 # Force re-link of existing libraries if different than expected
588 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
589
590 if (isInspectorFrontend()) {
591     exit exitStatus(copyInspectorFrontendFiles());
592 }
593
594 if (isWx()) {
595     $makeArgs .= " --port=wx";
596
597     downloadWafIfNeeded();
598     @options = split(/ /, $makeArgs);
599     @projects = ();
600     my $result = buildWafProject('.', $clean, @options);
601     exit exitStatus($result) if exitStatus($result);
602 }
603
604 if (isChromium()) {
605     # Currently chromium does not honour the features passed to build-webkit.
606     # Until this is solved, we issue a warning about that.
607     foreach (@features) {
608         if (${$_->{value}} ne $_->{default}) {
609             print "\n";
610             print "===========================================================\n";
611             print " Chromium does not honor the features passed to build-webkit.\n";
612             print " The preferred way is to set up your overrides in ~/.gyp/include.gypi.\n";
613             print " See https://trac.webkit.org/wiki/Chromium#Buildingwithfeaturedefines\n";
614             print " on how to do that.\n";
615             print "===========================================================\n";
616             last;
617         }
618     }
619
620     @options = @ARGV;
621     # Chromium doesn't build by project directories.
622     @projects = ();
623     push @options, "--makeargs=" . $makeArgs if $makeArgs;
624     my $result = buildChromium($clean, @options);
625     exit exitStatus($result) if exitStatus($result);
626 }
627
628 if (isEfl()) {
629     # By default we build using all of the available CPUs.
630     $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
631     buildCMakeProjectOrExit($clean, "Efl", $prefixPath, $makeArgs, cMakeArgsFromFeatures(), $cmakeArgs);
632 }
633
634 if (isWinCE()) {
635     buildCMakeProjectOrExit($clean, "WinCE", $prefixPath, $makeArgs, ("-DCMAKE_WINCE_SDK=\"STANDARDSDK_500 (ARMV4I)\"", cMakeArgsFromFeatures()), $cmakeArgs);
636 }
637
638 if (isBlackBerry()) {
639     my %archInfo = blackberryTargetArchitecture();
640     my $arch = $archInfo{"arch"};
641     my $cpu = $archInfo{"cpu"};
642     my $cpuDir = $archInfo{"cpuDir"};
643     my $buSuffix = $archInfo{"buSuffix"};
644
645     my @cmakeExtraOptions;
646     if ($cpu eq "a9") {
647         $cpu = $arch . "v7le";
648         push @cmakeExtraOptions, '-DTARGETING_PLAYBOOK=1';
649     }
650
651     my $stageDir = $ENV{"STAGE_DIR"};
652     my $stageLib = File::Spec->catdir($stageDir, $cpuDir, "lib");
653     my $stageUsrLib = File::Spec->catdir($stageDir, $cpuDir, "usr", "lib");
654     my $stageInc = File::Spec->catdir($stageDir, "usr", "include");
655
656     my $qnxHost = $ENV{"QNX_HOST"};
657     my $numberOfJobs;
658     my $ccCommand;
659     my $cxxCommand;
660     if ($ENV{"USE_ICECC"}) {
661         chomp($ccCommand = `which icecc`);
662         $cxxCommand = $ccCommand;
663         $numberOfJobs = 50; # 50 is the number we choose for internal development
664     } else {
665         $ccCommand = File::Spec->catfile($qnxHost, "usr", "bin", "qcc");
666         $cxxCommand = $ccCommand;
667         $numberOfJobs = numberOfCPUs();
668     }
669     $makeArgs .= ($makeArgs ? " " : "") . "-j" . $numberOfJobs if $makeArgs !~ /-j\s*\d+/;
670
671     if ($ENV{"CCWRAP"}) {
672         $ccCommand = $ENV{"CCWRAP"};
673         push @cmakeExtraOptions, "-DCMAKE_C_COMPILER_ARG1=qcc";
674         push @cmakeExtraOptions, "-DCMAKE_CXX_COMPILER_ARG1=qcc";
675     }
676
677     push @cmakeExtraOptions, "-DCMAKE_SKIP_RPATH='ON'" if isDarwin();
678     push @cmakeExtraOptions, "-DENABLE_DRT=1" if $ENV{"ENABLE_DRT"};
679
680     my @includeSystemDirectories;
681     push @includeSystemDirectories, File::Spec->catdir($stageInc, "grskia", "skia");
682     push @includeSystemDirectories, File::Spec->catdir($stageInc, "grskia");
683     push @includeSystemDirectories, File::Spec->catdir($stageInc, "harfbuzz");
684     push @includeSystemDirectories, File::Spec->catdir($stageInc, "imf");
685     push @includeSystemDirectories, $stageInc;
686     push @includeSystemDirectories, File::Spec->catdir($stageInc, "browser", "platform");
687     push @includeSystemDirectories, File::Spec->catdir($stageInc, "browser", "qsk");
688
689     my @cxxFlags;
690     push @cxxFlags, "-Wl,-rpath-link,$stageLib";
691     push @cxxFlags, "-Wl,-rpath-link," . File::Spec->catfile($stageUsrLib, "torch-webkit");
692     push @cxxFlags, "-Wl,-rpath-link,$stageUsrLib";
693     push @cxxFlags, "-L$stageLib";
694     push @cxxFlags, "-L$stageUsrLib";
695
696     if ($ENV{"PROFILE"}) {
697         push @cmakeExtraOptions, "-DPROFILING=1";
698         push @cxxFlags, "-p";
699     }
700
701     my @cmakeArgs;
702     push @cmakeArgs, "-DPUBLIC_BUILD=0";
703     push @cmakeArgs, '-DCMAKE_SYSTEM_NAME="QNX"';
704     push @cmakeArgs, "-DCMAKE_SYSTEM_PROCESSOR=\"$cpuDir\"";
705     push @cmakeArgs, '-DCMAKE_SYSTEM_VERSION="1"';
706     push @cmakeArgs, "-DCMAKE_C_COMPILER=\"$ccCommand\"";
707     push @cmakeArgs, "-DCMAKE_CXX_COMPILER=\"$cxxCommand\"";
708     push @cmakeArgs, "-DCMAKE_C_FLAGS=\"-Vgcc_nto${cpu} -g @cxxFlags\"";
709     push @cmakeArgs, "-DCMAKE_CXX_FLAGS=\"-Vgcc_nto${cpu}_cpp-ne -g -lang-c++ @cxxFlags\"";
710
711     # We cannot use CMAKE_INCLUDE_PATH since this describes the search path for header files in user directories.
712     # And the QNX system headers are in user directories on the host OS (i.e. they aren't installed in the host OS's
713     # system header search path). So, we need to inform g++ that these user directories (@includeSystemDirectories)
714     # are to be taken as the host OS's system header directories when building our port.
715     #
716     # Also, we cannot use CMAKE_SYSTEM_INCLUDE_PATH since that will override the entire system header path.
717     # So, we define the additional system include paths in ADDITIONAL_SYSTEM_INCLUDE_PATH. This list will
718     # be processed in OptionsBlackBerry.cmake.
719     push @cmakeArgs, '-DADDITIONAL_SYSTEM_INCLUDE_PATH="' . join(';', @includeSystemDirectories) . '"';
720
721     # FIXME: Make this more general purpose such that we can pass a list of directories and files.
722     push @cmakeArgs, '-DTHIRD_PARTY_ICU_DIR="' . File::Spec->catdir($stageInc, "unicode") . '"';
723     push @cmakeArgs, '-DTHIRD_PARTY_UNICODE_FILE="' . File::Spec->catfile($stageInc, "unicode.h") . '"';
724
725     push @cmakeArgs, "-DCMAKE_LIBRARY_PATH=\"$stageLib;$stageUsrLib\"";
726     push @cmakeArgs, '-DCMAKE_AR="' . File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ar") . '"';
727     push @cmakeArgs, '-DCMAKE_RANLIB="' . File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ranlib") . '"';
728     push @cmakeArgs, '-DCMAKE_LD="'. File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ld") . '"';
729     push @cmakeArgs, '-DCMAKE_LINKER="' . File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ld") . '"';
730     push @cmakeArgs, "-DECLIPSE_CDT4_GENERATE_SOURCE_PROJECT=TRUE";
731     push @cmakeArgs, '-G"Eclipse CDT4 - Unix Makefiles"';
732     push @cmakeArgs, @cmakeExtraOptions;
733
734     $prefixPath = $stageDir unless $prefixPath;
735
736     buildCMakeProjectOrExit($clean, "BlackBerry", $prefixPath, $makeArgs, (@cmakeArgs, cMakeArgsFromFeatures()));
737 }
738
739 # Build, and abort if the build fails.
740 for my $dir (@projects) {
741     chdir $dir or die;
742     my $result = 0;
743
744     # For Gtk and Qt the WebKit project builds all others
745     if ((isGtk() || isQt()) && $dir ne "Source/WebKit") {
746         chdirWebKit();
747         next;
748     }
749
750     my $project = basename($dir);
751     if (isGtk()) {
752         $result = buildGtkProject($project, $clean, !$noWebKit2, @options);
753     } elsif (isQt()) {
754         #FIXME: $dir should probably be $project.
755         $result = buildQMakeQtProject($dir, $clean, @options);
756     } elsif (isAppleMacWebKit()) {
757         my @local_options = @options;
758         push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $project ne "ANGLE";
759         my $useGYPProject = $useGYP && ($project =~ "WebCore|JavaScriptCore|JavaScriptGlue");
760         my $projectPath = $useGYPProject ? "gyp/$project" : $project;
761         $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
762     } elsif (isAppleWinWebKit()) {
763         if ($project eq "WebKit") {
764             $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
765         }
766     }
767     # Various build* calls above may change the CWD.
768     chdirWebKit();
769
770     if (exitStatus($result)) {
771         my $scriptDir = relativeScriptsDir();
772         if (usingVisualStudioExpress()) {
773             # Visual Studio Express is so lame it can't stdout build failures.
774             # So we find its logs and dump them to the console ourselves.
775             system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
776         }
777         if (isAppleWinWebKit()) {
778             print "\n\n===== BUILD FAILED ======\n\n";
779             print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
780             my $baseProductDir = baseProductDir();
781             print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
782         }
783         exit exitStatus($result);
784     }
785 }
786
787 # Don't report the "WebKit is now built" message after a clean operation.
788 exit if $clean;
789
790 # Write out congratulations message.
791 writeCongrats();
792
793 exit 0;
794
795 sub cMakeArgsFromFeatures()
796 {
797     my @args;
798     foreach (@features) {
799         my $featureName = $_->{define};
800         if ($featureName) {
801             my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
802             push @args, "-D$featureName=$featureEnabled";
803         }
804     }
805     return @args;
806 }
807
808 sub checkForJavaSDK()
809 {
810     my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
811     if (-e $jniHeader) {
812         return;
813     }
814     print "\nCan't find required $jniHeader, build will fail.\n\n";
815     print "After installing \"Java for Mac OS X 10.6 Update 3\", the Java Developer Package is required to build WebKit.\n";
816     print "Please install the package from http://connect.apple.com (found under Downloads > Java).\n\n";
817     print "For more information, see:\n";
818     print "https://lists.webkit.org/pipermail/webkit-dev/2010-October/014867.html\n";
819     print "https://webkit.org/building/tools.html\n\n";
820     exit 1;
821 }
822
823 sub formatBuildTime($)
824 {
825     my ($buildTime) = @_;
826
827     my $buildHours = int($buildTime / 3600);
828     my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
829     my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
830
831     if ($buildHours) {
832         return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
833     }
834     return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
835 }
836
837 sub writeCongrats()
838 {
839     my $launcherPath = launcherPath();
840     my $launcherName = launcherName();
841     my $endTime = time();
842     my $buildTime = formatBuildTime($endTime - $startTime);
843
844     print "\n";
845     print "===========================================================\n";
846     print " WebKit is now built ($buildTime). \n";
847     if (!isChromium()) {
848         print " To run $launcherName with this newly-built code, use the\n";
849         print " \"$launcherPath\" script.\n";
850     }
851     print "===========================================================\n";
852 }