1 # Copyright (C) 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
2 # Copyright (C) 2009 Google Inc. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 # its contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # Module to share code to get to WebKit directories.
42 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
45 @EXPORT = qw(&chdirWebKit &baseProductDir &productDir &XcodeOptions &XcodeOptionString &XcodeOptionStringNoConfig &passedConfiguration &setConfiguration &safariPath &checkFrameworks ¤tSVNRevision);
55 my @baseProductDirOption;
57 my $configurationForVisualStudio;
58 my $configurationProductDir;
60 my $currentSVNRevision;
64 my %qtFeatureDefaults;
71 my $isInspectorFrontend;
73 # Variables for Win32 support
77 my $willUseVCExpressWhenBuilding = 0;
79 # Defined in VCSUtils.
82 sub determineSourceDir
85 $sourceDir = $FindBin::Bin;
86 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
88 # walks up path checking each directory to see if it is the main WebKit project dir,
89 # defined by containing Sources, WebCore, and WebKit
90 until ((-d "$sourceDir/Source" && -d "$sourceDir/Source/WebCore" && -d "$sourceDir/Source/WebKit") || (-d "$sourceDir/Internal" && -d "$sourceDir/OpenSource"))
92 if ($sourceDir !~ s|/[^/]+$||) {
93 die "Could not find top level webkit directory above source directory using FindBin.\n";
97 $sourceDir = "$sourceDir/OpenSource" if -d "$sourceDir/OpenSource";
100 sub currentPerlPath()
104 $thisPerl .= $Config{_exe} unless $thisPerl =~ m/$Config{_exe}$/i;
109 # used for scripts which are stored in a non-standard location
115 sub determineBaseProductDir
117 return if defined $baseProductDir;
118 determineSourceDir();
120 $baseProductDir = $ENV{"WEBKITOUTPUTDIR"};
122 if (!defined($baseProductDir) and isAppleMacWebKit()) {
123 # Silently remove ~/Library/Preferences/xcodebuild.plist which can
124 # cause build failure. The presence of
125 # ~/Library/Preferences/xcodebuild.plist can prevent xcodebuild from
126 # respecting global settings such as a custom build products directory
127 # (<rdar://problem/5585899>).
128 my $personalPlistFile = $ENV{HOME} . "/Library/Preferences/xcodebuild.plist";
129 if (-e $personalPlistFile) {
130 unlink($personalPlistFile) || die "Could not delete $personalPlistFile: $!";
133 open PRODUCT, "defaults read com.apple.Xcode PBXApplicationwideBuildSettings 2> " . File::Spec->devnull() . " |" or die;
134 $baseProductDir = join '', <PRODUCT>;
137 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
138 undef $baseProductDir unless $baseProductDir =~ /^\//;
140 if (!defined($baseProductDir)) {
141 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> " . File::Spec->devnull() . " |" or die;
142 $baseProductDir = <PRODUCT>;
144 if ($baseProductDir) {
145 chomp $baseProductDir;
146 undef $baseProductDir unless $baseProductDir =~ /^\//;
149 } elsif (isSymbian()) {
150 # Shadow builds are not supported on Symbian
151 $baseProductDir = $sourceDir;
154 if (!defined($baseProductDir)) { # Port-spesific checks failed, use default
155 $baseProductDir = "$sourceDir/WebKitBuild";
158 if (isGit() && isGitBranchBuild()) {
159 my $branch = gitBranch();
160 $baseProductDir = "$baseProductDir/$branch";
163 if (isAppleMacWebKit()) {
164 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
165 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
166 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
167 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
168 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
169 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir");
173 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
175 $ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
176 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
177 chomp $unixBuildPath;
178 $baseProductDir = $unixBuildPath;
182 sub setBaseProductDir($)
184 ($baseProductDir) = @_;
187 sub determineConfiguration
189 return if defined $configuration;
190 determineBaseProductDir();
191 if (open CONFIGURATION, "$baseProductDir/Configuration") {
192 $configuration = <CONFIGURATION>;
195 if ($configuration) {
196 chomp $configuration;
197 # compatibility for people who have old Configuration files
198 $configuration = "Release" if $configuration eq "Deployment";
199 $configuration = "Debug" if $configuration eq "Development";
201 $configuration = "Release";
205 sub determineArchitecture
207 return if defined $architecture;
208 # make sure $architecture is defined for non-apple-mac builds
210 return unless isAppleMacWebKit();
212 determineBaseProductDir();
213 if (open ARCHITECTURE, "$baseProductDir/Architecture") {
214 $architecture = <ARCHITECTURE>;
220 if (isTiger() or isLeopard()) {
221 $architecture = `arch`;
223 my $supports64Bit = `sysctl -n hw.optional.x86_64`;
224 chomp $supports64Bit;
225 $architecture = $supports64Bit ? 'x86_64' : `arch`;
231 sub determineNumberOfCPUs
233 return if defined $numberOfCPUs;
235 # First try the nproc utility, if it exists. If we get no
236 # results fall back to just interpretting /proc directly.
237 chomp($numberOfCPUs = `nproc 2> /dev/null`);
238 if ($numberOfCPUs eq "") {
239 $numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`);
241 } elsif (isWindows() || isCygwin()) {
242 if (defined($ENV{NUMBER_OF_PROCESSORS})) {
243 $numberOfCPUs = $ENV{NUMBER_OF_PROCESSORS};
246 $numberOfCPUs = `ls /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor | wc -w`;
248 } elsif (isDarwin()) {
249 $numberOfCPUs = `sysctl -n hw.ncpu`;
255 my ($productDir) = @_;
257 $jscName .= "_debug" if configurationForVisualStudio() eq "Debug_All";
258 $jscName .= ".exe" if (isWindows() || isCygwin());
259 return "$productDir/$jscName" if -e "$productDir/$jscName";
260 return "$productDir/JavaScriptCore.framework/Resources/$jscName";
263 sub argumentsForConfiguration()
265 determineConfiguration();
266 determineArchitecture();
269 push(@args, '--debug') if $configuration eq "Debug";
270 push(@args, '--release') if $configuration eq "Release";
271 push(@args, '--32-bit') if $architecture ne "x86_64";
272 push(@args, '--qt') if isQt();
273 push(@args, '--symbian') if isSymbian();
274 push(@args, '--gtk') if isGtk();
275 push(@args, '--efl') if isEfl();
276 push(@args, '--wince') if isWinCE();
277 push(@args, '--wx') if isWx();
278 push(@args, '--chromium') if isChromium();
279 push(@args, '--inspector-frontend') if isInspectorFrontend();
283 sub determineConfigurationForVisualStudio
285 return if defined $configurationForVisualStudio;
286 determineConfiguration();
287 # FIXME: We should detect when Debug_All or Release_LTCG has been chosen.
288 $configurationForVisualStudio = $configuration;
291 sub usesPerConfigurationBuildDirectory
293 # [Gtk][Efl] We don't have Release/Debug configurations in straight
294 # autotool builds (non build-webkit). In this case and if
295 # WEBKITOUTPUTDIR exist, use that as our configuration dir. This will
296 # allows us to run run-webkit-tests without using build-webkit.
298 # Symbian builds do not have Release/Debug configurations either.
299 return ($ENV{"WEBKITOUTPUTDIR"} && (isGtk() || isEfl())) || isSymbian() || isAppleWinWebKit();
302 sub determineConfigurationProductDir
304 return if defined $configurationProductDir;
305 determineBaseProductDir();
306 determineConfiguration();
307 if (isAppleWinWebKit() && !isWx()) {
308 $configurationProductDir = File::Spec->catdir($baseProductDir, configurationForVisualStudio(), "bin");
310 if (usesPerConfigurationBuildDirectory()) {
311 $configurationProductDir = "$baseProductDir";
313 $configurationProductDir = "$baseProductDir/$configuration";
318 sub setConfigurationProductDir($)
320 ($configurationProductDir) = @_;
323 sub determineCurrentSVNRevision
325 return if defined $currentSVNRevision;
326 determineSourceDir();
327 $currentSVNRevision = svnRevisionForDirectory($sourceDir);
328 return $currentSVNRevision;
334 determineSourceDir();
335 chdir $sourceDir or die;
340 determineBaseProductDir();
341 return $baseProductDir;
346 determineSourceDir();
352 determineConfigurationProductDir();
353 return $configurationProductDir;
358 my $productDir = productDir();
359 $productDir .= "/JavaScriptCore" if isQt();
360 $productDir .= "/$configuration" if (isQt() && isWindows());
361 $productDir .= "/Programs" if (isGtk() || isEfl());
368 determineConfiguration();
369 return $configuration;
372 sub configurationForVisualStudio()
374 determineConfigurationForVisualStudio();
375 return $configurationForVisualStudio;
378 sub currentSVNRevision
380 determineCurrentSVNRevision();
381 return $currentSVNRevision;
386 determineBaseProductDir();
387 determineConfiguration();
388 determineArchitecture();
389 return (@baseProductDirOption, "-configuration", $configuration, "ARCHS=$architecture");
392 sub XcodeOptionString
394 return join " ", XcodeOptions();
397 sub XcodeOptionStringNoConfig
399 return join " ", @baseProductDirOption;
402 sub XcodeCoverageSupportOptions()
404 my @coverageSupportOptions = ();
405 push @coverageSupportOptions, "GCC_GENERATE_TEST_COVERAGE_FILES=YES";
406 push @coverageSupportOptions, "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES";
407 push @coverageSupportOptions, "EXTRA_LINK= \$(EXTRA_LINK) -ftest-coverage -fprofile-arcs";
408 push @coverageSupportOptions, "OTHER_CFLAGS= \$(OTHER_CFLAGS) -DCOVERAGE -MD";
409 push @coverageSupportOptions, "OTHER_LDFLAGS=\$(OTHER_LDFLAGS) -ftest-coverage -fprofile-arcs -lgcov";
410 return @coverageSupportOptions;
413 my $passedConfiguration;
414 my $searchedForPassedConfiguration;
415 sub determinePassedConfiguration
417 return if $searchedForPassedConfiguration;
418 $searchedForPassedConfiguration = 1;
420 my $isWinCairo = checkForArgumentAndRemoveFromARGV("--wincairo");
422 for my $i (0 .. $#ARGV) {
424 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
425 splice(@ARGV, $i, 1);
426 $passedConfiguration = "Debug";
427 $passedConfiguration .= "_Cairo_CFLite" if ($isWinCairo && isCygwin());
430 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
431 splice(@ARGV, $i, 1);
432 $passedConfiguration = "Release";
433 $passedConfiguration .= "_Cairo_CFLite" if ($isWinCairo && isCygwin());
436 if ($opt =~ /^--profil(e|ing)$/i) {
437 splice(@ARGV, $i, 1);
438 $passedConfiguration = "Profiling";
439 $passedConfiguration .= "_Cairo_CFLite" if ($isWinCairo && isCygwin());
443 $passedConfiguration = undef;
446 sub passedConfiguration
448 determinePassedConfiguration();
449 return $passedConfiguration;
456 if (my $config = shift @_) {
457 $configuration = $config;
461 determinePassedConfiguration();
462 $configuration = $passedConfiguration if $passedConfiguration;
466 my $passedArchitecture;
467 my $searchedForPassedArchitecture;
468 sub determinePassedArchitecture
470 return if $searchedForPassedArchitecture;
471 $searchedForPassedArchitecture = 1;
473 for my $i (0 .. $#ARGV) {
475 if ($opt =~ /^--32-bit$/i) {
476 splice(@ARGV, $i, 1);
477 if (isAppleMacWebKit()) {
478 $passedArchitecture = `arch`;
479 chomp $passedArchitecture;
484 $passedArchitecture = undef;
487 sub passedArchitecture
489 determinePassedArchitecture();
490 return $passedArchitecture;
495 determineArchitecture();
496 return $architecture;
501 determineNumberOfCPUs();
502 return $numberOfCPUs;
507 if (my $arch = shift @_) {
508 $architecture = $arch;
512 determinePassedArchitecture();
513 $architecture = $passedArchitecture if $passedArchitecture;
517 sub safariPathFromSafariBundle
519 my ($safariBundle) = @_;
521 return "$safariBundle/Contents/MacOS/Safari" if isAppleMacWebKit();
522 return $safariBundle if isAppleWinWebKit();
525 sub installedSafariPath
529 if (isAppleMacWebKit()) {
530 $safariBundle = "/Applications/Safari.app";
531 } elsif (isAppleWinWebKit()) {
532 $safariBundle = `"$configurationProductDir/FindSafari.exe"`;
533 $safariBundle =~ s/[\r\n]+$//;
534 $safariBundle = `cygpath -u '$safariBundle'` if isCygwin();
535 $safariBundle =~ s/[\r\n]+$//;
536 $safariBundle .= "Safari.exe";
539 return safariPathFromSafariBundle($safariBundle);
545 # Use WEBKIT_SAFARI environment variable if present.
546 my $safariBundle = $ENV{WEBKIT_SAFARI};
547 if (!$safariBundle) {
548 determineConfigurationProductDir();
549 # Use Safari.app in product directory if present (good for Safari development team).
550 if (isAppleMacWebKit() && -d "$configurationProductDir/Safari.app") {
551 $safariBundle = "$configurationProductDir/Safari.app";
552 } elsif (isAppleWinWebKit()) {
553 my $path = "$configurationProductDir/Safari.exe";
554 my $debugPath = "$configurationProductDir/Safari_debug.exe";
556 if (configurationForVisualStudio() eq "Debug_All" && -x $debugPath) {
557 $safariBundle = $debugPath;
559 $safariBundle = $path;
562 if (!$safariBundle) {
563 return installedSafariPath();
566 my $safariPath = safariPathFromSafariBundle($safariBundle);
567 die "Can't find executable at $safariPath.\n" if isAppleMacWebKit() && !-x $safariPath;
571 sub builtDylibPathForName
573 my $libraryName = shift;
574 determineConfigurationProductDir();
576 return "$configurationProductDir/$libraryName";
579 $libraryName = "QtWebKit";
580 if (isDarwin() and -d "$configurationProductDir/lib/$libraryName.framework") {
581 return "$configurationProductDir/lib/$libraryName.framework/$libraryName";
582 } elsif (isDarwin() and -d "$configurationProductDir/lib") {
583 return "$configurationProductDir/lib/lib$libraryName.dylib";
584 } elsif (isWindows()) {
585 if (configuration() eq "Debug") {
586 # On Windows, there is a "d" suffix to the library name. See <http://trac.webkit.org/changeset/53924/>.
590 my $mkspec = `qmake -query QMAKE_MKSPECS`;
591 $mkspec =~ s/[\n|\r]$//g;
592 my $qtMajorVersion = retrieveQMakespecVar("$mkspec/qconfig.pri", "QT_MAJOR_VERSION");
593 if (not $qtMajorVersion) {
594 $qtMajorVersion = "";
596 return "$configurationProductDir/lib/$libraryName$qtMajorVersion.dll";
598 return "$configurationProductDir/lib/lib$libraryName.so";
602 return "$configurationProductDir/libwxwebkit.dylib";
605 my $libraryDir = "$configurationProductDir/.libs/";
606 my $extension = isDarwin() ? "dylib" : "so";
607 if (-e $libraryDir . "libwebkitgtk-3.0.$extension") {
608 return $libraryDir . "libwebkitgtk-3.0.$extension";
610 return $libraryDir . "libwebkitgtk-1.0.$extension";
613 return "$configurationProductDir/$libraryName/../.libs/libewebkit.so";
616 return "$configurationProductDir/$libraryName";
618 if (isAppleMacWebKit()) {
619 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
621 if (isAppleWinWebKit()) {
622 if ($libraryName eq "JavaScriptCore") {
623 return "$baseProductDir/lib/$libraryName.lib";
625 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
629 die "Unsupported platform, can't determine built library locations.\nTry `build-webkit --help` for more information.\n";
632 # Check to see that all the frameworks are built.
633 sub checkFrameworks # FIXME: This is a poor name since only the Mac calls built WebCore a Framework.
635 return if isCygwin() || isWindows();
636 my @frameworks = ("JavaScriptCore", "WebCore");
637 push(@frameworks, "WebKit") if isAppleMacWebKit(); # FIXME: This seems wrong, all ports should have a WebKit these days.
638 for my $framework (@frameworks) {
639 my $path = builtDylibPathForName($framework);
640 die "Can't find built framework at \"$path\".\n" unless -e $path;
644 sub isInspectorFrontend()
646 determineIsInspectorFrontend();
647 return $isInspectorFrontend;
650 sub determineIsInspectorFrontend()
652 return if defined($isInspectorFrontend);
653 $isInspectorFrontend = checkForArgumentAndRemoveFromARGV("--inspector-frontend");
664 determineIsSymbian();
668 sub qtFeatureDefaults()
670 determineQtFeatureDefaults();
671 return %qtFeatureDefaults;
677 my $devnull = File::Spec->devnull();
678 return `$command --version 2> $devnull`;
681 sub determineQtFeatureDefaults()
683 return if %qtFeatureDefaults;
684 die "ERROR: qmake missing but required to build WebKit.\n" if not commandExists("qmake");
685 my $originalCwd = getcwd();
686 chdir File::Spec->catfile(sourceDir(), "Source", "WebCore");
687 my $defaults = `qmake CONFIG+=compute_defaults 2>&1`;
690 while ($defaults =~ m/(\S+?)=(\S+?)/gi) {
691 $qtFeatureDefaults{$1}=$2;
695 sub checkForArgumentAndRemoveFromARGV
697 my $argToCheck = shift;
698 return checkForArgumentAndRemoveFromArrayRef($argToCheck, \@ARGV);
701 sub checkForArgumentAndRemoveFromArrayRef
703 my ($argToCheck, $arrayRef) = @_;
705 foreach my $index (0 .. $#$arrayRef) {
706 my $opt = $$arrayRef[$index];
707 if ($opt =~ /^$argToCheck$/i ) {
708 push(@indicesToRemove, $index);
711 foreach my $index (@indicesToRemove) {
712 splice(@$arrayRef, $index, 1);
714 return $#indicesToRemove > -1;
720 return if defined($isQt);
722 # Allow override in case QTDIR is not set.
723 if (checkForArgumentAndRemoveFromARGV("--qt")) {
728 # The presence of QTDIR only means Qt if --gtk or --wx or --efl are not on the command-line
729 if (isGtk() || isWx() || isEfl()) {
734 $isQt = defined($ENV{'QTDIR'});
737 sub determineIsSymbian()
739 return if defined($isSymbian);
741 if (checkForArgumentAndRemoveFromARGV("--symbian")) {
749 return if defined($isEfl);
750 $isEfl = checkForArgumentAndRemoveFromARGV("--efl");
767 return if defined($isGtk);
768 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
777 sub determineIsWinCE()
779 return if defined($isWinCE);
780 $isWinCE = checkForArgumentAndRemoveFromARGV("--wince");
791 return if defined($isWx);
792 $isWx = checkForArgumentAndRemoveFromARGV("--wx");
800 foreach my $opt (@ARGV) {
801 if ($opt =~ /^--wx-args/i ) {
802 @ARGV = grep(!/^--wx-args/i, @ARGV);
804 $rawWxArgs =~ s/--wx-args=//i;
807 @wxArgs = split(/,/, $rawWxArgs);
812 # Determine if this is debian, ubuntu, linspire, or something similar.
815 return -e "/etc/debian_version";
820 return -e "/etc/fedora-release";
825 determineIsChromium();
829 sub determineIsChromium()
831 return if defined($isChromium);
832 $isChromium = checkForArgumentAndRemoveFromARGV("--chromium");
837 return ($^O eq "cygwin") || 0;
840 sub determineWinVersion()
842 return if $winVersion;
849 my $versionString = `uname -s`;
850 $versionString =~ /(\d\.\d)/;
856 determineWinVersion();
862 return winVersion() eq "6.1";
867 return winVersion() eq "6.0";
872 return winVersion() eq "5.1";
877 return ($^O eq "darwin") || 0;
882 return ($^O eq "MSWin32") || 0;
887 return ($^O eq "msys") || 0;
892 return ($^O eq "linux") || 0;
897 return !(isQt() or isGtk() or isWx() or isChromium() or isEfl() or isWinCE());
900 sub isAppleMacWebKit()
902 return isAppleWebKit() && isDarwin();
905 sub isAppleWinWebKit()
907 return isAppleWebKit() && (isCygwin() || isWindows());
910 sub isPerianInstalled()
912 if (!isAppleWebKit()) {
916 if (-d "/Library/QuickTime/Perian.component") {
920 if (-d "$ENV{HOME}/Library/QuickTime/Perian.component") {
927 sub determineOSXVersion()
929 return if $osXVersion;
936 my $version = `sw_vers -productVersion`;
937 my @splitVersion = split(/\./, $version);
938 @splitVersion >= 2 or die "Invalid version $version";
940 "major" => $splitVersion[0],
941 "minor" => $splitVersion[1],
942 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
948 determineOSXVersion();
954 return isDarwin() && osXVersion()->{"minor"} == 4;
959 return isDarwin() && osXVersion()->{"minor"} == 5;
964 return isDarwin() && osXVersion()->{"minor"} == 6;
969 return $ENV{'OS'} eq 'Windows_NT';
972 sub relativeScriptsDir()
974 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel(dirname($0), getcwd()), "");
975 if ($scriptDir eq "") {
983 my $relativeScriptsPath = relativeScriptsDir();
984 if (isGtk() || isQt() || isWx() || isEfl() || isWinCE()) {
985 return "$relativeScriptsPath/run-launcher";
986 } elsif (isAppleWebKit()) {
987 return "$relativeScriptsPath/run-safari";
994 return "GtkLauncher";
996 return "QtTestBrowser";
999 } elsif (isAppleWebKit()) {
1002 return "EWebLauncher";
1003 } elsif (isWinCE()) {
1004 return "WinCELauncher";
1008 sub checkRequiredSystemConfig
1011 chomp(my $productVersion = `sw_vers -productVersion`);
1012 if ($productVersion lt "10.4") {
1013 print "*************************************************************\n";
1014 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
1015 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
1016 print "*************************************************************\n";
1018 my $xcodeVersion = `xcodebuild -version`;
1019 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 747) {
1020 print "*************************************************************\n";
1021 print "Xcode Version 2.3 or later is required to build WebKit.\n";
1022 print "You have an earlier version of Xcode, thus the build will\n";
1023 print "most likely fail. The latest Xcode is available from the web:\n";
1024 print "http://developer.apple.com/tools/xcode\n";
1025 print "*************************************************************\n";
1027 } elsif (isGtk() or isQt() or isWx() or isEfl()) {
1028 my @cmds = qw(flex bison gperf);
1030 foreach my $cmd (@cmds) {
1031 push @missing, $cmd if not commandExists($cmd);
1035 my $list = join ", ", @missing;
1036 die "ERROR: $list missing but required to build WebKit.\n";
1039 # Win32 and other platforms may want to check for minimum config
1042 sub determineWindowsSourceDir()
1044 return if $windowsSourceDir;
1045 $windowsSourceDir = sourceDir();
1046 chomp($windowsSourceDir = `cygpath -w '$windowsSourceDir'`) if isCygwin();
1049 sub windowsSourceDir()
1051 determineWindowsSourceDir();
1052 return $windowsSourceDir;
1055 sub windowsLibrariesDir()
1057 return windowsSourceDir() . "\\WebKitLibraries\\win";
1060 sub windowsOutputDir()
1062 return windowsSourceDir() . "\\WebKitBuild";
1065 sub setupAppleWinEnv()
1067 return unless isAppleWinWebKit();
1069 if (isWindowsNT()) {
1070 my $restartNeeded = 0;
1071 my %variablesToSet = ();
1073 # Setting the environment variable 'CYGWIN' to 'tty' makes cygwin enable extra support (i.e., termios)
1074 # for UNIX-like ttys in the Windows console
1075 $variablesToSet{CYGWIN} = "tty" unless $ENV{CYGWIN};
1077 # Those environment variables must be set to be able to build inside Visual Studio.
1078 $variablesToSet{WEBKITLIBRARIESDIR} = windowsLibrariesDir() unless $ENV{WEBKITLIBRARIESDIR};
1079 $variablesToSet{WEBKITOUTPUTDIR} = windowsOutputDir() unless $ENV{WEBKITOUTPUTDIR};
1081 foreach my $variable (keys %variablesToSet) {
1082 print "Setting the Environment Variable '" . $variable . "' to '" . $variablesToSet{$variable} . "'\n\n";
1083 system qw(regtool -s set), '\\HKEY_CURRENT_USER\\Environment\\' . $variable, $variablesToSet{$variable};
1084 $restartNeeded ||= $variable eq "WEBKITLIBRARIESDIR" || $variable eq "WEBKITOUTPUTDIR";
1087 if ($restartNeeded) {
1088 print "Please restart your computer before attempting to build inside Visual Studio.\n\n";
1091 if (!$ENV{'WEBKITLIBRARIESDIR'}) {
1092 print "Warning: You must set the 'WebKitLibrariesDir' environment variable\n";
1093 print " to be able build WebKit from within Visual Studio.\n";
1094 print " Make sure that 'WebKitLibrariesDir' points to the\n";
1095 print " 'WebKitLibraries/win' directory, not the 'WebKitLibraries/' directory.\n\n";
1097 if (!$ENV{'WEBKITOUTPUTDIR'}) {
1098 print "Warning: You must set the 'WebKitOutputDir' environment variable\n";
1099 print " to be able build WebKit from within Visual Studio.\n\n";
1104 sub setupCygwinEnv()
1106 return if !isCygwin() && !isWindows();
1107 return if $vcBuildPath;
1110 my $programFilesPath = $ENV{'PROGRAMFILES(X86)'} || $ENV{'PROGRAMFILES'} || "C:\\Program Files";
1111 if ($ENV{'VSINSTALLDIR'}) {
1112 $vsInstallDir = $ENV{'VSINSTALLDIR'};
1114 $vsInstallDir = File::Spec->catdir($programFilesPath, "Microsoft Visual Studio 8");
1116 chomp($vsInstallDir = `cygpath "$vsInstallDir"`) if isCygwin();
1117 $vcBuildPath = File::Spec->catfile($vsInstallDir, qw(Common7 IDE devenv.com));
1118 if (-e $vcBuildPath) {
1119 # Visual Studio is installed; we can use pdevenv to build.
1120 # FIXME: Make pdevenv work with non-Cygwin Perl.
1121 $vcBuildPath = File::Spec->catfile(sourceDir(), qw(Tools Scripts pdevenv)) if isCygwin();
1123 # Visual Studio not found, try VC++ Express
1124 $vcBuildPath = File::Spec->catfile($vsInstallDir, qw(Common7 IDE VCExpress.exe));
1125 if (! -e $vcBuildPath) {
1126 print "*************************************************************\n";
1127 print "Cannot find '$vcBuildPath'\n";
1128 print "Please execute the file 'vcvars32.bat' from\n";
1129 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
1130 print "to setup the necessary environment variables.\n";
1131 print "*************************************************************\n";
1134 $willUseVCExpressWhenBuilding = 1;
1137 my $qtSDKPath = File::Spec->catdir($programFilesPath, "QuickTime SDK");
1138 if (0 && ! -e $qtSDKPath) {
1139 print "*************************************************************\n";
1140 print "Cannot find '$qtSDKPath'\n";
1141 print "Please download the QuickTime SDK for Windows from\n";
1142 print "http://developer.apple.com/quicktime/download/\n";
1143 print "*************************************************************\n";
1147 unless ($ENV{WEBKITLIBRARIESDIR}) {
1148 $ENV{'WEBKITLIBRARIESDIR'} = File::Spec->catdir($sourceDir, "WebKitLibraries", "win");
1149 chomp($ENV{WEBKITLIBRARIESDIR} = `cygpath -wa $ENV{WEBKITLIBRARIESDIR}`) if isCygwin();
1152 print "Building results into: ", baseProductDir(), "\n";
1153 print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
1154 print "WEBKITLIBRARIESDIR is set to: ", $ENV{"WEBKITLIBRARIESDIR"}, "\n";
1157 sub dieIfWindowsPlatformSDKNotInstalled
1159 my $registry32Path = "/proc/registry/";
1160 my $registry64Path = "/proc/registry64/";
1161 my $windowsPlatformSDKRegistryEntry = "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1";
1163 # FIXME: It would be better to detect whether we are using 32- or 64-bit Windows
1164 # and only check the appropriate entry. But for now we just blindly check both.
1165 return if (-e $registry32Path . $windowsPlatformSDKRegistryEntry) || (-e $registry64Path . $windowsPlatformSDKRegistryEntry);
1167 print "*************************************************************\n";
1168 print "Cannot find registry entry '$windowsPlatformSDKRegistryEntry'.\n";
1169 print "Please download and install the Microsoft Windows Server 2003 R2\n";
1170 print "Platform SDK from <http://www.microsoft.com/downloads/details.aspx?\n";
1171 print "familyid=0baf2b35-c656-4969-ace8-e4c0c0716adb&displaylang=en>.\n\n";
1172 print "Then follow step 2 in the Windows section of the \"Installing Developer\n";
1173 print "Tools\" instructions at <http://www.webkit.org/building/tools.html>.\n";
1174 print "*************************************************************\n";
1178 sub copyInspectorFrontendFiles
1180 my $productDir = productDir();
1181 my $sourceInspectorPath = sourceDir() . "/Source/WebCore/inspector/front-end/";
1182 my $inspectorResourcesDirPath = $ENV{"WEBKITINSPECTORRESOURCESDIR"};
1184 if (!defined($inspectorResourcesDirPath)) {
1185 $inspectorResourcesDirPath = "";
1188 if (isAppleMacWebKit()) {
1189 $inspectorResourcesDirPath = $productDir . "/WebCore.framework/Resources/inspector";
1190 } elsif (isAppleWinWebKit()) {
1191 $inspectorResourcesDirPath = $productDir . "/WebKit.resources/inspector";
1192 } elsif (isQt() || isGtk()) {
1193 my $prefix = $ENV{"WebKitInstallationPrefix"};
1194 $inspectorResourcesDirPath = (defined($prefix) ? $prefix : "/usr/share") . "/webkit-1.0/webinspector";
1196 my $prefix = $ENV{"WebKitInstallationPrefix"};
1197 $inspectorResourcesDirPath = (defined($prefix) ? $prefix : "/usr/share") . "/ewebkit/webinspector";
1200 if (! -d $inspectorResourcesDirPath) {
1201 print "*************************************************************\n";
1202 print "Cannot find '$inspectorResourcesDirPath'.\n" if (defined($inspectorResourcesDirPath));
1203 print "Make sure that you have built WebKit first.\n" if (! -d $productDir || defined($inspectorResourcesDirPath));
1204 print "Optionally, set the environment variable 'WebKitInspectorResourcesDir'\n";
1205 print "to point to the directory that contains the WebKit Inspector front-end\n";
1206 print "files for the built WebCore framework.\n";
1207 print "*************************************************************\n";
1210 return system "rsync", "-aut", "--exclude=/.DS_Store", "--exclude=*.re2js", "--exclude=.svn/", !isQt() ? "--exclude=/WebKit.qrc" : "", $sourceInspectorPath, $inspectorResourcesDirPath;
1213 sub buildXCodeProject($$@)
1215 my ($project, $clean, @extraOptions) = @_;
1218 push(@extraOptions, "-alltargets");
1219 push(@extraOptions, "clean");
1222 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
1225 sub usingVisualStudioExpress()
1228 return $willUseVCExpressWhenBuilding;
1231 sub buildVisualStudioProject
1233 my ($project, $clean) = @_;
1236 my $config = configurationForVisualStudio();
1238 dieIfWindowsPlatformSDKNotInstalled() if $willUseVCExpressWhenBuilding;
1240 chomp($project = `cygpath -w "$project"`) if isCygwin();
1242 my $action = "/build";
1247 my @command = ($vcBuildPath, $project, $action, $config);
1249 print join(" ", @command), "\n";
1250 return system @command;
1253 sub downloadWafIfNeeded
1255 # get / update waf if needed
1256 my $waf = "$sourceDir/Tools/wx/waf";
1257 my $wafURL = 'http://wxwebkit.wxcommunity.com/downloads/deps/waf';
1259 my $result = system "curl -o $waf $wafURL";
1266 my ($project, $shouldClean, @options) = @_;
1268 # set the PYTHONPATH for waf
1269 my $pythonPath = $ENV{'PYTHONPATH'};
1270 if (!defined($pythonPath)) {
1273 my $sourceDir = sourceDir();
1274 my $newPythonPath = "$sourceDir/Tools/wx/build:$pythonPath";
1276 $newPythonPath = `cygpath --mixed --path $newPythonPath`;
1278 $ENV{'PYTHONPATH'} = $newPythonPath;
1280 print "Building $project\n";
1282 my $wafCommand = "$sourceDir/Tools/wx/waf";
1283 if ($ENV{'WXWEBKIT_WAF'}) {
1284 $wafCommand = $ENV{'WXWEBKIT_WAF'};
1287 $wafCommand = `cygpath --windows "$wafCommand"`;
1291 return system $wafCommand, "clean", "distclean";
1294 return system $wafCommand, 'configure', 'build', 'install', @options;
1297 sub retrieveQMakespecVar
1300 my $varname = $_[1];
1302 my $varvalue = undef;
1303 #print "retrieveMakespecVar " . $mkspec . ", " . $varname . "\n";
1306 open SPEC, "<$mkspec" or return $varvalue;
1308 if ($_ =~ /\s*include\((.+)\)/) {
1309 # open the included mkspec
1310 my $oldcwd = getcwd();
1311 (my $volume, my $directories, my $file) = File::Spec->splitpath($mkspec);
1312 my $newcwd = "$volume$directories";
1313 chdir $newcwd if $newcwd;
1314 $varvalue = retrieveQMakespecVar($1, $varname);
1316 } elsif ($_ =~ /$varname\s*=\s*([^\s]+)/) {
1325 sub qtMakeCommand($)
1327 my ($qmakebin) = @_;
1328 chomp(my $mkspec = `$qmakebin -query QMAKE_MKSPECS`);
1329 $mkspec .= "/default";
1330 my $compiler = retrieveQMakespecVar("$mkspec/qmake.conf", "QMAKE_CC");
1332 #print "default spec: " . $mkspec . "\n";
1333 #print "compiler found: " . $compiler . "\n";
1335 if ($compiler && $compiler eq "cl") {
1342 sub autotoolsFlag($$)
1344 my ($flag, $feature) = @_;
1345 my $prefix = $flag ? "--enable" : "--disable";
1347 return $prefix . '-' . $feature;
1350 sub autogenArgumentsHaveChanged($@)
1352 my ($filename, @currentArguments) = @_;
1354 if (! -e $filename) {
1358 open(AUTOTOOLS_ARGUMENTS, $filename);
1359 chomp(my $previousArguments = <AUTOTOOLS_ARGUMENTS>);
1360 close(AUTOTOOLS_ARGUMENTS);
1362 return $previousArguments ne join(" ", @currentArguments);
1365 sub buildAutotoolsProject($@)
1367 my ($project, $clean, @buildParams) = @_;
1370 my $dir = productDir();
1371 my $config = passedConfiguration() || configuration();
1375 my $makeArgs = $ENV{"WebKitMakeArguments"} || "";
1376 for my $i (0 .. $#buildParams) {
1377 my $opt = $buildParams[$i];
1378 if ($opt =~ /^--makeargs=(.*)/i ) {
1379 $makeArgs = $makeArgs . " " . $1;
1380 } elsif ($opt =~ /^--prefix=(.*)/i ) {
1383 push @buildArgs, $opt;
1387 # Automatically determine the number of CPUs for make only
1388 # if make arguments haven't already been specified.
1389 if ($makeArgs eq "") {
1390 $makeArgs = "-j" . numberOfCPUs();
1393 # WebKit is the default target, so we don't need to specify anything.
1394 if ($project eq "JavaScriptCore") {
1395 $makeArgs .= " jsc";
1398 $prefix = $ENV{"WebKitInstallationPrefix"} if !defined($prefix);
1399 push @buildArgs, "--prefix=" . $prefix if defined($prefix);
1401 # check if configuration is Debug
1402 if ($config =~ m/debug/i) {
1403 push @buildArgs, "--enable-debug";
1405 push @buildArgs, "--disable-debug";
1408 # Use rm to clean the build directory since distclean may miss files
1409 if ($clean && -d $dir) {
1410 system "rm", "-rf", "$dir";
1414 File::Path::mkpath($dir) or die "Failed to create build directory " . $dir
1416 chdir $dir or die "Failed to cd into " . $dir . "\n";
1422 # If GNUmakefile exists, don't run autogen.sh. The makefile should be
1423 # smart enough to track autotools dependencies and re-run autogen.sh
1424 # when build files change.
1425 my $autogenArgumentsFile = "previous-autogen-arguments.txt";
1427 if (!(-e "GNUmakefile") or autogenArgumentsHaveChanged($autogenArgumentsFile, @buildArgs)) {
1429 # Write autogen.sh arguments to a file so that we can detect
1430 # when they change and automatically re-run it.
1431 open(AUTOTOOLS_ARGUMENTS, ">$autogenArgumentsFile");
1432 print AUTOTOOLS_ARGUMENTS join(" ", @buildArgs);
1433 close(AUTOTOOLS_ARGUMENTS);
1435 print "Calling configure in " . $dir . "\n\n";
1436 print "Installation prefix directory: $prefix\n" if(defined($prefix));
1438 # Make the path relative since it will appear in all -I compiler flags.
1439 # Long argument lists cause bizarre slowdowns in libtool.
1440 my $relSourceDir = File::Spec->abs2rel($sourceDir) || ".";
1441 $result = system "$relSourceDir/autogen.sh", @buildArgs;
1443 die "Failed to setup build environment using 'autotools'!\n";
1447 $result = system "$make $makeArgs";
1449 die "\nFailed to build WebKit using '$make'!\n";
1456 sub buildCMakeProject($@)
1458 my ($port, $clean, @buildParams) = @_;
1459 my $dir = File::Spec->canonpath(baseProductDir());
1460 my $config = configuration();
1462 my $cmakeBuildArgs = "";
1466 if ($port =~ m/wince/i) {
1467 if ($config =~ m/debug/i) {
1468 $cmakeBuildArgs .= " --config Debug";
1469 } elsif ($config =~ m/release/i) {
1470 $cmakeBuildArgs .= " --config Release";
1473 $makeArgs .= " -j" . numberOfCPUs() if ($makeArgs !~ m/-j\s*\d+/);
1477 print "Cleaning the build directory '$dir'\n";
1478 $dir = File::Spec->catfile($dir, $config);
1479 File::Path::remove_tree($dir, {keep_root => 1});
1482 my $cmakebin = "cmake";
1483 my $cmakeBuildCommand = $cmakebin . " --build .";
1485 push @buildArgs, "-DPORT=$port";
1487 for my $i (0 .. $#buildParams) {
1488 my $opt = $buildParams[$i];
1489 if ($opt =~ /^--makeargs=(.*)/i ) {
1491 } elsif ($opt =~ /^--prefix=(.*)/i ) {
1492 push @buildArgs, "-DCMAKE_INSTALL_PREFIX=$1";
1494 push @buildArgs, $opt;
1498 if ($config =~ m/debug/i) {
1499 push @buildArgs, "-DCMAKE_BUILD_TYPE=Debug";
1500 } elsif ($config =~ m/release/i) {
1501 push @buildArgs, "-DCMAKE_BUILD_TYPE=Release";
1504 push @buildArgs, sourceDir() . "/Source";
1506 $dir = File::Spec->catfile($dir, $config);
1507 File::Path::mkpath($dir);
1508 chdir $dir or die "Failed to cd into " . $dir . "\n";
1510 print "Calling '$cmakebin @buildArgs' in " . $dir . "\n\n";
1511 my $result = system "$cmakebin @buildArgs";
1513 die "Failed while running $cmakebin to generate makefiles!\n";
1516 $cmakeBuildArgs .= " -- " . $makeArgs;
1518 print "Calling '$cmakeBuildCommand $cmakeBuildArgs' in " . $dir . "\n\n";
1519 $result = system "$cmakeBuildCommand $cmakeBuildArgs";
1521 die "Failed to build $port port\n";
1530 sub buildCMakeEflProject($@)
1532 my ($clean, @buildArgs) = @_;
1533 return buildCMakeProject("Efl", $clean, @buildArgs);
1536 sub buildCMakeWinCEProject($@)
1538 my ($sdk, $clean, @buildArgs) = @_;
1539 return buildCMakeProject("WinCE -DCMAKE_WINCE_SDK=\"" . $sdk . "\"", $clean, @buildArgs);
1542 sub buildQMakeProject($@)
1544 my ($clean, @buildParams) = @_;
1546 my @buildArgs = ("-r");
1548 my $qmakebin = "qmake"; # Allow override of the qmake binary from $PATH
1552 for my $i (0 .. $#buildParams) {
1553 my $opt = $buildParams[$i];
1554 if ($opt =~ /^--qmake=(.*)/i ) {
1556 } elsif ($opt =~ /^--qmakearg=(.*)/i ) {
1557 push @buildArgs, $1;
1558 } elsif ($opt =~ /^--makeargs=(.*)/i ) {
1560 } elsif ($opt =~ /^--install-headers=(.*)/i ) {
1561 $installHeaders = $1;
1562 } elsif ($opt =~ /^--install-libs=(.*)/i ) {
1565 push @buildArgs, $opt;
1569 my $make = qtMakeCommand($qmakebin);
1570 my $config = configuration();
1571 push @buildArgs, "INSTALL_HEADERS=" . $installHeaders if defined($installHeaders);
1572 push @buildArgs, "INSTALL_LIBS=" . $installLibs if defined($installLibs);
1573 my $dir = File::Spec->canonpath(productDir());
1574 File::Path::mkpath($dir);
1575 chdir $dir or die "Failed to cd into " . $dir . "\n";
1577 print "Generating derived sources\n\n";
1579 push @buildArgs, "OUTPUT_DIR=" . $dir;
1581 my @dsQmakeArgs = @buildArgs;
1582 push @dsQmakeArgs, "-r";
1583 push @dsQmakeArgs, sourceDir() . "/Source/DerivedSources.pro";
1584 push @dsQmakeArgs, "-o Makefile.DerivedSources";
1585 print "Calling '$qmakebin @dsQmakeArgs' in " . $dir . "\n\n";
1586 my $result = system "$qmakebin @dsQmakeArgs";
1588 die "Failed while running $qmakebin to generate derived sources!\n";
1591 # FIXME: Iterate over different source directories manually to workaround a problem with qmake+extraTargets+s60
1592 # To avoid overwriting of Makefile.DerivedSources in the root dir use Makefile.DerivedSources.Tools for Tools
1593 my @subdirs = ("JavaScriptCore", "WebCore", "WebKit/qt/Api");
1594 if (grep { $_ eq "CONFIG+=webkit2"} @buildArgs) {
1595 push @subdirs, "WebKit2";
1596 if ( -e sourceDir() ."/Tools/DerivedSources.pro" ) {
1597 @dsQmakeArgs = @buildArgs;
1598 push @dsQmakeArgs, "-r";
1599 push @dsQmakeArgs, sourceDir() . "/Tools/DerivedSources.pro";
1600 push @dsQmakeArgs, "-o Makefile.DerivedSources.Tools";
1601 print "Calling '$qmakebin @dsQmakeArgs' in " . $dir . "\n\n";
1602 my $result = system "$qmakebin @dsQmakeArgs";
1604 die "Failed while running $qmakebin to generate derived sources for Tools!\n";
1606 push @subdirs, "MiniBrowser";
1607 push @subdirs, "WebKitTestRunner";
1611 for my $subdir (@subdirs) {
1612 my $dsMakefile = "Makefile.DerivedSources";
1613 print "Calling '$make $makeargs -C $subdir -f $dsMakefile generated_files' in " . $dir . "/$subdir\n\n";
1614 if ($make eq "nmake") {
1615 my $subdirWindows = $subdir;
1616 $subdirWindows =~ s:/:\\:g;
1617 $result = system "pushd $subdirWindows && $make $makeargs -f $dsMakefile generated_files && popd";
1619 $result = system "$make $makeargs -C $subdir -f $dsMakefile generated_files";
1622 die "Failed to generate ${subdir}'s derived sources!\n";
1626 if ($config =~ m/debug/i) {
1627 push @buildArgs, "CONFIG-=release";
1628 push @buildArgs, "CONFIG+=debug";
1630 my $passedConfig = passedConfiguration() || "";
1631 if (!isDarwin() || $passedConfig =~ m/release/i) {
1632 push @buildArgs, "CONFIG+=release";
1633 push @buildArgs, "CONFIG-=debug";
1635 push @buildArgs, "CONFIG+=debug";
1636 push @buildArgs, "CONFIG+=debug_and_release";
1640 push @buildArgs, sourceDir() . "/Source/WebKit.pro";
1641 print "Calling '$qmakebin @buildArgs' in " . $dir . "\n\n";
1642 print "Installation headers directory: $installHeaders\n" if(defined($installHeaders));
1643 print "Installation libraries directory: $installLibs\n" if(defined($installLibs));
1645 $result = system "$qmakebin @buildArgs";
1647 die "Failed to setup build environment using $qmakebin!\n";
1650 $buildArgs[-1] = sourceDir() . "/Tools/Tools.pro";
1651 print "Calling '$qmakebin @buildArgs -o Makefile.Tools' in " . $dir . "\n\n";
1653 $result = system "$qmakebin @buildArgs -o Makefile.Tools";
1655 die "Failed to setup build environment using $qmakebin!\n";
1658 # Manually create makefiles for the examples so we don't build by default
1659 my $examplesDir = $dir . "/WebKit/qt/examples";
1660 File::Path::mkpath($examplesDir);
1661 $buildArgs[-1] = sourceDir() . "/Source/WebKit/qt/examples/examples.pro";
1662 chdir $examplesDir or die;
1663 print "Calling '$qmakebin @buildArgs' in " . $examplesDir . "\n\n";
1664 $result = system "$qmakebin @buildArgs";
1665 die "Failed to create makefiles for the examples!\n" if $result ne 0;
1668 my $makeTools = "echo No Makefile for Tools. Skipping make";
1670 if (-e "$dir/Makefile.Tools") {
1671 $makeTools = "$make $makeargs -f Makefile.Tools";
1675 print "Calling '$make $makeargs distclean' in " . $dir . "\n\n";
1676 $result = system "$make $makeargs distclean";
1677 $result = $result || system "$makeTools distclean";
1678 } elsif (isSymbian()) {
1679 print "\n\nWebKit is now configured for building, but you have to make\n";
1680 print "a choice about the target yourself. To start the build run:\n\n";
1681 print " make release-armv5|debug-winscw|etc.\n\n";
1683 print "Calling '$make $makeargs' in " . $dir . "\n\n";
1684 $result = system "$make $makeargs";
1685 $result = $result || system "$makeTools";
1692 sub buildQMakeQtProject($$@)
1694 my ($project, $clean, @buildArgs) = @_;
1696 return buildQMakeProject($clean, @buildArgs);
1701 my ($project, $clean, @buildArgs) = @_;
1703 if ($project ne "WebKit" and $project ne "JavaScriptCore") {
1704 die "Unsupported project: $project. Supported projects: WebKit, JavaScriptCore\n";
1707 return buildAutotoolsProject($project, $clean, @buildArgs);
1710 sub buildChromiumMakefile($$)
1712 my ($target, $clean) = @_;
1714 return system qw(rm -rf out);
1716 my $config = configuration();
1717 my $numCpus = numberOfCPUs();
1718 my @command = ("make", "-fMakefile.chromium", "-j$numCpus", "BUILDTYPE=$config", $target);
1719 print join(" ", @command) . "\n";
1720 return system @command;
1723 sub buildChromiumVisualStudioProject($$)
1725 my ($projectPath, $clean) = @_;
1727 my $config = configuration();
1728 my $action = "/build";
1729 $action = "/clean" if $clean;
1731 # Find Visual Studio installation.
1733 my $programFilesPath = $ENV{'PROGRAMFILES'} || "C:\\Program Files";
1734 if ($ENV{'VSINSTALLDIR'}) {
1735 $vsInstallDir = $ENV{'VSINSTALLDIR'};
1737 $vsInstallDir = "$programFilesPath/Microsoft Visual Studio 8";
1739 $vsInstallDir = `cygpath "$vsInstallDir"` if isCygwin();
1740 chomp $vsInstallDir;
1741 $vcBuildPath = "$vsInstallDir/Common7/IDE/devenv.com";
1742 if (! -e $vcBuildPath) {
1743 # Visual Studio not found, try VC++ Express
1744 $vcBuildPath = "$vsInstallDir/Common7/IDE/VCExpress.exe";
1745 if (! -e $vcBuildPath) {
1746 print "*************************************************************\n";
1747 print "Cannot find '$vcBuildPath'\n";
1748 print "Please execute the file 'vcvars32.bat' from\n";
1749 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
1750 print "to setup the necessary environment variables.\n";
1751 print "*************************************************************\n";
1756 # Create command line and execute it.
1757 my @command = ($vcBuildPath, $projectPath, $action, $config);
1758 print "Building results into: ", baseProductDir(), "\n";
1759 print join(" ", @command), "\n";
1760 return system @command;
1763 sub buildChromium($@)
1765 my ($clean, @options) = @_;
1767 # We might need to update DEPS or re-run GYP if things have changed.
1768 if (checkForArgumentAndRemoveFromArrayRef("--update-chromium", \@options)) {
1769 system("perl", "Tools/Scripts/update-webkit-chromium") == 0 or die $!;
1774 # Mac build - builds the root xcode project.
1775 $result = buildXCodeProject("Source/WebKit/chromium/WebKit", $clean, "-configuration", configuration(), @options);
1776 } elsif (isCygwin() || isWindows()) {
1777 # Windows build - builds the root visual studio solution.
1778 $result = buildChromiumVisualStudioProject("Source/WebKit/chromium/WebKit.sln", $clean);
1779 } elsif (isLinux()) {
1780 # Linux build - build using make.
1781 $ result = buildChromiumMakefile("all", $clean);
1783 print STDERR "This platform is not supported by chromium.\n";
1788 sub appleApplicationSupportPath
1790 open INSTALL_DIR, "</proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Apple\ Inc./Apple\ Application\ Support/InstallDir";
1791 my $path = <INSTALL_DIR>;
1792 $path =~ s/[\r\n\x00].*//;
1795 my $unixPath = `cygpath -u '$path'`;
1800 sub setPathForRunningWebKitApp
1804 if (isAppleWinWebKit()) {
1805 $env->{PATH} = join(':', productDir(), dirname(installedSafariPath()), appleApplicationSupportPath(), $env->{PATH} || "");
1807 my $qtLibs = `qmake -query QT_INSTALL_LIBS`;
1808 $qtLibs =~ s/[\n|\r]$//g;
1809 $env->{PATH} = join(';', $qtLibs, productDir() . "/lib", $env->{PATH} || "");
1815 my ($debugger) = @_;
1817 if (isAppleMacWebKit()) {
1818 return system "$FindBin::Bin/gdb-safari", argumentsForConfiguration() if $debugger;
1820 my $productDir = productDir();
1821 print "Starting Safari with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
1822 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1823 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
1824 if (!isTiger() && architecture()) {
1825 return system "arch", "-" . architecture(), safariPath(), @ARGV;
1827 return system safariPath(), @ARGV;
1831 if (isAppleWinWebKit()) {
1833 my $productDir = productDir();
1836 chomp($ENV{WEBKITNIGHTLY} = `cygpath -wa "$productDir"`);
1837 my $safariPath = safariPath();
1838 chomp($safariPath = `cygpath -wa "$safariPath"`);
1839 $result = system $vcBuildPath, "/debugexe", "\"$safariPath\"", @ARGV;
1841 $result = system File::Spec->catfile(productDir(), "WebKit.exe"), @ARGV;
1843 return $result if $result;
1851 if (isAppleMacWebKit()) {
1852 my $productDir = productDir();
1853 print "Starting MiniBrowser with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
1854 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1855 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
1856 my $miniBrowserPath = "$productDir/MiniBrowser.app/Contents/MacOS/MiniBrowser";
1857 if (!isTiger() && architecture()) {
1858 return system "arch", "-" . architecture(), $miniBrowserPath, @ARGV;
1860 return system $miniBrowserPath, @ARGV;
1867 sub debugMiniBrowser
1869 if (isAppleMacWebKit()) {
1870 my $gdbPath = "/usr/bin/gdb";
1871 die "Can't find gdb executable. Is gdb installed?\n" unless -x $gdbPath;
1873 my $productDir = productDir();
1875 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1876 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = 'YES';
1878 my $miniBrowserPath = "$productDir/MiniBrowser.app/Contents/MacOS/MiniBrowser";
1880 print "Starting MiniBrowser under gdb with DYLD_FRAMEWORK_PATH set to point to built WebKit2 in $productDir.\n";
1881 my @architectureFlags = ("-arch", architecture()) if !isTiger();
1882 exec $gdbPath, @architectureFlags, $miniBrowserPath or die;
1889 sub runWebKitTestRunner
1891 if (isAppleMacWebKit()) {
1892 my $productDir = productDir();
1893 print "Starting WebKitTestRunner with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
1894 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1895 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
1896 my $webKitTestRunnerPath = "$productDir/WebKitTestRunner";
1897 if (!isTiger() && architecture()) {
1898 return system "arch", "-" . architecture(), $webKitTestRunnerPath, @ARGV;
1900 return system $webKitTestRunnerPath, @ARGV;
1907 sub debugWebKitTestRunner
1909 if (isAppleMacWebKit()) {
1910 my $gdbPath = "/usr/bin/gdb";
1911 die "Can't find gdb executable. Is gdb installed?\n" unless -x $gdbPath;
1913 my $productDir = productDir();
1914 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1915 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = 'YES';
1917 my $webKitTestRunnerPath = "$productDir/WebKitTestRunner";
1919 print "Starting WebKitTestRunner under gdb with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
1920 my @architectureFlags = ("-arch", architecture()) if !isTiger();
1921 exec $gdbPath, @architectureFlags, $webKitTestRunnerPath or die;
1928 sub runTestWebKitAPI
1930 if (isAppleMacWebKit()) {
1931 my $productDir = productDir();
1932 print "Starting TestWebKitAPI with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
1933 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1934 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
1935 my $testWebKitAPIPath = "$productDir/TestWebKitAPI";
1936 if (!isTiger() && architecture()) {
1937 return system "arch", "-" . architecture(), $testWebKitAPIPath, @ARGV;
1939 return system $testWebKitAPIPath, @ARGV;