[CherryPick] Input Method upversion
[framework/web/webkit-efl.git] / Tools / Scripts / build-webkit
1 #!/usr/bin/perl -w
2
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.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
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. 
20 #
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.
31
32 # Build script wrapper for the WebKit Open Source Project.
33
34 use strict;
35 use File::Basename;
36 use File::Find;
37 use File::Spec;
38 use FindBin;
39 use Getopt::Long qw(:config pass_through);
40 use lib $FindBin::Bin;
41 use webkitdirs;
42 use webkitperl::FeatureList qw(getFeatureOptionList);
43 use POSIX;
44
45 sub cMakeArgsFromFeatures();
46 sub checkForJavaSDK();
47 sub formatBuildTime($);
48 sub writeCongrats();
49
50 my $originalWorkingDirectory = getcwd();
51 chdirWebKit();
52
53 my $showHelp = 0;
54 my $clean = 0;
55 my $useGYP = 0;
56 my $minimal = 0;
57 my $installHeaders;
58 my $installLibs;
59 my $prefixPath;
60 my $makeArgs = "";
61 my $cmakeArgs;
62 my $onlyWebKitProject = 0;
63 my $noWebKit2 = 0;
64 my $coverageSupport = 0;
65 my $startTime = time();
66
67 my @features = getFeatureOptionList();
68
69 # Update defaults from Qt's project file
70 if (isQt()) {
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.
73     foreach (@ARGV) {
74         if (/^--qmake=(.*)/) {
75             setQmakeBinaryPath($1);
76         } elsif (/^--help$/) {
77             $showHelp = 1;
78         }
79     }
80
81     my %qtDefaults;
82     if ($showHelp) {
83         %qtDefaults = qtFeatureDefaults();
84     }
85
86     foreach (@features) {
87         $_->{default} = (%qtDefaults ? $qtDefaults{$_->{define}} || 0 : -1);
88     }
89 }
90
91 # Additional environment parameters
92 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
93
94 # Initialize values from defaults
95 foreach (@ARGV) {
96     if ($_ eq '--minimal') {
97         $minimal = 1;
98     }
99 }
100
101 # Initialize values from defaults
102 foreach (@features) {
103     ${$_->{value}} = ($minimal ? 0 : $_->{default});
104 }
105
106 my $programName = basename($0);
107 my $usage = <<EOF;
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)
114
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
123
124   --inspector-frontend              Copy changes to the inspector front-end files to the build directory
125
126   --install-headers=<path>          Set installation path for the headers (Qt only)
127   --install-libs=<path>             Set installation path for the libraries (Qt only)
128
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")
133
134   --minimal                         No optional features, unless explicitly enabled
135
136   --only-webkit                     Build only the WebKit project
137   --no-webkit2                      Omit WebKit2 code from the build
138
139 EOF
140
141 my %options = (
142     'help' => \$showHelp,
143     'clean' => \$clean,
144     'gyp' => \$useGYP,
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,
154 );
155
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};
161 }
162
163 GetOptions(%options);
164
165 if ($showHelp) {
166    print STDERR $usage;
167    exit 1;
168 }
169
170 checkRequiredSystemConfig();
171 setConfiguration();
172
173 my $productDir = productDir();
174
175 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
176 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && -e $productDir);
177
178 sub unlinkZeroFiles()
179 {
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$/) {
185         unlink $file;
186         print "0 byte sized file removed from build directory: $file\n";
187     }
188 }
189
190 # Check that all the project directories are there.
191 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
192
193 # Build WTF as a separate static library on ports which support it.
194 splice @projects, 0, 0, "Source/WTF" if isAppleMacWebKit() or isAppleWinWebKit();
195
196 for my $dir (@projects) {
197     if (! -d $dir) {
198         die "Error: No $dir directory found. Please do a fresh checkout.\n";
199     }
200 }
201
202 if (!isQt() && !-d "WebKitLibraries") {
203     die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
204 }
205
206 # Generate the generate project files from .gyp files
207 if ($useGYP) {
208     system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
209 }
210
211 my @options = ();
212
213 # enable autotool options accordingly
214 if (isGtk()) {
215     @options = @ARGV;
216     foreach (@features) {
217         push @options, autotoolsFlag(${$_->{value}}, $_->{option});
218     }
219
220     push @options, "--prefix=" . $prefixPath if defined($prefixPath);
221     push @options, "--makeargs=" . $makeArgs if $makeArgs;
222 } elsif (isAppleMacWebKit()) {
223     checkForJavaSDK();
224     push @options, XcodeOptions();
225
226     sub option($$$)
227     {
228         my ($feature, $isEnabled, $defaultValue) = @_;
229         return "" if $defaultValue == $isEnabled;
230         return $feature . "=" . ($isEnabled ? $feature : "");
231     }
232
233     foreach (@features) {
234         my $option = option($_->{define}, ${$_->{value}}, $_->{default});
235         push @options, $option unless $option eq "";
236     }
237
238     # ANGLE must come before WebCore
239     splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
240
241     # WebKit2 is only supported in SnowLeopard and later at present.
242     push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
243
244     # Build Tools needed for Apple ports
245     push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
246     
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;
255 } elsif (isQt()) {
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;
260
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";
263     }
264
265     @options = (@ARGV, @options);
266
267     foreach (@features) {
268         push @options, "DEFINES+=$_->{define}=${$_->{value}}" if $_->{define} && ${$_->{value}} != $_->{default};
269     }
270 }
271
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;
276
277 if (isInspectorFrontend()) {
278     exit exitStatus(copyInspectorFrontendFiles());
279 }
280
281 my $result = 0;
282
283 if (isWx()) {
284     $makeArgs .= " --port=wx";
285
286     downloadWafIfNeeded();
287     @options = split(/ /, $makeArgs);
288     @projects = ();
289     $result = buildWafProject('.', $clean, @options);
290     exit exitStatus($result) if exitStatus($result);
291 }
292
293 if (isChromium()) {
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}) {
298             print "\n";
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";
305             last;
306         }
307     }
308
309     @options = @ARGV;
310     # Chromium doesn't build by project directories.
311     @projects = ();
312     push @options, "--makeargs=" . $makeArgs if $makeArgs;
313     $result = buildChromium($clean, @options);
314     exit exitStatus($result) if exitStatus($result);
315 }
316
317 if (isEfl()) {
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;
322
323     # We remove CMakeCache to avoid the bots to reuse cached flags when
324     # we enable new features. This forces a reconfiguration.
325     removeCMakeCache();
326
327     buildCMakeProjectOrExit($clean, "Efl", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
328 }
329
330 if (isWinCE()) {
331     buildCMakeProjectOrExit($clean, "WinCE", $prefixPath, $makeArgs, (cmakeBasedPortArguments(), cMakeArgsFromFeatures()), $cmakeArgs);
332 }
333
334 if (isBlackBerry()) {
335     my $numberOfJobs;
336     if ($ENV{"USE_ICECC"}) {
337         $numberOfJobs = 50; # 50 is the number we choose for internal development
338     } else {
339         $numberOfJobs = numberOfCPUs();
340     }
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);
344 }
345
346 if (isQt()) {
347     @projects = (); # An empty projects list will build the default projects
348     $result = buildQMakeProjects(\@projects, $clean, @options);
349     exit exitStatus($result) if exitStatus($result);
350 }
351
352 # Build, and abort if the build fails.
353 for my $dir (@projects) {
354     chdir $dir or die;
355     $result = 0;
356
357     # For Gtk the WebKit project builds all others
358     if (isGtk() && $dir ne "Source/WebKit") {
359         chdirWebKit();
360         next;
361     }
362
363     my $project = basename($dir);
364     if (isGtk()) {
365         if ($noWebKit2) {
366             unshift(@options, "--disable-webkit2");
367         }
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);
379         }
380     }
381     # Various build* calls above may change the CWD.
382     chdirWebKit();
383
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"));
390         }
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";
396         }
397         exit exitStatus($result);
398     }
399 }
400
401 # Don't report the "WebKit is now built" message after a clean operation.
402 exit if $clean;
403
404 # Don't report congrats message if build was interrupted by the user.
405 exit if ($result & 127) == SIGINT;
406
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;
410
411 # Write out congratulations message.
412 writeCongrats();
413
414 exit 0;
415
416 sub cMakeArgsFromFeatures()
417 {
418     my @args;
419     foreach (@features) {
420         my $featureName = $_->{define};
421         if ($featureName) {
422             my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
423             push @args, "-D$featureName=$featureEnabled";
424         }
425     }
426     return @args;
427 }
428
429 sub checkForJavaSDK()
430 {
431     my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
432     if (-e $jniHeader) {
433         return;
434     }
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";
441     exit 1;
442 }
443
444 sub formatBuildTime($)
445 {
446     my ($buildTime) = @_;
447
448     my $buildHours = int($buildTime / 3600);
449     my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
450     my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
451
452     if ($buildHours) {
453         return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
454     }
455     return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
456 }
457
458 sub writeCongrats()
459 {
460     my $launcherPath = launcherPath();
461     my $launcherName = launcherName();
462     my $endTime = time();
463     my $buildTime = formatBuildTime($endTime - $startTime);
464
465     print "\n";
466     print "===========================================================\n";
467     print " WebKit is now built ($buildTime). \n";
468     if (!isChromium()) {
469         print " To run $launcherName with this newly-built code, use the\n";
470         print " \"$launcherPath\" script.\n";
471     }
472     print "===========================================================\n";
473 }