3 # Copyright (C) 2005, 2006 Apple Inc. All rights reserved.
4 # Copyright (C) 2009 Google Inc. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
30 # Build script wrapper for the WebKit Open Source Project.
36 use Getopt::Long qw(:config pass_through);
37 use lib $FindBin::Bin;
39 use webkitperl::features;
42 sub formatBuildTime($);
45 my $originalWorkingDirectory = getcwd();
52 my $startTime = time();
54 my ($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);
62 { option => "3d-canvas", desc => "Toggle 3D canvas support",
63 define => "ENABLE_3D_CANVAS", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDCanvasSupport },
65 { option => "3d-rendering", desc => "Toggle 3D rendering support",
66 define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDRenderingSupport },
68 { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
69 define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
71 { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
72 define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport },
74 { option => "coverage", desc => "Toggle code coverage support",
75 define => "", default => 0, value => \$coverageSupport },
77 { option => "database", desc => "Toggle Database Support",
78 define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport },
80 { option => "datagrid", desc => "Toggle Datagrid Support",
81 define => "ENABLE_DATAGRID", default => 0, value => \$datagridSupport },
83 { option => "datalist", desc => "Toggle HTML5 datalist support",
84 define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
86 { option => "dom-storage", desc => "Toggle DOM Storage Support",
87 define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport },
89 { option => "eventsource", desc => "Toggle server-sent events support",
90 define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport },
92 { option => "filters", desc => "Toggle Filters support",
93 define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt()), value => \$filtersSupport },
95 { option => "geolocation", desc => "Toggle Geolocation support",
96 define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport },
98 { option => "icon-database", desc => "Toggle Icon database support",
99 define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
101 { option => "indexed-database", desc => "Toggle Indexed Database API support",
102 define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
104 { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
105 define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
107 { option => "mathml", desc => "Toggle MathML support",
108 define => "ENABLE_MATHML", default => 0, value => \$mathmlSupport },
110 { option => "notifications", desc => "Toggle Desktop Notifications Support",
111 define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
113 { option => "offline-web-applications", desc => "Toggle Offline Web Application Support",
114 define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport },
116 { option => "ruby", desc => "Toggle HTML5 Ruby support",
117 define => "ENABLE_RUBY", default => 1, value => \$rubySupport },
119 { option => "shared-workers", desc => "Toggle SharedWorkers support",
120 define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport },
122 { option => "svg", desc => "Toggle SVG support",
123 define => "ENABLE_SVG", default => 1, value => \$svgSupport },
125 { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)",
126 define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport },
128 { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)",
129 define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport },
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 },
134 { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
135 define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
137 { option => "svg-foreign-object", desc => "Toggle SVG foreign object support (implies SVG support)",
138 define => "ENABLE_SVG_FOREIGN_OBJECT", default => 1, value => \$svgForeignObjectSupport },
140 { option => "svg-use", desc => "Toggle SVG use element support (implies SVG support)",
141 define => "ENABLE_SVG_USE", default => 1, value => \$svgUseSupport },
143 { option => "video", desc => "Toggle Video support",
144 define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport },
146 { option => "web-sockets", desc => "Toggle Web Sockets support",
147 define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
149 { option => "wml", desc => "Toggle WML support",
150 define => "ENABLE_WML", default => 0, value => \$wmlSupport },
152 { option => "xhtmlmp", desc => "Toggle XHTML-MP support",
153 define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport },
155 { option => "wcss", desc => "Toggle WCSS support",
156 define => "ENABLE_WCSS", default => 0, value => \$wcssSupport },
158 { option => "workers", desc => "Toggle Web Workers support",
159 define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport },
161 { option => "xpath", desc => "Toggle XPath support",
162 define => "ENABLE_XPATH", default => 1, value => \$xpathSupport },
164 { option => "xslt", desc => "Toggle XSLT support",
165 define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
168 # Update defaults from Qt's project file
170 my %qtDefaults = qtFeatureDefaults();
171 foreach (@features) {
172 $_->{default} = $qtDefaults{$_->{define}} || 0;
176 # Additional environment parameters
177 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
179 # Initialize values from defaults
181 if ($_ eq '--minimal') {
187 # Initialize values from defaults
188 foreach (@features) {
189 ${$_->{value}} = ($_->{default} && !$minimal) || 0;
192 $svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport
193 || $svgDOMObjCBindingsSupport || $svgFontsSupport
194 || $svgForeignObjectSupport || $svgUseSupport;
197 my $programName = basename($0);
199 Usage: $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
209 --makeargs=<arguments> Optional Makefile flags
211 --minimal No optional features, unless explicitly enabled.
216 'help' => \$showHelp,
218 'makeargs=s' => \$makeArgs,
219 'minimal' => \$minimal,
222 # Build usage text and options list from features
223 foreach (@features) {
224 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
225 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
226 $options{"$_->{option}!"} = $_->{value};
229 GetOptions(%options);
236 checkRequiredSystemConfig();
239 my $productDir = productDir();
241 # Check that all the project directories are there.
242 my @projects = ("JavaScriptCore", "WebCore", "WebKit");
243 # Only Apple builds JavaScriptGlue, and only on the Mac
244 splice @projects, 1, 0, "JavaScriptGlue" if isAppleMacWebKit();
246 my @otherDirs = ("WebKitLibraries");
247 for my $dir (@projects, @otherDirs) {
249 die "Error: No $dir directory found. Please do a fresh checkout.\n";
255 # enable autotool options accordingly
257 foreach (@features) {
258 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
261 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
262 } elsif (isAppleMacWebKit()) {
263 push @options, XcodeOptions();
267 my ($feature, $isEnabled) = @_;
268 return $feature . "=" . ($isEnabled ? $feature : " ");
271 foreach (@features) {
272 if ($_->{option} eq "coverage") {
273 push @options, XcodeCoverageSupportOptions() if $coverageSupport;
275 push @options, option($_->{define}, ${$_->{value}});
279 # Copy library and header from WebKitLibraries to a findable place in the product directory.
281 my @librariesToCopy = (
282 "libWebKitSystemInterfaceTiger.a",
283 "libWebKitSystemInterfaceLeopard.a",
284 "libWebKitSystemInterfaceSnowLeopard.a",
285 "libWebCoreSQLite3.a",
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;
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;
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;
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;
318 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
320 foreach (@features) {
321 push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default};
325 # Force re-link of existing libraries if different than expected
326 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
328 if (isInspectorFrontend()) {
329 exit exitStatus(copyInspectorFrontendFiles());
333 downloadWafIfNeeded();
334 push @projects, 'WebKitTools/DumpRenderTree';
335 push @projects, 'WebKitTools/wx/browser';
336 push @projects, 'WebKit/wx/bindings/python';
340 # Chromium doesn't build by project directories.
342 my $result = buildChromium($clean, @options);
343 exit exitStatus($result) if exitStatus($result);
346 # Build, and abort if the build fails.
347 for my $dir (@projects) {
351 # For Gtk and Qt the WebKit project builds all others
352 if ((isGtk() || isQt()) && $dir ne "WebKit") {
358 $result = buildGtkProject($dir, $clean, @options);
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);
369 if (defined($makeArgs)) {
370 @options = split(/ /, $makeArgs);
372 if ($dir eq "WebKit" && isWx()) {
376 $result = buildWafProject($dir, $clean, @options);
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";
387 exit exitStatus($result);
392 # Don't report the "WebKit is now built" message after a clean operation.
395 # Write out congratulations message.
400 sub formatBuildTime($)
402 my ($buildTime) = @_;
404 my $buildHours = int($buildTime / 3600);
405 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
406 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
409 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
411 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
416 my $launcherPath = launcherPath();
417 my $launcherName = launcherName();
418 my $endTime = time();
419 my $buildTime = formatBuildTime($endTime - $startTime);
422 print "===========================================================\n";
423 print " WebKit is now built ($buildTime). \n";
425 print " To run $launcherName with this newly-built code, use the\n";
426 print " \"$launcherPath\" script.\n";
428 print "===========================================================\n";