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);
46 my @baseProductDirOption;
48 my $configurationProductDir;
51 sub determineSourceDir
54 $sourceDir = $FindBin::Bin;
55 if ($sourceDir !~ s|/[^/]+/[^/]+$||) {
56 die "Could not find two levels above source directory using FindBin.\n";
60 sub determineBaseProductDir
62 return if defined $baseProductDir;
64 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> /dev/null |" or die;
65 $baseProductDir = <PRODUCT>;
67 if ($baseProductDir) {
68 chomp $baseProductDir;
69 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
70 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
71 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
72 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
73 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
74 @baseProductDirOption = ();
76 $baseProductDir = "$sourceDir/WebKitBuild";
77 @baseProductDirOption = ("SYMROOT=$baseProductDir");
81 sub determineConfiguration
83 return if defined $configuration;
84 determineBaseProductDir();
85 if (open CONFIGURATION, "$baseProductDir/Configuration") {
86 $configuration = <CONFIGURATION>;
91 # compatibility for people who have old Configuration files
92 $configuration = "Release" if $configuration eq "Deployment";
93 $configuration = "Debug" if $configuration eq "Development";
95 $configuration = "Release";
99 sub determineConfigurationProductDir
101 return if defined $configurationProductDir;
102 determineBaseProductDir();
103 determineConfiguration();
104 $configurationProductDir = "$baseProductDir/$configuration";
109 determineSourceDir();
110 chdir $sourceDir or die;
115 determineBaseProductDir();
116 return $baseProductDir;
121 determineConfigurationProductDir();
122 return $configurationProductDir;
127 determineBaseProductDir();
128 determineConfiguration();
129 return (@baseProductDirOption, "-configuration", $configuration);
132 sub XcodeOptionString
134 return join " ", XcodeOptions();
137 sub XcodeOptionStringNoConfig
139 return join " ", @baseProductDirOption;
142 my $passedConfiguration;
143 my $searchedForPassedConfiguration;
144 sub determinePassedConfiguration
146 return if $searchedForPassedConfiguration;
147 $searchedForPassedConfiguration = 1;
148 for my $i (0 .. $#ARGV) {
150 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
151 splice(@ARGV, $i, 1);
152 $passedConfiguration = "Debug";
155 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
156 splice(@ARGV, $i, 1);
157 $passedConfiguration = "Release";
161 $passedConfiguration = undef;
164 sub passedConfiguration
166 determinePassedConfiguration();
167 return $passedConfiguration;
172 determinePassedConfiguration();
173 $configuration = $passedConfiguration if $passedConfiguration;
179 # Use WEBKIT_SAFARI environment variable if present.
180 my $safariBundle = $ENV{WEBKIT_SAFARI};
181 if (!$safariBundle) {
182 determineConfigurationProductDir();
183 # Use Safari.app in product directory if present (good for Safari development team).
184 if (-d "$configurationProductDir/Safari.app") {
185 $safariBundle = "$configurationProductDir/Safari.app";
187 # Otherwise use Safari.app in Applications directory.
188 $safariBundle = "/Applications/Safari.app";
191 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
192 die "Can't find executable at $safariPath.\n" unless -x $safariPath;
196 sub builtDylibPathForName
198 my $framework = shift;
199 determineConfigurationProductDir();
200 return "$configurationProductDir/$framework.framework/Versions/A/$framework";
203 # Check to see that all the frameworks are built.
206 for my $framework ("JavaScriptCore", "WebCore", "WebKit") {
207 my $path = builtDylibPathForName($framework);
208 die "Can't find built framework at \"$path\".\n" unless -x $path;
215 open NM, "-|", "nm", $path or die;
216 my $hasSVGSupport = 0;
218 $hasSVGSupport = 1 if /SVGElement/;
221 return $hasSVGSupport;
224 sub removeLibraryDependingOnSVG
226 my $frameworkName = shift;
227 my $shouldHaveSVG = shift;
229 my $path = builtDylibPathForName($frameworkName);
230 return unless -x $path;
232 my $hasSVG = hasSVGSupport($path);
233 system "rm -f $path" if ($shouldHaveSVG xor $hasSVG);
236 sub checkWebCoreSVGSupport
238 my $required = shift;
239 my $framework = "WebCore";
240 my $path = builtDylibPathForName($framework);
241 my $hasSVG = hasSVGSupport($path);
242 if ($required && !$hasSVG) {
243 die "$framework at \"$path\" does not include SVG Support, please run build-webkit --svg\n";
248 sub checkRequiredSystemConfig
250 chomp(my $productVersion = `sw_vers -productVersion`);
251 if ($productVersion lt "10.4") {
252 print "*************************************************************\n";
253 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
254 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
255 print "*************************************************************\n";
257 my $xcodeVersion = `xcodebuild -version`;
258 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 620) {
259 print "*************************************************************\n";
260 print "Xcode Version 2.1 or later is required to build WebKit.\n";
261 print "You have an earlier version of Xcode, thus the build will\n";
262 print "most likely fail. The latest Xcode is available from the web:\n";
263 print "http://developer.apple.com/tools/xcode\n";
264 print "*************************************************************\n";