1#!/usr/bin/perl -w 2 3# Copyright (C) 2005, 2006 Apple Inc. All rights reserved. 4# Copyright (C) 2009 Google Inc. All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 16# its contributors may be used to endorse or promote products derived 17# from this software without specific prior written permission. 18# 19# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30# Build script wrapper for the WebKit Open Source Project. 31 32use strict; 33use File::Basename; 34use File::Spec; 35use FindBin; 36use Getopt::Long qw(:config pass_through); 37use lib $FindBin::Bin; 38use webkitdirs; 39use webkitperl::features; 40use POSIX; 41 42sub formatBuildTime($); 43sub writeCongrats(); 44 45my $originalWorkingDirectory = getcwd(); 46chdirWebKit(); 47 48my $showHelp = 0; 49my $clean = 0; 50my $minimal = 0; 51my $makeArgs; 52my $startTime = time(); 53 54my ($threeDCanvasSupport, $threeDRenderingSupport, $channelMessagingSupport, $clientBasedGeolocationSupport, $databaseSupport, $datagridSupport, $datalistSupport, 55 $domStorageSupport, $eventsourceSupport, $filtersSupport, $geolocationSupport, $iconDatabaseSupport, $indexedDatabaseSupport, 56 $javaScriptDebuggerSupport, $mathmlSupport, $offlineWebApplicationSupport, $rubySupport, $sharedWorkersSupport, 57 $svgSupport, $svgAnimationSupport, $svgAsImageSupport, $svgDOMObjCBindingsSupport, $svgFontsSupport, 58 $svgForeignObjectSupport, $svgUseSupport, $videoSupport, $webSocketsSupport, $wmlSupport, $wcssSupport, $xhtmlmpSupport, $workersSupport, 59 $xpathSupport, $xsltSupport, $coverageSupport, $notificationsSupport); 60 61my @features = ( 62 { option => "3d-canvas", desc => "Toggle 3D canvas support", 63 define => "ENABLE_3D_CANVAS", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDCanvasSupport }, 64 65 { option => "3d-rendering", desc => "Toggle 3D rendering support", 66 define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDRenderingSupport }, 67 68 { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support", 69 define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport }, 70 71 { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support", 72 define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport }, 73 74 { option => "coverage", desc => "Toggle code coverage support", 75 define => "", default => 0, value => \$coverageSupport }, 76 77 { option => "database", desc => "Toggle Database Support", 78 define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport }, 79 80 { option => "datagrid", desc => "Toggle Datagrid Support", 81 define => "ENABLE_DATAGRID", default => 0, value => \$datagridSupport }, 82 83 { option => "datalist", desc => "Toggle HTML5 datalist support", 84 define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport }, 85 86 { option => "dom-storage", desc => "Toggle DOM Storage Support", 87 define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport }, 88 89 { option => "eventsource", desc => "Toggle server-sent events support", 90 define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport }, 91 92 { option => "filters", desc => "Toggle Filters support", 93 define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt()), value => \$filtersSupport }, 94 95 { option => "geolocation", desc => "Toggle Geolocation support", 96 define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport }, 97 98 { option => "icon-database", desc => "Toggle Icon database support", 99 define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport }, 100 101 { option => "indexed-database", desc => "Toggle Indexed Database API support", 102 define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport }, 103 104 { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support", 105 define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport }, 106 107 { option => "mathml", desc => "Toggle MathML support", 108 define => "ENABLE_MATHML", default => 0, value => \$mathmlSupport }, 109 110 { option => "notifications", desc => "Toggle Desktop Notifications Support", 111 define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport }, 112 113 { option => "offline-web-applications", desc => "Toggle Offline Web Application Support", 114 define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport }, 115 116 { option => "ruby", desc => "Toggle HTML5 Ruby support", 117 define => "ENABLE_RUBY", default => 1, value => \$rubySupport }, 118 119 { option => "shared-workers", desc => "Toggle SharedWorkers support", 120 define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport }, 121 122 { option => "svg", desc => "Toggle SVG support", 123 define => "ENABLE_SVG", default => 1, value => \$svgSupport }, 124 125 { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)", 126 define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport }, 127 128 { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)", 129 define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport }, 130 131 { option => "svg-dom-objc-bindings", desc => "Toggle SVG DOM Objective-C bindings support (implies SVG support)", 132 define => "ENABLE_SVG_DOM_OBJC_BINDINGS", default => isAppleMacWebKit(), value => \$svgDOMObjCBindingsSupport }, 133 134 { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)", 135 define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport }, 136 137 { option => "svg-foreign-object", desc => "Toggle SVG foreign object support (implies SVG support)", 138 define => "ENABLE_SVG_FOREIGN_OBJECT", default => 1, value => \$svgForeignObjectSupport }, 139 140 { option => "svg-use", desc => "Toggle SVG use element support (implies SVG support)", 141 define => "ENABLE_SVG_USE", default => 1, value => \$svgUseSupport }, 142 143 { option => "video", desc => "Toggle Video support", 144 define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport }, 145 146 { option => "web-sockets", desc => "Toggle Web Sockets support", 147 define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport }, 148 149 { option => "wml", desc => "Toggle WML support", 150 define => "ENABLE_WML", default => 0, value => \$wmlSupport }, 151 152 { option => "xhtmlmp", desc => "Toggle XHTML-MP support", 153 define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport }, 154 155 { option => "wcss", desc => "Toggle WCSS support", 156 define => "ENABLE_WCSS", default => 0, value => \$wcssSupport }, 157 158 { option => "workers", desc => "Toggle Web Workers support", 159 define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport }, 160 161 { option => "xpath", desc => "Toggle XPath support", 162 define => "ENABLE_XPATH", default => 1, value => \$xpathSupport }, 163 164 { option => "xslt", desc => "Toggle XSLT support", 165 define => "ENABLE_XSLT", default => 1, value => \$xsltSupport }, 166); 167 168# Update defaults from Qt's project file 169if (isQt()) { 170 my %qtDefaults = qtFeatureDefaults(); 171 foreach (@features) { 172 $_->{default} = $qtDefaults{$_->{define}} || 0; 173 } 174} 175 176# Additional environment parameters 177push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'}); 178 179# Initialize values from defaults 180foreach (@ARGV) { 181 if ($_ eq '--minimal') { 182 $minimal = 1; 183 last; 184 } 185} 186 187# Initialize values from defaults 188foreach (@features) { 189 ${$_->{value}} = ($_->{default} && !$minimal) || 0; 190} 191 192$svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport 193 || $svgDOMObjCBindingsSupport || $svgFontsSupport 194 || $svgForeignObjectSupport || $svgUseSupport; 195 196 197my $programName = basename($0); 198my $usage = <<EOF; 199Usage: $programName [options] [options to pass to build system] 200 --help Show this help message 201 --clean Cleanup the build directory 202 --debug Compile in debug mode 203 --cairo-win32 Build using Cairo (rather than CoreGraphics) on Windows 204 --chromium Build the Chromium port on Mac/Win/Linux 205 --gtk Build the GTK+ port 206 --qt Build the Qt port 207 --inspector-frontend Copy changes to the inspector front-end files to the build directory 208 209 --makeargs=<arguments> Optional Makefile flags 210 211 --minimal No optional features, unless explicitly enabled. 212 213EOF 214 215my %options = ( 216 'help' => \$showHelp, 217 'clean' => \$clean, 218 'makeargs=s' => \$makeArgs, 219 'minimal' => \$minimal, 220); 221 222# Build usage text and options list from features 223foreach (@features) { 224 my $opt = sprintf("%-35s", " --[no-]$_->{option}"); 225 $usage .= "$opt $_->{desc} (default: $_->{default})\n"; 226 $options{"$_->{option}!"} = $_->{value}; 227} 228 229GetOptions(%options); 230 231if ($showHelp) { 232 print STDERR $usage; 233 exit 1; 234} 235 236checkRequiredSystemConfig(); 237setConfiguration(); 238 239my $productDir = productDir(); 240 241# Check that all the project directories are there. 242my @projects = ("JavaScriptCore", "WebCore", "WebKit"); 243# Only Apple builds JavaScriptGlue, and only on the Mac 244splice @projects, 1, 0, "JavaScriptGlue" if isAppleMacWebKit(); 245 246my @otherDirs = ("WebKitLibraries"); 247for my $dir (@projects, @otherDirs) { 248 if (! -d $dir) { 249 die "Error: No $dir directory found. Please do a fresh checkout.\n"; 250 } 251} 252 253my @options = (); 254 255# enable autotool options accordingly 256if (isGtk()) { 257 foreach (@features) { 258 push @options, autotoolsFlag(${$_->{value}}, $_->{option}); 259 } 260 261 push @options, "--makeargs=" . $makeArgs if defined($makeArgs); 262} elsif (isAppleMacWebKit()) { 263 push @options, XcodeOptions(); 264 265 sub option($$) 266 { 267 my ($feature, $isEnabled) = @_; 268 return $feature . "=" . ($isEnabled ? $feature : " "); 269 } 270 271 foreach (@features) { 272 if ($_->{option} eq "coverage") { 273 push @options, XcodeCoverageSupportOptions() if $coverageSupport; 274 } else { 275 push @options, option($_->{define}, ${$_->{value}}); 276 } 277 } 278 279 # Copy library and header from WebKitLibraries to a findable place in the product directory. 280 281 my @librariesToCopy = ( 282 "libWebKitSystemInterfaceTiger.a", 283 "libWebKitSystemInterfaceLeopard.a", 284 "libWebKitSystemInterfaceSnowLeopard.a", 285 "libWebCoreSQLite3.a", 286 ); 287 foreach my $libName (@librariesToCopy) { 288 my $srcLib = "WebKitLibraries/" . $libName; 289 my $lib = "$productDir/" . $libName; 290 if (!-e $lib || -M $lib > -M $srcLib) { 291 print "Updating $lib\n"; 292 system "ditto", $srcLib, $lib; 293 system "ranlib", $lib; 294 } 295 } 296 297 # FIXME: This code should be abstracted to not be copy/paste. 298 my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h"; 299 my $header = "$productDir/usr/local/include/WebKitSystemInterface.h"; 300 if (!-e $header || -M $header > -M $srcHeader) { 301 print "Updating $header\n"; 302 system "mkdir", "-p", "$productDir/usr/local/include"; 303 system "ditto", $srcHeader, $header; 304 } 305 306 my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3"; 307 my $headerDir = "$productDir/WebCoreSQLite3"; 308 if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) { 309 print "Updating $headerDir\n"; 310 system "ditto", $srcHeaderDir, $headerDir; 311 } 312} elsif (isAppleWinWebKit()) { 313 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found. 314 # Will fail if WebKitSupportLibrary.zip is not in source root. 315 (system("perl WebKitTools/Scripts/update-webkit-support-libs") == 0) or die; 316} elsif (isQt()) { 317 @options = @ARGV; 318 push @options, "--makeargs=" . $makeArgs if defined($makeArgs); 319 320 foreach (@features) { 321 push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default}; 322 } 323} 324 325# Force re-link of existing libraries if different than expected 326removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport); 327 328if (isInspectorFrontend()) { 329 exit exitStatus(copyInspectorFrontendFiles()); 330} 331 332if (isWx()) { 333 downloadWafIfNeeded(); 334 push @projects, 'WebKitTools/DumpRenderTree'; 335 push @projects, 'WebKitTools/wx/browser'; 336 push @projects, 'WebKit/wx/bindings/python'; 337} 338 339if (isChromium()) { 340 # Chromium doesn't build by project directories. 341 @projects = (); 342 my $result = buildChromium($clean, @options); 343 exit exitStatus($result) if exitStatus($result); 344} 345 346# Build, and abort if the build fails. 347for my $dir (@projects) { 348 chdir $dir or die; 349 my $result = 0; 350 351 # For Gtk and Qt the WebKit project builds all others 352 if ((isGtk() || isQt()) && $dir ne "WebKit") { 353 chdir ".." or die; 354 next; 355 } 356 357 if (isGtk()) { 358 $result = buildGtkProject($dir, $clean, @options); 359 } elsif (isQt()) { 360 $result = buildQMakeQtProject($dir, $clean, @options); 361 } elsif (isAppleMacWebKit()) { 362 $result = buildXCodeProject($dir, $clean, @options, @ARGV); 363 } elsif (isAppleWinWebKit()) { 364 if ($dir eq "WebKit") { 365 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean); 366 } 367 } elsif (isWx()) { 368 @options = (); 369 if (defined($makeArgs)) { 370 @options = split(/ /, $makeArgs); 371 } 372 if ($dir eq "WebKit" && isWx()) { 373 chdir 'wx' or die; 374 } 375 376 $result = buildWafProject($dir, $clean, @options); 377 } 378 379 if (exitStatus($result)) { 380 if (isAppleWinWebKit()) { 381 print "\n\n===== BUILD FAILED ======\n\n"; 382 my $scriptDir = relativeScriptsDir(); 383 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n"; 384 my $baseProductDir = baseProductDir(); 385 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n"; 386 } 387 exit exitStatus($result); 388 } 389 chdirWebKit(); 390} 391 392# Don't report the "WebKit is now built" message after a clean operation. 393exit if $clean; 394 395# Write out congratulations message. 396writeCongrats(); 397 398exit 0; 399 400sub formatBuildTime($) 401{ 402 my ($buildTime) = @_; 403 404 my $buildHours = int($buildTime / 3600); 405 my $buildMins = int(($buildTime - $buildHours * 3600) / 60); 406 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60; 407 408 if ($buildHours) { 409 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs); 410 } 411 return sprintf("%02dm:%02ds", $buildMins, $buildSecs); 412} 413 414sub writeCongrats() 415{ 416 my $launcherPath = launcherPath(); 417 my $launcherName = launcherName(); 418 my $endTime = time(); 419 my $buildTime = formatBuildTime($endTime - $startTime); 420 421 print "\n"; 422 print "===========================================================\n"; 423 print " WebKit is now built ($buildTime). \n"; 424 if (!isChromium()) { 425 print " To run $launcherName with this newly-built code, use the\n"; 426 print " \"$launcherPath\" script.\n"; 427 } 428 print "===========================================================\n"; 429} 430