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 if ($framework eq "JavaScriptCore") {
259 return "$baseProductDir/lib/$framework.lib";
261 return "$baseProductDir/$framework.intermediate/$configuration/$framework.intermediate/$framework.lib";
265 return "$configurationProductDir/$framework";
268 die "Unsupported platform, can't determine built library locations.";
271 # Check to see that all the frameworks are built.
274 my @frameworks = ("JavaScriptCore", "WebCore");
275 push(@frameworks, "WebKit") if isOSX();
276 for my $framework (@frameworks) {
277 my $path = builtDylibPathForName($framework);
278 die "Can't find built framework at \"$path\".\n" unless -x $path;
284 return 0 if isCygwin();
288 if ((isQt()) and ($path =~ /WebCore/)) {
289 $path .= "/../lib/libWebCore-unity.so";
292 open NM, "-|", "nm", $path or die;
293 my $hasSVGSupport = 0;
295 $hasSVGSupport = 1 if /SVGElement/;
298 return $hasSVGSupport;
301 sub removeLibraryDependingOnSVG
303 my $frameworkName = shift;
304 my $shouldHaveSVG = shift;
306 my $path = builtDylibPathForName($frameworkName);
307 return unless -x $path;
309 my $hasSVG = hasSVGSupport($path);
310 system "rm -f $path" if ($shouldHaveSVG xor $hasSVG);
313 sub checkWebCoreSVGSupport
315 my $required = shift;
316 my $framework = "WebCore";
317 my $path = builtDylibPathForName($framework);
318 my $hasSVG = hasSVGSupport($path);
319 if ($required && !$hasSVG) {
320 die "$framework at \"$path\" does not include SVG Support, please run build-webkit --svg\n";
327 return ($^O eq "linux") and defined($ENV{'QTDIR'})
332 return ($^O eq "cygwin");
337 return ($^O eq "darwin");
340 sub checkRequiredSystemConfig
343 chomp(my $productVersion = `sw_vers -productVersion`);
344 if ($productVersion lt "10.4") {
345 print "*************************************************************\n";
346 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
347 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
348 print "*************************************************************\n";
350 my $xcodeVersion = `xcodebuild -version`;
351 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 747) {
352 print "*************************************************************\n";
353 print "Xcode Version 2.3 or later is required to build WebKit.\n";
354 print "You have an earlier version of Xcode, thus the build will\n";
355 print "most likely fail. The latest Xcode is available from the web:\n";
356 print "http://developer.apple.com/tools/xcode\n";
357 print "*************************************************************\n";
360 # Win32 and other platforms may want to check for minimum config
365 return if !isCygwin();
366 return if $devenvPath;
368 my $programFilesPath = `cygpath "$ENV{'PROGRAMFILES'}"`;
369 chomp $programFilesPath;
370 $devenvPath = "$programFilesPath/Microsoft Visual Studio 8/Common7/IDE/devenv.com";
371 $windowsTmpPath = `cygpath -w /tmp`;
372 chomp $windowsTmpPath;
373 print "Building results into: ", baseProductDir(), "\n";
374 print "WebKitOutputDir is set to: ", $ENV{"WebKitOutputDir"}, "\n";
377 sub buildVisualStudioProject($)
382 chdir "$project.vcproj" or die "Failed to cd into $project.vcproj\n";
383 my $config = configuration();
385 print "$devenvPath $project.sln /build $config";
386 my $result = system $devenvPath, "$project.sln", "/build", $config;
391 sub buildCMakeProject($$)
393 my ($project, $colorize) = @_;
395 if ($project ne "WebKit") {
396 die "Qt/Linux builds JavaScriptCore/WebCore/WebKitQt in one shot! Only call it for 'WebKit'.\n";
399 my $config = configuration();
400 my $prefix = $ENV{"WebKitInstallationPrefix"};
402 my @buildArgs = ("-DCMAKE_BUILD_TYPE=$config");
403 push @buildArgs, "-DCMAKE_INSTALL_PREFIX=" . $prefix if(defined($prefix));
404 push @buildArgs, "-DWEBKIT_DO_NOT_USE_COLORFUL_OUTPUT=" . ($colorize ? "OFF" : "ON");
405 push @buildArgs, "../../";
407 print "Calling 'cmake @buildArgs' in " . baseProductDir() . "/$config ...\n\n";
408 print "Installation directory: $prefix\n" if(defined($prefix));
410 system "mkdir -p " . baseProductDir() . "/$config";
411 chdir baseProductDir() . "/$config" or die "Failed to cd into " . baseProductDir() . "/$config \n";
413 my $result = system "cmake", @buildArgs;
415 die "Failed to setup build environment using cmake!\n";
418 $result = system "make";