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 checkForJavaSDK();
47 sub formatBuildTime($);
50 my $originalWorkingDirectory = getcwd();
62 my $onlyWebKitProject = 0;
64 my $coverageSupport = 0;
65 my $startTime = time();
67 my @features = getFeatureOptionList();
69 # Update defaults from Qt's project file
71 # Take a sneek peek at the arguments, since we will need the qmake binary early
72 # on to do profile parsing. We also need to know if we're showing the help-text.
74 if (/^--qmake=(.*)/) {
75 setQmakeBinaryPath($1);
76 } elsif (/^--help$/) {
83 %qtDefaults = qtFeatureDefaults();
87 $_->{default} = (%qtDefaults ? $qtDefaults{$_->{define}} || 0 : -1);
91 # Additional environment parameters
92 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
94 # Initialize values from defaults
96 if ($_ eq '--minimal') {
101 # Initialize values from defaults
102 foreach (@features) {
103 ${$_->{value}} = ($minimal ? 0 : $_->{default});
106 my $programName = basename($0);
108 Usage: $programName [options] [options to pass to build system]
109 --help Show this help message
110 --clean Cleanup the build directory
111 --debug Compile in debug mode
112 --gyp Use GYP-generated project files
113 --coverage Enable Code Coverage support (Mac only)
115 --blackberry Build the BlackBerry port on Mac/Linux
116 --chromium Build the Chromium port on Mac/Win/Linux
117 --chromium-android Build the Chromium port on Android
118 --efl Build the EFL port
119 --gtk Build the GTK+ port
120 --qt Build the Qt port
121 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
122 --wince Build the WinCE port
124 --inspector-frontend Copy changes to the inspector front-end files to the build directory
126 --install-headers=<path> Set installation path for the headers (Qt only)
127 --install-libs=<path> Set installation path for the libraries (Qt only)
129 --prefix=<path> Set installation prefix to the given path (Gtk/Efl/BlackBerry only)
130 --makeargs=<arguments> Optional Makefile flags
131 --qmakearg=<arguments> Optional qmake flags (Qt only, e.g. --qmakearg="CONFIG+=webkit2" to build WebKit2)
132 --cmakearg=<arguments> Optional CMake flags (e.g. --cmakearg="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
134 --minimal No optional features, unless explicitly enabled
136 --only-webkit Build only the WebKit project
137 --no-webkit2 Omit WebKit2 code from the build
142 'help' => \$showHelp,
145 'install-headers=s' => \$installHeaders,
146 'install-libs=s' => \$installLibs,
147 'prefix=s' => \$prefixPath,
148 'makeargs=s' => \$makeArgs,
149 'cmakeargs=s' => \$cmakeArgs,
150 'minimal' => \$minimal,
151 'only-webkit' => \$onlyWebKitProject,
152 'no-webkit2' => \$noWebKit2,
153 'coverage' => \$coverageSupport,
156 # Build usage text and options list from features
157 foreach (@features) {
158 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
159 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
160 $options{"$_->{option}!"} = $_->{value};
163 GetOptions(%options);
170 checkRequiredSystemConfig();
173 my $productDir = productDir();
175 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
176 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && -e $productDir);
178 sub unlinkZeroFiles()
180 my $file = $File::Find::name;
181 # Remove 0 byte sized files, except
182 # - directories (Because they are always 0 byte sized on Windows)
183 # - .d files used for dependency tracking
184 if (! -d $file && ! -s $file && $file !~ m/\.d$/) {
186 print "0 byte sized file removed from build directory: $file\n";
190 # Check that all the project directories are there.
191 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
193 # Build WTF as a separate static library on ports which support it.
194 splice @projects, 0, 0, "Source/WTF" if isAppleMacWebKit() or isAppleWinWebKit();
196 for my $dir (@projects) {
198 die "Error: No $dir directory found. Please do a fresh checkout.\n";
202 if (!isQt() && !-d "WebKitLibraries") {
203 die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
206 # Generate the generate project files from .gyp files
208 system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
213 # enable autotool options accordingly
216 foreach (@features) {
217 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
220 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
221 push @options, "--makeargs=" . $makeArgs if $makeArgs;
222 } elsif (isAppleMacWebKit()) {
224 push @options, XcodeOptions();
228 my ($feature, $isEnabled, $defaultValue) = @_;
229 return "" if $defaultValue == $isEnabled;
230 return $feature . "=" . ($isEnabled ? $feature : "");
233 foreach (@features) {
234 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
235 push @options, $option unless $option eq "";
238 # ANGLE must come before WebCore
239 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
241 # WebKit2 is only supported in SnowLeopard and later at present.
242 push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
244 # Build Tools needed for Apple ports
245 push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
247 # Copy library and header from WebKitLibraries to a findable place in the product directory.
248 (system("perl", "Tools/Scripts/copy-webkitlibraries-to-product-directory", $productDir) == 0) or die;
249 } elsif (isWinCairo()) {
250 (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
251 } elsif (isAppleWinWebKit()) {
252 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
253 # Will fail if WebKitSupportLibrary.zip is not in source root.
254 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
256 push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
257 push @options, "--install-libs=" . $installLibs if defined($installLibs);
258 push @options, "--makeargs=" . $makeArgs if $makeArgs;
259 push @options, "--qmakearg=CONFIG+=no_webkit2" if $noWebKit2;
261 if (checkForArgumentAndRemoveFromARGV("-2")) {
262 print "Note: WebKit2 is now built by default, you don't need to pass -2. Disable using --no-webkit2\n";
265 @options = (@ARGV, @options);
267 foreach (@features) {
268 push @options, "DEFINES+=$_->{define}=${$_->{value}}" if $_->{define} && ${$_->{value}} != $_->{default};
272 # If asked to build just the WebKit project, overwrite the projects
273 # list after all of the port specific tweaks have been made to
274 # build options, etc.
275 @projects = ("Source/WebKit") if $onlyWebKitProject;
277 if (isInspectorFrontend()) {
278 exit exitStatus(copyInspectorFrontendFiles());
284 $makeArgs .= " --port=wx";
286 downloadWafIfNeeded();
287 @options = split(/ /, $makeArgs);
289 $result = buildWafProject('.', $clean, @options);
290 exit exitStatus($result) if exitStatus($result);
294 # Currently chromium does not honour the features passed to build-webkit.
295 # Until this is solved, we issue a warning about that.
296 foreach (@features) {
297 if (${$_->{value}} ne $_->{default}) {
299 print "===========================================================\n";
300 print " Chromium does not honor the features passed to build-webkit.\n";
301 print " The preferred way is to set up your overrides in ~/.gyp/include.gypi.\n";
302 print " See https://trac.webkit.org/wiki/Chromium#Buildingwithfeaturedefines\n";
303 print " on how to do that.\n";
304 print "===========================================================\n";
310 # Chromium doesn't build by project directories.
312 push @options, "--makeargs=" . $makeArgs if $makeArgs;
313 $result = buildChromium($clean, @options);
314 exit exitStatus($result) if exitStatus($result);
318 # By default we build using all of the available CPUs.
319 $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
320 $cmakeArgs .= ($cmakeArgs ? " " : "") . "-DENABLE_WEBKIT=ON";
321 $cmakeArgs .= " -DENABLE_WEBKIT2=ON" if !$noWebKit2;
323 # We remove CMakeCache to avoid the bots to reuse cached flags when
324 # we enable new features. This forces a reconfiguration.
327 buildCMakeProjectOrExit($clean, "Efl", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
331 buildCMakeProjectOrExit($clean, "WinCE", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
334 if (isBlackBerry()) {
336 if ($ENV{"USE_ICECC"}) {
337 $numberOfJobs = 50; # 50 is the number we choose for internal development
339 $numberOfJobs = numberOfCPUs();
341 $makeArgs .= ($makeArgs ? " " : "") . "-j" . $numberOfJobs if $makeArgs !~ /-j\s*\d+/;
342 $prefixPath = $ENV{"STAGE_DIR"} unless $prefixPath;
343 buildCMakeProjectOrExit($clean, "BlackBerry", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
347 @projects = (); # An empty projects list will build the default projects
348 $result = buildQMakeProjects(\@projects, $clean, @options);
349 exit exitStatus($result) if exitStatus($result);
352 # Build, and abort if the build fails.
353 for my $dir (@projects) {
357 # For Gtk the WebKit project builds all others
358 if (isGtk() && $dir ne "Source/WebKit") {
363 my $project = basename($dir);
366 unshift(@options, "--disable-webkit2");
368 $result = buildGtkProject($project, $clean, @options);
369 } elsif (isAppleMacWebKit()) {
370 my @local_options = @options;
371 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $project ne "ANGLE";
372 my $useGYPProject = $useGYP && ($project =~ "WebCore|JavaScriptCore");
373 my $projectPath = $useGYPProject ? "gyp/$project" : $project;
374 $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
375 $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
376 } elsif (isAppleWinWebKit()) {
377 if ($project eq "WebKit") {
378 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
381 # Various build* calls above may change the CWD.
384 if (exitStatus($result)) {
385 my $scriptDir = relativeScriptsDir();
386 if (usingVisualStudioExpress()) {
387 # Visual Studio Express is so lame it can't stdout build failures.
388 # So we find its logs and dump them to the console ourselves.
389 system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
391 if (isAppleWinWebKit()) {
392 print "\n\n===== BUILD FAILED ======\n\n";
393 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
394 my $baseProductDir = baseProductDir();
395 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
397 exit exitStatus($result);
401 # Don't report the "WebKit is now built" message after a clean operation.
404 # Don't report congrats message if build was interrupted by the user.
405 exit if ($result & 127) == SIGINT;
407 # Explicitly chdir back to where exit will take us anyway, since the following "launcher"
408 # message is relative to that directory.
409 chdir $originalWorkingDirectory;
411 # Write out congratulations message.
416 sub cMakeArgsFromFeatures()
419 foreach (@features) {
420 my $featureName = $_->{define};
422 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
423 push @args, "-D$featureName=$featureEnabled";
429 sub checkForJavaSDK()
431 my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
435 print "\nCan't find required $jniHeader, build will fail.\n\n";
436 print "After installing \"Java for Mac OS X 10.6 Update 3\", the Java Developer Package is required to build WebKit.\n";
437 print "Please install the package from http://connect.apple.com (found under Downloads > Java).\n\n";
438 print "For more information, see:\n";
439 print "https://lists.webkit.org/pipermail/webkit-dev/2010-October/014867.html\n";
440 print "https://webkit.org/building/tools.html\n\n";
444 sub formatBuildTime($)
446 my ($buildTime) = @_;
448 my $buildHours = int($buildTime / 3600);
449 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
450 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
453 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
455 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
460 my $launcherPath = launcherPath();
461 my $launcherName = launcherName();
462 my $endTime = time();
463 my $buildTime = formatBuildTime($endTime - $startTime);
466 print "===========================================================\n";
467 print " WebKit is now built ($buildTime). \n";
469 print " To run $launcherName with this newly-built code, use the\n";
470 print " \"$launcherPath\" script.\n";
472 print "===========================================================\n";