1 # Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
13 # its contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Module to share code to get to WebKit directories.
35 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
38 @EXPORT = qw(&chdirWebKit &baseProductDir &productDir &XcodeOptions &XcodeOptionString &XcodeOptionStringNoConfig &passedConfiguration &setConfiguration &safariPath &checkFrameworks ¤tSVNRevision);
46 my @baseProductDirOption;
48 my $configurationProductDir;
50 my $currentSVNRevision;
52 # Variables for Win32 support
56 sub determineSourceDir
59 $sourceDir = $FindBin::Bin;
60 if ($sourceDir !~ s|/[^/]+/[^/]+$||) {
61 die "Could not find two levels above source directory using FindBin.\n";
65 # used for scripts which are stored in a non-standard location
71 sub determineBaseProductDir
73 return if defined $baseProductDir;
76 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> /dev/null |" or die;
77 $baseProductDir = <PRODUCT>;
79 if ($baseProductDir) {
80 chomp $baseProductDir;
83 $baseProductDir = $ENV{"WEBKITOUTPUTDIR"};
84 if (isCygwin() && $baseProductDir) {
85 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
87 $baseProductDir = $unixBuildPath;
91 if ($baseProductDir && isOSX()) {
92 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
93 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
94 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
95 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
96 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
97 @baseProductDirOption = ();
100 if (!defined($baseProductDir)) {
101 $baseProductDir = "$sourceDir/WebKitBuild";
102 @baseProductDirOption = ("SYMROOT=$baseProductDir") if (isOSX());
104 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
106 $ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
111 sub determineConfiguration
113 return if defined $configuration;
114 determineBaseProductDir();
115 if (open CONFIGURATION, "$baseProductDir/Configuration") {
116 $configuration = <CONFIGURATION>;
119 if ($configuration) {
120 chomp $configuration;
121 # compatibility for people who have old Configuration files
122 $configuration = "Release" if $configuration eq "Deployment";
123 $configuration = "Debug" if $configuration eq "Development";
125 $configuration = "Release";
129 sub determineConfigurationProductDir
131 return if defined $configurationProductDir;
132 determineBaseProductDir();
134 $configurationProductDir = "$baseProductDir/bin";
136 determineConfiguration();
137 $configurationProductDir = "$baseProductDir/$configuration";
141 sub determineCurrentSVNRevision
143 return if defined $currentSVNRevision;
144 determineSourceDir();
145 my $svnInfo = `svn info $sourceDir | grep Revision:`;
146 ($currentSVNRevision) = ($svnInfo =~ m/Revision: (\d+).*/g);
147 die "Unable to determine current SVN revision in $sourceDir" unless (defined $currentSVNRevision);
148 return $currentSVNRevision;
154 determineSourceDir();
155 chdir $sourceDir or die;
160 determineBaseProductDir();
161 return $baseProductDir;
166 determineConfigurationProductDir();
167 return $configurationProductDir;
172 determineConfiguration();
173 return $configuration;
176 sub currentSVNRevision
178 determineCurrentSVNRevision();
179 return $currentSVNRevision;
184 determineBaseProductDir();
185 determineConfiguration();
186 return (@baseProductDirOption, "-configuration", $configuration);
189 sub XcodeOptionString
191 return join " ", XcodeOptions();
194 sub XcodeOptionStringNoConfig
196 return join " ", @baseProductDirOption;
199 my $passedConfiguration;
200 my $searchedForPassedConfiguration;
201 sub determinePassedConfiguration
203 return if $searchedForPassedConfiguration;
204 $searchedForPassedConfiguration = 1;
205 for my $i (0 .. $#ARGV) {
207 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
208 splice(@ARGV, $i, 1);
209 $passedConfiguration = "Debug";
212 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
213 splice(@ARGV, $i, 1);
214 $passedConfiguration = "Release";
218 $passedConfiguration = undef;
221 sub passedConfiguration
223 determinePassedConfiguration();
224 return $passedConfiguration;
229 determinePassedConfiguration();
230 $configuration = $passedConfiguration if $passedConfiguration;
236 # Use WEBKIT_SAFARI environment variable if present.
237 my $safariBundle = $ENV{WEBKIT_SAFARI};
238 if (!$safariBundle) {
239 determineConfigurationProductDir();
240 # Use Safari.app in product directory if present (good for Safari development team).
241 if (-d "$configurationProductDir/Safari.app") {
242 $safariBundle = "$configurationProductDir/Safari.app";
244 # Otherwise use Safari.app in Applications directory.
245 $safariBundle = "/Applications/Safari.app";
248 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
249 die "Can't find executable at $safariPath.\n" unless -x $safariPath;
253 sub builtDylibPathForName
255 my $framework = shift;
256 determineConfigurationProductDir();
258 return "$configurationProductDir/$framework.framework/Versions/A/$framework";
261 if ($framework eq "JavaScriptCore") {
262 return "$baseProductDir/lib/$framework.lib";
264 return "$baseProductDir/$framework.intermediate/$configuration/$framework.intermediate/$framework.lib";
268 return "$configurationProductDir/$framework";
271 die "Unsupported platform, can't determine built library locations.";
274 # Check to see that all the frameworks are built.
277 my @frameworks = ("JavaScriptCore", "WebCore");
278 push(@frameworks, "WebKit") if isOSX();
279 for my $framework (@frameworks) {
280 my $path = builtDylibPathForName($framework);
281 die "Can't find built framework at \"$path\".\n" unless -x $path;
287 return 0 if isCygwin();
291 if ((isQt()) and ($path =~ /WebCore/)) {
292 $path .= "/../lib/libWebCore-unity.so";
295 open NM, "-|", "nm", $path or die;
296 my $hasSVGSupport = 0;
298 $hasSVGSupport = 1 if /SVGElement/;
301 return $hasSVGSupport;
304 sub removeLibraryDependingOnSVG
306 my $frameworkName = shift;
307 my $shouldHaveSVG = shift;
309 my $path = builtDylibPathForName($frameworkName);
310 return unless -x $path;
312 my $hasSVG = hasSVGSupport($path);
313 system "rm -f $path" if ($shouldHaveSVG xor $hasSVG);
316 sub checkWebCoreSVGSupport
318 my $required = shift;
319 my $framework = "WebCore";
320 my $path = builtDylibPathForName($framework);
321 my $hasSVG = hasSVGSupport($path);
322 if ($required && !$hasSVG) {
323 die "$framework at \"$path\" does not include SVG Support, please run build-webkit --svg\n";
330 return ($^O eq "linux") and defined($ENV{'QTDIR'})
335 return ($^O eq "cygwin");
340 return ($^O eq "darwin");
343 sub checkRequiredSystemConfig
346 chomp(my $productVersion = `sw_vers -productVersion`);
347 if ($productVersion lt "10.4") {
348 print "*************************************************************\n";
349 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
350 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
351 print "*************************************************************\n";
353 my $xcodeVersion = `xcodebuild -version`;
354 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 747) {
355 print "*************************************************************\n";
356 print "Xcode Version 2.3 or later is required to build WebKit.\n";
357 print "You have an earlier version of Xcode, thus the build will\n";
358 print "most likely fail. The latest Xcode is available from the web:\n";
359 print "http://developer.apple.com/tools/xcode\n";
360 print "*************************************************************\n";
363 # Win32 and other platforms may want to check for minimum config
368 return if !isCygwin();
369 return if $devenvPath;
371 my $programFilesPath = `cygpath "$ENV{'PROGRAMFILES'}"`;
372 chomp $programFilesPath;
373 $devenvPath = "$programFilesPath/Microsoft Visual Studio 8/Common7/IDE/devenv.com";
374 $windowsTmpPath = `cygpath -w /tmp`;
375 chomp $windowsTmpPath;
376 print "Building results into: ", baseProductDir(), "\n";
377 print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
380 sub buildVisualStudioProject($)
385 chdir "$project.vcproj" or die "Failed to cd into $project.vcproj\n";
386 my $config = configuration();
388 print "$devenvPath $project.sln /build $config";
389 my $result = system $devenvPath, "$project.sln", "/build", $config;
394 sub buildCMakeProject($$)
396 my ($project, $colorize) = @_;
398 if ($project ne "WebKit") {
399 die "Qt/Linux builds JavaScriptCore/WebCore/WebKitQt in one shot! Only call it for 'WebKit'.\n";
402 my $config = configuration();
403 my $prefix = $ENV{"WebKitInstallationPrefix"};
405 my @buildArgs = ("-DCMAKE_BUILD_TYPE=$config");
406 push @buildArgs, "-DCMAKE_INSTALL_PREFIX=" . $prefix if(defined($prefix));
407 push @buildArgs, "-DWEBKIT_DO_NOT_USE_COLORFUL_OUTPUT=" . ($colorize ? "OFF" : "ON");
408 push @buildArgs, "../../";
410 print "Calling 'cmake @buildArgs' in " . baseProductDir() . "/$config ...\n\n";
411 print "Installation directory: $prefix\n" if(defined($prefix));
413 system "mkdir -p " . baseProductDir() . "/$config";
414 chdir baseProductDir() . "/$config" or die "Failed to cd into " . baseProductDir() . "/$config \n";
416 my $result = system "cmake", @buildArgs;
418 die "Failed to setup build environment using cmake!\n";
421 $result = system "make";