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();
63 my $onlyWebKitProject = 0;
65 my $coverageSupport = 0;
66 my $startTime = time();
68 my @features = getFeatureOptionList();
70 # Update defaults from Qt's project file
72 # Take a sneek peek at the arguments, since we will need the qmake binary early
73 # on to do profile parsing. We also need to know if we're showing the help-text.
75 if (/^--qmake=(.*)/) {
76 setQmakeBinaryPath($1);
77 } elsif (/^--help$/) {
84 %qtDefaults = qtFeatureDefaults();
88 $_->{default} = (%qtDefaults ? $qtDefaults{$_->{define}} || 0 : -1);
92 # Additional environment parameters
93 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
95 # Initialize values from defaults
97 if ($_ eq '--minimal') {
99 } elsif ($_ eq '--v8') {
104 # Initialize values from defaults
105 foreach (@features) {
106 ${$_->{value}} = ($minimal ? 0 : $_->{default});
109 my $programName = basename($0);
111 Usage: $programName [options] [options to pass to build system]
112 --help Show this help message
113 --clean Cleanup the build directory
114 --debug Compile in debug mode
115 --gyp Use GYP-generated project files
116 --coverage Enable Code Coverage support (Mac only)
118 --blackberry Build the BlackBerry port on Mac/Linux
119 --chromium Build the Chromium port on Mac/Win/Linux
120 --chromium-android Build the Chromium port on Android
121 --efl Build the EFL port
122 --gtk Build the GTK+ port
123 --qt Build the Qt port
124 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
125 --wince Build the WinCE port
127 --inspector-frontend Copy changes to the inspector front-end files to the build directory
129 --install-headers=<path> Set installation path for the headers (Qt only)
130 --install-libs=<path> Set installation path for the libraries (Qt only)
131 --v8 Use V8 as JavaScript engine (Qt only)
133 --prefix=<path> Set installation prefix to the given path (Gtk/Efl/BlackBerry only)
134 --makeargs=<arguments> Optional Makefile flags
135 --qmakearg=<arguments> Optional qmake flags (Qt only, e.g. --qmakearg="CONFIG+=webkit2" to build WebKit2)
136 --cmakearg=<arguments> Optional CMake flags (e.g. --cmakearg="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
138 --minimal No optional features, unless explicitly enabled
140 --only-webkit Build only the WebKit project
141 --no-webkit2 Omit WebKit2 code from the build
146 'help' => \$showHelp,
149 'install-headers=s' => \$installHeaders,
150 'install-libs=s' => \$installLibs,
151 'prefix=s' => \$prefixPath,
152 'makeargs=s' => \$makeArgs,
153 'cmakeargs=s' => \$cmakeArgs,
154 'minimal' => \$minimal,
156 'only-webkit' => \$onlyWebKitProject,
157 'no-webkit2' => \$noWebKit2,
158 'coverage' => \$coverageSupport,
161 # Build usage text and options list from features
162 foreach (@features) {
163 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
164 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
165 $options{"$_->{option}!"} = $_->{value};
168 GetOptions(%options);
175 checkRequiredSystemConfig();
178 my $productDir = productDir();
180 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
181 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && -e $productDir);
183 sub unlinkZeroFiles()
185 my $file = $File::Find::name;
186 # Remove 0 size files, except .d files used for dependency tracking
187 if (! -s $file && $file !~ m/\.d$/) {
189 print "0 byte sized file removed from build directory: $file\n";
193 # Check that all the project directories are there.
194 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
196 # Build WTF as a separate static library on ports which support it.
197 splice @projects, 0, 0, "Source/WTF" if isAppleMacWebKit() or isAppleWinWebKit();
199 for my $dir (@projects) {
201 die "Error: No $dir directory found. Please do a fresh checkout.\n";
205 if (!isQt() && !-d "WebKitLibraries") {
206 die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
209 # Generate the generate project files from .gyp files
211 system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
216 # enable autotool options accordingly
219 foreach (@features) {
220 push @options, autotoolsFlag(${$_->{value}}, $_->{option});
223 push @options, "--prefix=" . $prefixPath if defined($prefixPath);
224 push @options, "--makeargs=" . $makeArgs if $makeArgs;
225 } elsif (isAppleMacWebKit()) {
227 push @options, XcodeOptions();
231 my ($feature, $isEnabled, $defaultValue) = @_;
232 return "" if $defaultValue == $isEnabled;
233 return $feature . "=" . ($isEnabled ? $feature : "");
236 foreach (@features) {
237 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
238 push @options, $option unless $option eq "";
241 # ANGLE must come before WebCore
242 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
244 # WebKit2 is only supported in SnowLeopard and later at present.
245 push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
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 print "Building WebKit2 with v8 is not supported currently. Disabling WebKit2.\n";
273 # FIXME: Deal with this in defaults_pre, once Qt has support for getting at the
274 # command line arguments at that stage.
275 push @options, "CONFIG+=v8 CONFIG+=no_webkit2";
279 # If asked to build just the WebKit project, overwrite the projects
280 # list after all of the port specific tweaks have been made to
281 # build options, etc.
282 @projects = ("Source/WebKit") if $onlyWebKitProject;
284 if (isInspectorFrontend()) {
285 exit exitStatus(copyInspectorFrontendFiles());
291 $makeArgs .= " --port=wx";
293 downloadWafIfNeeded();
294 @options = split(/ /, $makeArgs);
296 $result = buildWafProject('.', $clean, @options);
297 exit exitStatus($result) if exitStatus($result);
301 # Currently chromium does not honour the features passed to build-webkit.
302 # Until this is solved, we issue a warning about that.
303 foreach (@features) {
304 if (${$_->{value}} ne $_->{default}) {
306 print "===========================================================\n";
307 print " Chromium does not honor the features passed to build-webkit.\n";
308 print " The preferred way is to set up your overrides in ~/.gyp/include.gypi.\n";
309 print " See https://trac.webkit.org/wiki/Chromium#Buildingwithfeaturedefines\n";
310 print " on how to do that.\n";
311 print "===========================================================\n";
317 # Chromium doesn't build by project directories.
319 push @options, "--makeargs=" . $makeArgs if $makeArgs;
320 $result = buildChromium($clean, @options);
321 exit exitStatus($result) if exitStatus($result);
325 # By default we build using all of the available CPUs.
326 $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
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 $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
375 } elsif (isAppleWinWebKit()) {
376 if ($project eq "WebKit") {
377 $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
380 # Various build* calls above may change the CWD.
383 if (exitStatus($result)) {
384 my $scriptDir = relativeScriptsDir();
385 if (usingVisualStudioExpress()) {
386 # Visual Studio Express is so lame it can't stdout build failures.
387 # So we find its logs and dump them to the console ourselves.
388 system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
390 if (isAppleWinWebKit()) {
391 print "\n\n===== BUILD FAILED ======\n\n";
392 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
393 my $baseProductDir = baseProductDir();
394 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
396 exit exitStatus($result);
400 # Don't report the "WebKit is now built" message after a clean operation.
403 # Don't report congrats message if build was interrupted by the user.
404 exit if ($result & 127) == SIGINT;
406 # Explicitly chdir back to where exit will take us anyway, since the following "launcher"
407 # message is relative to that directory.
408 chdir $originalWorkingDirectory;
410 # Write out congratulations message.
415 sub cMakeArgsFromFeatures()
418 foreach (@features) {
419 my $featureName = $_->{define};
421 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
422 push @args, "-D$featureName=$featureEnabled";
428 sub checkForJavaSDK()
430 my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
434 print "\nCan't find required $jniHeader, build will fail.\n\n";
435 print "After installing \"Java for Mac OS X 10.6 Update 3\", the Java Developer Package is required to build WebKit.\n";
436 print "Please install the package from http://connect.apple.com (found under Downloads > Java).\n\n";
437 print "For more information, see:\n";
438 print "https://lists.webkit.org/pipermail/webkit-dev/2010-October/014867.html\n";
439 print "https://webkit.org/building/tools.html\n\n";
443 sub formatBuildTime($)
445 my ($buildTime) = @_;
447 my $buildHours = int($buildTime / 3600);
448 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
449 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
452 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
454 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
459 my $launcherPath = launcherPath();
460 my $launcherName = launcherName();
461 my $endTime = time();
462 my $buildTime = formatBuildTime($endTime - $startTime);
465 print "===========================================================\n";
466 print " WebKit is now built ($buildTime). \n";
468 print " To run $launcherName with this newly-built code, use the\n";
469 print " \"$launcherPath\" script.\n";
471 print "===========================================================\n";