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.
37 use Getopt::Long qw(:config pass_through);
38 use lib $FindBin::Bin;
40 use webkitperl::features;
43 sub formatBuildTime($);
46 my $originalWorkingDirectory = getcwd();
56 my $startTime = time();
58 my ($linkPrefetchSupport, $threeDCanvasSupport, $threeDRenderingSupport, $channelMessagingSupport, $clientBasedGeolocationSupport, $databaseSupport, $datagridSupport, $datalistSupport,
59 $domStorageSupport, $eventsourceSupport, $filtersSupport, $geolocationSupport, $iconDatabaseSupport, $imageResizerSupport, $indexedDatabaseSupport, $inputSpeechSupport,
60 $javaScriptDebuggerSupport, $mathmlSupport, $offlineWebApplicationSupport, $rubySupport, $systemMallocSupport, $sandboxSupport, $sharedWorkersSupport,
61 $svgSupport, $svgAnimationSupport, $svgAsImageSupport, $svgDOMObjCBindingsSupport, $svgFontsSupport,
62 $svgForeignObjectSupport, $svgUseSupport, $videoSupport, $webSocketsSupport, $webTimingSupport, $wmlSupport, $wcssSupport, $xhtmlmpSupport, $workersSupport,
63 $xpathSupport, $xsltSupport, $coverageSupport, $notificationsSupport, $blobSliceSupport, $tiledBackingStoreSupport,
64 $fileReaderSupport, $fileWriterSupport, $fileSystemSupport, $directoryUploadSupport);
67 { option => "link-prefetch", desc => "Toggle pre fetching support",
68 define => "ENABLE_LINK_PREFETCH", default => 0, value => \$linkPrefetchSupport },
70 { option => "3d-canvas", desc => "Toggle 3D canvas support",
71 define => "ENABLE_3D_CANVAS", default => (isAppleMacWebKit() && !isTiger() && !isLeopard()), value => \$threeDCanvasSupport },
73 { option => "3d-rendering", desc => "Toggle 3D rendering support",
74 define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDRenderingSupport },
76 { option => "blob-slice", desc => "Toggle Blob.slice support",
77 define => "ENABLE_BLOB_SLICE", default => (isAppleMacWebKit()), value => \$blobSliceSupport },
79 { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
80 define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
82 { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
83 define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport },
85 { option => "coverage", desc => "Toggle code coverage support",
86 define => "", default => 0, value => \$coverageSupport },
88 { option => "database", desc => "Toggle Database Support",
89 define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport },
91 { option => "datagrid", desc => "Toggle Datagrid Support",
92 define => "ENABLE_DATAGRID", default => 0, value => \$datagridSupport },
94 { option => "datalist", desc => "Toggle HTML5 datalist support",
95 define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
97 { option => "directory-upload", desc => "Toogle Directory upload support",
98 define => "ENABLE_DIRECTORY_UPLOAD", default => 0, value => \$directoryUploadSupport },
100 { option => "dom-storage", desc => "Toggle DOM Storage Support",
101 define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport },
103 { option => "eventsource", desc => "Toggle server-sent events support",
104 define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport },
106 { option => "filters", desc => "Toggle Filters support",
107 define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt()), value => \$filtersSupport },
109 { option => "geolocation", desc => "Toggle Geolocation support",
110 define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport },
112 { option => "icon-database", desc => "Toggle Icon database support",
113 define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
115 { option => "image-resizer", desc => "Toggle Image Resizer API support",
116 define => "ENABLE_IMAGE_RESIZER", default => 0, value => \$imageResizerSupport },
118 { option => "indexed-database", desc => "Toggle Indexed Database API support",
119 define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
121 { option => "input-speech", desc => "Speech Input API support",
122 define => "ENABLE_INPUT_SPEECH", default => 0, value => \$inputSpeechSupport },
124 { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
125 define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
127 { option => "mathml", desc => "Toggle MathML support",
128 define => "ENABLE_MATHML", default => 0, value => \$mathmlSupport },
130 { option => "notifications", desc => "Toggle Desktop Notifications Support",
131 define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
133 { option => "offline-web-applications", desc => "Toggle Offline Web Application Support",
134 define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport },
136 { option => "ruby", desc => "Toggle HTML5 Ruby support",
137 define => "ENABLE_RUBY", default => 1, value => \$rubySupport },
139 { option => "system-malloc", desc => "Toggle system allocator instead of TCmalloc",
140 define => "USE_SYSTEM_MALLOC", default => 0, value => \$systemMallocSupport },
142 { option => "sandbox", desc => "Toggle HTML5 Sandboxed iframe support",
143 define => "ENABLE_SANDBOX", default => 1, value => \$sandboxSupport },
145 { option => "shared-workers", desc => "Toggle SharedWorkers support",
146 define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport },
148 { option => "svg", desc => "Toggle SVG support",
149 define => "ENABLE_SVG", default => 1, value => \$svgSupport },
151 { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)",
152 define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport },
154 { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)",
155 define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport },
157 { option => "svg-dom-objc-bindings", desc => "Toggle SVG DOM Objective-C bindings support (implies SVG support)",
158 define => "ENABLE_SVG_DOM_OBJC_BINDINGS", default => isAppleMacWebKit(), value => \$svgDOMObjCBindingsSupport },
160 { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
161 define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
163 { option => "svg-foreign-object", desc => "Toggle SVG foreign object support (implies SVG support)",
164 define => "ENABLE_SVG_FOREIGN_OBJECT", default => 1, value => \$svgForeignObjectSupport },
166 { option => "svg-use", desc => "Toggle SVG use element support (implies SVG support)",
167 define => "ENABLE_SVG_USE", default => 1, value => \$svgUseSupport },
169 { option => "tiled-backing-store", desc => "Toggle Tiled Backing Store support",
170 define => "ENABLE_TILED_BACKING_STORE", default => isQt(), value => \$tiledBackingStoreSupport },
172 { option => "video", desc => "Toggle Video support",
173 define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport },
175 { option => "web-sockets", desc => "Toggle Web Sockets support",
176 define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
178 { option => "web-timing", desc => "Toggle Web Timing support",
179 define => "ENABLE_WEB_TIMING", default => 0, value=> \$webTimingSupport },
181 { option => "wml", desc => "Toggle WML support",
182 define => "ENABLE_WML", default => 0, value => \$wmlSupport },
184 { option => "xhtmlmp", desc => "Toggle XHTML-MP support",
185 define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport },
187 { option => "wcss", desc => "Toggle WCSS support",
188 define => "ENABLE_WCSS", default => 0, value => \$wcssSupport },
190 { option => "workers", desc => "Toggle Web Workers support",
191 define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport },
193 { option => "xpath", desc => "Toggle XPath support",
194 define => "ENABLE_XPATH", default => 1, value => \$xpathSupport },
196 { option => "xslt", desc => "Toggle XSLT support",
197 define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
199 { option => "file-reader", desc => "Toggle FileReader support",
200 define => "ENABLE_FILE_READER", default => isAppleWebKit(), value => \$fileReaderSupport },
202 { option => "file-writer", desc => "Toggle FileWriter support",
203 define => "ENABLE_FILE_WRITER", default => 0, value => \$fileWriterSupport },
205 { option => "file-system", desc => "Toggle FileSystem support",
206 define => "ENABLE_FILE_SYSTEM", default => 0, value => \$fileSystemSupport },
209 # Update defaults from Qt's project file
211 my %qtDefaults = qtFeatureDefaults();
212 foreach (@features) {
213 $_->{default} = $qtDefaults{$_->{define}} || 0;
217 # Additional environment parameters
218 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
220 # Initialize values from defaults
222 if ($_ eq '--minimal') {
228 # Initialize values from defaults
229 foreach (@features) {
230 ${$_->{value}} = ($_->{default} && !$minimal) || 0;
233 $svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport
234 || $svgDOMObjCBindingsSupport || $svgFontsSupport
235 || $svgForeignObjectSupport || $svgUseSupport;
238 my $programName = basename($0);
240 Usage: $programName [options] [options to pass to build system]
241 --help Show this help message
242 --clean Cleanup the build directory
243 --debug Compile in debug mode
244 --cairo-win32 Build using Cairo (rather than CoreGraphics) on Windows
245 --chromium Build the Chromium port on Mac/Win/Linux
246 --gtk Build the GTK+ port
247 --qt Build the Qt port
248 --inspector-frontend Copy changes to the inspector front-end files to the build directory
250 --install-headers=<path> Set installation path for the headers (Qt only)
251 --install-libs=<path> Set installation path for the libraries (Qt only)
253 --prefix=<path> Set installation prefix to the given path (Gtk only)
254 --makeargs=<arguments> Optional Makefile flags
256 --minimal No optional features, unless explicitly enabled.
261 'help' => \$showHelp,
263 'install-headers=s' => \$installHeaders,
264 'install-libs=s' => \$installLibs,
265 'prefix=s' => \$prefixPath,
266 'makeargs=s' => \$makeArgs,
267 'minimal' => \$minimal,
270 # Build usage text and options list from features
271 foreach (@features) {
272 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
273 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
274 $options{"$_->{option}!"} = $_->{value};
277 GetOptions(%options);
284 checkRequiredSystemConfig();
287 my $productDir = productDir();
289 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
290 File::Find::find(\&unlinkZeroFiles, $productDir) if isQt();
292 sub unlinkZeroFiles ()
294 my $file = $File::Find::name;
297 print "0 byte sized file removed from build directory: $file\n";
301 # Check that all the project directories are there.
302 my @projects = ("JavaScriptCore", "WebCore", "WebKit");
304 my @otherDirs = ("WebKitLibraries");
305 for my $dir (@projects, @otherDirs) {
307 die "Error: No $dir directory found. Please do a fresh checkout.\n";
313 # enable autotool options accordingly
316 foreach (@features) {
317 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
320 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
321 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
322 } elsif (isAppleMacWebKit()) {
323 push @options, XcodeOptions();
327 my ($feature, $isEnabled, $defaultValue) = @_;
328 return "" if $defaultValue == $isEnabled;
329 return $feature . "=" . ($isEnabled ? $feature : " ");
332 foreach (@features) {
333 if ($_->{option} eq "coverage") {
334 push @options, XcodeCoverageSupportOptions() if $coverageSupport;
336 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
337 push @options, $option unless $option eq "";
341 # Apple builds JavaScriptGlue, and only on the Mac.
342 splice @projects, 1, 0, "JavaScriptGlue";
344 # WebKit2 is only supported in SnowLeopard and later at present.
345 push @projects, ("WebKit2", "WebKitTools/MiniBrowser") if osXVersion()->{"minor"} >= 6;
347 # Copy library and header from WebKitLibraries to a findable place in the product directory.
348 my @librariesToCopy = (
349 "libWebKitSystemInterfaceTiger.a",
350 "libWebKitSystemInterfaceLeopard.a",
351 "libWebKitSystemInterfaceSnowLeopard.a",
352 "libWebCoreSQLite3.a",
354 foreach my $libName (@librariesToCopy) {
355 my $srcLib = "WebKitLibraries/" . $libName;
356 my $lib = "$productDir/" . $libName;
357 if (!-e $lib || -M $lib > -M $srcLib) {
358 print "Updating $lib\n";
359 system "ditto", $srcLib, $lib;
360 system "ranlib", $lib;
364 # FIXME: This code should be abstracted to not be copy/paste.
365 my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h";
366 my $header = "$productDir/usr/local/include/WebKitSystemInterface.h";
367 if (!-e $header || -M $header > -M $srcHeader) {
368 print "Updating $header\n";
369 system "mkdir", "-p", "$productDir/usr/local/include";
370 system "ditto", $srcHeader, $header;
373 my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3";
374 my $headerDir = "$productDir/WebCoreSQLite3";
375 if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) {
376 print "Updating $headerDir\n";
377 system "ditto", $srcHeaderDir, $headerDir;
379 } elsif (isAppleWinWebKit()) {
380 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
381 # Will fail if WebKitSupportLibrary.zip is not in source root.
382 (system("perl WebKitTools/Scripts/update-webkit-support-libs") == 0) or die;
385 push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
386 push @options, "--install-libs=" . $installLibs if defined($installLibs);
387 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
389 foreach (@features) {
390 push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default};
394 push @options, "CONFIG+=minimal";
398 # Force re-link of existing libraries if different than expected
399 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
401 if (isInspectorFrontend()) {
402 exit exitStatus(copyInspectorFrontendFiles());
406 downloadWafIfNeeded();
407 push @projects, 'WebKitTools/DumpRenderTree';
408 push @projects, 'WebKitTools/wx/browser';
409 push @projects, 'WebKit/wx/bindings/python';
414 # Chromium doesn't build by project directories.
416 my $result = buildChromium($clean, @options);
417 exit exitStatus($result) if exitStatus($result);
420 # Build, and abort if the build fails.
421 for my $dir (@projects) {
425 # For Gtk and Qt the WebKit project builds all others
426 if ((isGtk() || isQt()) && $dir ne "WebKit") {
432 $result = buildGtkProject($dir, $clean, @options);
434 $result = buildQMakeQtProject($dir, $clean, @options);
435 } elsif (isAppleMacWebKit()) {
436 $dir = "MiniBrowser" if $dir eq "WebKitTools/MiniBrowser";
437 $result = buildXCodeProject($dir, $clean, @options, @ARGV);
438 } elsif (isAppleWinWebKit()) {
439 if ($dir eq "WebKit") {
440 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
444 if (defined($makeArgs)) {
445 @options = split(/ /, $makeArgs);
447 if ($dir eq "WebKit" && isWx()) {
451 $result = buildWafProject($dir, $clean, @options);
454 if (exitStatus($result)) {
455 if (isAppleWinWebKit()) {
456 print "\n\n===== BUILD FAILED ======\n\n";
457 my $scriptDir = relativeScriptsDir();
458 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
459 my $baseProductDir = baseProductDir();
460 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
462 exit exitStatus($result);
467 # Don't report the "WebKit is now built" message after a clean operation.
470 # Write out congratulations message.
475 sub formatBuildTime($)
477 my ($buildTime) = @_;
479 my $buildHours = int($buildTime / 3600);
480 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
481 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
484 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
486 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
491 my $launcherPath = launcherPath();
492 my $launcherName = launcherName();
493 my $endTime = time();
494 my $buildTime = formatBuildTime($endTime - $startTime);
497 print "===========================================================\n";
498 print " WebKit is now built ($buildTime). \n";
500 print " To run $launcherName with this newly-built code, use the\n";
501 print " \"$launcherPath\" script.\n";
503 print "===========================================================\n";