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,
88 $mediaStatisticsSupport,
90 $netscapePluginSupport,
91 $notificationsSupport,
92 $offlineWebApplicationSupport,
93 $orientationEventsSupport,
95 $registerProtocolHandlerSupport,
96 $sharedWorkersSupport,
100 $svgDOMObjCBindingsSupport,
102 $svgForeignObjectSupport,
104 $systemMallocSupport,
105 $tiledBackingStoreSupport,
110 $webInspectorSupport,
121 { option => "3d-canvas", desc => "Toggle 3D canvas (WebGL) support",
122 define => "ENABLE_WEBGL", default => (isAppleMacWebKit() && !isTiger() && !isLeopard()), value => \$threeDCanvasSupport },
124 { option => "3d-rendering", desc => "Toggle 3D rendering support",
125 define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDRenderingSupport },
127 { option => "accelerated-2d-canvas", desc => "Toggle accelerated 2D canvas support",
128 define => "ENABLE_ACCELERATED_2D_CANVAS", default => 0, value => \$accelerated2dCanvasSupport },
130 { option => "blob", desc => "Toggle Blob support",
131 define => "ENABLE_BLOB", default => (isAppleMacWebKit() || isGtk()), value => \$blobSupport },
133 { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
134 define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
136 { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
137 define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport },
139 { option => "coverage", desc => "Toggle code coverage support",
140 define => "", default => 0, value => \$coverageSupport },
142 { option => "database", desc => "Toggle Database Support",
143 define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport },
145 { option => "datagrid", desc => "Toggle Datagrid Support",
146 define => "ENABLE_DATAGRID", default => 0, value => \$datagridSupport },
148 { option => "datalist", desc => "Toggle HTML5 datalist support",
149 define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
151 { option => "device-orientation", desc => "Toggle DeviceOrientation support",
152 define => "ENABLE_DEVICE_ORIENTATION", default => 0, value => \$deviceOrientationSupport },
154 { option => "directory-upload", desc => "Toogle Directory upload support",
155 define => "ENABLE_DIRECTORY_UPLOAD", default => 0, value => \$directoryUploadSupport },
157 { option => "dom-storage", desc => "Toggle DOM Storage Support",
158 define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport },
160 { option => "eventsource", desc => "Toggle server-sent events support",
161 define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport },
163 { option => "file-system", desc => "Toggle FileSystem support",
164 define => "ENABLE_FILE_SYSTEM", default => 0, value => \$fileSystemSupport },
166 { option => "filters", desc => "Toggle Filters support",
167 define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt() || isEfl()), value => \$filtersSupport },
169 { option => "fullscreen-api", desc => "Toggle Fullscreen API support",
170 define => "ENABLE_FULLSCREEN_API", default => (isAppleMacWebKit() || isGtk()), value => \$fullscreenAPISupport },
172 { option => "geolocation", desc => "Toggle Geolocation support",
173 define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport },
175 { option => "icon-database", desc => "Toggle Icon database support",
176 define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
178 { option => "image-resizer", desc => "Toggle Image Resizer API support",
179 define => "ENABLE_IMAGE_RESIZER", default => 0, value => \$imageResizerSupport },
181 { option => "indexed-database", desc => "Toggle Indexed Database API support",
182 define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
184 { option => "input-speech", desc => "Speech Input API support",
185 define => "ENABLE_INPUT_SPEECH", default => 0, value => \$inputSpeechSupport },
187 { option => "inspector", desc => "Toggle Web Inspector support",
188 define => "ENABLE_INSPECTOR", default => 1, value => \$webInspectorSupport },
190 { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
191 define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
193 { option => "link-prefetch", desc => "Toggle pre fetching support",
194 define => "ENABLE_LINK_PREFETCH", default => 0, value => \$linkPrefetchSupport },
196 { option => "mathml", desc => "Toggle MathML support",
197 define => "ENABLE_MATHML", default => 1, value => \$mathmlSupport },
199 { option => "media-statistics", desc => "Toggle Media Statistics support",
200 define => "ENABLE_MEDIA_STATISTICS", default => 0, value => \$mediaStatisticsSupport },
202 { option => "meter-tag", desc => "Meter Tag support",
203 define => "ENABLE_METER_TAG", default => !isAppleWinWebKit(), value => \$meterTagSupport },
205 { option => "netscape-plugin", desc => "Netscape Plugin support",
206 define => "ENABLE_NETSCAPE_PLUGIN_API", default => !isEfl(), value => \$netscapePluginSupport },
208 { option => "notifications", desc => "Toggle Desktop Notifications Support",
209 define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
211 { option => "offline-web-applications", desc => "Toggle Offline Web Application Support",
212 define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport },
214 { option => "orientation-events", desc => "Toggle Orientation Events support",
215 define => "ENABLE_ORIENTATION_EVENTS", default => 0, value => \$orientationEventsSupport },
217 { option => "progress-tag", desc => "Progress Tag support",
218 define => "ENABLE_PROGRESS_TAG", default => 1, value => \$progressTagSupport },
220 { option => "register-protocol-handler", desc => "Register Protocol Handler support",
221 define => "ENABLE_REGISTER_PROTOCOL_HANDLER", default => 0, value => \$registerProtocolHandlerSupport },
223 { option => "system-malloc", desc => "Toggle system allocator instead of TCmalloc",
224 define => "USE_SYSTEM_MALLOC", default => 0, value => \$systemMallocSupport },
226 { option => "shared-workers", desc => "Toggle SharedWorkers support",
227 define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport },
229 { option => "svg", desc => "Toggle SVG support",
230 define => "ENABLE_SVG", default => 1, value => \$svgSupport },
232 { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)",
233 define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport },
235 { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)",
236 define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport },
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 },
241 { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
242 define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
244 { option => "svg-foreign-object", desc => "Toggle SVG foreign object support (implies SVG support)",
245 define => "ENABLE_SVG_FOREIGN_OBJECT", default => 1, value => \$svgForeignObjectSupport },
247 { option => "svg-use", desc => "Toggle SVG use element support (implies SVG support)",
248 define => "ENABLE_SVG_USE", default => 1, value => \$svgUseSupport },
250 { option => "tiled-backing-store", desc => "Toggle Tiled Backing Store support",
251 define => "ENABLE_TILED_BACKING_STORE", default => isQt(), value => \$tiledBackingStoreSupport },
253 { option => "touch-events", desc => "Toggle Touch Events support",
254 define => "ENABLE_TOUCH_EVENTS", default => isQt(), value => \$touchEventsSupport },
256 { option => "video", desc => "Toggle Video support",
257 define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport },
259 { option => "wcss", desc => "Toggle WCSS support",
260 define => "ENABLE_WCSS", default => 0, value => \$wcssSupport },
262 { option => "web-audio", desc => "Toggle Web Audio support",
263 define => "ENABLE_WEB_AUDIO", default => 0, value=> \$webAudioSupport },
265 { option => "web-sockets", desc => "Toggle Web Sockets support",
266 define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
268 { option => "web-timing", desc => "Toggle Web Timing support",
269 define => "ENABLE_WEB_TIMING", default => 0, value=> \$webTimingSupport },
271 { option => "wml", desc => "Toggle WML support",
272 define => "ENABLE_WML", default => 0, value => \$wmlSupport },
274 { option => "workers", desc => "Toggle Web Workers support",
275 define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport },
277 { option => "xhtmlmp", desc => "Toggle XHTML-MP support",
278 define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport },
280 { option => "xpath", desc => "Toggle XPath support",
281 define => "ENABLE_XPATH", default => 1, value => \$xpathSupport },
283 { option => "xslt", desc => "Toggle XSLT support",
284 define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
287 # Update defaults from Qt's project file
289 # Take a sneek peek at the arguments, since we will need the qmake binary early
290 # on to do profile parsing.
292 if (/^--qmake=(.*)/) {
293 setQmakeBinaryPath($1);
296 my %qtDefaults = qtFeatureDefaults();
297 foreach (@features) {
298 $_->{default} = $qtDefaults{$_->{define}} || 0;
302 # Additional environment parameters
303 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
305 # Initialize values from defaults
307 if ($_ eq '--minimal') {
309 } elsif ($_ eq '--v8') {
314 # Initialize values from defaults
315 foreach (@features) {
316 ${$_->{value}} = ($_->{default} && !$minimal) || 0;
319 $svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport
320 || $svgDOMObjCBindingsSupport || $svgFontsSupport
321 || $svgForeignObjectSupport || $svgUseSupport;
324 my $programName = basename($0);
326 Usage: $programName [options] [options to pass to build system]
327 --help Show this help message
328 --clean Cleanup the build directory
329 --debug Compile in debug mode
331 --chromium Build the Chromium port on Mac/Win/Linux
332 --efl Build the EFL port
333 --gtk Build the GTK+ port
334 --qt Build the Qt port
335 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
336 --wince Build the WinCE port
338 --inspector-frontend Copy changes to the inspector front-end files to the build directory
340 --install-headers=<path> Set installation path for the headers (Qt only)
341 --install-libs=<path> Set installation path for the libraries (Qt only)
342 --v8 Use V8 as JavaScript engine (Qt only)
344 --prefix=<path> Set installation prefix to the given path (Gtk/Efl only)
345 --makeargs=<arguments> Optional Makefile flags
347 --minimal No optional features, unless explicitly enabled.
352 'help' => \$showHelp,
354 'install-headers=s' => \$installHeaders,
355 'install-libs=s' => \$installLibs,
356 'prefix=s' => \$prefixPath,
357 'makeargs=s' => \$makeArgs,
358 'minimal' => \$minimal,
360 'no-webkit2' => \$noWebKit2,
363 # Build usage text and options list from features
364 foreach (@features) {
365 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
366 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
367 $options{"$_->{option}!"} = $_->{value};
370 GetOptions(%options);
377 checkRequiredSystemConfig();
380 my $productDir = productDir();
382 # Remove Qt makefiles from productDir.
383 # https://bugs.webkit.org/show_bug.cgi?id=54466
384 File::Find::find(sub {unlink $File::Find::name if $File::Find::name =~ m/Makefile/;}, $productDir) if (isQt() && !isSymbian() && -e $productDir);
386 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
387 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && !isSymbian() && -e $productDir);
389 sub unlinkZeroFiles ()
391 my $file = $File::Find::name;
394 print "0 byte sized file removed from build directory: $file\n";
398 # Check that all the project directories are there.
399 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
401 my @otherDirs = ("WebKitLibraries");
402 for my $dir (@projects, @otherDirs) {
404 die "Error: No $dir directory found. Please do a fresh checkout.\n";
410 # enable autotool options accordingly
413 foreach (@features) {
414 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
417 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
418 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
419 } elsif (isAppleMacWebKit()) {
421 push @options, XcodeOptions();
425 my ($feature, $isEnabled, $defaultValue) = @_;
426 return "" if $defaultValue == $isEnabled;
427 return $feature . "=" . ($isEnabled ? $feature : "");
430 foreach (@features) {
431 if ($_->{option} ne "coverage") {
432 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
433 push @options, $option unless $option eq "";
437 # Apple builds JavaScriptGlue, and only on the Mac.
438 splice @projects, 1, 0, "Source/JavaScriptGlue";
440 # ANGLE must come before WebCore
441 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
443 # WebKit2 is only supported in SnowLeopard and later at present.
444 push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
446 # Copy library and header from WebKitLibraries to a findable place in the product directory.
447 my @librariesToCopy = (
448 "libWebKitSystemInterfaceTiger.a",
449 "libWebKitSystemInterfaceLeopard.a",
450 "libWebKitSystemInterfaceSnowLeopard.a",
451 "libWebCoreSQLite3.a",
453 foreach my $libName (@librariesToCopy) {
454 my $srcLib = "WebKitLibraries/" . $libName;
455 my $lib = "$productDir/" . $libName;
456 if (!-e $lib || -M $lib > -M $srcLib) {
457 print "Updating $lib\n";
458 system "ditto", $srcLib, $lib;
459 system "ranlib", $lib;
463 # FIXME: This code should be abstracted to not be copy/paste.
464 my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h";
465 my $header = "$productDir/usr/local/include/WebKitSystemInterface.h";
466 if (!-e $header || -M $header > -M $srcHeader) {
467 print "Updating $header\n";
468 system "mkdir", "-p", "$productDir/usr/local/include";
469 system "ditto", $srcHeader, $header;
472 my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3";
473 my $headerDir = "$productDir/WebCoreSQLite3";
474 if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) {
475 print "Updating $headerDir\n";
476 system "ditto", $srcHeaderDir, $headerDir;
478 } elsif (isAppleWinWebKit()) {
479 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
480 # Will fail if WebKitSupportLibrary.zip is not in source root.
481 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
484 push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
485 push @options, "--install-libs=" . $installLibs if defined($installLibs);
486 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
488 foreach (@features) {
489 push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default};
493 push @options, "CONFIG+=minimal";
497 push @options, "CONFIG+=v8";
501 # Force re-link of existing libraries if different than expected
502 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
504 if (isInspectorFrontend()) {
505 exit exitStatus(copyInspectorFrontendFiles());
509 downloadWafIfNeeded();
511 if (defined($makeArgs)) {
512 @options = split(/ /, $makeArgs);
515 my $result = buildWafProject('.', $clean, @options);
516 exit exitStatus($result) if exitStatus($result);
521 # Chromium doesn't build by project directories.
523 my $result = buildChromium($clean, @options);
524 exit exitStatus($result) if exitStatus($result);
530 foreach (@features) {
531 my $featureName = $_->{define};
533 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
534 push @options, "-D$featureName=$featureEnabled";
537 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
538 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
539 my $result = buildCMakeEflProject($clean, @options);
540 exit exitStatus($result) if exitStatus($result);
546 foreach (@features) {
547 my $featureName = $_->{define};
549 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
550 push @options, "-D$featureName=$featureEnabled";
553 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
554 my $result = buildCMakeWinCEProject("STANDARDSDK_500 (ARMV4I)", $clean, @options);
555 exit exitStatus($result) if exitStatus($result);
558 # Build, and abort if the build fails.
559 for my $dir (@projects) {
563 # For Gtk and Qt the WebKit project builds all others
564 if ((isGtk() || isQt()) && $dir ne "Source/WebKit") {
569 my $project = basename($dir);
571 $result = buildGtkProject($project, $clean, @options);
573 #FIXME: $dir should probably be $project.
574 $result = buildQMakeQtProject($dir, $clean, @options);
575 } elsif (isAppleMacWebKit()) {
576 my @local_options = @options;
577 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $project ne "ANGLE";
578 $result = buildXCodeProject($project, $clean, @local_options, @ARGV);
579 } elsif (isAppleWinWebKit()) {
580 if ($project eq "WebKit") {
581 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
584 # Various build* calls above may change the CWD.
587 if (exitStatus($result)) {
588 my $scriptDir = relativeScriptsDir();
589 if (usingVisualStudioExpress()) {
590 # Visual Studio Express is so lame it can't stdout build failures.
591 # So we find its logs and dump them to the console ourselves.
592 system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
594 if (isAppleWinWebKit()) {
595 print "\n\n===== BUILD FAILED ======\n\n";
596 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
597 my $baseProductDir = baseProductDir();
598 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
600 exit exitStatus($result);
604 # Don't report the "WebKit is now built" message after a clean operation.
607 # Write out congratulations message.
612 sub checkForJavaSDK()
614 my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
618 print "\nCan't find required $jniHeader, build will fail.\n\n";
619 print "After installing \"Java for Mac OS X 10.6 Update 3\", the Java Developer Package is required to build WebKit.\n";
620 print "Please install the package from http://connect.apple.com (found under Dowloads > Java).\n\n";
621 print "For more information, see:\n";
622 print "https://lists.webkit.org/pipermail/webkit-dev/2010-October/014867.html\n";
623 print "https://webkit.org/building/tools.html\n\n";
627 sub formatBuildTime($)
629 my ($buildTime) = @_;
631 my $buildHours = int($buildTime / 3600);
632 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
633 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
636 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
638 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
643 my $launcherPath = launcherPath();
644 my $launcherName = launcherName();
645 my $endTime = time();
646 my $buildTime = formatBuildTime($endTime - $startTime);
649 print "===========================================================\n";
650 print " WebKit is now built ($buildTime). \n";
652 print " To run $launcherName with this newly-built code, use the\n";
653 print " \"$launcherPath\" script.\n";
655 print "===========================================================\n";