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