1 # Copyright (C) 2005, 2006, 2007, 2010 Apple Inc. All rights reserved.
2 # Copyright (C) 2009 Google Inc. All rights reserved.
3 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 # its contributors may be used to endorse or promote products derived
16 # from this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # Module to share code to get to WebKit directories.
36 use File::Path qw(mkpath rmtree);
43 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
46 @EXPORT = qw(&chdirWebKit &baseProductDir &productDir &XcodeOptions &XcodeOptionString &XcodeOptionStringNoConfig &passedConfiguration &setConfiguration &safariPath &checkFrameworks ¤tSVNRevision);
56 my @baseProductDirOption;
58 my $configurationForVisualStudio;
59 my $configurationProductDir;
61 my $currentSVNRevision;
65 my $qmakebin = "qmake"; # Allow override of the qmake binary from $PATH
67 my %qtFeatureDefaults;
75 my $isChromiumAndroid;
76 my $isInspectorFrontend;
79 # Variables for Win32 support
83 my $willUseVCExpressWhenBuilding = 0;
85 # Defined in VCSUtils.
88 sub determineSourceDir
91 $sourceDir = $FindBin::Bin;
92 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
94 # walks up path checking each directory to see if it is the main WebKit project dir,
95 # defined by containing Sources, WebCore, and WebKit
96 until ((-d "$sourceDir/Source" && -d "$sourceDir/Source/WebCore" && -d "$sourceDir/Source/WebKit") || (-d "$sourceDir/Internal" && -d "$sourceDir/OpenSource"))
98 if ($sourceDir !~ s|/[^/]+$||) {
99 die "Could not find top level webkit directory above source directory using FindBin.\n";
103 $sourceDir = "$sourceDir/OpenSource" if -d "$sourceDir/OpenSource";
106 sub currentPerlPath()
110 $thisPerl .= $Config{_exe} unless $thisPerl =~ m/$Config{_exe}$/i;
115 sub setQmakeBinaryPath($)
120 # used for scripts which are stored in a non-standard location
126 sub determineBaseProductDir
128 return if defined $baseProductDir;
129 determineSourceDir();
131 $baseProductDir = $ENV{"WEBKITOUTPUTDIR"};
133 if (!defined($baseProductDir) and isAppleMacWebKit()) {
134 # Silently remove ~/Library/Preferences/xcodebuild.plist which can
135 # cause build failure. The presence of
136 # ~/Library/Preferences/xcodebuild.plist can prevent xcodebuild from
137 # respecting global settings such as a custom build products directory
138 # (<rdar://problem/5585899>).
139 my $personalPlistFile = $ENV{HOME} . "/Library/Preferences/xcodebuild.plist";
140 if (-e $personalPlistFile) {
141 unlink($personalPlistFile) || die "Could not delete $personalPlistFile: $!";
144 my $xcodebuildVersionOutput = `xcodebuild -version`;
145 my $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : "3.0";
146 my $xcodeDefaultsDomain = (eval "v$xcodeVersion" lt v4) ? "com.apple.Xcode" : "com.apple.dt.Xcode";
147 my $xcodeDefaultsPrefix = (eval "v$xcodeVersion" lt v4) ? "PBX" : "IDE";
149 open PRODUCT, "defaults read $xcodeDefaultsDomain ${xcodeDefaultsPrefix}ApplicationwideBuildSettings 2> " . File::Spec->devnull() . " |" or die;
150 $baseProductDir = join '', <PRODUCT>;
153 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
154 undef $baseProductDir unless $baseProductDir =~ /^\//;
155 } elsif (isSymbian()) {
156 # Shadow builds are not supported on Symbian
157 $baseProductDir = $sourceDir;
158 } elsif (isChromium()) {
159 if (isLinux() || isChromiumAndroid()) {
160 $baseProductDir = "$sourceDir/out";
161 } elsif (isDarwin()) {
162 $baseProductDir = "$sourceDir/Source/WebKit/chromium/xcodebuild";
163 } elsif (isWindows() || isCygwin()) {
164 # FIXME: set the correct baseProductDir for chromium-win.
168 if (!defined($baseProductDir)) { # Port-spesific checks failed, use default
169 $baseProductDir = "$sourceDir/WebKitBuild";
172 if (isGit() && isGitBranchBuild()) {
173 my $branch = gitBranch();
174 $baseProductDir = "$baseProductDir/$branch";
177 if (isAppleMacWebKit()) {
178 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
179 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
180 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
181 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
182 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
183 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir");
187 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
189 $ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
190 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
191 chomp $unixBuildPath;
192 $baseProductDir = $unixBuildPath;
196 sub setBaseProductDir($)
198 ($baseProductDir) = @_;
201 sub determineConfiguration
203 return if defined $configuration;
204 determineBaseProductDir();
205 if (open CONFIGURATION, "$baseProductDir/Configuration") {
206 $configuration = <CONFIGURATION>;
209 if ($configuration) {
210 chomp $configuration;
211 # compatibility for people who have old Configuration files
212 $configuration = "Release" if $configuration eq "Deployment";
213 $configuration = "Debug" if $configuration eq "Development";
215 $configuration = "Release";
218 if ($configuration && isWinCairo()) {
219 $configuration .= "_Cairo_CFLite";
223 sub determineArchitecture
225 return if defined $architecture;
226 # make sure $architecture is defined for non-apple-mac builds
228 return unless isAppleMacWebKit();
230 determineBaseProductDir();
231 if (open ARCHITECTURE, "$baseProductDir/Architecture") {
232 $architecture = <ARCHITECTURE>;
239 $architecture = `arch`;
241 my $supports64Bit = `sysctl -n hw.optional.x86_64`;
242 chomp $supports64Bit;
243 $architecture = $supports64Bit ? 'x86_64' : `arch`;
249 sub determineNumberOfCPUs
251 return if defined $numberOfCPUs;
253 # First try the nproc utility, if it exists. If we get no
254 # results fall back to just interpretting /proc directly.
255 chomp($numberOfCPUs = `nproc 2> /dev/null`);
256 if ($numberOfCPUs eq "") {
257 $numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`);
259 } elsif (isWindows() || isCygwin()) {
260 if (defined($ENV{NUMBER_OF_PROCESSORS})) {
261 $numberOfCPUs = $ENV{NUMBER_OF_PROCESSORS};
264 $numberOfCPUs = `ls /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor | wc -w`;
266 } elsif (isDarwin()) {
267 $numberOfCPUs = `sysctl -n hw.ncpu`;
273 my ($productDir) = @_;
275 $jscName .= "_debug" if configurationForVisualStudio() eq "Debug_All";
276 $jscName .= ".exe" if (isWindows() || isCygwin());
277 return "$productDir/$jscName" if -e "$productDir/$jscName";
278 return "$productDir/JavaScriptCore.framework/Resources/$jscName";
281 sub argumentsForConfiguration()
283 determineConfiguration();
284 determineArchitecture();
287 push(@args, '--debug') if $configuration eq "Debug";
288 push(@args, '--release') if $configuration eq "Release";
289 push(@args, '--32-bit') if $architecture ne "x86_64";
290 push(@args, '--qt') if isQt();
291 push(@args, '--symbian') if isSymbian();
292 push(@args, '--gtk') if isGtk();
293 push(@args, '--efl') if isEfl();
294 push(@args, '--wince') if isWinCE();
295 push(@args, '--wx') if isWx();
296 push(@args, '--chromium') if isChromium() && !isChromiumAndroid();
297 push(@args, '--chromium-android') if isChromiumAndroid();
298 push(@args, '--inspector-frontend') if isInspectorFrontend();
302 sub determineConfigurationForVisualStudio
304 return if defined $configurationForVisualStudio;
305 determineConfiguration();
306 # FIXME: We should detect when Debug_All or Production has been chosen.
307 $configurationForVisualStudio = $configuration;
310 sub usesPerConfigurationBuildDirectory
312 # [Gtk][Efl] We don't have Release/Debug configurations in straight
313 # autotool builds (non build-webkit). In this case and if
314 # WEBKITOUTPUTDIR exist, use that as our configuration dir. This will
315 # allows us to run run-webkit-tests without using build-webkit.
317 # Symbian builds do not have Release/Debug configurations either.
318 return ($ENV{"WEBKITOUTPUTDIR"} && (isGtk() || isEfl())) || isSymbian() || isAppleWinWebKit();
321 sub determineConfigurationProductDir
323 return if defined $configurationProductDir;
324 determineBaseProductDir();
325 determineConfiguration();
326 if (isAppleWinWebKit() && !isWx()) {
327 $configurationProductDir = File::Spec->catdir($baseProductDir, configurationForVisualStudio(), "bin");
329 if (usesPerConfigurationBuildDirectory()) {
330 $configurationProductDir = "$baseProductDir";
332 $configurationProductDir = "$baseProductDir/$configuration";
337 sub setConfigurationProductDir($)
339 ($configurationProductDir) = @_;
342 sub determineCurrentSVNRevision
344 return if defined $currentSVNRevision;
345 determineSourceDir();
346 $currentSVNRevision = svnRevisionForDirectory($sourceDir);
347 return $currentSVNRevision;
353 determineSourceDir();
354 chdir $sourceDir or die;
359 determineBaseProductDir();
360 return $baseProductDir;
365 determineSourceDir();
371 determineConfigurationProductDir();
372 return $configurationProductDir;
377 my $productDir = productDir();
378 $productDir .= "/JavaScriptCore" if isQt();
379 $productDir .= "/$configuration" if (isQt() && isWindows());
380 $productDir .= "/Programs" if (isGtk() || isEfl());
387 determineConfiguration();
388 return $configuration;
391 sub configurationForVisualStudio()
393 determineConfigurationForVisualStudio();
394 return $configurationForVisualStudio;
397 sub currentSVNRevision
399 determineCurrentSVNRevision();
400 return $currentSVNRevision;
405 determineGenerateDsym();
406 return $generateDsym;
409 sub determineGenerateDsym()
411 return if defined($generateDsym);
412 $generateDsym = checkForArgumentAndRemoveFromARGV("--dsym");
415 sub argumentsForXcode()
418 push @args, "DEBUG_INFORMATION_FORMAT=dwarf-with-dsym" if generateDsym();
424 determineBaseProductDir();
425 determineConfiguration();
426 determineArchitecture();
427 return (@baseProductDirOption, "-configuration", $configuration, "ARCHS=$architecture", argumentsForXcode());
430 sub XcodeOptionString
432 return join " ", XcodeOptions();
435 sub XcodeOptionStringNoConfig
437 return join " ", @baseProductDirOption;
440 sub XcodeCoverageSupportOptions()
442 my @coverageSupportOptions = ();
443 push @coverageSupportOptions, "GCC_GENERATE_TEST_COVERAGE_FILES=YES";
444 push @coverageSupportOptions, "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES";
445 push @coverageSupportOptions, "EXTRA_LINK= \$(EXTRA_LINK) -ftest-coverage -fprofile-arcs";
446 push @coverageSupportOptions, "OTHER_CFLAGS= \$(OTHER_CFLAGS) -DCOVERAGE -MD";
447 push @coverageSupportOptions, "OTHER_LDFLAGS=\$(OTHER_LDFLAGS) -ftest-coverage -fprofile-arcs -lgcov";
448 return @coverageSupportOptions;
451 my $passedConfiguration;
452 my $searchedForPassedConfiguration;
453 sub determinePassedConfiguration
455 return if $searchedForPassedConfiguration;
456 $searchedForPassedConfiguration = 1;
458 for my $i (0 .. $#ARGV) {
460 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
461 splice(@ARGV, $i, 1);
462 $passedConfiguration = "Debug";
463 $passedConfiguration .= "_Cairo_CFLite" if (isWinCairo() && isCygwin());
466 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
467 splice(@ARGV, $i, 1);
468 $passedConfiguration = "Release";
469 $passedConfiguration .= "_Cairo_CFLite" if (isWinCairo() && isCygwin());
472 if ($opt =~ /^--profil(e|ing)$/i) {
473 splice(@ARGV, $i, 1);
474 $passedConfiguration = "Profiling";
475 $passedConfiguration .= "_Cairo_CFLite" if (isWinCairo() && isCygwin());
479 $passedConfiguration = undef;
482 sub passedConfiguration
484 determinePassedConfiguration();
485 return $passedConfiguration;
492 if (my $config = shift @_) {
493 $configuration = $config;
497 determinePassedConfiguration();
498 $configuration = $passedConfiguration if $passedConfiguration;
502 my $passedArchitecture;
503 my $searchedForPassedArchitecture;
504 sub determinePassedArchitecture
506 return if $searchedForPassedArchitecture;
507 $searchedForPassedArchitecture = 1;
509 for my $i (0 .. $#ARGV) {
511 if ($opt =~ /^--32-bit$/i) {
512 splice(@ARGV, $i, 1);
513 if (isAppleMacWebKit() || isWx()) {
514 $passedArchitecture = `arch`;
515 chomp $passedArchitecture;
520 $passedArchitecture = undef;
523 sub passedArchitecture
525 determinePassedArchitecture();
526 return $passedArchitecture;
531 determineArchitecture();
532 return $architecture;
537 determineNumberOfCPUs();
538 return $numberOfCPUs;
543 if (my $arch = shift @_) {
544 $architecture = $arch;
548 determinePassedArchitecture();
549 $architecture = $passedArchitecture if $passedArchitecture;
553 sub safariPathFromSafariBundle
555 my ($safariBundle) = @_;
557 return "$safariBundle/Contents/MacOS/Safari" if isAppleMacWebKit();
558 return $safariBundle if isAppleWinWebKit();
561 sub installedSafariPath
565 if (isAppleMacWebKit()) {
566 $safariBundle = "/Applications/Safari.app";
567 } elsif (isAppleWinWebKit()) {
568 $safariBundle = `"$configurationProductDir/FindSafari.exe"`;
569 $safariBundle =~ s/[\r\n]+$//;
570 $safariBundle = `cygpath -u '$safariBundle'` if isCygwin();
571 $safariBundle =~ s/[\r\n]+$//;
572 $safariBundle .= "Safari.exe";
575 return safariPathFromSafariBundle($safariBundle);
581 # Use WEBKIT_SAFARI environment variable if present.
582 my $safariBundle = $ENV{WEBKIT_SAFARI};
583 if (!$safariBundle) {
584 determineConfigurationProductDir();
585 # Use Safari.app in product directory if present (good for Safari development team).
586 if (isAppleMacWebKit() && -d "$configurationProductDir/Safari.app") {
587 $safariBundle = "$configurationProductDir/Safari.app";
588 } elsif (isAppleWinWebKit()) {
589 my $path = "$configurationProductDir/Safari.exe";
590 my $debugPath = "$configurationProductDir/Safari_debug.exe";
592 if (configurationForVisualStudio() eq "Debug_All" && -x $debugPath) {
593 $safariBundle = $debugPath;
595 $safariBundle = $path;
598 if (!$safariBundle) {
599 return installedSafariPath();
602 my $safariPath = safariPathFromSafariBundle($safariBundle);
603 die "Can't find executable at $safariPath.\n" if isAppleMacWebKit() && !-x $safariPath;
607 sub builtDylibPathForName
609 my $libraryName = shift;
610 determineConfigurationProductDir();
612 return "$configurationProductDir/$libraryName";
615 $libraryName = "QtWebKit";
616 if (isDarwin() and -d "$configurationProductDir/lib/$libraryName.framework") {
617 return "$configurationProductDir/lib/$libraryName.framework/$libraryName";
618 } elsif (isDarwin() and -d "$configurationProductDir/lib") {
619 return "$configurationProductDir/lib/lib$libraryName.dylib";
620 } elsif (isWindows()) {
621 if (configuration() eq "Debug") {
622 # On Windows, there is a "d" suffix to the library name. See <http://trac.webkit.org/changeset/53924/>.
626 my $mkspec = `$qmakebin -query QMAKE_MKSPECS`;
627 $mkspec =~ s/[\n|\r]$//g;
628 my $qtMajorVersion = retrieveQMakespecVar("$mkspec/qconfig.pri", "QT_MAJOR_VERSION");
629 if (not $qtMajorVersion) {
630 $qtMajorVersion = "";
632 return "$configurationProductDir/lib/$libraryName$qtMajorVersion.dll";
634 return "$configurationProductDir/lib/lib$libraryName.so";
638 return "$configurationProductDir/libwxwebkit.dylib";
641 # WebKitGTK+ for GTK2, WebKitGTK+ for GTK3, and WebKit2 respectively.
642 my @libraries = ("libwebkitgtk-1.0", "libwebkitgtk-3.0", "libwebkit2gtk-1.0");
643 my $extension = isDarwin() ? ".dylib" : ".so";
645 foreach $libraryName (@libraries) {
646 my $libraryPath = "$configurationProductDir/.libs/" . $libraryName . $extension;
647 return $libraryPath if -e $libraryPath;
652 return "$configurationProductDir/$libraryName/../WebKit/libewebkit.so";
655 return "$configurationProductDir/$libraryName";
657 if (isAppleMacWebKit()) {
658 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
660 if (isAppleWinWebKit()) {
661 if ($libraryName eq "JavaScriptCore") {
662 return "$baseProductDir/lib/$libraryName.lib";
664 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
668 die "Unsupported platform, can't determine built library locations.\nTry `build-webkit --help` for more information.\n";
671 # Check to see that all the frameworks are built.
672 sub checkFrameworks # FIXME: This is a poor name since only the Mac calls built WebCore a Framework.
674 return if isCygwin() || isWindows();
675 my @frameworks = ("JavaScriptCore", "WebCore");
676 push(@frameworks, "WebKit") if isAppleMacWebKit(); # FIXME: This seems wrong, all ports should have a WebKit these days.
677 for my $framework (@frameworks) {
678 my $path = builtDylibPathForName($framework);
679 die "Can't find built framework at \"$path\".\n" unless -e $path;
683 sub isInspectorFrontend()
685 determineIsInspectorFrontend();
686 return $isInspectorFrontend;
689 sub determineIsInspectorFrontend()
691 return if defined($isInspectorFrontend);
692 $isInspectorFrontend = checkForArgumentAndRemoveFromARGV("--inspector-frontend");
703 my $qtVersion = `$qmakebin --version`;
704 $qtVersion =~ s/^(.*)Qt version (\d\.\d)(.*)/$2/s ;
710 determineIsSymbian();
714 sub qtFeatureDefaults()
716 determineQtFeatureDefaults();
717 return %qtFeatureDefaults;
723 my $devnull = File::Spec->devnull();
724 return `$command --version 2> $devnull`;
727 sub determineQtFeatureDefaults()
729 return if %qtFeatureDefaults;
730 die "ERROR: qmake missing but required to build WebKit.\n" if not commandExists($qmakebin);
731 my $originalCwd = getcwd();
732 chdir File::Spec->catfile(sourceDir(), "Source", "WebCore");
733 my $defaults = `$qmakebin CONFIG+=compute_defaults 2>&1`;
736 while ($defaults =~ m/(\S+?)=(\S+?)/gi) {
737 $qtFeatureDefaults{$1}=$2;
741 sub checkForArgumentAndRemoveFromARGV
743 my $argToCheck = shift;
744 return checkForArgumentAndRemoveFromArrayRef($argToCheck, \@ARGV);
747 sub checkForArgumentAndRemoveFromArrayRef
749 my ($argToCheck, $arrayRef) = @_;
751 foreach my $index (0 .. $#$arrayRef) {
752 my $opt = $$arrayRef[$index];
753 if ($opt =~ /^$argToCheck$/i ) {
754 push(@indicesToRemove, $index);
757 foreach my $index (@indicesToRemove) {
758 splice(@$arrayRef, $index, 1);
760 return $#indicesToRemove > -1;
765 if (defined($isWK2)) {
768 if (checkForArgumentAndRemoveFromARGV("-2")) {
778 return if defined($isQt);
780 # Allow override in case QTDIR is not set.
781 if (checkForArgumentAndRemoveFromARGV("--qt")) {
786 # The presence of QTDIR only means Qt if --gtk or --wx or --efl are not on the command-line
787 if (isGtk() || isWx() || isEfl()) {
792 $isQt = defined($ENV{'QTDIR'});
795 sub determineIsSymbian()
797 return if defined($isSymbian);
799 if (checkForArgumentAndRemoveFromARGV("--symbian")) {
807 return if defined($isEfl);
808 $isEfl = checkForArgumentAndRemoveFromARGV("--efl");
825 return if defined($isGtk);
826 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
835 sub determineIsWinCE()
837 return if defined($isWinCE);
838 $isWinCE = checkForArgumentAndRemoveFromARGV("--wince");
849 return if defined($isWx);
850 $isWx = checkForArgumentAndRemoveFromARGV("--wx");
858 foreach my $opt (@ARGV) {
859 if ($opt =~ /^--wx-args/i ) {
860 @ARGV = grep(!/^--wx-args/i, @ARGV);
862 $rawWxArgs =~ s/--wx-args=//i;
865 @wxArgs = split(/,/, $rawWxArgs);
870 # Determine if this is debian, ubuntu, linspire, or something similar.
873 return -e "/etc/debian_version";
878 return -e "/etc/fedora-release";
883 determineIsChromium();
884 determineIsChromiumAndroid();
885 return $isChromium || $isChromiumAndroid;
888 sub determineIsChromium()
890 return if defined($isChromium);
891 $isChromium = checkForArgumentAndRemoveFromARGV("--chromium");
894 sub isChromiumAndroid()
896 determineIsChromiumAndroid();
897 return $isChromiumAndroid;
900 sub determineIsChromiumAndroid()
902 return if defined($isChromiumAndroid);
903 $isChromiumAndroid = checkForArgumentAndRemoveFromARGV("--chromium-android");
908 determineIsWinCairo();
912 sub determineIsWinCairo()
914 return if defined($isWinCairo);
915 $isWinCairo = checkForArgumentAndRemoveFromARGV("--wincairo");
920 return ($^O eq "cygwin") || 0;
925 return isWindows() || isCygwin() || isMsys();
928 sub determineWinVersion()
930 return if $winVersion;
932 if (!isAnyWindows()) {
937 my $versionString = `cmd /c ver`;
938 $versionString =~ /(\d)\.(\d)\.(\d+)/;
949 determineWinVersion();
955 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 1 && winVersion()->{build} == 7600;
960 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 0;
965 return isAnyWindows() && winVersion()->{major} == 5 && winVersion()->{minor} == 1;
970 return ($^O eq "darwin") || 0;
975 return ($^O eq "MSWin32") || 0;
980 return ($^O eq "msys") || 0;
985 return ($^O eq "linux") || 0;
990 return $Config{archname} =~ /^arm-/;
995 return !(isQt() or isGtk() or isWx() or isChromium() or isEfl() or isWinCE());
998 sub isAppleMacWebKit()
1000 return isAppleWebKit() && isDarwin();
1003 sub isAppleWinWebKit()
1005 return isAppleWebKit() && (isCygwin() || isWindows());
1008 sub isPerianInstalled()
1010 if (!isAppleWebKit()) {
1014 if (-d "/Library/QuickTime/Perian.component") {
1018 if (-d "$ENV{HOME}/Library/QuickTime/Perian.component") {
1025 sub determineOSXVersion()
1027 return if $osXVersion;
1034 my $version = `sw_vers -productVersion`;
1035 my @splitVersion = split(/\./, $version);
1036 @splitVersion >= 2 or die "Invalid version $version";
1038 "major" => $splitVersion[0],
1039 "minor" => $splitVersion[1],
1040 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
1046 determineOSXVersion();
1052 return isDarwin() && osXVersion()->{"minor"} == 5;
1057 return isDarwin() && osXVersion()->{"minor"} == 6;
1062 return isDarwin() && osXVersion()->{"minor"} == 7;
1067 return $ENV{'OS'} eq 'Windows_NT';
1070 sub relativeScriptsDir()
1072 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel($FindBin::Bin, getcwd()), "");
1073 if ($scriptDir eq "") {
1081 my $relativeScriptsPath = relativeScriptsDir();
1082 if (isGtk() || isQt() || isWx() || isEfl() || isWinCE()) {
1083 return "$relativeScriptsPath/run-launcher";
1084 } elsif (isAppleWebKit()) {
1085 return "$relativeScriptsPath/run-safari";
1092 return "GtkLauncher";
1094 return "QtTestBrowser";
1097 } elsif (isAppleWebKit()) {
1100 return "EWebLauncher";
1101 } elsif (isWinCE()) {
1102 return "WinCELauncher";
1106 sub checkRequiredSystemConfig
1109 chomp(my $productVersion = `sw_vers -productVersion`);
1110 if (eval "v$productVersion" lt v10.4) {
1111 print "*************************************************************\n";
1112 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
1113 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
1114 print "*************************************************************\n";
1116 my $xcodebuildVersionOutput = `xcodebuild -version`;
1117 my $devToolsCoreVersion = ($xcodebuildVersionOutput =~ /DevToolsCore-(\d+)/) ? $1 : undef;
1118 my $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : undef;
1119 if (!$devToolsCoreVersion && !$xcodeVersion
1120 || $devToolsCoreVersion && $devToolsCoreVersion < 747
1121 || $xcodeVersion && eval "v$xcodeVersion" lt v2.3) {
1122 print "*************************************************************\n";
1123 print "Xcode Version 2.3 or later is required to build WebKit.\n";
1124 print "You have an earlier version of Xcode, thus the build will\n";
1125 print "most likely fail. The latest Xcode is available from the web:\n";
1126 print "http://developer.apple.com/tools/xcode\n";
1127 print "*************************************************************\n";
1129 } elsif (isGtk() or isQt() or isWx() or isEfl()) {
1130 my @cmds = qw(flex bison gperf);
1132 foreach my $cmd (@cmds) {
1133 push @missing, $cmd if not commandExists($cmd);
1137 my $list = join ", ", @missing;
1138 die "ERROR: $list missing but required to build WebKit.\n";
1141 # Win32 and other platforms may want to check for minimum config
1144 sub determineWindowsSourceDir()
1146 return if $windowsSourceDir;
1147 $windowsSourceDir = sourceDir();
1148 chomp($windowsSourceDir = `cygpath -w '$windowsSourceDir'`) if isCygwin();
1151 sub windowsSourceDir()
1153 determineWindowsSourceDir();
1154 return $windowsSourceDir;
1157 sub windowsLibrariesDir()
1159 return windowsSourceDir() . "\\WebKitLibraries\\win";
1162 sub windowsOutputDir()
1164 return windowsSourceDir() . "\\WebKitBuild";
1167 sub setupAppleWinEnv()
1169 return unless isAppleWinWebKit();
1171 if (isWindowsNT()) {
1172 my $restartNeeded = 0;
1173 my %variablesToSet = ();
1175 # Setting the environment variable 'CYGWIN' to 'tty' makes cygwin enable extra support (i.e., termios)
1176 # for UNIX-like ttys in the Windows console
1177 $variablesToSet{CYGWIN} = "tty" unless $ENV{CYGWIN};
1179 # Those environment variables must be set to be able to build inside Visual Studio.
1180 $variablesToSet{WEBKITLIBRARIESDIR} = windowsLibrariesDir() unless $ENV{WEBKITLIBRARIESDIR};
1181 $variablesToSet{WEBKITOUTPUTDIR} = windowsOutputDir() unless $ENV{WEBKITOUTPUTDIR};
1183 foreach my $variable (keys %variablesToSet) {
1184 print "Setting the Environment Variable '" . $variable . "' to '" . $variablesToSet{$variable} . "'\n\n";
1185 system qw(regtool -s set), '\\HKEY_CURRENT_USER\\Environment\\' . $variable, $variablesToSet{$variable};
1186 $restartNeeded ||= $variable eq "WEBKITLIBRARIESDIR" || $variable eq "WEBKITOUTPUTDIR";
1189 if ($restartNeeded) {
1190 print "Please restart your computer before attempting to build inside Visual Studio.\n\n";
1193 if (!$ENV{'WEBKITLIBRARIESDIR'}) {
1194 print "Warning: You must set the 'WebKitLibrariesDir' environment variable\n";
1195 print " to be able build WebKit from within Visual Studio.\n";
1196 print " Make sure that 'WebKitLibrariesDir' points to the\n";
1197 print " 'WebKitLibraries/win' directory, not the 'WebKitLibraries/' directory.\n\n";
1199 if (!$ENV{'WEBKITOUTPUTDIR'}) {
1200 print "Warning: You must set the 'WebKitOutputDir' environment variable\n";
1201 print " to be able build WebKit from within Visual Studio.\n\n";
1206 sub setupCygwinEnv()
1208 return if !isCygwin() && !isWindows();
1209 return if $vcBuildPath;
1212 my $programFilesPath = $ENV{'PROGRAMFILES(X86)'} || $ENV{'PROGRAMFILES'} || "C:\\Program Files";
1213 if ($ENV{'VSINSTALLDIR'}) {
1214 $vsInstallDir = $ENV{'VSINSTALLDIR'};
1216 $vsInstallDir = File::Spec->catdir($programFilesPath, "Microsoft Visual Studio 8");
1218 chomp($vsInstallDir = `cygpath "$vsInstallDir"`) if isCygwin();
1219 $vcBuildPath = File::Spec->catfile($vsInstallDir, qw(Common7 IDE devenv.com));
1220 if (-e $vcBuildPath) {
1221 # Visual Studio is installed; we can use pdevenv to build.
1222 # FIXME: Make pdevenv work with non-Cygwin Perl.
1223 $vcBuildPath = File::Spec->catfile(sourceDir(), qw(Tools Scripts pdevenv)) if isCygwin();
1225 # Visual Studio not found, try VC++ Express
1226 $vcBuildPath = File::Spec->catfile($vsInstallDir, qw(Common7 IDE VCExpress.exe));
1227 if (! -e $vcBuildPath) {
1228 print "*************************************************************\n";
1229 print "Cannot find '$vcBuildPath'\n";
1230 print "Please execute the file 'vcvars32.bat' from\n";
1231 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
1232 print "to setup the necessary environment variables.\n";
1233 print "*************************************************************\n";
1236 $willUseVCExpressWhenBuilding = 1;
1239 my $qtSDKPath = File::Spec->catdir($programFilesPath, "QuickTime SDK");
1240 if (0 && ! -e $qtSDKPath) {
1241 print "*************************************************************\n";
1242 print "Cannot find '$qtSDKPath'\n";
1243 print "Please download the QuickTime SDK for Windows from\n";
1244 print "http://developer.apple.com/quicktime/download/\n";
1245 print "*************************************************************\n";
1249 unless ($ENV{WEBKITLIBRARIESDIR}) {
1250 $ENV{'WEBKITLIBRARIESDIR'} = File::Spec->catdir($sourceDir, "WebKitLibraries", "win");
1251 chomp($ENV{WEBKITLIBRARIESDIR} = `cygpath -wa '$ENV{WEBKITLIBRARIESDIR}'`) if isCygwin();
1254 print "Building results into: ", baseProductDir(), "\n";
1255 print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
1256 print "WEBKITLIBRARIESDIR is set to: ", $ENV{"WEBKITLIBRARIESDIR"}, "\n";
1259 sub dieIfWindowsPlatformSDKNotInstalled
1261 my $registry32Path = "/proc/registry/";
1262 my $registry64Path = "/proc/registry64/";
1263 my $windowsPlatformSDKRegistryEntry = "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1";
1265 # FIXME: It would be better to detect whether we are using 32- or 64-bit Windows
1266 # and only check the appropriate entry. But for now we just blindly check both.
1267 return if (-e $registry32Path . $windowsPlatformSDKRegistryEntry) || (-e $registry64Path . $windowsPlatformSDKRegistryEntry);
1269 print "*************************************************************\n";
1270 print "Cannot find registry entry '$windowsPlatformSDKRegistryEntry'.\n";
1271 print "Please download and install the Microsoft Windows Server 2003 R2\n";
1272 print "Platform SDK from <http://www.microsoft.com/downloads/details.aspx?\n";
1273 print "familyid=0baf2b35-c656-4969-ace8-e4c0c0716adb&displaylang=en>.\n\n";
1274 print "Then follow step 2 in the Windows section of the \"Installing Developer\n";
1275 print "Tools\" instructions at <http://www.webkit.org/building/tools.html>.\n";
1276 print "*************************************************************\n";
1280 sub copyInspectorFrontendFiles
1282 my $productDir = productDir();
1283 my $sourceInspectorPath = sourceDir() . "/Source/WebCore/inspector/front-end/";
1284 my $inspectorResourcesDirPath = $ENV{"WEBKITINSPECTORRESOURCESDIR"};
1286 if (!defined($inspectorResourcesDirPath)) {
1287 $inspectorResourcesDirPath = "";
1290 if (isAppleMacWebKit()) {
1291 $inspectorResourcesDirPath = $productDir . "/WebCore.framework/Resources/inspector";
1292 } elsif (isAppleWinWebKit()) {
1293 $inspectorResourcesDirPath = $productDir . "/WebKit.resources/inspector";
1294 } elsif (isQt() || isGtk()) {
1295 my $prefix = $ENV{"WebKitInstallationPrefix"};
1296 $inspectorResourcesDirPath = (defined($prefix) ? $prefix : "/usr/share") . "/webkit-1.0/webinspector";
1298 my $prefix = $ENV{"WebKitInstallationPrefix"};
1299 $inspectorResourcesDirPath = (defined($prefix) ? $prefix : "/usr/share") . "/ewebkit/webinspector";
1302 if (! -d $inspectorResourcesDirPath) {
1303 print "*************************************************************\n";
1304 print "Cannot find '$inspectorResourcesDirPath'.\n" if (defined($inspectorResourcesDirPath));
1305 print "Make sure that you have built WebKit first.\n" if (! -d $productDir || defined($inspectorResourcesDirPath));
1306 print "Optionally, set the environment variable 'WebKitInspectorResourcesDir'\n";
1307 print "to point to the directory that contains the WebKit Inspector front-end\n";
1308 print "files for the built WebCore framework.\n";
1309 print "*************************************************************\n";
1312 return system "rsync", "-aut", "--exclude=/.DS_Store", "--exclude=*.re2js", "--exclude=.svn/", !isQt() ? "--exclude=/WebKit.qrc" : "", $sourceInspectorPath, $inspectorResourcesDirPath;
1315 sub buildXCodeProject($$@)
1317 my ($project, $clean, @extraOptions) = @_;
1320 push(@extraOptions, "-alltargets");
1321 push(@extraOptions, "clean");
1324 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
1327 sub usingVisualStudioExpress()
1330 return $willUseVCExpressWhenBuilding;
1333 sub buildVisualStudioProject
1335 my ($project, $clean) = @_;
1338 my $config = configurationForVisualStudio();
1340 dieIfWindowsPlatformSDKNotInstalled() if $willUseVCExpressWhenBuilding;
1342 chomp($project = `cygpath -w "$project"`) if isCygwin();
1344 my $action = "/build";
1349 my @command = ($vcBuildPath, $project, $action, $config);
1351 print join(" ", @command), "\n";
1352 return system @command;
1355 sub downloadWafIfNeeded
1357 # get / update waf if needed
1358 my $waf = "$sourceDir/Tools/waf/waf";
1359 my $wafURL = 'http://wxwebkit.kosoftworks.com/downloads/deps/waf';
1361 my $result = system "curl -o $waf $wafURL";
1368 my ($project, $shouldClean, @options) = @_;
1370 # set the PYTHONPATH for waf
1371 my $pythonPath = $ENV{'PYTHONPATH'};
1372 if (!defined($pythonPath)) {
1375 my $sourceDir = sourceDir();
1376 my $newPythonPath = "$sourceDir/Tools/waf/build:$pythonPath";
1378 $newPythonPath = `cygpath --mixed --path $newPythonPath`;
1380 $ENV{'PYTHONPATH'} = $newPythonPath;
1382 print "Building $project\n";
1384 my $wafCommand = "$sourceDir/Tools/waf/waf";
1385 if ($ENV{'WXWEBKIT_WAF'}) {
1386 $wafCommand = $ENV{'WXWEBKIT_WAF'};
1389 $wafCommand = `cygpath --windows "$wafCommand"`;
1393 return system $wafCommand, "uninstall", "clean", "distclean";
1396 return system $wafCommand, 'configure', 'build', 'install', @options;
1399 sub retrieveQMakespecVar
1402 my $varname = $_[1];
1404 my $varvalue = undef;
1405 #print "retrieveMakespecVar " . $mkspec . ", " . $varname . "\n";
1408 open SPEC, "<$mkspec" or return $varvalue;
1410 if ($_ =~ /\s*include\((.+)\)/) {
1411 # open the included mkspec
1412 my $oldcwd = getcwd();
1413 (my $volume, my $directories, my $file) = File::Spec->splitpath($mkspec);
1414 my $newcwd = "$volume$directories";
1415 chdir $newcwd if $newcwd;
1416 $varvalue = retrieveQMakespecVar($1, $varname);
1418 } elsif ($_ =~ /$varname\s*=\s*([^\s]+)/) {
1427 sub qtMakeCommand($)
1429 my ($qmakebin) = @_;
1430 chomp(my $mkspec = `$qmakebin -query QMAKE_MKSPECS`);
1431 $mkspec .= "/default";
1432 my $compiler = retrieveQMakespecVar("$mkspec/qmake.conf", "QMAKE_CC");
1434 #print "default spec: " . $mkspec . "\n";
1435 #print "compiler found: " . $compiler . "\n";
1437 if ($compiler && $compiler eq "cl") {
1444 sub autotoolsFlag($$)
1446 my ($flag, $feature) = @_;
1447 my $prefix = $flag ? "--enable" : "--disable";
1449 return $prefix . '-' . $feature;
1452 sub runAutogenForAutotoolsProject($@)
1454 my ($dir, $prefix, $sourceDir, $saveArguments, $argumentsFile, @buildArgs) = @_;
1456 print "Calling autogen.sh in " . $dir . "\n\n";
1457 print "Installation prefix directory: $prefix\n" if(defined($prefix));
1459 if ($saveArguments) {
1460 # Write autogen.sh arguments to a file so that we can detect
1461 # when they change and automatically re-run it.
1462 open(AUTOTOOLS_ARGUMENTS, ">$argumentsFile");
1463 print AUTOTOOLS_ARGUMENTS join(" ", @buildArgs);
1464 close(AUTOTOOLS_ARGUMENTS);
1467 # Make the path relative since it will appear in all -I compiler flags.
1468 # Long argument lists cause bizarre slowdowns in libtool.
1469 my $relSourceDir = File::Spec->abs2rel($sourceDir) || ".";
1470 if (system("$relSourceDir/autogen.sh", @buildArgs) ne 0) {
1471 die "Calling autogen.sh failed!\n";
1475 sub autogenArgumentsHaveChanged($@)
1477 my ($filename, @currentArguments) = @_;
1479 if (! -e $filename) {
1483 open(AUTOTOOLS_ARGUMENTS, $filename);
1484 chomp(my $previousArguments = <AUTOTOOLS_ARGUMENTS>);
1485 close(AUTOTOOLS_ARGUMENTS);
1487 my $joinedCurrentArguments = join(" ", @currentArguments);
1488 if ($previousArguments ne $joinedCurrentArguments) {
1489 print "Previous autogen arguments were: $previousArguments\n\n";
1490 print "New autogen arguments are: $joinedCurrentArguments\n";
1497 sub buildAutotoolsProject($@)
1499 my ($project, $clean, @buildParams) = @_;
1502 my $dir = productDir();
1503 my $config = passedConfiguration() || configuration();
1507 my $makeArgs = $ENV{"WebKitMakeArguments"} || "";
1508 for my $i (0 .. $#buildParams) {
1509 my $opt = $buildParams[$i];
1510 if ($opt =~ /^--makeargs=(.*)/i ) {
1511 $makeArgs = $makeArgs . " " . $1;
1512 } elsif ($opt =~ /^--prefix=(.*)/i ) {
1515 push @buildArgs, $opt;
1519 # Automatically determine the number of CPUs for make only
1520 # if make arguments haven't already been specified.
1521 if ($makeArgs eq "") {
1522 $makeArgs = "-j" . numberOfCPUs();
1525 # WebKit is the default target, so we don't need to specify anything.
1526 if ($project eq "JavaScriptCore") {
1527 $makeArgs .= " jsc";
1530 # This is a temporary work-around to enable building WebKit2 on the bots,
1531 # but ensuring that it does not ship until the API is stable.
1532 if ($project eq "WebKit" and isGtk()) {
1533 push @buildArgs, "--enable-webkit2";
1536 $prefix = $ENV{"WebKitInstallationPrefix"} if !defined($prefix);
1537 push @buildArgs, "--prefix=" . $prefix if defined($prefix);
1539 # check if configuration is Debug
1540 if ($config =~ m/debug/i) {
1541 push @buildArgs, "--enable-debug";
1543 push @buildArgs, "--disable-debug";
1546 # Use rm to clean the build directory since distclean may miss files
1547 if ($clean && -d $dir) {
1548 system "rm", "-rf", "$dir";
1552 File::Path::mkpath($dir) or die "Failed to create build directory " . $dir
1554 chdir $dir or die "Failed to cd into " . $dir . "\n";
1560 # If GNUmakefile exists, don't run autogen.sh unless its arguments
1561 # have changed. The makefile should be smart enough to track autotools
1562 # dependencies and re-run autogen.sh when build files change.
1563 my $autogenArgumentsFile = "previous-autogen-arguments.txt";
1564 my $saveAutogenArguments = $project eq "WebKit";
1565 if (!(-e "GNUmakefile")) {
1566 runAutogenForAutotoolsProject($dir, $prefix, $sourceDir, $saveAutogenArguments, $autogenArgumentsFile, @buildArgs);
1569 if ($saveAutogenArguments and autogenArgumentsHaveChanged($autogenArgumentsFile, @buildArgs)) {
1570 runAutogenForAutotoolsProject($dir, $prefix, $sourceDir, $saveAutogenArguments, $autogenArgumentsFile, @buildArgs);
1573 if (system("$make $makeArgs") ne 0) {
1574 die "\nFailed to build WebKit using '$make'!\n";
1581 sub generateBuildSystemFromCMakeProject
1583 my ($port, $prefixPath, @cmakeArgs) = @_;
1584 my $config = configuration();
1585 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1586 File::Path::mkpath($buildPath) unless -d $buildPath;
1587 my $originalWorkingDirectory = getcwd();
1588 chdir($buildPath) or die;
1591 push @args, "-DPORT=\"$port\"";
1592 push @args, "-DCMAKE_INSTALL_PREFIX=\"$prefixPath\"" if $prefixPath;
1593 if ($config =~ /release/i) {
1594 push @args, "-DCMAKE_BUILD_TYPE=Release";
1595 } elsif ($config =~ /debug/i) {
1596 push @args, "-DCMAKE_BUILD_TYPE=Debug";
1598 push @args, @cmakeArgs if @cmakeArgs;
1599 push @args, '"' . File::Spec->catdir(sourceDir(), "Source") . '"';
1601 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1602 # parsed for shell metacharacters.
1603 my $returnCode = system("cmake @args");
1605 chdir($originalWorkingDirectory);
1609 sub buildCMakeGeneratedProject($)
1611 my ($makeArgs) = @_;
1612 my $config = configuration();
1613 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1614 if (! -d $buildPath) {
1615 die "Must call generateBuildSystemFromCMakeProject() before building CMake project.";
1617 my @args = ("--build", $buildPath, "--config", $config);
1618 push @args, ("--", $makeArgs) if $makeArgs;
1620 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1621 # parsed for shell metacharacters. In particular, $makeArgs may contain such metacharacters.
1622 return system("cmake @args");
1625 sub cleanCMakeGeneratedProject()
1627 my $config = configuration();
1628 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1629 if (-d $buildPath) {
1630 return system("cmake", "--build", $buildPath, "--config", $config, "--target", "clean");
1635 sub buildCMakeProjectOrExit($$$$@)
1637 my ($clean, $port, $prefixPath, $makeArgs, @cmakeArgs) = @_;
1640 $returnCode = exitStatus(cleanCMakeGeneratedProject());
1641 exit($returnCode) if $returnCode;
1643 $returnCode = exitStatus(generateBuildSystemFromCMakeProject($port, $prefixPath, @cmakeArgs));
1644 exit($returnCode) if $returnCode;
1645 $returnCode = exitStatus(buildCMakeGeneratedProject($makeArgs));
1646 exit($returnCode) if $returnCode;
1649 sub buildQMakeProject($@)
1651 my ($project, $clean, @buildParams) = @_;
1653 my @subdirs = ("JavaScriptCore", "WebCore", "WebKit/qt/Api");
1654 if (grep { $_ eq $project } @subdirs) {
1655 @subdirs = ($project);
1660 my @buildArgs = ("-r");
1665 for my $i (0 .. $#buildParams) {
1666 my $opt = $buildParams[$i];
1667 if ($opt =~ /^--qmake=(.*)/i ) {
1669 } elsif ($opt =~ /^--qmakearg=(.*)/i ) {
1670 push @buildArgs, $1;
1671 } elsif ($opt =~ /^--makeargs=(.*)/i ) {
1673 } elsif ($opt =~ /^--install-headers=(.*)/i ) {
1674 $installHeaders = $1;
1675 } elsif ($opt =~ /^--install-libs=(.*)/i ) {
1678 push @buildArgs, $opt;
1682 my $make = qtMakeCommand($qmakebin);
1683 my $config = configuration();
1684 push @buildArgs, "INSTALL_HEADERS=" . $installHeaders if defined($installHeaders);
1685 push @buildArgs, "INSTALL_LIBS=" . $installLibs if defined($installLibs);
1686 my $dir = File::Spec->canonpath(productDir());
1688 my $originalCwd = getcwd();
1689 chdir File::Spec->catfile(sourceDir(), "Source", "WebCore");
1690 my $defaults = `$qmakebin CONFIG+=compute_defaults 2>&1`;
1693 # On Symbian qmake needs to run in the same directory where the pro file is located.
1695 $dir = $sourceDir . "/Source";
1698 File::Path::mkpath($dir);
1699 chdir $dir or die "Failed to cd into " . $dir . "\n";
1701 my $pathToDefaultsTxt = File::Spec->catfile( $dir, "defaults.txt" );
1702 my $defaultsTxt = "";
1703 if(open DEFAULTS, "$pathToDefaultsTxt"){
1704 while (<DEFAULTS>) {
1709 # Automatic clean build isn't supported on Symbian yet, see https://bugs.webkit.org/show_bug.cgi?id=67706 for details.
1710 if (($defaults ne $defaultsTxt) and !isSymbian()){
1711 print "Make clean build because the Defines are changed.\n";
1713 File::Path::rmtree($dir);
1714 File::Path::mkpath($dir);
1715 chdir $dir or die "Failed to cd into " . $dir . "\n";
1716 open DEFAULTS, ">$pathToDefaultsTxt";
1717 print DEFAULTS $defaults;
1721 print "Generating derived sources\n\n";
1723 push @buildArgs, "OUTPUT_DIR=" . $dir;
1725 my @dsQmakeArgs = @buildArgs;
1726 push @dsQmakeArgs, "-r";
1727 push @dsQmakeArgs, sourceDir() . "/Source/DerivedSources.pro";
1729 push @dsQmakeArgs, "-after SUBDIRS=" . $project. "/DerivedSources.pro";
1731 push @dsQmakeArgs, "-o Makefile.DerivedSources";
1732 print "Calling '$qmakebin @dsQmakeArgs' in " . $dir . "\n\n";
1733 my $result = system "$qmakebin @dsQmakeArgs";
1735 die "Failed while running $qmakebin to generate derived sources!\n";
1738 if ($project ne "JavaScriptCore") {
1739 # FIXME: Iterate over different source directories manually to workaround a problem with qmake+extraTargets+s60
1740 # To avoid overwriting of Makefile.DerivedSources in the root dir use Makefile.DerivedSources.Tools for Tools
1741 if (grep { $_ eq "CONFIG+=webkit2"} @buildArgs) {
1742 push @subdirs, "WebKit2";
1743 if ( -e sourceDir() ."/Tools/DerivedSources.pro" ) {
1744 @dsQmakeArgs = @buildArgs;
1745 push @dsQmakeArgs, "-r";
1746 push @dsQmakeArgs, sourceDir() . "/Tools/DerivedSources.pro";
1747 push @dsQmakeArgs, "-o Makefile.DerivedSources.Tools";
1748 print "Calling '$qmakebin @dsQmakeArgs' in " . $dir . "\n\n";
1749 my $result = system "$qmakebin @dsQmakeArgs";
1751 die "Failed while running $qmakebin to generate derived sources for Tools!\n";
1753 push @subdirs, "WebKitTestRunner";
1758 for my $subdir (@subdirs) {
1759 my $dsMakefile = "Makefile.DerivedSources";
1760 print "Calling '$make $makeargs -C $subdir -f $dsMakefile generated_files' in " . $dir . "/$subdir\n\n";
1761 if ($make eq "nmake") {
1762 my $subdirWindows = $subdir;
1763 $subdirWindows =~ s:/:\\:g;
1764 $result = system "pushd $subdirWindows && $make $makeargs -f $dsMakefile generated_files && popd";
1766 $result = system "$make $makeargs -C $subdir -f $dsMakefile generated_files";
1769 die "Failed to generate ${subdir}'s derived sources!\n";
1773 if ($config =~ m/debug/i) {
1774 push @buildArgs, "CONFIG-=release";
1775 push @buildArgs, "CONFIG+=debug";
1777 my $passedConfig = passedConfiguration() || "";
1778 if (!isDarwin() || $passedConfig =~ m/release/i) {
1779 push @buildArgs, "CONFIG+=release";
1780 push @buildArgs, "CONFIG-=debug";
1782 push @buildArgs, "CONFIG+=debug";
1783 push @buildArgs, "CONFIG+=debug_and_release";
1788 push @buildArgs, "-after SUBDIRS=" . $project . "/" . $project . ".pro ";
1789 if ($project eq "JavaScriptCore") {
1790 push @buildArgs, "-after SUBDIRS+=" . $project . "/jsc.pro ";
1793 push @buildArgs, sourceDir() . "/Source/WebKit.pro";
1794 print "Calling '$qmakebin @buildArgs' in " . $dir . "\n\n";
1795 print "Installation headers directory: $installHeaders\n" if(defined($installHeaders));
1796 print "Installation libraries directory: $installLibs\n" if(defined($installLibs));
1798 $result = system "$qmakebin @buildArgs";
1800 die "Failed to setup build environment using $qmakebin!\n";
1805 $buildArgs[-1] = sourceDir() . "/Tools/Tools.pro";
1806 $makefile = "Makefile.Tools";
1808 # On Symbian qmake needs to run in the same directory where the pro file is located.
1810 $dir = $sourceDir . "/Tools";
1811 chdir $dir or die "Failed to cd into " . $dir . "\n";
1812 $makefile = "bld.inf";
1815 print "Calling '$qmakebin @buildArgs -o $makefile' in " . $dir . "\n\n";
1816 $result = system "$qmakebin @buildArgs -o $makefile";
1818 die "Failed to setup build environment using $qmakebin!\n";
1823 # Manually create makefiles for the examples so we don't build by default
1824 my $examplesDir = $dir . "/WebKit/qt/examples";
1825 File::Path::mkpath($examplesDir);
1826 $buildArgs[-1] = sourceDir() . "/Source/WebKit/qt/examples/examples.pro";
1827 chdir $examplesDir or die;
1828 print "Calling '$qmakebin @buildArgs' in " . $examplesDir . "\n\n";
1829 $result = system "$qmakebin @buildArgs";
1830 die "Failed to create makefiles for the examples!\n" if $result ne 0;
1834 my $makeTools = "echo";
1836 $makeTools = "echo No Makefile for Tools. Skipping make";
1838 if (-e "$dir/$makefile") {
1839 $makeTools = "$make $makeargs -f $makefile";
1844 print "Calling '$make $makeargs distclean' in " . $dir . "\n\n";
1845 $result = system "$make $makeargs distclean";
1846 $result = $result || system "$makeTools distclean";
1847 } elsif (isSymbian()) {
1848 print "\n\nWebKit is now configured for building, but you have to make\n";
1849 print "a choice about the target yourself. To start the build run:\n\n";
1850 print " make release-armv5|debug-winscw|etc.\n\n";
1852 print "Calling '$make $makeargs' in " . $dir . "\n\n";
1853 $result = system "$make $makeargs";
1854 $result = $result || system "$makeTools";
1861 sub buildQMakeQtProject($$@)
1863 my ($project, $clean, @buildArgs) = @_;
1865 return buildQMakeProject("", $clean, @buildArgs);
1870 my ($project, $clean, @buildArgs) = @_;
1872 if ($project ne "WebKit" and $project ne "JavaScriptCore") {
1873 die "Unsupported project: $project. Supported projects: WebKit, JavaScriptCore\n";
1876 return buildAutotoolsProject($project, $clean, @buildArgs);
1879 sub buildChromiumMakefile($$@)
1881 my ($target, $clean, @options) = @_;
1883 return system qw(rm -rf out);
1885 my $config = configuration();
1886 my $numCpus = numberOfCPUs();
1889 $makeArgs = $1 if /^--makeargs=(.*)/i;
1891 $makeArgs = "-j$numCpus" if not $makeArgs;
1892 my $command = "make -fMakefile.chromium $makeArgs BUILDTYPE=$config $target";
1894 return system $command;
1897 sub buildChromiumVisualStudioProject($$)
1899 my ($projectPath, $clean) = @_;
1901 my $config = configuration();
1902 my $action = "/build";
1903 $action = "/clean" if $clean;
1905 # Find Visual Studio installation.
1907 my $programFilesPath = $ENV{'PROGRAMFILES'} || "C:\\Program Files";
1908 if ($ENV{'VSINSTALLDIR'}) {
1909 $vsInstallDir = $ENV{'VSINSTALLDIR'};
1911 $vsInstallDir = "$programFilesPath/Microsoft Visual Studio 8";
1913 $vsInstallDir = `cygpath "$vsInstallDir"` if isCygwin();
1914 chomp $vsInstallDir;
1915 $vcBuildPath = "$vsInstallDir/Common7/IDE/devenv.com";
1916 if (! -e $vcBuildPath) {
1917 # Visual Studio not found, try VC++ Express
1918 $vcBuildPath = "$vsInstallDir/Common7/IDE/VCExpress.exe";
1919 if (! -e $vcBuildPath) {
1920 print "*************************************************************\n";
1921 print "Cannot find '$vcBuildPath'\n";
1922 print "Please execute the file 'vcvars32.bat' from\n";
1923 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
1924 print "to setup the necessary environment variables.\n";
1925 print "*************************************************************\n";
1930 # Create command line and execute it.
1931 my @command = ($vcBuildPath, $projectPath, $action, $config);
1932 print "Building results into: ", baseProductDir(), "\n";
1933 print join(" ", @command), "\n";
1934 return system @command;
1937 sub buildChromium($@)
1939 my ($clean, @options) = @_;
1941 # We might need to update DEPS or re-run GYP if things have changed.
1942 if (checkForArgumentAndRemoveFromArrayRef("--update-chromium", \@options)) {
1943 system("perl", "Tools/Scripts/update-webkit-chromium") == 0 or die $!;
1947 if (isChromiumAndroid()) {
1948 # Building Chromium for Android needs to cross-compile using the
1949 # Toolchains supplied by the Android NDK.
1950 my $ndkBaseDir = sourceDir() . "/Source/WebKit/chromium/third_party/android-ndk-r6";
1951 my $platform = isDarwin() ? "darwin-x86" : "linux-x86";
1953 my $toolchainBase = $ndkBaseDir . "/toolchains/arm-linux-androideabi-4.4.3/prebuilt/" . $platform . "/bin/arm-linux-androideabi-";
1955 $ENV{AR} = $toolchainBase . "ar";
1956 $ENV{CC} = $toolchainBase . "gcc";
1957 $ENV{CXX} = $toolchainBase . "g++";
1958 $ENV{LINK} = $toolchainBase . "gcc";
1959 $ENV{RANLIB} = $toolchainBase . "ranlib";
1960 $ENV{STRIP} = $toolchainBase . "strip";
1962 $result = buildChromiumMakefile("all", $clean);
1963 } elsif (isDarwin()) {
1964 # Mac build - builds the root xcode project.
1965 $result = buildXCodeProject("Source/WebKit/chromium/WebKit", $clean, "-configuration", configuration(), @options);
1966 } elsif (isCygwin() || isWindows()) {
1967 # Windows build - builds the root visual studio solution.
1968 $result = buildChromiumVisualStudioProject("Source/WebKit/chromium/WebKit.sln", $clean);
1969 } elsif (isLinux()) {
1970 # Linux build - build using make.
1971 $result = buildChromiumMakefile("all", $clean, @options);
1973 print STDERR "This platform is not supported by chromium.\n";
1978 sub appleApplicationSupportPath
1980 open INSTALL_DIR, "</proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Apple\ Inc./Apple\ Application\ Support/InstallDir";
1981 my $path = <INSTALL_DIR>;
1982 $path =~ s/[\r\n\x00].*//;
1985 my $unixPath = `cygpath -u '$path'`;
1990 sub setPathForRunningWebKitApp
1994 if (isAppleWinWebKit()) {
1995 $env->{PATH} = join(':', productDir(), dirname(installedSafariPath()), appleApplicationSupportPath(), $env->{PATH} || "");
1997 my $qtLibs = `$qmakebin -query QT_INSTALL_LIBS`;
1998 $qtLibs =~ s/[\n|\r]$//g;
1999 $env->{PATH} = join(';', $qtLibs, productDir() . "/lib", $env->{PATH} || "");
2005 my ($debugger) = @_;
2007 if (isAppleMacWebKit()) {
2008 return system "$FindBin::Bin/gdb-safari", argumentsForConfiguration() if $debugger;
2010 my $productDir = productDir();
2011 print "Starting Safari with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2012 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2013 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2014 if (architecture()) {
2015 return system "arch", "-" . architecture(), safariPath(), @ARGV;
2017 return system safariPath(), @ARGV;
2021 if (isAppleWinWebKit()) {
2023 my $productDir = productDir();
2026 chomp($ENV{WEBKITNIGHTLY} = `cygpath -wa "$productDir"`);
2027 my $safariPath = safariPath();
2028 chomp($safariPath = `cygpath -wa "$safariPath"`);
2029 $result = system $vcBuildPath, "/debugexe", "\"$safariPath\"", @ARGV;
2031 $result = system File::Spec->catfile(productDir(), "WebKit.exe"), @ARGV;
2033 return $result if $result;
2041 if (isAppleMacWebKit()) {
2042 my $productDir = productDir();
2043 print "Starting MiniBrowser with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
2044 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2045 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2046 my $miniBrowserPath = "$productDir/MiniBrowser.app/Contents/MacOS/MiniBrowser";
2047 if (architecture()) {
2048 return system "arch", "-" . architecture(), $miniBrowserPath, @ARGV;
2050 return system $miniBrowserPath, @ARGV;
2057 sub debugMiniBrowser
2059 if (isAppleMacWebKit()) {
2060 my $gdbPath = "/usr/bin/gdb";
2061 die "Can't find gdb executable. Is gdb installed?\n" unless -x $gdbPath;
2063 my $productDir = productDir();
2065 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2066 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = 'YES';
2068 my $miniBrowserPath = "$productDir/MiniBrowser.app/Contents/MacOS/MiniBrowser";
2070 print "Starting MiniBrowser under gdb with DYLD_FRAMEWORK_PATH set to point to built WebKit2 in $productDir.\n";
2071 my @architectureFlags = ("-arch", architecture());
2072 exec $gdbPath, @architectureFlags, $miniBrowserPath or die;
2079 sub runWebKitTestRunner
2081 if (isAppleMacWebKit()) {
2082 my $productDir = productDir();
2083 print "Starting WebKitTestRunner with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
2084 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2085 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2086 my $webKitTestRunnerPath = "$productDir/WebKitTestRunner";
2087 if (architecture()) {
2088 return system "arch", "-" . architecture(), $webKitTestRunnerPath, @ARGV;
2090 return system $webKitTestRunnerPath, @ARGV;
2093 my $productDir = productDir();
2094 my $injectedBundlePath = "$productDir/Libraries/.libs/libTestRunnerInjectedBundle";
2095 print "Starting WebKitTestRunner with TEST_RUNNER_INJECTED_BUNDLE_FILENAME set to point to $injectedBundlePath.\n";
2096 $ENV{TEST_RUNNER_INJECTED_BUNDLE_FILENAME} = $injectedBundlePath;
2097 my @args = ("$productDir/Programs/WebKitTestRunner", @ARGV);
2098 return system {$args[0] } @args;
2104 sub debugWebKitTestRunner
2106 if (isAppleMacWebKit()) {
2107 my $gdbPath = "/usr/bin/gdb";
2108 die "Can't find gdb executable. Is gdb installed?\n" unless -x $gdbPath;
2110 my $productDir = productDir();
2111 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2112 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = 'YES';
2114 my $webKitTestRunnerPath = "$productDir/WebKitTestRunner";
2116 print "Starting WebKitTestRunner under gdb with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
2117 my @architectureFlags = ("-arch", architecture());
2118 exec $gdbPath, @architectureFlags, $webKitTestRunnerPath or die;
2125 sub runTestWebKitAPI
2127 if (isAppleMacWebKit()) {
2128 my $productDir = productDir();
2129 print "Starting TestWebKitAPI with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
2130 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2131 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2132 my $testWebKitAPIPath = "$productDir/TestWebKitAPI";
2133 if (architecture()) {
2134 return system "arch", "-" . architecture(), $testWebKitAPIPath, @ARGV;
2136 return system $testWebKitAPIPath, @ARGV;