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($);
47 my $originalWorkingDirectory = getcwd();
58 my $startTime = time();
62 $threeDRenderingSupport,
63 $accelerated2dCanvasSupport,
65 $channelMessagingSupport,
66 $clientBasedGeolocationSupport,
71 $deviceOrientationSupport,
72 $directoryUploadSupport,
77 $fullscreenAPISupport,
81 $indexedDatabaseSupport,
83 $javaScriptDebuggerSupport,
87 $notificationsSupport,
88 $offlineWebApplicationSupport,
90 $sharedWorkersSupport,
94 $svgDOMObjCBindingsSupport,
96 $svgForeignObjectSupport,
99 $tiledBackingStoreSupport,
103 $webInspectorSupport,
114 { option => "3d-canvas", desc => "Toggle 3D canvas support",
115 define => "ENABLE_3D_CANVAS", default => (isAppleMacWebKit() && !isTiger() && !isLeopard()), value => \$threeDCanvasSupport },
117 { option => "3d-rendering", desc => "Toggle 3D rendering support",
118 define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDRenderingSupport },
120 { option => "accelerated-2d-canvas", desc => "Toggle accelerated 2D canvas support",
121 define => "ENABLE_ACCELERATED_2D_CANVAS", default => 0, value => \$accelerated2dCanvasSupport },
123 { option => "blob", desc => "Toggle Blob support",
124 define => "ENABLE_BLOB", default => (isAppleMacWebKit()), value => \$blobSupport },
126 { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
127 define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
129 { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
130 define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport },
132 { option => "coverage", desc => "Toggle code coverage support",
133 define => "", default => 0, value => \$coverageSupport },
135 { option => "database", desc => "Toggle Database Support",
136 define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport },
138 { option => "datagrid", desc => "Toggle Datagrid Support",
139 define => "ENABLE_DATAGRID", default => 0, value => \$datagridSupport },
141 { option => "datalist", desc => "Toggle HTML5 datalist support",
142 define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
144 { option => "device-orientation", desc => "Toggle DeviceOrientation support",
145 define => "ENABLE_DEVICE_ORIENTATION", default => 0, value => \$deviceOrientationSupport },
147 { option => "directory-upload", desc => "Toogle Directory upload support",
148 define => "ENABLE_DIRECTORY_UPLOAD", default => 0, value => \$directoryUploadSupport },
150 { option => "dom-storage", desc => "Toggle DOM Storage Support",
151 define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport },
153 { option => "eventsource", desc => "Toggle server-sent events support",
154 define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport },
156 { option => "file-system", desc => "Toggle FileSystem support",
157 define => "ENABLE_FILE_SYSTEM", default => 0, value => \$fileSystemSupport },
159 { option => "filters", desc => "Toggle Filters support",
160 define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt() || isEfl()), value => \$filtersSupport },
162 { option => "fullscreen-api", desc => "Toggle Fullscreen API support",
163 define => "ENABLE_FULLSCREEN_API", default => isAppleMacWebKit(), value => \$fullscreenAPISupport },
165 { option => "geolocation", desc => "Toggle Geolocation support",
166 define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport },
168 { option => "icon-database", desc => "Toggle Icon database support",
169 define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
171 { option => "image-resizer", desc => "Toggle Image Resizer API support",
172 define => "ENABLE_IMAGE_RESIZER", default => 0, value => \$imageResizerSupport },
174 { option => "indexed-database", desc => "Toggle Indexed Database API support",
175 define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
177 { option => "input-speech", desc => "Speech Input API support",
178 define => "ENABLE_INPUT_SPEECH", default => 0, value => \$inputSpeechSupport },
180 { option => "inspector", desc => "Toggle Web Inspector support",
181 define => "ENABLE_INSPECTOR", default => 1, value => \$webInspectorSupport },
183 { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
184 define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
186 { option => "link-prefetch", desc => "Toggle pre fetching support",
187 define => "ENABLE_LINK_PREFETCH", default => 0, value => \$linkPrefetchSupport },
189 { option => "mathml", desc => "Toggle MathML support",
190 define => "ENABLE_MATHML", default => 1, value => \$mathmlSupport },
192 { option => "meter-tag", desc => "Meter Tag support",
193 define => "ENABLE_METER_TAG", default => !isGtk() && !isAppleWinWebKit(), value => \$meterTagSupport },
195 { option => "notifications", desc => "Toggle Desktop Notifications Support",
196 define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
198 { option => "offline-web-applications", desc => "Toggle Offline Web Application Support",
199 define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport },
201 { option => "progress-tag", desc => "Progress Tag support",
202 define => "ENABLE_PROGRESS_TAG", default => 1, value => \$progressTagSupport },
204 { option => "system-malloc", desc => "Toggle system allocator instead of TCmalloc",
205 define => "USE_SYSTEM_MALLOC", default => 0, value => \$systemMallocSupport },
207 { option => "shared-workers", desc => "Toggle SharedWorkers support",
208 define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport },
210 { option => "svg", desc => "Toggle SVG support",
211 define => "ENABLE_SVG", default => 1, value => \$svgSupport },
213 { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)",
214 define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport },
216 { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)",
217 define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport },
219 { option => "svg-dom-objc-bindings", desc => "Toggle SVG DOM Objective-C bindings support (implies SVG support)",
220 define => "ENABLE_SVG_DOM_OBJC_BINDINGS", default => isAppleMacWebKit(), value => \$svgDOMObjCBindingsSupport },
222 { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
223 define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
225 { option => "svg-foreign-object", desc => "Toggle SVG foreign object support (implies SVG support)",
226 define => "ENABLE_SVG_FOREIGN_OBJECT", default => 1, value => \$svgForeignObjectSupport },
228 { option => "svg-use", desc => "Toggle SVG use element support (implies SVG support)",
229 define => "ENABLE_SVG_USE", default => 1, value => \$svgUseSupport },
231 { option => "tiled-backing-store", desc => "Toggle Tiled Backing Store support",
232 define => "ENABLE_TILED_BACKING_STORE", default => isQt(), value => \$tiledBackingStoreSupport },
234 { option => "video", desc => "Toggle Video support",
235 define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport },
237 { option => "wcss", desc => "Toggle WCSS support",
238 define => "ENABLE_WCSS", default => 0, value => \$wcssSupport },
240 { option => "web-audio", desc => "Toggle Web Audio support",
241 define => "ENABLE_WEB_AUDIO", default => 0, value=> \$webAudioSupport },
243 { option => "web-sockets", desc => "Toggle Web Sockets support",
244 define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
246 { option => "web-timing", desc => "Toggle Web Timing support",
247 define => "ENABLE_WEB_TIMING", default => 0, value=> \$webTimingSupport },
249 { option => "wml", desc => "Toggle WML support",
250 define => "ENABLE_WML", default => 0, value => \$wmlSupport },
252 { option => "workers", desc => "Toggle Web Workers support",
253 define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport },
255 { option => "xhtmlmp", desc => "Toggle XHTML-MP support",
256 define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport },
258 { option => "xpath", desc => "Toggle XPath support",
259 define => "ENABLE_XPATH", default => 1, value => \$xpathSupport },
261 { option => "xslt", desc => "Toggle XSLT support",
262 define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
265 # Update defaults from Qt's project file
267 my %qtDefaults = qtFeatureDefaults();
268 foreach (@features) {
269 $_->{default} = $qtDefaults{$_->{define}} || 0;
273 # Additional environment parameters
274 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
276 # Initialize values from defaults
278 if ($_ eq '--minimal') {
280 } elsif ($_ eq '--v8') {
285 # Initialize values from defaults
286 foreach (@features) {
287 ${$_->{value}} = ($_->{default} && !$minimal) || 0;
290 $svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport
291 || $svgDOMObjCBindingsSupport || $svgFontsSupport
292 || $svgForeignObjectSupport || $svgUseSupport;
295 my $programName = basename($0);
297 Usage: $programName [options] [options to pass to build system]
298 --help Show this help message
299 --clean Cleanup the build directory
300 --debug Compile in debug mode
301 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
302 --chromium Build the Chromium port on Mac/Win/Linux
303 --gtk Build the GTK+ port
304 --qt Build the Qt port
305 --efl Build the EFL port
306 --inspector-frontend Copy changes to the inspector front-end files to the build directory
308 --install-headers=<path> Set installation path for the headers (Qt only)
309 --install-libs=<path> Set installation path for the libraries (Qt only)
310 --v8 Use V8 as JavaScript engine (Qt only)
312 --prefix=<path> Set installation prefix to the given path (Gtk/Efl only)
313 --makeargs=<arguments> Optional Makefile flags
315 --minimal No optional features, unless explicitly enabled.
320 'help' => \$showHelp,
322 'install-headers=s' => \$installHeaders,
323 'install-libs=s' => \$installLibs,
324 'prefix=s' => \$prefixPath,
325 'makeargs=s' => \$makeArgs,
326 'minimal' => \$minimal,
330 # Build usage text and options list from features
331 foreach (@features) {
332 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
333 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
334 $options{"$_->{option}!"} = $_->{value};
337 GetOptions(%options);
344 checkRequiredSystemConfig();
347 my $productDir = productDir();
349 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
350 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && -e $productDir);
352 sub unlinkZeroFiles ()
354 my $file = $File::Find::name;
357 print "0 byte sized file removed from build directory: $file\n";
361 # Check that all the project directories are there.
362 my @projects = ("JavaScriptCore", "WebCore", "WebKit");
364 my @otherDirs = ("WebKitLibraries");
365 for my $dir (@projects, @otherDirs) {
367 die "Error: No $dir directory found. Please do a fresh checkout.\n";
373 # enable autotool options accordingly
376 foreach (@features) {
377 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
380 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
381 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
382 } elsif (isAppleMacWebKit()) {
383 push @options, XcodeOptions();
387 my ($feature, $isEnabled, $defaultValue) = @_;
388 return "" if $defaultValue == $isEnabled;
389 return $feature . "=" . ($isEnabled ? $feature : " ");
392 foreach (@features) {
393 if ($_->{option} ne "coverage") {
394 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
395 push @options, $option unless $option eq "";
399 # Apple builds JavaScriptGlue, and only on the Mac.
400 splice @projects, 1, 0, "JavaScriptGlue";
402 # ANGLE must come before WebCore
403 splice @projects, 0, 0, "ANGLE";
405 # WebKit2 is only supported in SnowLeopard and later at present.
406 push @projects, ("WebKit2", "WebKitTools/MiniBrowser") if osXVersion()->{"minor"} >= 6;
408 # Copy library and header from WebKitLibraries to a findable place in the product directory.
409 my @librariesToCopy = (
410 "libWebKitSystemInterfaceTiger.a",
411 "libWebKitSystemInterfaceLeopard.a",
412 "libWebKitSystemInterfaceSnowLeopard.a",
413 "libWebCoreSQLite3.a",
415 foreach my $libName (@librariesToCopy) {
416 my $srcLib = "WebKitLibraries/" . $libName;
417 my $lib = "$productDir/" . $libName;
418 if (!-e $lib || -M $lib > -M $srcLib) {
419 print "Updating $lib\n";
420 system "ditto", $srcLib, $lib;
421 system "ranlib", $lib;
425 # FIXME: This code should be abstracted to not be copy/paste.
426 my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h";
427 my $header = "$productDir/usr/local/include/WebKitSystemInterface.h";
428 if (!-e $header || -M $header > -M $srcHeader) {
429 print "Updating $header\n";
430 system "mkdir", "-p", "$productDir/usr/local/include";
431 system "ditto", $srcHeader, $header;
434 my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3";
435 my $headerDir = "$productDir/WebCoreSQLite3";
436 if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) {
437 print "Updating $headerDir\n";
438 system "ditto", $srcHeaderDir, $headerDir;
440 } elsif (isAppleWinWebKit()) {
441 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
442 # Will fail if WebKitSupportLibrary.zip is not in source root.
443 (system("perl WebKitTools/Scripts/update-webkit-support-libs") == 0) or die;
446 push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
447 push @options, "--install-libs=" . $installLibs if defined($installLibs);
448 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
450 foreach (@features) {
451 push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default};
455 push @options, "CONFIG+=minimal";
459 push @options, "CONFIG+=v8";
463 # Force re-link of existing libraries if different than expected
464 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
466 if (isInspectorFrontend()) {
467 exit exitStatus(copyInspectorFrontendFiles());
471 downloadWafIfNeeded();
473 if (defined($makeArgs)) {
474 @options = split(/ /, $makeArgs);
477 my $result = buildWafProject('.', $clean, @options);
478 exit exitStatus($result) if exitStatus($result);
483 # Chromium doesn't build by project directories.
485 my $result = buildChromium($clean, @options);
486 exit exitStatus($result) if exitStatus($result);
492 foreach (@features) {
493 my $featureName = $_->{define};
495 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
496 push @options, "-D$featureName=$featureEnabled";
499 push @options, "--makeargs=" . $makeArgs if defined($makeArgs);
500 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
501 my $result = buildCMakeEflProject($clean, @options);
502 exit exitStatus($result) if exitStatus($result);
505 # Build, and abort if the build fails.
506 for my $dir (@projects) {
510 # For Gtk and Qt the WebKit project builds all others
511 if ((isGtk() || isQt()) && $dir ne "WebKit") {
517 $result = buildGtkProject($dir, $clean, @options);
519 $result = buildQMakeQtProject($dir, $clean, @options);
520 } elsif (isAppleMacWebKit()) {
521 $dir = "MiniBrowser" if $dir eq "WebKitTools/MiniBrowser";
522 my @local_options = @options;
523 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $dir ne "ANGLE";
524 $result = buildXCodeProject($dir, $clean, @local_options, @ARGV);
525 } elsif (isAppleWinWebKit()) {
526 if ($dir eq "WebKit") {
527 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
530 # Various build* calls above may change the CWD.
533 if (exitStatus($result)) {
534 my $scriptDir = relativeScriptsDir();
535 if (usingVisualStudioExpress()) {
536 # Visual Studio Express is so lame it can't stdout build failures.
537 # So we find its logs and dump them to the console ourselves.
538 system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
540 if (isAppleWinWebKit()) {
541 print "\n\n===== BUILD FAILED ======\n\n";
542 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
543 my $baseProductDir = baseProductDir();
544 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
546 exit exitStatus($result);
550 # Don't report the "WebKit is now built" message after a clean operation.
553 # Write out congratulations message.
558 sub formatBuildTime($)
560 my ($buildTime) = @_;
562 my $buildHours = int($buildTime / 3600);
563 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
564 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
567 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
569 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
574 my $launcherPath = launcherPath();
575 my $launcherName = launcherName();
576 my $endTime = time();
577 my $buildTime = formatBuildTime($endTime - $startTime);
580 print "===========================================================\n";
581 print " WebKit is now built ($buildTime). \n";
583 print " To run $launcherName with this newly-built code, use the\n";
584 print " \"$launcherPath\" script.\n";
586 print "===========================================================\n";