3 # Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 # Copyright (C) 2009 Google Inc. All rights reserved.
5 # Copyright (C) 2010 moiji-mobile.com All rights reserved.
6 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
18 # its contributors may be used to endorse or promote products derived
19 # from this software without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
22 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
25 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # Build script wrapper for the WebKit Open Source Project.
39 use Getopt::Long qw(:config pass_through);
40 use lib $FindBin::Bin;
42 use webkitperl::FeatureList qw(getFeatureOptionList);
45 sub cMakeArgsFromFeatures();
46 sub formatBuildTime($);
49 my $originalWorkingDirectory = getcwd();
61 my $onlyWebKitProject = 0;
63 my $coverageSupport = 0;
64 my $startTime = time();
66 my @features = getFeatureOptionList();
68 # Update defaults from Qt's project file
70 # Take a sneek peek at the arguments, since we will need the qmake binary early
71 # on to do profile parsing. We also need to know if we're showing the help-text.
73 if (/^--qmake=(.*)/) {
74 setQmakeBinaryPath($1);
75 } elsif (/^--help$/) {
82 %qtDefaults = qtFeatureDefaults();
86 $_->{default} = (%qtDefaults ? $qtDefaults{$_->{define}} || 0 : -1);
90 # Additional environment parameters
91 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
93 # Initialize values from defaults
95 if ($_ eq '--minimal') {
100 # Initialize values from defaults
101 foreach (@features) {
102 ${$_->{value}} = ($minimal ? 0 : $_->{default});
105 my $programName = basename($0);
107 Usage: $programName [options] [options to pass to build system]
108 --help Show this help message
109 --clean Cleanup the build directory
110 --debug Compile in debug mode
111 --gyp Use GYP-generated project files
112 --coverage Enable Code Coverage support (Mac only)
114 --blackberry Build the BlackBerry port on Mac/Linux
115 --chromium Build the Chromium port on Mac/Win/Linux
116 --chromium-android Build the Chromium port on Android
117 --efl Build the EFL port
118 --gtk Build the GTK+ port
119 --qt Build the Qt port
120 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
121 --wince Build the WinCE port
123 --inspector-frontend Copy changes to the inspector front-end files to the build directory
125 --install-headers=<path> Set installation path for the headers (Qt only)
126 --install-libs=<path> Set installation path for the libraries (Qt only)
128 --prefix=<path> Set installation prefix to the given path (Gtk/Efl/BlackBerry only)
129 --makeargs=<arguments> Optional Makefile flags
130 --qmakearg=<arguments> Optional qmake flags (Qt only, e.g. --qmakearg="CONFIG+=webkit2" to build WebKit2)
131 --cmakeargs=<arguments> Optional CMake flags (e.g. --cmakeargs="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
133 --minimal No optional features, unless explicitly enabled
135 --only-webkit Build only the WebKit project
136 --no-webkit2 Omit WebKit2 code from the build
141 'help' => \$showHelp,
144 'install-headers=s' => \$installHeaders,
145 'install-libs=s' => \$installLibs,
146 'prefix=s' => \$prefixPath,
147 'makeargs=s' => \$makeArgs,
148 'cmakeargs=s' => \$cmakeArgs,
149 'minimal' => \$minimal,
150 'only-webkit' => \$onlyWebKitProject,
151 'no-webkit2' => \$noWebKit2,
152 'coverage' => \$coverageSupport,
155 # Build usage text and options list from features
156 foreach (@features) {
157 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
158 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
159 $options{"$_->{option}!"} = $_->{value};
162 GetOptions(%options);
169 checkRequiredSystemConfig();
172 my $productDir = productDir();
174 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
175 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && -e $productDir);
177 sub unlinkZeroFiles()
179 my $file = $File::Find::name;
180 # Remove 0 byte sized files, except
181 # - directories (Because they are always 0 byte sized on Windows)
182 # - .d files used for dependency tracking
183 if (! -d $file && ! -s $file && $file !~ m/\.d$/) {
185 print "0 byte sized file removed from build directory: $file\n";
189 # Check that all the project directories are there.
190 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
192 # Build WTF as a separate static library on ports which support it.
193 splice @projects, 0, 0, "Source/WTF" if isAppleMacWebKit() or isAppleWinWebKit();
195 for my $dir (@projects) {
197 die "Error: No $dir directory found. Please do a fresh checkout.\n";
201 if (!isQt() && !-d "WebKitLibraries") {
202 die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
205 # Generate the generate project files from .gyp files
207 system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
212 # enable autotool options accordingly
215 foreach (@features) {
216 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
219 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
220 push @options, "--makeargs=" . $makeArgs if $makeArgs;
221 } elsif (isAppleMacWebKit()) {
222 push @options, XcodeOptions();
226 my ($feature, $isEnabled, $defaultValue) = @_;
227 return "" if $defaultValue == $isEnabled;
228 return $feature . "=" . ($isEnabled ? $feature : "");
231 foreach (@features) {
232 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
233 push @options, $option unless $option eq "";
236 # ANGLE must come before WebCore
237 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
239 # WebKit2 is only supported in SnowLeopard and later at present.
240 push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
242 # Build Tools needed for Apple ports
243 push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
245 # Copy library and header from WebKitLibraries to a findable place in the product directory.
246 (system("perl", "Tools/Scripts/copy-webkitlibraries-to-product-directory", $productDir) == 0) or die;
247 } elsif (isWinCairo()) {
248 (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
249 } elsif (isAppleWinWebKit()) {
250 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
251 # Will fail if WebKitSupportLibrary.zip is not in source root.
252 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
254 push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
255 push @options, "--install-libs=" . $installLibs if defined($installLibs);
256 push @options, "--makeargs=" . $makeArgs if $makeArgs;
257 push @options, "WEBKIT_CONFIG-=build_webkit2" if $noWebKit2;
259 if (checkForArgumentAndRemoveFromARGV("-2")) {
260 print "Note: WebKit2 is now built by default, you don't need to pass -2. Disable using --no-webkit2\n";
263 @options = (@ARGV, @options);
265 foreach (@features) {
266 if ($_->{define} && ${$_->{value}} != $_->{default}) {
267 my $define = lc($_->{define});
268 $define =~ s/^enable_//;
269 push @options, "WEBKIT_CONFIG" . (${$_->{value}} == 1 ? "+" : "-") . "=" . $define;
274 # If asked to build just the WebKit project, overwrite the projects
275 # list after all of the port specific tweaks have been made to
276 # build options, etc.
277 @projects = ("Source/WebKit") if $onlyWebKitProject;
279 if (isInspectorFrontend()) {
280 exit exitStatus(copyInspectorFrontendFiles());
286 $makeArgs .= " --port=wx";
288 downloadWafIfNeeded();
289 @options = split(/ /, $makeArgs);
291 $result = buildWafProject('.', $clean, @options);
292 exit exitStatus($result) if exitStatus($result);
296 # Currently chromium does not honour the features passed to build-webkit.
297 # Until this is solved, we issue a warning about that.
298 foreach (@features) {
299 if (${$_->{value}} ne $_->{default}) {
301 print "===========================================================\n";
302 print " Chromium does not honor the features passed to build-webkit.\n";
303 print " The preferred way is to set up your overrides in ~/.gyp/include.gypi.\n";
304 print " See https://trac.webkit.org/wiki/Chromium#Buildingwithfeaturedefines\n";
305 print " on how to do that.\n";
306 print "===========================================================\n";
312 # Chromium doesn't build by project directories.
314 push @options, "--makeargs=" . $makeArgs if $makeArgs;
315 $result = buildChromium($clean, @options);
316 exit exitStatus($result) if exitStatus($result);
320 # By default we build using all of the available CPUs.
321 $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
322 $cmakeArgs = "-DENABLE_WEBKIT2=OFF " . $cmakeArgs if $noWebKit2;
324 # We remove CMakeCache to avoid the bots to reuse cached flags when
325 # we enable new features. This forces a reconfiguration.
328 buildCMakeProjectOrExit($clean, "Efl", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
332 buildCMakeProjectOrExit($clean, "WinCE", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
335 if (isBlackBerry()) {
337 if ($ENV{"USE_ICECC"}) {
338 $numberOfJobs = 50; # 50 is the number we choose for internal development
340 $numberOfJobs = numberOfCPUs();
342 $makeArgs .= ($makeArgs ? " " : "") . "-j" . $numberOfJobs if $makeArgs !~ /-j\s*\d+/;
343 $prefixPath = $ENV{"STAGE_DIR"} unless $prefixPath;
344 buildCMakeProjectOrExit($clean, "BlackBerry", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
348 @projects = (); # An empty projects list will build the default projects
349 $result = buildQMakeProjects(\@projects, $clean, @options);
350 exit exitStatus($result) if exitStatus($result);
353 # Build, and abort if the build fails.
354 for my $dir (@projects) {
358 # For Gtk the WebKit project builds all others
359 if (isGtk() && $dir ne "Source/WebKit") {
364 my $project = basename($dir);
367 unshift(@options, "--disable-webkit2");
369 $result = buildGtkProject($project, $clean, @options);
370 } elsif (isAppleMacWebKit()) {
371 my @local_options = @options;
372 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $project ne "ANGLE";
373 my $useGYPProject = $useGYP && ($project =~ "WebCore|JavaScriptCore");
374 my $projectPath = $useGYPProject ? "gyp/$project" : $project;
375 $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
376 $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
377 } elsif (isAppleWinWebKit()) {
378 if ($project eq "WebKit") {
379 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
382 # Various build* calls above may change the CWD.
385 if (exitStatus($result)) {
386 my $scriptDir = relativeScriptsDir();
387 if (usingVisualStudioExpress()) {
388 # Visual Studio Express is so lame it can't stdout build failures.
389 # So we find its logs and dump them to the console ourselves.
390 system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
392 if (isAppleWinWebKit()) {
393 print "\n\n===== BUILD FAILED ======\n\n";
394 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
395 my $baseProductDir = baseProductDir();
396 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
398 exit exitStatus($result);
402 # Don't report the "WebKit is now built" message after a clean operation.
405 # Don't report congrats message if build was interrupted by the user.
406 exit if ($result & 127) == SIGINT;
408 # Explicitly chdir back to where exit will take us anyway, since the following "launcher"
409 # message is relative to that directory.
410 chdir $originalWorkingDirectory;
412 # Write out congratulations message.
417 sub cMakeArgsFromFeatures()
420 foreach (@features) {
421 my $featureName = $_->{define};
423 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
424 push @args, "-D$featureName=$featureEnabled";
430 sub formatBuildTime($)
432 my ($buildTime) = @_;
434 my $buildHours = int($buildTime / 3600);
435 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
436 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
439 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
441 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
446 my $launcherPath = launcherPath();
447 my $launcherName = launcherName();
448 my $endTime = time();
449 my $buildTime = formatBuildTime($endTime - $startTime);
452 print "====================================================================\n";
453 print " WebKit is now built ($buildTime). \n";
455 print " To run $launcherName with this newly-built code, use the\n";
456 print " \"$launcherPath\" script.\n";
458 print "====================================================================\n";