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;
53 # Variables for Win32 support
57 sub determineSourceDir
60 $sourceDir = $FindBin::Bin;
61 if ($sourceDir !~ s|/[^/]+/[^/]+$||) {
62 die "Could not find two levels above source directory using FindBin.\n";
66 # used for scripts which are stored in a non-standard location
72 sub determineBaseProductDir
74 return if defined $baseProductDir;
77 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> /dev/null |" or die;
78 $baseProductDir = <PRODUCT>;
80 if ($baseProductDir) {
81 chomp $baseProductDir;
84 $baseProductDir = $ENV{"WebKitOutputDir"};
85 if (isCygwin() && $baseProductDir) {
86 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
88 $baseProductDir = $unixBuildPath;
92 if ($baseProductDir && isOSX()) {
93 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
94 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
95 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
96 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
97 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
98 @baseProductDirOption = ();
101 if (!defined($baseProductDir)) {
102 $baseProductDir = "$sourceDir/WebKitBuild";
103 @baseProductDirOption = ("SYMROOT=$baseProductDir") if (isOSX());
105 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
107 $ENV{"WebKitOutputDir"} = $dosBuildPath;
112 sub determineConfiguration
114 return if defined $configuration;
115 determineBaseProductDir();
116 if (open CONFIGURATION, "$baseProductDir/Configuration") {
117 $configuration = <CONFIGURATION>;
120 if ($configuration) {
121 chomp $configuration;
122 # compatibility for people who have old Configuration files
123 $configuration = "Release" if $configuration eq "Deployment";
124 $configuration = "Debug" if $configuration eq "Development";
126 $configuration = "Release";
130 sub determineConfigurationProductDir
132 return if defined $configurationProductDir;
133 determineBaseProductDir();
134 determineConfiguration();
135 $configurationProductDir = "$baseProductDir/$configuration";
138 sub determineCurrentSVNRevision
140 return if defined $currentSVNRevision;
141 determineSourceDir();
142 my $svnInfo = `svn info $sourceDir | grep Revision:`;
143 ($currentSVNRevision) = ($svnInfo =~ m/Revision: (\d+).*/g);
144 die "Unable to determine current SVN revision in $sourceDir" unless (defined $currentSVNRevision);
145 return $currentSVNRevision;
151 determineSourceDir();
152 chdir $sourceDir or die;
157 determineBaseProductDir();
158 return $baseProductDir;
163 determineConfigurationProductDir();
164 return $configurationProductDir;
169 determineConfiguration();
170 return $configuration;
173 sub currentSVNRevision
175 determineCurrentSVNRevision();
176 return $currentSVNRevision;
181 determineBaseProductDir();
182 determineConfiguration();
183 return (@baseProductDirOption, "-configuration", $configuration);
186 sub XcodeOptionString
188 return join " ", XcodeOptions();
191 sub XcodeOptionStringNoConfig
193 return join " ", @baseProductDirOption;
196 my $passedConfiguration;
197 my $searchedForPassedConfiguration;
198 sub determinePassedConfiguration
200 return if $searchedForPassedConfiguration;
201 $searchedForPassedConfiguration = 1;
202 for my $i (0 .. $#ARGV) {
204 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
205 splice(@ARGV, $i, 1);
206 $passedConfiguration = "Debug";
209 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
210 splice(@ARGV, $i, 1);
211 $passedConfiguration = "Release";
215 $passedConfiguration = undef;
218 sub passedConfiguration
220 determinePassedConfiguration();
221 return $passedConfiguration;
226 determinePassedConfiguration();
227 $configuration = $passedConfiguration if $passedConfiguration;
233 # Use WEBKIT_SAFARI environment variable if present.
234 my $safariBundle = $ENV{WEBKIT_SAFARI};
235 if (!$safariBundle) {
236 determineConfigurationProductDir();
237 # Use Safari.app in product directory if present (good for Safari development team).
238 if (-d "$configurationProductDir/Safari.app") {
239 $safariBundle = "$configurationProductDir/Safari.app";
241 # Otherwise use Safari.app in Applications directory.
242 $safariBundle = "/Applications/Safari.app";
245 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
246 die "Can't find executable at $safariPath.\n" unless -x $safariPath;
250 sub builtDylibPathForName
252 my $framework = shift;
253 determineConfigurationProductDir();
255 return "$configurationProductDir/$framework.framework/Versions/A/$framework";
258 return "$baseProductDir/$framework.intermediate/$configuration/$framework.intermediate/$framework.lib";
260 die "Unsupported platform, can't determine built library locations.";
263 # Check to see that all the frameworks are built.
266 my @frameworks = ("JavaScriptCore", "WebCore");
267 push(@frameworks, "WebKit") if isOSX();
268 for my $framework (@frameworks) {
269 my $path = builtDylibPathForName($framework);
270 die "Can't find built framework at \"$path\".\n" unless -x $path;
276 return 0 if isCygwin();
278 open NM, "-|", "nm", $path or die;
279 my $hasSVGSupport = 0;
281 $hasSVGSupport = 1 if /SVGElement/;
284 return $hasSVGSupport;
287 sub removeLibraryDependingOnSVG
289 my $frameworkName = shift;
290 my $shouldHaveSVG = shift;
292 my $path = builtDylibPathForName($frameworkName);
293 return unless -x $path;
295 my $hasSVG = hasSVGSupport($path);
296 system "rm -f $path" if ($shouldHaveSVG xor $hasSVG);
299 sub checkWebCoreSVGSupport
301 my $required = shift;
302 my $framework = "WebCore";
303 my $path = builtDylibPathForName($framework);
304 my $hasSVG = hasSVGSupport($path);
305 if ($required && !$hasSVG) {
306 die "$framework at \"$path\" does not include SVG Support, please run build-webkit --svg\n";
314 return ($^O eq "cygwin");
319 return ($^O eq "darwin");
322 sub checkRequiredSystemConfig
325 chomp(my $productVersion = `sw_vers -productVersion`);
326 if ($productVersion lt "10.4") {
327 print "*************************************************************\n";
328 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
329 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
330 print "*************************************************************\n";
332 my $xcodeVersion = `xcodebuild -version`;
333 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 620) {
334 print "*************************************************************\n";
335 print "Xcode Version 2.1 or later is required to build WebKit.\n";
336 print "You have an earlier version of Xcode, thus the build will\n";
337 print "most likely fail. The latest Xcode is available from the web:\n";
338 print "http://developer.apple.com/tools/xcode\n";
339 print "*************************************************************\n";
342 # Win32 and other platforms may want to check for minimum config
347 return if !isCygwin();
348 return if $devenvPath;
350 my $programFilesPath = `cygpath "$ENV{'PROGRAMFILES'}"`;
351 chomp $programFilesPath;
352 $devenvPath = "$programFilesPath/Microsoft Visual Studio 8/Common7/IDE/devenv.com";
353 $windowsTmpPath = `cygpath -w /tmp`;
354 chomp $windowsTmpPath;
355 print "Building results into: ", baseProductDir(), "\n";
356 print "WebKitOutputDir is set to: ", $ENV{"WebKitOutputDir"}, "\n";
359 sub buildVisualStudioProject($)
364 chdir "$project.vcproj" or die "Failed to cd into $project.vcproj\n";
365 my $config = configuration();
367 print "$devenvPath $project.sln /build $config";
368 my $result = system $devenvPath, "$project.sln", "/build", $config;