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;
61 # walks up path checking each directory to see if it is the main WebKit project dir,
62 # defined by containing JavaScriptCore, WebCore, and WebKit
63 until (-d "$sourceDir/JavaScriptCore" && -d "$sourceDir/WebCore" && -d "$sourceDir/WebKit")
65 if ($sourceDir !~ s|/[^/]+$||) {
66 die "Could not find top level webkit directory above source directory using FindBin.\n";
71 # used for scripts which are stored in a non-standard location
77 sub determineBaseProductDir
79 return if defined $baseProductDir;
82 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> /dev/null |" or die;
83 $baseProductDir = <PRODUCT>;
85 if ($baseProductDir) {
86 chomp $baseProductDir;
89 $baseProductDir = $ENV{"WEBKITOUTPUTDIR"};
90 if (isCygwin() && $baseProductDir) {
91 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
93 $baseProductDir = $unixBuildPath;
97 if ($baseProductDir && isOSX()) {
98 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
99 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
100 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
101 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
102 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
103 @baseProductDirOption = ();
106 if (!defined($baseProductDir)) {
107 $baseProductDir = "$sourceDir/WebKitBuild";
108 @baseProductDirOption = ("SYMROOT=$baseProductDir") if (isOSX());
110 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
112 $ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
117 sub determineConfiguration
119 return if defined $configuration;
120 determineBaseProductDir();
121 if (open CONFIGURATION, "$baseProductDir/Configuration") {
122 $configuration = <CONFIGURATION>;
125 if ($configuration) {
126 chomp $configuration;
127 # compatibility for people who have old Configuration files
128 $configuration = "Release" if $configuration eq "Deployment";
129 $configuration = "Debug" if $configuration eq "Development";
131 $configuration = "Release";
135 sub determineConfigurationProductDir
137 return if defined $configurationProductDir;
138 determineBaseProductDir();
140 $configurationProductDir = "$baseProductDir/bin";
142 determineConfiguration();
143 $configurationProductDir = "$baseProductDir/$configuration";
147 sub determineCurrentSVNRevision
149 return if defined $currentSVNRevision;
150 determineSourceDir();
151 my $svnInfo = `svn info $sourceDir | grep Revision:`;
152 ($currentSVNRevision) = ($svnInfo =~ m/Revision: (\d+).*/g);
153 die "Unable to determine current SVN revision in $sourceDir" unless (defined $currentSVNRevision);
154 return $currentSVNRevision;
160 determineSourceDir();
161 chdir $sourceDir or die;
166 determineBaseProductDir();
167 return $baseProductDir;
172 determineConfigurationProductDir();
173 return $configurationProductDir;
178 determineConfiguration();
179 return $configuration;
182 sub currentSVNRevision
184 determineCurrentSVNRevision();
185 return $currentSVNRevision;
190 determineBaseProductDir();
191 determineConfiguration();
192 return (@baseProductDirOption, "-configuration", $configuration);
195 sub XcodeOptionString
197 return join " ", XcodeOptions();
200 sub XcodeOptionStringNoConfig
202 return join " ", @baseProductDirOption;
205 my $passedConfiguration;
206 my $searchedForPassedConfiguration;
207 sub determinePassedConfiguration
209 return if $searchedForPassedConfiguration;
210 $searchedForPassedConfiguration = 1;
211 for my $i (0 .. $#ARGV) {
213 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
214 splice(@ARGV, $i, 1);
215 $passedConfiguration = "Debug";
218 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
219 splice(@ARGV, $i, 1);
220 $passedConfiguration = "Release";
224 $passedConfiguration = undef;
227 sub passedConfiguration
229 determinePassedConfiguration();
230 return $passedConfiguration;
235 determinePassedConfiguration();
236 $configuration = $passedConfiguration if $passedConfiguration;
242 # Use WEBKIT_SAFARI environment variable if present.
243 my $safariBundle = $ENV{WEBKIT_SAFARI};
244 if (!$safariBundle) {
245 determineConfigurationProductDir();
246 # Use Safari.app in product directory if present (good for Safari development team).
247 if (-d "$configurationProductDir/Safari.app") {
248 $safariBundle = "$configurationProductDir/Safari.app";
250 # Otherwise use Safari.app in Applications directory.
251 $safariBundle = "/Applications/Safari.app";
254 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
255 die "Can't find executable at $safariPath.\n" unless -x $safariPath;
259 sub builtDylibPathForName
261 my $framework = shift;
262 determineConfigurationProductDir();
264 return "$configurationProductDir/$framework.framework/Versions/A/$framework";
267 if ($framework eq "JavaScriptCore") {
268 return "$baseProductDir/lib/$framework.lib";
270 return "$baseProductDir/$framework.intermediate/$configuration/$framework.intermediate/$framework.lib";
274 return "$configurationProductDir/$framework";
277 die "Unsupported platform, can't determine built library locations.";
280 # Check to see that all the frameworks are built.
283 my @frameworks = ("JavaScriptCore", "WebCore");
284 push(@frameworks, "WebKit") if isOSX();
285 for my $framework (@frameworks) {
286 my $path = builtDylibPathForName($framework);
287 die "Can't find built framework at \"$path\".\n" unless -x $path;
293 return 0 if isCygwin();
297 if ((isQt()) and ($path =~ /WebCore/)) {
298 $path .= "/../lib/libWebCore-unity.so";
301 open NM, "-|", "nm", $path or die;
302 my $hasSVGSupport = 0;
304 $hasSVGSupport = 1 if /SVGElement/;
307 return $hasSVGSupport;
310 sub removeLibraryDependingOnSVG
312 my $frameworkName = shift;
313 my $shouldHaveSVG = shift;
315 my $path = builtDylibPathForName($frameworkName);
316 return unless -x $path;
318 my $hasSVG = hasSVGSupport($path);
319 system "rm -f $path" if ($shouldHaveSVG xor $hasSVG);
322 sub checkWebCoreSVGSupport
324 my $required = shift;
325 my $framework = "WebCore";
326 my $path = builtDylibPathForName($framework);
327 my $hasSVG = hasSVGSupport($path);
328 if ($required && !$hasSVG) {
329 die "$framework at \"$path\" does not include SVG Support, please run build-webkit --svg\n";
336 return ($^O eq "linux") and defined($ENV{'QTDIR'})
341 return ($^O eq "cygwin");
346 return ($^O eq "darwin");
349 sub checkRequiredSystemConfig
352 chomp(my $productVersion = `sw_vers -productVersion`);
353 if ($productVersion lt "10.4") {
354 print "*************************************************************\n";
355 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
356 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
357 print "*************************************************************\n";
359 my $xcodeVersion = `xcodebuild -version`;
360 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 747) {
361 print "*************************************************************\n";
362 print "Xcode Version 2.3 or later is required to build WebKit.\n";
363 print "You have an earlier version of Xcode, thus the build will\n";
364 print "most likely fail. The latest Xcode is available from the web:\n";
365 print "http://developer.apple.com/tools/xcode\n";
366 print "*************************************************************\n";
369 # Win32 and other platforms may want to check for minimum config
374 return if !isCygwin();
375 return if $devenvPath;
377 my $programFilesPath = `cygpath "$ENV{'PROGRAMFILES'}"`;
378 chomp $programFilesPath;
379 $devenvPath = "$programFilesPath/Microsoft Visual Studio 8/Common7/IDE/devenv.com";
380 $windowsTmpPath = `cygpath -w /tmp`;
381 chomp $windowsTmpPath;
382 print "Building results into: ", baseProductDir(), "\n";
383 print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
386 sub buildVisualStudioProject($)
391 chdir "$project.vcproj" or die "Failed to cd into $project.vcproj\n";
392 my $config = configuration();
394 print "$devenvPath $project.sln /build $config";
395 my $result = system $devenvPath, "$project.sln", "/build", $config;
400 sub buildCMakeProject($$)
402 my ($project, $colorize) = @_;
404 if ($project ne "WebKit") {
405 die "Qt/Linux builds JavaScriptCore/WebCore/WebKitQt in one shot! Only call it for 'WebKit'.\n";
408 my $config = configuration();
409 my $prefix = $ENV{"WebKitInstallationPrefix"};
411 my @buildArgs = ("-DCMAKE_BUILD_TYPE=$config");
412 push @buildArgs, "-DCMAKE_INSTALL_PREFIX=" . $prefix if(defined($prefix));
413 push @buildArgs, "-DWEBKIT_DO_NOT_USE_COLORFUL_OUTPUT=" . ($colorize ? "OFF" : "ON");
414 push @buildArgs, "../../";
416 print "Calling 'cmake @buildArgs' in " . baseProductDir() . "/$config ...\n\n";
417 print "Installation directory: $prefix\n" if(defined($prefix));
419 system "mkdir -p " . baseProductDir() . "/$config";
420 chdir baseProductDir() . "/$config" or die "Failed to cd into " . baseProductDir() . "/$config \n";
422 my $result = system "cmake", @buildArgs;
424 die "Failed to setup build environment using cmake!\n";
427 $result = system "make";