1 # Copyright (C) 2005, 2006, 2007 Apple 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.
38 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
41 @EXPORT = qw(&chdirWebKit &baseProductDir &productDir &XcodeOptions &XcodeOptionString &XcodeOptionStringNoConfig &passedConfiguration &setConfiguration &safariPath &checkFrameworks ¤tSVNRevision);
49 my @baseProductDirOption;
51 my $configurationForVisualStudio;
52 my $configurationProductDir;
54 my $currentSVNRevision;
63 # Variables for Win32 support
67 sub determineSourceDir
70 $sourceDir = $FindBin::Bin;
71 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
73 # walks up path checking each directory to see if it is the main WebKit project dir,
74 # defined by containing JavaScriptCore, WebCore, and WebKit
75 until ((-d "$sourceDir/JavaScriptCore" && -d "$sourceDir/WebCore" && -d "$sourceDir/WebKit") || (-d "$sourceDir/Internal" && -d "$sourceDir/OpenSource"))
77 if ($sourceDir !~ s|/[^/]+$||) {
78 die "Could not find top level webkit directory above source directory using FindBin.\n";
82 $sourceDir = "$sourceDir/OpenSource" if -d "$sourceDir/OpenSource";
85 # used for scripts which are stored in a non-standard location
91 sub determineBaseProductDir
93 return if defined $baseProductDir;
95 if (isAppleMacWebKit()) {
96 open PRODUCT, "defaults read com.apple.Xcode PBXApplicationwideBuildSettings 2> /dev/null |" or die;
97 $baseProductDir = join '', <PRODUCT>;
100 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
101 undef $baseProductDir unless $baseProductDir =~ /^\//;
103 if (!defined($baseProductDir)) {
104 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> /dev/null |" or die;
105 $baseProductDir = <PRODUCT>;
107 if ($baseProductDir) {
108 chomp $baseProductDir;
109 undef $baseProductDir unless $baseProductDir =~ /^\//;
113 $baseProductDir = $ENV{"WEBKITOUTPUTDIR"};
114 if (isAppleWinWebKit() && $baseProductDir) {
115 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
116 chomp $unixBuildPath;
117 $baseProductDir = $unixBuildPath;
121 if ($baseProductDir && isAppleMacWebKit()) {
122 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
123 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
124 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
125 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
126 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
127 @baseProductDirOption = ();
130 if (!defined($baseProductDir)) {
131 $baseProductDir = "$sourceDir/WebKitBuild";
133 if (isGit() && isGitBranchBuild()) {
134 my $branch = gitBranch();
135 $baseProductDir = "$baseProductDir/$branch";
138 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir") if (isAppleMacWebKit());
140 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
142 $ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
147 sub setBaseProductDir($)
149 ($baseProductDir) = @_;
152 sub determineConfiguration
154 return if defined $configuration;
155 determineBaseProductDir();
156 if (open CONFIGURATION, "$baseProductDir/Configuration") {
157 $configuration = <CONFIGURATION>;
160 if ($configuration) {
161 chomp $configuration;
162 # compatibility for people who have old Configuration files
163 $configuration = "Release" if $configuration eq "Deployment";
164 $configuration = "Debug" if $configuration eq "Development";
166 $configuration = "Release";
170 sub argumentsForConfiguration()
172 determineConfiguration();
175 push(@args, '--debug') if $configuration eq "Debug";
176 push(@args, '--release') if $configuration eq "Release";
177 push(@args, '--qt') if isQt();
178 push(@args, '--gtk') if isGtk();
179 push(@args, '--wx') if isWx();
180 push(@args, '--chromium') if isChromium();
184 sub determineConfigurationForVisualStudio
186 return if defined $configurationForVisualStudio;
187 determineConfiguration();
188 $configurationForVisualStudio = $configuration;
189 return unless $configuration eq "Debug";
191 chomp(my $dir = `cygpath -ua '$ENV{WEBKITLIBRARIESDIR}'`);
192 $configurationForVisualStudio = "Debug_Internal" if -f "$dir/bin/CoreFoundation_debug.dll";
195 sub determineConfigurationProductDir
197 return if defined $configurationProductDir;
198 determineBaseProductDir();
199 determineConfiguration();
200 if (isAppleWinWebKit() && !isWx()) {
201 $configurationProductDir = "$baseProductDir/bin";
203 $configurationProductDir = "$baseProductDir/$configuration";
207 sub setConfigurationProductDir($)
209 ($configurationProductDir) = @_;
212 sub determineCurrentSVNRevision
214 return if defined $currentSVNRevision;
215 determineSourceDir();
216 $currentSVNRevision = svnRevisionForDirectory($sourceDir);
217 return $currentSVNRevision;
223 determineSourceDir();
224 chdir $sourceDir or die;
229 determineBaseProductDir();
230 return $baseProductDir;
235 determineSourceDir();
241 determineConfigurationProductDir();
242 return $configurationProductDir;
247 determineConfiguration();
248 return $configuration;
251 sub configurationForVisualStudio()
253 determineConfigurationForVisualStudio();
254 return $configurationForVisualStudio;
257 sub currentSVNRevision
259 determineCurrentSVNRevision();
260 return $currentSVNRevision;
265 determineBaseProductDir();
266 determineConfiguration();
267 return (@baseProductDirOption, "-configuration", $configuration);
270 sub XcodeOptionString
272 return join " ", XcodeOptions();
275 sub XcodeOptionStringNoConfig
277 return join " ", @baseProductDirOption;
280 sub XcodeCoverageSupportOptions()
282 my @coverageSupportOptions = ();
283 push @coverageSupportOptions, "GCC_GENERATE_TEST_COVERAGE_FILES=YES";
284 push @coverageSupportOptions, "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES";
285 push @coverageSupportOptions, "EXTRA_LINK= -ftest-coverage -fprofile-arcs";
286 push @coverageSupportOptions, "OTHER_CFLAGS= -MD";
287 push @coverageSupportOptions, "OTHER_LDFLAGS=\$(OTHER_LDFLAGS) -ftest-coverage -fprofile-arcs -framework AppKit";
288 return @coverageSupportOptions;
291 my $passedConfiguration;
292 my $searchedForPassedConfiguration;
293 sub determinePassedConfiguration
295 return if $searchedForPassedConfiguration;
296 $searchedForPassedConfiguration = 1;
298 my $isWinCairo = checkForArgumentAndRemoveFromARGV("--cairo-win32");
300 for my $i (0 .. $#ARGV) {
302 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
303 splice(@ARGV, $i, 1);
304 $passedConfiguration = "Debug";
305 $passedConfiguration .= "_Cairo" if ($isWinCairo && isCygwin());
308 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
309 splice(@ARGV, $i, 1);
310 $passedConfiguration = "Release";
311 $passedConfiguration .= "_Cairo" if ($isWinCairo && isCygwin());
314 if ($opt =~ /^--profil(e|ing)$/i) {
315 splice(@ARGV, $i, 1);
316 $passedConfiguration = "Profiling";
317 $passedConfiguration .= "_Cairo" if ($isWinCairo && isCygwin());
321 $passedConfiguration = undef;
324 sub passedConfiguration
326 determinePassedConfiguration();
327 return $passedConfiguration;
332 if (my $config = shift @_) {
333 $configuration = $config;
337 determinePassedConfiguration();
338 $configuration = $passedConfiguration if $passedConfiguration;
341 sub safariPathFromSafariBundle
343 my ($safariBundle) = @_;
345 return "$safariBundle/Contents/MacOS/Safari" if isAppleMacWebKit();
346 return $safariBundle if isAppleWinWebKit();
349 sub installedSafariPath
353 if (isAppleMacWebKit()) {
354 $safariBundle = "/Applications/Safari.app";
355 } elsif (isAppleWinWebKit()) {
356 $safariBundle = `"$configurationProductDir/FindSafari.exe"`;
357 $safariBundle =~ s/[\r\n]+$//;
358 $safariBundle = `cygpath -u '$safariBundle'`;
359 $safariBundle =~ s/[\r\n]+$//;
360 $safariBundle .= "Safari.exe";
363 return safariPathFromSafariBundle($safariBundle);
369 # Use WEBKIT_SAFARI environment variable if present.
370 my $safariBundle = $ENV{WEBKIT_SAFARI};
371 if (!$safariBundle) {
372 determineConfigurationProductDir();
373 # Use Safari.app in product directory if present (good for Safari development team).
374 if (isAppleMacWebKit() && -d "$configurationProductDir/Safari.app") {
375 $safariBundle = "$configurationProductDir/Safari.app";
376 } elsif (isAppleWinWebKit() && -x "$configurationProductDir/bin/Safari.exe") {
377 $safariBundle = "$configurationProductDir/bin/Safari.exe";
379 return installedSafariPath();
382 my $safariPath = safariPathFromSafariBundle($safariBundle);
383 die "Can't find executable at $safariPath.\n" if isAppleMacWebKit() && !-x $safariPath;
387 sub builtDylibPathForName
389 my $libraryName = shift;
390 determineConfigurationProductDir();
391 if (isQt() or isGtk() or isChromium()) {
392 return "$configurationProductDir/$libraryName";
394 if (isAppleMacWebKit()) {
395 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
397 if (isAppleWinWebKit()) {
398 if ($libraryName eq "JavaScriptCore") {
399 return "$baseProductDir/lib/$libraryName.lib";
401 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
405 die "Unsupported platform, can't determine built library locations.";
408 # Check to see that all the frameworks are built.
411 return if isCygwin();
412 my @frameworks = ("JavaScriptCore", "WebCore");
413 push(@frameworks, "WebKit") if isAppleMacWebKit();
414 for my $framework (@frameworks) {
415 my $path = builtDylibPathForName($framework);
416 die "Can't find built framework at \"$path\".\n" unless -x $path;
422 return 0 if isCygwin();
430 if (isGtk() and $path =~ /WebCore/) {
431 $path .= "/../.libs/libwebkit-1.0.so";
434 my $hasSVGSupport = 0;
436 open NM, "-|", "nm", $path or die;
438 $hasSVGSupport = 1 if /SVGElement/;
442 return $hasSVGSupport;
445 sub removeLibraryDependingOnSVG
447 my $frameworkName = shift;
448 my $shouldHaveSVG = shift;
450 my $path = builtDylibPathForName($frameworkName);
451 return unless -x $path;
453 my $hasSVG = hasSVGSupport($path);
454 system "rm -f $path" if ($shouldHaveSVG xor $hasSVG);
457 sub checkWebCoreSVGSupport
459 my $required = shift;
460 my $framework = "WebCore";
461 my $path = builtDylibPathForName($framework);
462 my $hasSVG = hasSVGSupport($path);
463 if ($required && !$hasSVG) {
464 die "$framework at \"$path\" does not include SVG Support, please run build-webkit --svg\n";
469 sub hasAcceleratedCompositingSupport
471 return 0 if isCygwin();
475 my $useAcceleratedCompositing = 0;
477 open NM, "-|", "nm", $path or die;
479 $useAcceleratedCompositing = 1 if /GraphicsLayer/;
483 return $useAcceleratedCompositing;
486 sub checkWebCoreAcceleratedCompositingSupport
488 my $required = shift;
489 my $framework = "WebCore";
490 my $path = builtDylibPathForName($framework);
491 my $hasAcceleratedCompositing = hasAcceleratedCompositingSupport($path);
492 if ($required && !$hasAcceleratedCompositing) {
493 die "$framework at \"$path\" does not use accelerated compositing\n";
495 return $hasAcceleratedCompositing;
498 sub has3DTransformsSupport
500 return 0 if isCygwin();
504 my $has3DTransformsSupport = 0;
506 open NM, "-|", "nm", $path or die;
508 $has3DTransformsSupport = 1 if /WebCoreHas3DTransforms/;
512 return $has3DTransformsSupport;
515 sub checkWebCore3DTransformsSupport
517 my $required = shift;
518 my $framework = "WebCore";
519 my $path = builtDylibPathForName($framework);
520 my $has3DTransforms = has3DTransformsSupport($path);
521 if ($required && !$has3DTransforms) {
522 die "$framework at \"$path\" does not include 3D Transforms Support, please run build-webkit --3d-transforms\n";
524 return $has3DTransforms;
529 return 0 if isCygwin();
534 # FIXME: Check built library for WML support, just like Gtk does it below.
538 if (isGtk() and $path =~ /WebCore/) {
539 $path .= "/../.libs/webkit-1.0.so";
542 my $hasWMLSupport = 0;
544 open NM, "-|", "nm", $path or die;
546 $hasWMLSupport = 1 if /WMLElement/;
550 return $hasWMLSupport;
553 sub removeLibraryDependingOnWML
555 my $frameworkName = shift;
556 my $shouldHaveWML = shift;
558 my $path = builtDylibPathForName($frameworkName);
559 return unless -x $path;
561 my $hasWML = hasWMLSupport($path);
562 system "rm -f $path" if ($shouldHaveWML xor $hasWML);
565 sub checkWebCoreWMLSupport
567 my $required = shift;
568 my $framework = "WebCore";
569 my $path = builtDylibPathForName($framework);
570 my $hasWML = hasWMLSupport($path);
571 if ($required && !$hasWML) {
572 die "$framework at \"$path\" does not include WML Support, please run build-webkit --wml\n";
583 sub checkForArgumentAndRemoveFromARGV
585 my $argToCheck = shift;
586 foreach my $opt (@ARGV) {
587 if ($opt =~ /^$argToCheck$/i ) {
588 @ARGV = grep(!/^$argToCheck$/i, @ARGV);
597 return if defined($isQt);
599 # Allow override in case QTDIR is not set.
600 if (checkForArgumentAndRemoveFromARGV("--qt")) {
605 # The presence of QTDIR only means Qt if --gtk is not on the command-line
611 $isQt = defined($ENV{'QTDIR'});
622 return if defined($isGtk);
623 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
634 return if defined($isWx);
635 $isWx = checkForArgumentAndRemoveFromARGV("--wx");
643 foreach my $opt (@ARGV) {
644 if ($opt =~ /^--wx-args/i ) {
645 @ARGV = grep(!/^--wx-args/i, @ARGV);
647 $rawWxArgs =~ s/--wx-args=//i;
650 @wxArgs = split(/,/, $rawWxArgs);
655 # Determine if this is debian, ubuntu, linspire, or something similar.
658 return -e "/etc/debian_version";
663 determineIsChromium();
667 sub determineIsChromium()
669 return if defined($isChromium);
670 $isChromium = checkForArgumentAndRemoveFromARGV("--chromium");
675 return ($^O eq "cygwin") || 0;
680 return ($^O eq "darwin") || 0;
685 return !(isQt() or isGtk() or isWx() or isChromium());
688 sub isAppleMacWebKit()
690 return isAppleWebKit() && isDarwin();
693 sub isAppleWinWebKit()
695 return isAppleWebKit() && isCygwin();
698 sub isPerianInstalled()
700 if (!isAppleWebKit()) {
704 if (-d "/Library/QuickTime/Perian.component") {
708 if (-d "$ENV{HOME}/Library/QuickTime/Perian.component") {
715 sub determineOSXVersion()
717 return if $osXVersion;
724 my $version = `sw_vers -productVersion`;
725 my @splitVersion = split(/\./, $version);
726 @splitVersion >= 2 or die "Invalid version $version";
728 "major" => $splitVersion[0],
729 "minor" => $splitVersion[1],
730 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
736 determineOSXVersion();
742 return isDarwin() && osXVersion()->{"minor"} == 4;
747 return isDarwin() && osXVersion()->{"minor"} == 5;
752 return isDarwin() && osXVersion()->{"minor"} == 6;
755 sub relativeScriptsDir()
757 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel(dirname($0), getcwd()), "");
758 if ($scriptDir eq "") {
766 my $relativeScriptsPath = relativeScriptsDir();
767 if (isGtk() || isQt()) {
768 return "$relativeScriptsPath/run-launcher";
769 } elsif (isAppleWebKit()) {
770 return "$relativeScriptsPath/run-safari";
777 return "GtkLauncher";
780 } elsif (isAppleWebKit()) {
785 sub checkRequiredSystemConfig
788 chomp(my $productVersion = `sw_vers -productVersion`);
789 if ($productVersion lt "10.4") {
790 print "*************************************************************\n";
791 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
792 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
793 print "*************************************************************\n";
795 my $xcodeVersion = `xcodebuild -version`;
796 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 747) {
797 print "*************************************************************\n";
798 print "Xcode Version 2.3 or later is required to build WebKit.\n";
799 print "You have an earlier version of Xcode, thus the build will\n";
800 print "most likely fail. The latest Xcode is available from the web:\n";
801 print "http://developer.apple.com/tools/xcode\n";
802 print "*************************************************************\n";
804 } elsif (isGtk() or isQt() or isWx()) {
805 my @cmds = qw(flex bison gperf);
807 foreach my $cmd (@cmds) {
808 if (not `$cmd --version`) {
813 my $list = join ", ", @missing;
814 die "ERROR: $list missing but required to build WebKit.\n";
817 # Win32 and other platforms may want to check for minimum config
822 return if !isCygwin();
823 return if $vcBuildPath;
825 my $programFilesPath = `cygpath "$ENV{'PROGRAMFILES'}"`;
826 chomp $programFilesPath;
827 $vcBuildPath = "$programFilesPath/Microsoft Visual Studio 8/Common7/IDE/devenv.com";
828 if (! -e $vcBuildPath) {
829 # VC++ not found, try VC++ Express
831 if ($ENV{'VSINSTALLDIR'}) {
832 $vsInstallDir = $ENV{'VSINSTALLDIR'};
834 $programFilesPath = $ENV{'PROGRAMFILES'} || "C:\\Program Files";
835 $vsInstallDir = "$programFilesPath/Microsoft Visual Studio 8";
837 $vsInstallDir = `cygpath "$vsInstallDir"`;
839 $vcBuildPath = "$vsInstallDir/Common7/IDE/VCExpress.exe";
840 if (! -e $vcBuildPath) {
841 print "*************************************************************\n";
842 print "Cannot find '$vcBuildPath'\n";
843 print "Please execute the file 'vcvars32.bat' from\n";
844 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
845 print "to setup the necessary environment variables.\n";
846 print "*************************************************************\n";
851 my $qtSDKPath = "$programFilesPath/QuickTime SDK";
852 if (0 && ! -e $qtSDKPath) {
853 print "*************************************************************\n";
854 print "Cannot find '$qtSDKPath'\n";
855 print "Please download the QuickTime SDK for Windows from\n";
856 print "http://developer.apple.com/quicktime/download/\n";
857 print "*************************************************************\n";
861 chomp($ENV{'WEBKITLIBRARIESDIR'} = `cygpath -wa "$sourceDir/WebKitLibraries/win"`) unless $ENV{'WEBKITLIBRARIESDIR'};
863 $windowsTmpPath = `cygpath -w /tmp`;
864 chomp $windowsTmpPath;
865 print "Building results into: ", baseProductDir(), "\n";
866 print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
867 print "WEBKITLIBRARIESDIR is set to: ", $ENV{"WEBKITLIBRARIESDIR"}, "\n";
870 sub buildXCodeProject($$@)
872 my ($project, $clean, @extraOptions) = @_;
875 push(@extraOptions, "-alltargets");
876 push(@extraOptions, "clean");
879 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
882 sub buildVisualStudioProject
884 my ($project, $clean) = @_;
887 my $config = configurationForVisualStudio();
889 chomp(my $winProjectPath = `cygpath -w "$project"`);
891 my $command = "/build";
896 print "$vcBuildPath $winProjectPath /build $config\n";
897 return system $vcBuildPath, $winProjectPath, $command, $config;
900 sub buildSconsProject
902 my ($project, $shouldClean) = @_;
903 print "Building from $project/$project.scons\n";
905 my $sconsCommand = "scons";
907 # HACK: Launch scons with Win32 python instead of CYGWIN python
908 # Scons + MSVC only works under Win32 python
909 # http://scons.tigris.org/issues/show_bug.cgi?id=2266
910 $sconsCommand = "cmd /c 'C:\\Python26\\Scripts\\scons'";
913 return system $sconsCommand, "--clean";
915 return system $sconsCommand;
918 sub retrieveQMakespecVar
923 my $compiler = "unknown";
924 #print "retrieveMakespecVar " . $mkspec . ", " . $varname . "\n";
927 open SPEC, "<$mkspec" or return "make";
929 if ($_ =~ /\s*include\((.+)\)/) {
930 # open the included mkspec
931 my $oldcwd = getcwd();
932 (my $volume, my $directories, my $file) = File::Spec->splitpath($mkspec);
933 chdir "$volume$directories";
934 $compiler = retrieveQMakespecVar($1, $varname);
936 } elsif ($_ =~ /$varname\s*=\s*([^\s]+)/) {
948 chomp(my $mkspec = `$qmakebin -query QMAKE_MKSPECS`);
949 $mkspec .= "/default";
950 my $compiler = retrieveQMakespecVar("$mkspec/qmake.conf", "QMAKE_CC");
952 #print "default spec: " . $mkspec . "\n";
953 #print "compiler found: " . $compiler . "\n";
955 if ($compiler eq "cl") {
962 sub autotoolsFlag($$)
964 my ($flag, $feature) = @_;
965 my $prefix = $flag ? "--enable" : "--disable";
967 return $prefix . '-' . $feature;
970 sub buildAutotoolsProject($@)
972 my ($clean, @buildArgs) = @_;
975 my $dir = productDir();
976 my $config = passedConfiguration() || configuration();
977 my $prefix = $ENV{"WebKitInstallationPrefix"};
979 # check if configuration is Debug
980 if ($config =~ m/debug/i) {
981 push @buildArgs, "--enable-debug";
983 push @buildArgs, "--disable-debug";
986 # Use rm to clean the build directory since distclean may miss files
987 if ($clean && -d $dir) {
988 system "rm", "-rf", "$dir";
992 system "mkdir", "-p", "$dir";
994 die "Failed to create build directory " . $dir;
998 chdir $dir or die "Failed to cd into " . $dir . "\n";
1002 #$result = system $make, "distclean";
1006 print "Calling configure in " . $dir . "\n\n";
1007 print "Installation directory: $prefix\n" if(defined($prefix));
1009 # Make the path relative since it will appear in all -I compiler flags.
1010 # Long argument lists cause bizarre slowdowns in libtool.
1011 my $relSourceDir = File::Spec->abs2rel($sourceDir);
1012 $relSourceDir = "." if !$relSourceDir;
1014 $result = system "$relSourceDir/autogen.sh", @buildArgs;
1016 die "Failed to setup build environment using 'autotools'!\n";
1019 $result = system $make;
1021 die "\nFailed to build WebKit using '$make'!\n";
1028 sub buildQMakeProject($@)
1030 my ($clean, @buildParams) = @_;
1032 my @buildArgs = ("-r");
1034 my $qmakebin = "qmake"; # Allow override of the qmake binary from $PATH
1036 for my $i (0 .. $#buildParams) {
1037 my $opt = $buildParams[$i];
1038 if ($opt =~ /^--qmake=(.*)/i ) {
1040 } elsif ($opt =~ /^--qmakearg=(.*)/i ) {
1041 push @buildArgs, $1;
1042 } elsif ($opt =~ /^--makeargs=(.*)/i ) {
1045 push @buildArgs, $opt;
1049 my $make = qtMakeCommand($qmakebin);
1050 my $config = configuration();
1051 my $prefix = $ENV{"WebKitInstallationPrefix"};
1053 push @buildArgs, "OUTPUT_DIR=" . baseProductDir() . "/$config";
1054 push @buildArgs, sourceDir() . "/WebKit.pro";
1055 if ($config =~ m/debug/i) {
1056 push @buildArgs, "CONFIG-=release";
1057 push @buildArgs, "CONFIG+=debug";
1059 push @buildArgs, "CONFIG+=release";
1060 push @buildArgs, "CONFIG-=debug";
1063 my $dir = baseProductDir();
1065 system "mkdir", "-p", "$dir";
1067 die "Failed to create product directory " . $dir;
1070 $dir = $dir . "/$config";
1072 system "mkdir", "-p", "$dir";
1074 die "Failed to create build directory " . $dir;
1078 chdir $dir or die "Failed to cd into " . $dir . "\n";
1080 print "Calling '$qmakebin @buildArgs' in " . $dir . "\n\n";
1081 print "Installation directory: $prefix\n" if(defined($prefix));
1083 my $result = system $qmakebin, @buildArgs;
1085 die "Failed to setup build environment using $qmakebin!\n";
1089 $result = system "$make $makeargs distclean";
1091 $result = system "$make $makeargs";
1098 sub buildQMakeQtProject($$@)
1100 my ($project, $clean, @buildArgs) = @_;
1102 push @buildArgs, "CONFIG+=qt-port";
1104 return buildQMakeProject($clean, @buildArgs);
1107 sub buildGtkProject($$@)
1109 my ($project, $clean, @buildArgs) = @_;
1111 if ($project ne "WebKit") {
1112 die "The Gtk port builds JavaScriptCore, WebCore and WebKit in one shot! Only call it for 'WebKit'.\n";
1115 return buildAutotoolsProject($clean, @buildArgs);
1118 sub setPathForRunningWebKitApp
1122 return unless isAppleWinWebKit();
1124 $env->{PATH} = join(':', productDir(), dirname(installedSafariPath()), $env->{PATH} || "");
1129 my ($returnvalue) = @_;
1130 if ($^O eq "MSWin32") {
1131 return $returnvalue >> 8;
1133 return WEXITSTATUS($returnvalue);
1138 my ($debugger) = @_;
1140 if (isAppleMacWebKit()) {
1141 return system "$FindBin::Bin/gdb-safari", @ARGV if $debugger;
1143 my $productDir = productDir();
1144 print "Starting Safari with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
1145 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1146 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
1147 exportArchPreference();
1149 return system "arch", safariPath(), @ARGV;
1151 return system safariPath(), @ARGV;
1155 if (isAppleWinWebKit()) {
1156 my $script = "run-webkit-nightly.cmd";
1157 my $result = system "cp", "$FindBin::Bin/$script", productDir();
1158 return $result if $result;
1163 my $debuggerFlag = $debugger ? "/debugger" : "";
1164 $result = system "cmd", "/c", "call $script $debuggerFlag";
1174 ($forceRun64Bit) = @_;
1177 sub preferredArchitecture
1179 return unless isAppleMacWebKit();
1181 my $framework = shift;
1182 $framework = "WebKit" if !defined($framework);
1184 my $currentArchitecture = `arch`;
1185 chomp($currentArchitecture);
1188 if (!defined($forceRun64Bit)) {
1189 my $frameworkPath = builtDylibPathForName($framework);
1190 die "Couldn't find path for $framework" if !defined($frameworkPath);
1191 # The binary is 64-bit if one of the architectures it contains has "64" in the name
1192 $run64Bit = `lipo -info "$frameworkPath"` =~ /(are|architecture):.*64/;
1195 if ($forceRun64Bit or $run64Bit) {
1196 return ($currentArchitecture eq "i386") ? "x86_64" : "ppc64";
1198 return $currentArchitecture;
1201 sub exportArchPreference
1203 $ENV{ARCHPREFERENCE} = preferredArchitecture() if isAppleMacWebKit();