[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.24
[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 $v8 = 0;
58 my $installHeaders;
59 my $installLibs;
60 my $prefixPath;
61 my $makeArgs = "";
62 my $cmakeArgs;
63 my $onlyWebKitProject = 0;
64 my $noWebKit2 = 0;
65 my $coverageSupport = 0;
66 my $startTime = time();
67
68 my @features = getFeatureOptionList();
69
70 # Update defaults from Qt's project file
71 if (isQt()) {
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.
74     foreach (@ARGV) {
75         if (/^--qmake=(.*)/) {
76             setQmakeBinaryPath($1);
77         } elsif (/^--help$/) {
78             $showHelp = 1;
79         }
80     }
81
82     my %qtDefaults;
83     if ($showHelp) {
84         %qtDefaults = qtFeatureDefaults();
85     }
86
87     foreach (@features) {
88         $_->{default} = (%qtDefaults ? $qtDefaults{$_->{define}} || 0 : -1);
89     }
90 }
91
92 # Additional environment parameters
93 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
94
95 # Initialize values from defaults
96 foreach (@ARGV) {
97     if ($_ eq '--minimal') {
98         $minimal = 1;
99     } elsif ($_ eq '--v8') {
100         $v8 = 1;
101     }
102 }
103
104 # Initialize values from defaults
105 foreach (@features) {
106     ${$_->{value}} = ($minimal ? 0 : $_->{default});
107 }
108
109 my $programName = basename($0);
110 my $usage = <<EOF;
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)
117
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
126
127   --inspector-frontend              Copy changes to the inspector front-end files to the build directory
128
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)
132
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")
137
138   --minimal                         No optional features, unless explicitly enabled
139
140   --only-webkit                     Build only the WebKit project
141   --no-webkit2                      Omit WebKit2 code from the build
142
143 EOF
144
145 my %options = (
146     'help' => \$showHelp,
147     'clean' => \$clean,
148     'gyp' => \$useGYP,
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,
155     'v8' => \$v8,
156     'only-webkit' => \$onlyWebKitProject,
157     'no-webkit2' => \$noWebKit2,
158     'coverage' => \$coverageSupport,
159 );
160
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};
166 }
167
168 GetOptions(%options);
169
170 if ($showHelp) {
171    print STDERR $usage;
172    exit 1;
173 }
174
175 checkRequiredSystemConfig();
176 setConfiguration();
177
178 my $productDir = productDir();
179
180 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
181 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && -e $productDir);
182
183 sub unlinkZeroFiles()
184 {
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$/) {
188         unlink $file;
189         print "0 byte sized file removed from build directory: $file\n";
190     }
191 }
192
193 # Check that all the project directories are there.
194 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
195
196 # Build WTF as a separate static library on ports which support it.
197 splice @projects, 0, 0, "Source/WTF" if isAppleMacWebKit() or isAppleWinWebKit();
198
199 for my $dir (@projects) {
200     if (! -d $dir) {
201         die "Error: No $dir directory found. Please do a fresh checkout.\n";
202     }
203 }
204
205 if (!isQt() && !-d "WebKitLibraries") {
206     die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
207 }
208
209 # Generate the generate project files from .gyp files
210 if ($useGYP) {
211     system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
212 }
213
214 my @options = ();
215
216 # enable autotool options accordingly
217 if (isGtk()) {
218     @options = @ARGV;
219     foreach (@features) {
220         push @options, autotoolsFlag(${$_->{value}}, $_->{option});
221     }
222
223     push @options, "--prefix=" . $prefixPath if defined($prefixPath);
224     push @options, "--makeargs=" . $makeArgs if $makeArgs;
225 } elsif (isAppleMacWebKit()) {
226     checkForJavaSDK();
227     push @options, XcodeOptions();
228
229     sub option($$$)
230     {
231         my ($feature, $isEnabled, $defaultValue) = @_;
232         return "" if $defaultValue == $isEnabled;
233         return $feature . "=" . ($isEnabled ? $feature : "");
234     }
235
236     foreach (@features) {
237         my $option = option($_->{define}, ${$_->{value}}, $_->{default});
238         push @options, $option unless $option eq "";
239     }
240
241     # ANGLE must come before WebCore
242     splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
243
244     # WebKit2 is only supported in SnowLeopard and later at present.
245     push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
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     if ($v8) {
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";
276     }
277 }
278
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;
283
284 if (isInspectorFrontend()) {
285     exit exitStatus(copyInspectorFrontendFiles());
286 }
287
288 my $result = 0;
289
290 if (isWx()) {
291     $makeArgs .= " --port=wx";
292
293     downloadWafIfNeeded();
294     @options = split(/ /, $makeArgs);
295     @projects = ();
296     $result = buildWafProject('.', $clean, @options);
297     exit exitStatus($result) if exitStatus($result);
298 }
299
300 if (isChromium()) {
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}) {
305             print "\n";
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";
312             last;
313         }
314     }
315
316     @options = @ARGV;
317     # Chromium doesn't build by project directories.
318     @projects = ();
319     push @options, "--makeargs=" . $makeArgs if $makeArgs;
320     $result = buildChromium($clean, @options);
321     exit exitStatus($result) if exitStatus($result);
322 }
323
324 if (isEfl()) {
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);
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         $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
375     } elsif (isAppleWinWebKit()) {
376         if ($project eq "WebKit") {
377             $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
378         }
379     }
380     # Various build* calls above may change the CWD.
381     chdirWebKit();
382
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"));
389         }
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";
395         }
396         exit exitStatus($result);
397     }
398 }
399
400 # Don't report the "WebKit is now built" message after a clean operation.
401 exit if $clean;
402
403 # Don't report congrats message if build was interrupted by the user.
404 exit if ($result & 127) == SIGINT;
405
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;
409
410 # Write out congratulations message.
411 writeCongrats();
412
413 exit 0;
414
415 sub cMakeArgsFromFeatures()
416 {
417     my @args;
418     foreach (@features) {
419         my $featureName = $_->{define};
420         if ($featureName) {
421             my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
422             push @args, "-D$featureName=$featureEnabled";
423         }
424     }
425     return @args;
426 }
427
428 sub checkForJavaSDK()
429 {
430     my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
431     if (-e $jniHeader) {
432         return;
433     }
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";
440     exit 1;
441 }
442
443 sub formatBuildTime($)
444 {
445     my ($buildTime) = @_;
446
447     my $buildHours = int($buildTime / 3600);
448     my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
449     my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
450
451     if ($buildHours) {
452         return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
453     }
454     return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
455 }
456
457 sub writeCongrats()
458 {
459     my $launcherPath = launcherPath();
460     my $launcherName = launcherName();
461     my $endTime = time();
462     my $buildTime = formatBuildTime($endTime - $startTime);
463
464     print "\n";
465     print "===========================================================\n";
466     print " WebKit is now built ($buildTime). \n";
467     if (!isChromium()) {
468         print " To run $launcherName with this newly-built code, use the\n";
469         print " \"$launcherPath\" script.\n";
470     }
471     print "===========================================================\n";
472 }