3 # Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 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.
7 # Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 # 3. Neither the name of Apple Inc. ("Apple") nor the names of
19 # its contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
22 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
23 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
26 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 # Build script wrapper for the WebKit Open Source Project.
40 use Getopt::Long qw(:config pass_through no_auto_abbrev);
41 use lib $FindBin::Bin;
43 use List::Util qw(first);
44 use webkitperl::FeatureList qw(getFeatureOptionList);
47 sub cMakeArgsFromFeatures();
50 my $originalWorkingDirectory = getcwd();
61 my $onlyWebKitProject = 0;
62 my $coverageSupport = 0;
63 my $shouldRunStaticAnalyzer = 0;
64 my $startTime = time();
66 my @features = getFeatureOptionList();
68 # Additional environment parameters
69 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
71 # Initialize values from defaults
73 if ($_ eq '--minimal') {
78 # Initialize values from defaults
80 ${$_->{value}} = ($minimal ? 0 : $_->{default});
83 my $programName = basename($0);
85 Usage: $programName [options] [options to pass to build system]
86 --help Show this help message
87 --clean Cleanup the build directory
88 --debug Compile with Debug configuration
89 --release Compile with Release configuration
90 --sdk=<sdk> Use a specific Xcode SDK (iOS and Mac only)
91 --device Use "iphoneos.internal" SDK if installed, else "iphoneos" SDK (iOS only)
92 --ios-simulator Use the current iphonesimulator SDK (iOS only)
93 --coverage Enable code coverage support (Mac only)
94 --analyze Enable static anaylsis (iOS and Mac only)
96 --efl Build the EFL port
97 --gtk Build the GTK+ port
98 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
100 --inspector-frontend Copy Web Inspector user interface resources to the build directory
102 --prefix=<path> Set installation prefix to the given path (Gtk/Efl only)
103 --makeargs=<arguments> Optional Makefile flags
104 --cmakeargs=<arguments> Optional CMake flags (e.g. --cmakeargs="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
106 --minimal No optional features, unless explicitly enabled
108 --only-webkit Build only the WebKit project
113 'help' => \$showHelp,
115 'install-headers=s' => \$installHeaders,
116 'install-libs=s' => \$installLibs,
117 'prefix=s' => \$prefixPath,
118 'makeargs=s' => \$makeArgs,
119 'cmakeargs=s' => \$cmakeArgs,
120 'minimal' => \$minimal,
121 'only-webkit' => \$onlyWebKitProject,
122 'coverage' => \$coverageSupport,
123 'analyze' => \$shouldRunStaticAnalyzer,
126 # Build usage text and options list from features
127 foreach (@features) {
128 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
129 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
130 $options{"$_->{option}!"} = $_->{value};
133 GetOptions(%options);
140 checkRequiredSystemConfig();
143 my $productDir = productDir();
145 # Check that all the project directories are there.
146 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
148 # Build WTF as a separate static library on ports which support it.
149 splice @projects, 0, 0, "Source/WTF" if isAppleMacWebKit() or isAppleWinWebKit() or isWinCairo();
151 splice @projects, 0, 0, "Source/bmalloc" if isAppleMacWebKit();
153 for my $dir (@projects) {
155 die "Error: No $dir directory found. Please do a fresh checkout.\n";
159 if (!isIOSWebKit() && !-d "WebKitLibraries") {
160 die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
165 if (isAppleMacWebKit()) {
166 push @options, XcodeOptions();
169 my ($feature, $isEnabled, $defaultValue) = @_;
170 return "" if $defaultValue == $isEnabled;
171 return $feature . "=" . ($isEnabled ? $feature : "");
174 foreach (@features) {
175 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
176 push @options, $option unless $option eq "";
179 # ANGLE must come before WebCore
180 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
182 push @projects, ("Source/WebKit2");
184 if (!isIOSWebKit()) {
185 push @projects, ("Tools/MiniBrowser");
187 # WebInspectorUI must come after JavaScriptCore and WebCore but before WebKit and WebKit2
188 my $webKitIndex = first { $projects[$_] eq "Source/WebKit" } 0..$#projects;
189 splice(@projects, $webKitIndex, 0, "Source/WebInspectorUI");
191 # Copy library and header from WebKitLibraries to a findable place in the product directory.
192 my @copyLibrariesArgs = ("perl", "Tools/Scripts/copy-webkitlibraries-to-product-directory", "--wksi", "--llvm", productDir());
193 print(join(" ", @copyLibrariesArgs) . "\n");
194 (system(@copyLibrariesArgs) == 0) or die;
196 my @copyLibrariesArgs = (
197 "perl", "Tools/Scripts/copy-webkitlibraries-to-product-directory",
198 "--sdk", xcodeSDK(), "--wksi", "--llvm", "--prefer-system-llvm",
199 "--llvm-subdirectory", "internal-llvm", productDir(),
200 "--llvm-prefix", "/usr/local"
202 print(join(" ", @copyLibrariesArgs) . "\n");
203 (system(@copyLibrariesArgs) == 0) or die;
206 # Build Tools needed for Apple ports
207 push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
209 } elsif (isWinCairo()) {
210 (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
211 } elsif (isAppleWinWebKit()) {
212 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
213 # Will fail if WebKitSupportLibrary.zip is not in source root.
214 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
217 # If asked to build just the WebKit project, overwrite the projects
218 # list after all of the port specific tweaks have been made to
219 # build options, etc.
220 @projects = ("Source/WebKit") if $onlyWebKitProject;
224 if (isInspectorFrontend()) {
225 die "The --inspector-frontend option is not supported for CMake-based builds." if isCMakeBuild();
226 @projects = ("Source/WebInspectorUI");
229 if (isCMakeBuild()) {
231 # By default we build using all of the available CPUs.
232 $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
233 my $maxCPULoad = maxCPULoad() if $makeArgs !~ /-l\s*\d+\.?\d*/;
234 $makeArgs .= " -l" . maxCPULoad() if defined $maxCPULoad;
236 # We remove CMakeCache to avoid the bots to reuse cached flags when
237 # we enable new features. This forces a reconfiguration.
238 my @featureArgs = cMakeArgsFromFeatures();
239 removeCMakeCache(@featureArgs);
241 buildCMakeProjectOrExit($clean, cmakeBasedPortName(), $prefixPath, $makeArgs, (cmakeBasedPortArguments(), @featureArgs), $cmakeArgs);
244 # Build, and abort if the build fails.
245 for my $dir (@projects) {
249 my $project = basename($dir);
250 my $baseProductDir = baseProductDir();
251 if (isAppleMacWebKit()) {
252 my @local_options = @options;
253 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport;
254 push @local_options, XcodeStaticAnalyzerOption() if $shouldRunStaticAnalyzer;
255 my $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
256 $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
257 } elsif (isAppleWinWebKit() || isWinCairo()) {
259 if (exitStatus(generateBuildSystemFromCMakeProject(isWinCairo() ? "WinCairo" : "AppleWin"))) {
260 die "Run \"C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/vcvarsall.bat\" before build-webkit when using ninja";
263 chdir "WebKitBuild/" . configuration();
264 $result = system("ninja");
266 $result = buildVisualStudioProject("WebKitBuild/" . configuration() . "/WebKit.sln", $clean);
269 # Various build* calls above may change the CWD.
272 if (exitStatus($result)) {
273 my $scriptDir = relativeScriptsDir();
274 if (isAppleWinWebKit() || isWinCairo()) {
275 print "\n\n===== BUILD FAILED ======\n\n";
276 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
277 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
279 exit exitStatus($result);
283 # Don't report the "WebKit is now built" message after a clean operation.
286 # Don't report congrats message if build was interrupted by the user.
287 exit if ($result & 127) == SIGINT;
289 # Explicitly chdir back to where exit will take us anyway, since the following "launcher"
290 # message is relative to that directory.
291 chdir $originalWorkingDirectory;
293 # Write out congratulations message.
298 sub cMakeArgsFromFeatures()
301 foreach (@features) {
302 my $featureName = $_->{define};
304 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
305 push @args, "-D$featureName=$featureEnabled";
313 my $launcherPath = launcherPath();
314 my $launcherName = launcherName();
315 my $endTime = time();
316 my $buildTime = formatBuildTime($endTime - $startTime);
319 print "====================================================================\n";
320 print " WebKit is now built ($buildTime). \n";
321 if ($launcherPath && $launcherName) {
322 print " To run $launcherName with this newly-built code, use the\n";
323 print " \"$launcherPath\" script.\n";
325 print "====================================================================\n";