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.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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.
31 # Build script wrapper for the WebKit Open Source Project.
38 use Getopt::Long qw(:config pass_through);
39 use lib $FindBin::Bin;
41 use webkitperl::features;
44 sub formatBuildTime($);
46 sub checkForJavaSDK();
48 my $originalWorkingDirectory = getcwd();
60 my $startTime = time();
64 $threeDRenderingSupport,
65 $accelerated2dCanvasSupport,
67 $channelMessagingSupport,
68 $clientBasedGeolocationSupport,
73 $deviceOrientationSupport,
74 $directoryUploadSupport,
79 $fullscreenAPISupport,
83 $indexedDatabaseSupport,
85 $javaScriptDebuggerSupport,
89 $netscapePluginSupport,
90 $notificationsSupport,
91 $offlineWebApplicationSupport,
92 $orientationEventsSupport,
94 $sharedWorkersSupport,
98 $svgDOMObjCBindingsSupport,
100 $svgForeignObjectSupport,
102 $systemMallocSupport,
103 $tiledBackingStoreSupport,
108 $webInspectorSupport,
119 { option => "3d-canvas", desc => "Toggle 3D canvas support",
120 define => "ENABLE_3D_CANVAS", default => (isAppleMacWebKit() && !isTiger() && !isLeopard()), value => \$threeDCanvasSupport },
122 { option => "3d-rendering", desc => "Toggle 3D rendering support",
123 define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDRenderingSupport },
125 { option => "accelerated-2d-canvas", desc => "Toggle accelerated 2D canvas support",
126 define => "ENABLE_ACCELERATED_2D_CANVAS", default => 0, value => \$accelerated2dCanvasSupport },
128 { option => "blob", desc => "Toggle Blob support",
129 define => "ENABLE_BLOB", default => (isAppleMacWebKit() || isGtk()), value => \$blobSupport },
131 { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
132 define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
134 { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
135 define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport },
137 { option => "coverage", desc => "Toggle code coverage support",
138 define => "", default => 0, value => \$coverageSupport },
140 { option => "database", desc => "Toggle Database Support",
141 define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport },
143 { option => "datagrid", desc => "Toggle Datagrid Support",
144 define => "ENABLE_DATAGRID", default => 0, value => \$datagridSupport },
146 { option => "datalist", desc => "Toggle HTML5 datalist support",
147 define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
149 { option => "device-orientation", desc => "Toggle DeviceOrientation support",
150 define => "ENABLE_DEVICE_ORIENTATION", default => 0, value => \$deviceOrientationSupport },
152 { option => "directory-upload", desc => "Toogle Directory upload support",
153 define => "ENABLE_DIRECTORY_UPLOAD", default => 0, value => \$directoryUploadSupport },
155 { option => "dom-storage", desc => "Toggle DOM Storage Support",
156 define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport },
158 { option => "eventsource", desc => "Toggle server-sent events support",
159 define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport },
161 { option => "file-system", desc => "Toggle FileSystem support",
162 define => "ENABLE_FILE_SYSTEM", default => 0, value => \$fileSystemSupport },
164 { option => "filters", desc => "Toggle Filters support",
165 define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt() || isEfl()), value => \$filtersSupport },
167 { option => "fullscreen-api", desc => "Toggle Fullscreen API support",
168 define => "ENABLE_FULLSCREEN_API", default => (isAppleMacWebKit() || isGtk()), value => \$fullscreenAPISupport },
170 { option => "geolocation", desc => "Toggle Geolocation support",
171 define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport },
173 { option => "icon-database", desc => "Toggle Icon database support",
174 define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
176 { option => "image-resizer", desc => "Toggle Image Resizer API support",
177 define => "ENABLE_IMAGE_RESIZER", default => 0, value => \$imageResizerSupport },
179 { option => "indexed-database", desc => "Toggle Indexed Database API support",
180 define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
182 { option => "input-speech", desc => "Speech Input API support",
183 define => "ENABLE_INPUT_SPEECH", default => 0, value => \$inputSpeechSupport },
185 { option => "inspector", desc => "Toggle Web Inspector support",
186 define => "ENABLE_INSPECTOR", default => 1, value => \$webInspectorSupport },
188 { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
189 define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
191 { option => "link-prefetch", desc => "Toggle pre fetching support",
192 define => "ENABLE_LINK_PREFETCH", default => 0, value => \$linkPrefetchSupport },
194 { option => "mathml", desc => "Toggle MathML support",
195 define => "ENABLE_MATHML", default => 1, value => \$mathmlSupport },
197 { option => "meter-tag", desc => "Meter Tag support",
198 define => "ENABLE_METER_TAG", default => !isGtk() && !isAppleWinWebKit(), value => \$meterTagSupport },
200 { option => "netscape-plugin", desc => "Netscape Plugin support",
201 define => "ENABLE_NETSCAPE_PLUGIN_API", default => !isEfl(), value => \$netscapePluginSupport },
203 { option => "notifications", desc => "Toggle Desktop Notifications Support",
204 define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
206 { option => "offline-web-applications", desc => "Toggle Offline Web Application Support",
207 define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport },
209 { option => "orientation-events", desc => "Toggle Orientation Events support",
210 define => "ENABLE_ORIENTATION_EVENTS", default => 0, value => \$orientationEventsSupport },
212 { option => "progress-tag", desc => "Progress Tag support",
213 define => "ENABLE_PROGRESS_TAG", default => 1, value => \$progressTagSupport },
215 { option => "system-malloc", desc => "Toggle system allocator instead of TCmalloc",
216 define => "USE_SYSTEM_MALLOC", default => 0, value => \$systemMallocSupport },
218 { option => "shared-workers", desc => "Toggle SharedWorkers support",
219 define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport },
221 { option => "svg", desc => "Toggle SVG support",
222 define => "ENABLE_SVG", default => 1, value => \$svgSupport },
224 { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)",
225 define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport },
227 { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)",
228 define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport },
230 { option => "svg-dom-objc-bindings", desc => "Toggle SVG DOM Objective-C bindings support (implies SVG support)",
231 define => "ENABLE_SVG_DOM_OBJC_BINDINGS", default => isAppleMacWebKit(), value => \$svgDOMObjCBindingsSupport },
233 { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
234 define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
236 { option => "svg-foreign-object", desc => "Toggle SVG foreign object support (implies SVG support)",
237 define => "ENABLE_SVG_FOREIGN_OBJECT", default => 1, value => \$svgForeignObjectSupport },
239 { option => "svg-use", desc => "Toggle SVG use element support (implies SVG support)",
240 define => "ENABLE_SVG_USE", default => 1, value => \$svgUseSupport },
242 { option => "tiled-backing-store", desc => "Toggle Tiled Backing Store support",
243 define => "ENABLE_TILED_BACKING_STORE", default => isQt(), value => \$tiledBackingStoreSupport },
245 { option => "touch-events", desc => "Toggle Touch Events support",
246 define => "ENABLE_TOUCH_EVENTS", default => isQt(), value => \$touchEventsSupport },
248 { option => "video", desc => "Toggle Video support",
249 define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport },
251 { option => "wcss", desc => "Toggle WCSS support",
252 define => "ENABLE_WCSS", default => 0, value => \$wcssSupport },
254 { option => "web-audio", desc => "Toggle Web Audio support",
255 define => "ENABLE_WEB_AUDIO", default => 0, value=> \$webAudioSupport },
257 { option => "web-sockets", desc => "Toggle Web Sockets support",
258 define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
260 { option => "web-timing", desc => "Toggle Web Timing support",
261 define => "ENABLE_WEB_TIMING", default => 0, value=> \$webTimingSupport },
263 { option => "wml", desc => "Toggle WML support",
264 define => "ENABLE_WML", default => 0, value => \$wmlSupport },
266 { option => "workers", desc => "Toggle Web Workers support",
267 define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport },
269 { option => "xhtmlmp", desc => "Toggle XHTML-MP support",
270 define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport },
272 { option => "xpath", desc => "Toggle XPath support",
273 define => "ENABLE_XPATH", default => 1, value => \$xpathSupport },
275 { option => "xslt", desc => "Toggle XSLT support",
276 define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
279 # Update defaults from Qt's project file
281 my %qtDefaults = qtFeatureDefaults();
282 foreach (@features) {
283 $_->{default} = $qtDefaults{$_->{define}} || 0;
287 # Additional environment parameters
288 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
290 # Initialize values from defaults
292 if ($_ eq '--minimal') {
294 } elsif ($_ eq '--v8') {
299 # Initialize values from defaults
300 foreach (@features) {
301 ${$_->{value}} = ($_->{default} && !$minimal) || 0;
304 $svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport
305 || $svgDOMObjCBindingsSupport || $svgFontsSupport
306 || $svgForeignObjectSupport || $svgUseSupport;
309 my $programName = basename($0);
311 Usage: $programName [options] [options to pass to build system]
312 --help Show this help message
313 --clean Cleanup the build directory
314 --debug Compile in debug mode
316 --chromium Build the Chromium port on Mac/Win/Linux
317 --efl Build the EFL port
318 --gtk Build the GTK+ port
319 --qt Build the Qt port
320 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
321 --wince Build the WinCE port
323 --inspector-frontend Copy changes to the inspector front-end files to the build directory
325 --install-headers=<path> Set installation path for the headers (Qt only)
326 --install-libs=<path> Set installation path for the libraries (Qt only)
327 --v8 Use V8 as JavaScript engine (Qt only)
329 --prefix=<path> Set installation prefix to the given path (Gtk/Efl only)
330 --makeargs=<arguments> Optional Makefile flags
332 --minimal No optional features, unless explicitly enabled.
337 'help' => \$showHelp,
339 'install-headers=s' => \$installHeaders,
340 'install-libs=s' => \$installLibs,
341 'prefix=s' => \$prefixPath,
342 'makeargs=s' => \$makeArgs,
343 'minimal' => \$minimal,
345 'no-webkit2' => \$noWebKit2,
348 # Build usage text and options list from features
349 foreach (@features) {
350 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
351 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
352 $options{"$_->{option}!"} = $_->{value};
355 GetOptions(%options);
362 checkRequiredSystemConfig();
365 my $productDir = productDir();
367 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
368 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && !isSymbian() && -e $productDir);
370 sub unlinkZeroFiles ()
372 my $file = $File::Find::name;
375 print "0 byte sized file removed from build directory: $file\n";
379 # Check that all the project directories are there.
380 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
382 my @otherDirs = ("WebKitLibraries");
383 for my $dir (@projects, @otherDirs) {
385 die "Error: No $dir directory found. Please do a fresh checkout.\n";
391 # enable autotool options accordingly
394 foreach (@features) {
395 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
398 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
399 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
400 } elsif (isAppleMacWebKit()) {
402 push @options, XcodeOptions();
406 my ($feature, $isEnabled, $defaultValue) = @_;
407 return "" if $defaultValue == $isEnabled;
408 return $feature . "=" . ($isEnabled ? $feature : "");
411 foreach (@features) {
412 if ($_->{option} ne "coverage") {
413 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
414 push @options, $option unless $option eq "";
418 # Apple builds JavaScriptGlue, and only on the Mac.
419 splice @projects, 1, 0, "Source/JavaScriptGlue";
421 # ANGLE must come before WebCore
422 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
424 # WebKit2 is only supported in SnowLeopard and later at present.
425 push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
427 # Copy library and header from WebKitLibraries to a findable place in the product directory.
428 my @librariesToCopy = (
429 "libWebKitSystemInterfaceTiger.a",
430 "libWebKitSystemInterfaceLeopard.a",
431 "libWebKitSystemInterfaceSnowLeopard.a",
432 "libWebCoreSQLite3.a",
434 foreach my $libName (@librariesToCopy) {
435 my $srcLib = "WebKitLibraries/" . $libName;
436 my $lib = "$productDir/" . $libName;
437 if (!-e $lib || -M $lib > -M $srcLib) {
438 print "Updating $lib\n";
439 system "ditto", $srcLib, $lib;
440 system "ranlib", $lib;
444 # FIXME: This code should be abstracted to not be copy/paste.
445 my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h";
446 my $header = "$productDir/usr/local/include/WebKitSystemInterface.h";
447 if (!-e $header || -M $header > -M $srcHeader) {
448 print "Updating $header\n";
449 system "mkdir", "-p", "$productDir/usr/local/include";
450 system "ditto", $srcHeader, $header;
453 my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3";
454 my $headerDir = "$productDir/WebCoreSQLite3";
455 if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) {
456 print "Updating $headerDir\n";
457 system "ditto", $srcHeaderDir, $headerDir;
459 } elsif (isAppleWinWebKit()) {
460 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
461 # Will fail if WebKitSupportLibrary.zip is not in source root.
462 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
465 push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
466 push @options, "--install-libs=" . $installLibs if defined($installLibs);
467 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
469 foreach (@features) {
470 push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default};
474 push @options, "CONFIG+=minimal";
478 push @options, "CONFIG+=v8";
482 # Force re-link of existing libraries if different than expected
483 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
485 if (isInspectorFrontend()) {
486 exit exitStatus(copyInspectorFrontendFiles());
490 downloadWafIfNeeded();
492 if (defined($makeArgs)) {
493 @options = split(/ /, $makeArgs);
496 my $result = buildWafProject('.', $clean, @options);
497 exit exitStatus($result) if exitStatus($result);
502 # Chromium doesn't build by project directories.
504 my $result = buildChromium($clean, @options);
505 exit exitStatus($result) if exitStatus($result);
511 foreach (@features) {
512 my $featureName = $_->{define};
514 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
515 push @options, "-D$featureName=$featureEnabled";
518 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
519 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
520 my $result = buildCMakeEflProject($clean, @options);
521 exit exitStatus($result) if exitStatus($result);
527 foreach (@features) {
528 my $featureName = $_->{define};
530 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
531 push @options, "-D$featureName=$featureEnabled";
534 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
535 my $result = buildCMakeWinCEProject("STANDARDSDK_500 (ARMV4I)", $clean, @options);
536 exit exitStatus($result) if exitStatus($result);
539 # Build, and abort if the build fails.
540 for my $dir (@projects) {
544 # For Gtk and Qt the WebKit project builds all others
545 if ((isGtk() || isQt()) && $dir ne "Source/WebKit") {
550 my $project = basename($dir);
552 $result = buildGtkProject($project, $clean, @options);
554 #FIXME: $dir should probably be $project.
555 $result = buildQMakeQtProject($dir, $clean, @options);
556 } elsif (isAppleMacWebKit()) {
557 my @local_options = @options;
558 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $project ne "ANGLE";
559 $result = buildXCodeProject($project, $clean, @local_options, @ARGV);
560 } elsif (isAppleWinWebKit()) {
561 if ($project eq "WebKit") {
562 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
565 # Various build* calls above may change the CWD.
568 if (exitStatus($result)) {
569 my $scriptDir = relativeScriptsDir();
570 if (usingVisualStudioExpress()) {
571 # Visual Studio Express is so lame it can't stdout build failures.
572 # So we find its logs and dump them to the console ourselves.
573 system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
575 if (isAppleWinWebKit()) {
576 print "\n\n===== BUILD FAILED ======\n\n";
577 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
578 my $baseProductDir = baseProductDir();
579 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
581 exit exitStatus($result);
585 # Don't report the "WebKit is now built" message after a clean operation.
588 # Write out congratulations message.
593 sub checkForJavaSDK()
595 my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
599 print "\nCan't find required $jniHeader, build will fail.\n\n";
600 print "After installing \"Java for Mac OS X 10.6 Update 3\", the Java Developer Package is required to build WebKit.\n";
601 print "Please install the package from http://connect.apple.com (found under Dowloads > Java).\n\n";
602 print "For more information, see:\n";
603 print "https://lists.webkit.org/pipermail/webkit-dev/2010-October/014867.html\n";
604 print "https://webkit.org/building/tools.html\n\n";
608 sub formatBuildTime($)
610 my ($buildTime) = @_;
612 my $buildHours = int($buildTime / 3600);
613 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
614 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
617 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
619 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
624 my $launcherPath = launcherPath();
625 my $launcherName = launcherName();
626 my $endTime = time();
627 my $buildTime = formatBuildTime($endTime - $startTime);
630 print "===========================================================\n";
631 print " WebKit is now built ($buildTime). \n";
633 print " To run $launcherName with this newly-built code, use the\n";
634 print " \"$launcherPath\" script.\n";
636 print "===========================================================\n";