1 # Copyright (C) 2005, 2006, 2007, 2010, 2011, 2012 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.
35 use Digest::MD5 qw(md5_hex);
38 use File::Path qw(mkpath rmtree);
46 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
51 &XcodeOptionStringNoConfig
56 &cmakeBasedPortArguments
62 &printHelpAndExitForRunAndDebugWebKitAppIfNeeded
73 use constant USE_OPEN_COMMAND => 1; # Used in runMacWebKitApp().
74 use constant INCLUDE_OPTIONS_FOR_DEBUGGING => 1;
81 my @baseProductDirOption;
83 my $configurationForVisualStudio;
84 my $configurationProductDir;
86 my $currentSVNRevision;
92 my $qmakebin = "qmake"; # Allow override of the qmake binary from $PATH
101 my $isChromiumAndroid;
102 my $isChromiumMacMake;
104 my $forceChromiumUpdate;
105 my $isInspectorFrontend;
107 my $shouldTargetWebProcess;
108 my $shouldUseGuardMalloc;
111 # Variables for Win32 support
113 my $windowsSourceDir;
115 my $willUseVCExpressWhenBuilding = 0;
117 # Defined in VCSUtils.
120 sub determineSourceDir
122 return if $sourceDir;
123 $sourceDir = $FindBin::Bin;
124 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
126 # walks up path checking each directory to see if it is the main WebKit project dir,
127 # defined by containing Sources, WebCore, and WebKit
128 until ((-d "$sourceDir/Source" && -d "$sourceDir/Source/WebCore" && -d "$sourceDir/Source/WebKit") || (-d "$sourceDir/Internal" && -d "$sourceDir/OpenSource"))
130 if ($sourceDir !~ s|/[^/]+$||) {
131 die "Could not find top level webkit directory above source directory using FindBin.\n";
135 $sourceDir = "$sourceDir/OpenSource" if -d "$sourceDir/OpenSource";
138 sub currentPerlPath()
142 $thisPerl .= $Config{_exe} unless $thisPerl =~ m/$Config{_exe}$/i;
147 sub setQmakeBinaryPath($)
152 # used for scripts which are stored in a non-standard location
158 sub determineXcodeVersion
160 return if defined $xcodeVersion;
161 my $xcodebuildVersionOutput = `xcodebuild -version`;
162 $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : "3.0";
165 sub readXcodeUserDefault($)
167 my ($unprefixedKey) = @_;
169 determineXcodeVersion();
171 my $xcodeDefaultsDomain = (eval "v$xcodeVersion" lt v4) ? "com.apple.Xcode" : "com.apple.dt.Xcode";
172 my $xcodeDefaultsPrefix = (eval "v$xcodeVersion" lt v4) ? "PBX" : "IDE";
173 my $devnull = File::Spec->devnull();
175 my $value = `defaults read $xcodeDefaultsDomain ${xcodeDefaultsPrefix}${unprefixedKey} 2> ${devnull}`;
182 sub determineBaseProductDir
184 return if defined $baseProductDir;
185 determineSourceDir();
187 my $setSharedPrecompsDir;
188 $baseProductDir = $ENV{"WEBKITOUTPUTDIR"};
190 if (!defined($baseProductDir) and isAppleMacWebKit()) {
191 # Silently remove ~/Library/Preferences/xcodebuild.plist which can
192 # cause build failure. The presence of
193 # ~/Library/Preferences/xcodebuild.plist can prevent xcodebuild from
194 # respecting global settings such as a custom build products directory
195 # (<rdar://problem/5585899>).
196 my $personalPlistFile = $ENV{HOME} . "/Library/Preferences/xcodebuild.plist";
197 if (-e $personalPlistFile) {
198 unlink($personalPlistFile) || die "Could not delete $personalPlistFile: $!";
201 determineXcodeVersion();
203 if (eval "v$xcodeVersion" ge v4) {
204 my $buildLocationStyle = join '', readXcodeUserDefault("BuildLocationStyle");
205 if ($buildLocationStyle eq "Custom") {
206 my $buildLocationType = join '', readXcodeUserDefault("CustomBuildLocationType");
207 # FIXME: Read CustomBuildIntermediatesPath and set OBJROOT accordingly.
208 $baseProductDir = readXcodeUserDefault("CustomBuildProductsPath") if $buildLocationType eq "Absolute";
211 # DeterminedByTargets corresponds to a setting of "Legacy" in Xcode.
212 # It is the only build location style for which SHARED_PRECOMPS_DIR is not
213 # overridden when building from within Xcode.
214 $setSharedPrecompsDir = 1 if $buildLocationStyle ne "DeterminedByTargets";
217 if (!defined($baseProductDir)) {
218 $baseProductDir = join '', readXcodeUserDefault("ApplicationwideBuildSettings");
219 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
222 undef $baseProductDir unless $baseProductDir =~ /^\//;
223 } elsif (isChromium()) {
224 if (isLinux() || isChromiumAndroid() || isChromiumMacMake()) {
225 $baseProductDir = "$sourceDir/out";
226 } elsif (isDarwin()) {
227 $baseProductDir = "$sourceDir/Source/WebKit/chromium/xcodebuild";
228 } elsif (isWindows() || isCygwin()) {
229 $baseProductDir = "$sourceDir/Source/WebKit/chromium/build";
233 if (!defined($baseProductDir)) { # Port-specific checks failed, use default
234 $baseProductDir = "$sourceDir/WebKitBuild";
237 if (isBlackBerry()) {
238 my %archInfo = blackberryTargetArchitecture();
239 $baseProductDir = "$baseProductDir/" . $archInfo{"cpuDir"};
242 if (isGit() && isGitBranchBuild() && !isChromium()) {
243 my $branch = gitBranch();
244 $baseProductDir = "$baseProductDir/$branch";
247 if (isAppleMacWebKit()) {
248 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
249 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
250 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
251 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
252 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
253 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir");
254 push(@baseProductDirOption, "SHARED_PRECOMPS_DIR=${baseProductDir}/PrecompiledHeaders") if $setSharedPrecompsDir;
258 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
260 $ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
261 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
262 chomp $unixBuildPath;
263 $baseProductDir = $unixBuildPath;
267 sub setBaseProductDir($)
269 ($baseProductDir) = @_;
272 sub determineConfiguration
274 return if defined $configuration;
275 determineBaseProductDir();
276 if (open CONFIGURATION, "$baseProductDir/Configuration") {
277 $configuration = <CONFIGURATION>;
280 if ($configuration) {
281 chomp $configuration;
282 # compatibility for people who have old Configuration files
283 $configuration = "Release" if $configuration eq "Deployment";
284 $configuration = "Debug" if $configuration eq "Development";
286 $configuration = "Release";
289 if ($configuration && isWinCairo()) {
290 unless ($configuration =~ /_Cairo_CFLite$/) {
291 $configuration .= "_Cairo_CFLite";
296 sub determineArchitecture
298 return if defined $architecture;
299 # make sure $architecture is defined in all cases
302 determineBaseProductDir();
305 determineConfigurationProductDir();
306 my $host_triple = `grep -E '^host = ' $configurationProductDir/GNUmakefile`;
307 if ($host_triple =~ m/^host = ([^-]+)-/) {
308 # We have a configured build tree; use it.
311 } elsif (isAppleMacWebKit()) {
312 if (open ARCHITECTURE, "$baseProductDir/Architecture") {
313 $architecture = <ARCHITECTURE>;
319 my $supports64Bit = `sysctl -n hw.optional.x86_64`;
320 chomp $supports64Bit;
321 $architecture = 'x86_64' if $supports64Bit;
324 my $host_processor = "";
325 $host_processor = `cmake --system-information | grep CMAKE_SYSTEM_PROCESSOR`;
326 if ($host_processor =~ m/^CMAKE_SYSTEM_PROCESSOR \"([^"]+)\"/) {
327 # We have a configured build tree; use it.
329 $architecture = 'x86_64' if $architecture eq 'amd64';
333 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
334 # Fall back to output of `arch', if it is present.
335 $architecture = `arch`;
339 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
340 # Fall back to output of `uname -m', if it is present.
341 $architecture = `uname -m`;
346 sub determineNumberOfCPUs
348 return if defined $numberOfCPUs;
349 if (defined($ENV{NUMBER_OF_PROCESSORS})) {
350 $numberOfCPUs = $ENV{NUMBER_OF_PROCESSORS};
351 } elsif (isLinux()) {
352 # First try the nproc utility, if it exists. If we get no
353 # results fall back to just interpretting /proc directly.
354 chomp($numberOfCPUs = `nproc 2> /dev/null`);
355 if ($numberOfCPUs eq "") {
356 $numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`);
358 } elsif (isWindows() || isCygwin()) {
360 $numberOfCPUs = `ls /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor | wc -w`;
361 } elsif (isDarwin() || isFreeBSD()) {
362 chomp($numberOfCPUs = `sysctl -n hw.ncpu`);
368 my ($productDir) = @_;
370 $jscName .= "_debug" if configurationForVisualStudio() eq "Debug_All";
371 $jscName .= ".exe" if (isWindows() || isCygwin());
372 return "$productDir/$jscName" if -e "$productDir/$jscName";
373 return "$productDir/JavaScriptCore.framework/Resources/$jscName";
376 sub argumentsForConfiguration()
378 determineConfiguration();
379 determineArchitecture();
382 push(@args, '--debug') if $configuration eq "Debug";
383 push(@args, '--release') if $configuration eq "Release";
384 push(@args, '--32-bit') if $architecture ne "x86_64";
385 push(@args, '--qt') if isQt();
386 push(@args, '--gtk') if isGtk();
387 push(@args, '--efl') if isEfl();
388 push(@args, '--wincairo') if isWinCairo();
389 push(@args, '--wince') if isWinCE();
390 push(@args, '--wx') if isWx();
391 push(@args, '--blackberry') if isBlackBerry();
392 push(@args, '--chromium') if isChromium() && !isChromiumAndroid();
393 push(@args, '--chromium-android') if isChromiumAndroid();
394 push(@args, '--inspector-frontend') if isInspectorFrontend();
398 sub determineConfigurationForVisualStudio
400 return if defined $configurationForVisualStudio;
401 determineConfiguration();
402 # FIXME: We should detect when Debug_All or Production has been chosen.
403 $configurationForVisualStudio = $configuration;
406 sub usesPerConfigurationBuildDirectory
408 # [Gtk] We don't have Release/Debug configurations in straight
409 # autotool builds (non build-webkit). In this case and if
410 # WEBKITOUTPUTDIR exist, use that as our configuration dir. This will
411 # allows us to run run-webkit-tests without using build-webkit.
412 return ($ENV{"WEBKITOUTPUTDIR"} && isGtk()) || isAppleWinWebKit();
415 sub determineConfigurationProductDir
417 return if defined $configurationProductDir;
418 determineBaseProductDir();
419 determineConfiguration();
420 if (isAppleWinWebKit() && !isWx()) {
421 $configurationProductDir = File::Spec->catdir($baseProductDir, configurationForVisualStudio(), "bin");
423 if (usesPerConfigurationBuildDirectory()) {
424 $configurationProductDir = "$baseProductDir";
426 $configurationProductDir = "$baseProductDir/$configuration";
431 sub setConfigurationProductDir($)
433 ($configurationProductDir) = @_;
436 sub determineCurrentSVNRevision
438 # We always update the current SVN revision here, and leave the caching
439 # to currentSVNRevision(), so that changes to the SVN revision while the
440 # script is running can be picked up by calling this function again.
441 determineSourceDir();
442 $currentSVNRevision = svnRevisionForDirectory($sourceDir);
443 return $currentSVNRevision;
449 determineSourceDir();
450 chdir $sourceDir or die;
455 determineBaseProductDir();
456 return $baseProductDir;
461 determineSourceDir();
467 determineConfigurationProductDir();
468 return $configurationProductDir;
473 my $productDir = productDir();
474 $productDir .= "/bin" if (isQt() || isEfl());
475 $productDir .= "/Programs" if isGtk();
482 determineConfiguration();
483 return $configuration;
486 sub configurationForVisualStudio()
488 determineConfigurationForVisualStudio();
489 return $configurationForVisualStudio;
492 sub currentSVNRevision
494 determineCurrentSVNRevision() if not defined $currentSVNRevision;
495 return $currentSVNRevision;
500 determineGenerateDsym();
501 return $generateDsym;
504 sub determineGenerateDsym()
506 return if defined($generateDsym);
507 $generateDsym = checkForArgumentAndRemoveFromARGV("--dsym");
510 sub argumentsForXcode()
513 push @args, "DEBUG_INFORMATION_FORMAT=dwarf-with-dsym" if generateDsym();
519 determineBaseProductDir();
520 determineConfiguration();
521 determineArchitecture();
522 return (@baseProductDirOption, "-configuration", $configuration, "ARCHS=$architecture", argumentsForXcode());
525 sub XcodeOptionString
527 return join " ", XcodeOptions();
530 sub XcodeOptionStringNoConfig
532 return join " ", @baseProductDirOption;
535 sub XcodeCoverageSupportOptions()
537 my @coverageSupportOptions = ();
538 push @coverageSupportOptions, "GCC_GENERATE_TEST_COVERAGE_FILES=YES";
539 push @coverageSupportOptions, "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES";
540 push @coverageSupportOptions, "EXTRA_LINK= \$(EXTRA_LINK) -ftest-coverage -fprofile-arcs";
541 push @coverageSupportOptions, "OTHER_CFLAGS= \$(OTHER_CFLAGS) -DCOVERAGE -MD";
542 push @coverageSupportOptions, "OTHER_LDFLAGS=\$(OTHER_LDFLAGS) -ftest-coverage -fprofile-arcs -lgcov";
543 return @coverageSupportOptions;
546 my $passedConfiguration;
547 my $searchedForPassedConfiguration;
548 sub determinePassedConfiguration
550 return if $searchedForPassedConfiguration;
551 $searchedForPassedConfiguration = 1;
553 for my $i (0 .. $#ARGV) {
555 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
556 splice(@ARGV, $i, 1);
557 $passedConfiguration = "Debug";
558 $passedConfiguration .= "_Cairo_CFLite" if (isWinCairo() && isCygwin());
561 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
562 splice(@ARGV, $i, 1);
563 $passedConfiguration = "Release";
564 $passedConfiguration .= "_Cairo_CFLite" if (isWinCairo() && isCygwin());
567 if ($opt =~ /^--profil(e|ing)$/i) {
568 splice(@ARGV, $i, 1);
569 $passedConfiguration = "Profiling";
570 $passedConfiguration .= "_Cairo_CFLite" if (isWinCairo() && isCygwin());
574 $passedConfiguration = undef;
577 sub passedConfiguration
579 determinePassedConfiguration();
580 return $passedConfiguration;
587 if (my $config = shift @_) {
588 $configuration = $config;
592 determinePassedConfiguration();
593 $configuration = $passedConfiguration if $passedConfiguration;
597 my $passedArchitecture;
598 my $searchedForPassedArchitecture;
599 sub determinePassedArchitecture
601 return if $searchedForPassedArchitecture;
602 $searchedForPassedArchitecture = 1;
604 for my $i (0 .. $#ARGV) {
606 if ($opt =~ /^--32-bit$/i) {
607 splice(@ARGV, $i, 1);
608 if (isAppleMacWebKit() || isWx()) {
609 $passedArchitecture = `arch`;
610 chomp $passedArchitecture;
615 $passedArchitecture = undef;
618 sub passedArchitecture
620 determinePassedArchitecture();
621 return $passedArchitecture;
626 determineArchitecture();
627 return $architecture;
632 determineNumberOfCPUs();
633 return $numberOfCPUs;
638 if (my $arch = shift @_) {
639 $architecture = $arch;
643 determinePassedArchitecture();
644 $architecture = $passedArchitecture if $passedArchitecture;
647 sub executableHasEntitlements
649 my $executablePath = shift;
650 return (`codesign -d --entitlements - $executablePath 2>&1` =~ /<key>/);
653 sub safariPathFromSafariBundle
655 my ($safariBundle) = @_;
657 if (isAppleMacWebKit()) {
658 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
659 my $safariForWebKitDevelopmentPath = "$safariBundle/Contents/MacOS/SafariForWebKitDevelopment";
660 return $safariForWebKitDevelopmentPath if -f $safariForWebKitDevelopmentPath && executableHasEntitlements($safariPath);
663 return $safariBundle if isAppleWinWebKit();
666 sub installedSafariPath
670 if (isAppleMacWebKit()) {
671 $safariBundle = "/Applications/Safari.app";
672 } elsif (isAppleWinWebKit()) {
673 $safariBundle = readRegistryString("/HKLM/SOFTWARE/Apple Computer, Inc./Safari/InstallDir");
674 $safariBundle =~ s/[\r\n]+$//;
675 $safariBundle = `cygpath -u '$safariBundle'` if isCygwin();
676 $safariBundle =~ s/[\r\n]+$//;
677 $safariBundle .= "Safari.exe";
680 return safariPathFromSafariBundle($safariBundle);
686 # Use WEBKIT_SAFARI environment variable if present.
687 my $safariBundle = $ENV{WEBKIT_SAFARI};
688 if (!$safariBundle) {
689 determineConfigurationProductDir();
690 # Use Safari.app in product directory if present (good for Safari development team).
691 if (isAppleMacWebKit() && -d "$configurationProductDir/Safari.app") {
692 $safariBundle = "$configurationProductDir/Safari.app";
693 } elsif (isAppleWinWebKit()) {
694 my $path = "$configurationProductDir/Safari.exe";
695 my $debugPath = "$configurationProductDir/Safari_debug.exe";
697 if (configurationForVisualStudio() eq "Debug_All" && -x $debugPath) {
698 $safariBundle = $debugPath;
700 $safariBundle = $path;
703 if (!$safariBundle) {
704 return installedSafariPath();
707 my $safariPath = safariPathFromSafariBundle($safariBundle);
708 die "Can't find executable at $safariPath.\n" if isAppleMacWebKit() && !-x $safariPath;
712 sub builtDylibPathForName
714 my $libraryName = shift;
715 determineConfigurationProductDir();
717 return "$configurationProductDir/$libraryName";
719 if (isBlackBerry()) {
720 my $libraryExtension = $libraryName =~ /^WebKit$/i ? ".so" : ".a";
721 return "$configurationProductDir/$libraryName/lib" . lc($libraryName) . $libraryExtension;
724 my $isSearchingForWebCore = $libraryName =~ "WebCore";
725 $libraryName = "QtWebKit";
727 if (isDarwin() and -d "$configurationProductDir/lib/$libraryName.framework") {
728 $result = "$configurationProductDir/lib/$libraryName.framework/$libraryName";
729 } elsif (isDarwin() and -d "$configurationProductDir/lib") {
730 $result = "$configurationProductDir/lib/lib$libraryName.dylib";
731 } elsif (isWindows()) {
732 if (configuration() eq "Debug") {
733 # On Windows, there is a "d" suffix to the library name. See <http://trac.webkit.org/changeset/53924/>.
737 my $mkspec = `$qmakebin -query QMAKE_MKSPECS`;
738 $mkspec =~ s/[\n|\r]$//g;
739 my $qtMajorVersion = retrieveQMakespecVar("$mkspec/qconfig.pri", "QT_MAJOR_VERSION");
740 if (not $qtMajorVersion) {
741 $qtMajorVersion = "";
744 $result = "$configurationProductDir/lib/$libraryName$qtMajorVersion.dll";
746 $result = "$configurationProductDir/lib/lib$libraryName.so";
749 if ($isSearchingForWebCore) {
750 # With CONFIG+=force_static_libs_as_shared we have a shared library for each subdir.
751 # For feature detection to work it is necessary to return the path of the WebCore library here.
752 my $replacedWithWebCore = $result;
753 $replacedWithWebCore =~ s/$libraryName/WebCore/g;
754 if (-e $replacedWithWebCore) {
755 return $replacedWithWebCore;
762 return "$configurationProductDir/libwxwebkit.dylib";
765 # WebKitGTK+ for GTK2, WebKitGTK+ for GTK3, and WebKit2 respectively.
766 my @libraries = ("libwebkitgtk-1.0", "libwebkitgtk-3.0", "libwebkit2gtk-1.0");
767 my $extension = isDarwin() ? ".dylib" : ".so";
769 foreach $libraryName (@libraries) {
770 my $libraryPath = "$configurationProductDir/.libs/" . $libraryName . $extension;
771 return $libraryPath if -e $libraryPath;
776 return "$configurationProductDir/lib/libewebkit.so";
779 return "$configurationProductDir/$libraryName";
781 if (isAppleMacWebKit()) {
782 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
784 if (isAppleWinWebKit()) {
785 if ($libraryName eq "JavaScriptCore") {
786 return "$baseProductDir/lib/$libraryName.lib";
788 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
792 die "Unsupported platform, can't determine built library locations.\nTry `build-webkit --help` for more information.\n";
795 # Check to see that all the frameworks are built.
796 sub checkFrameworks # FIXME: This is a poor name since only the Mac calls built WebCore a Framework.
798 return if isCygwin() || isWindows();
799 my @frameworks = ("JavaScriptCore", "WebCore");
800 push(@frameworks, "WebKit") if isAppleMacWebKit(); # FIXME: This seems wrong, all ports should have a WebKit these days.
801 for my $framework (@frameworks) {
802 my $path = builtDylibPathForName($framework);
803 die "Can't find built framework at \"$path\".\n" unless -e $path;
807 sub isInspectorFrontend()
809 determineIsInspectorFrontend();
810 return $isInspectorFrontend;
813 sub determineIsInspectorFrontend()
815 return if defined($isInspectorFrontend);
816 $isInspectorFrontend = checkForArgumentAndRemoveFromARGV("--inspector-frontend");
827 my $qtVersion = `$qmakebin --version`;
828 $qtVersion =~ s/^(.*)Qt version (\d\.\d)(.*)/$2/s ;
832 sub qtFeatureDefaults
834 die "ERROR: qmake missing but required to build WebKit.\n" if not commandExists($qmakebin);
836 my $qmakepath = File::Spec->catfile(sourceDir(), "Tools", "qmake");
839 $qmakecommand = "(set QMAKEPATH=$qmakepath) && $qmakebin";
841 $qmakecommand = "QMAKEPATH=$qmakepath $qmakebin";
844 my $originalCwd = getcwd();
846 my $file = File::Spec->catfile($qmakepath, "configure.pro");
851 @buildArgs = (@buildArgs, @{$_[0]});
853 my $dir = File::Spec->catfile(productDir(), "Tools", "qmake");
854 File::Path::mkpath($dir);
855 chdir $dir or die "Failed to cd into " . $dir . "\n";
857 # Do a quick check of the features without running the config tests
858 push @buildArgs, "CONFIG+=quick_check";
861 my @defaults = `$qmakecommand @buildArgs -nocache $file 2>&1`;
863 my %qtFeatureDefaults;
866 while (/(\S+?)=(\S+?)/gi) {
867 $qtFeatureDefaults{$1}=$2;
869 } elsif (/ CONFIG:(.*)$/) {
873 } elsif (/Done computing defaults/) {
883 return %qtFeatureDefaults;
889 my $devnull = File::Spec->devnull();
890 return `$command --version 2> $devnull`;
893 sub checkForArgumentAndRemoveFromARGV
895 my $argToCheck = shift;
896 return checkForArgumentAndRemoveFromArrayRef($argToCheck, \@ARGV);
899 sub checkForArgumentAndRemoveFromArrayRef
901 my ($argToCheck, $arrayRef) = @_;
903 foreach my $index (0 .. $#$arrayRef) {
904 my $opt = $$arrayRef[$index];
905 if ($opt =~ /^$argToCheck$/i ) {
906 push(@indicesToRemove, $index);
909 foreach my $index (@indicesToRemove) {
910 splice(@$arrayRef, $index, 1);
912 return $#indicesToRemove > -1;
917 if (defined($isWK2)) {
920 if (checkForArgumentAndRemoveFromARGV("-2")) {
930 return if defined($isQt);
932 # Allow override in case QTDIR is not set.
933 if (checkForArgumentAndRemoveFromARGV("--qt")) {
938 # The presence of QTDIR only means Qt if --gtk or --wx or --efl or --blackberry or --chromium or --wincairo are not on the command-line
939 if (isGtk() || isWx() || isEfl() || isBlackBerry() || isChromium() || isWinCairo()) {
944 $isQt = defined($ENV{'QTDIR'});
949 determineIsBlackBerry();
950 return $isBlackBerry;
953 sub determineIsBlackBerry()
955 return if defined($isBlackBerry);
956 $isBlackBerry = checkForArgumentAndRemoveFromARGV("--blackberry");
959 sub blackberryTargetArchitecture()
961 my $arch = $ENV{"BLACKBERRY_ARCH_TYPE"} ? $ENV{"BLACKBERRY_ARCH_TYPE"} : "arm";
962 my $cpu = $ENV{"BLACKBERRY_ARCH_CPU"} ? $ENV{"BLACKBERRY_ARCH_CPU"} : "";
965 if (($cpu eq "v7le") || ($cpu eq "a9")) {
966 $cpuDir = $arch . "le-v7";
967 $buSuffix = $arch . "v7";
973 return ("arch" => $arch,
976 "buSuffix" => $buSuffix);
979 sub blackberryCMakeArguments()
981 my %archInfo = blackberryTargetArchitecture();
982 my $arch = $archInfo{"arch"};
983 my $cpu = $archInfo{"cpu"};
984 my $cpuDir = $archInfo{"cpuDir"};
985 my $buSuffix = $archInfo{"buSuffix"};
987 my @cmakeExtraOptions;
989 $cpu = $arch . "v7le";
990 push @cmakeExtraOptions, '-DTARGETING_PLAYBOOK=1';
993 my $stageDir = $ENV{"STAGE_DIR"};
994 my $stageLib = File::Spec->catdir($stageDir, $cpuDir, "lib");
995 my $stageUsrLib = File::Spec->catdir($stageDir, $cpuDir, "usr", "lib");
996 my $stageInc = File::Spec->catdir($stageDir, "usr", "include");
998 my $qnxHost = $ENV{"QNX_HOST"};
1001 if ($ENV{"USE_ICECC"}) {
1002 chomp($ccCommand = `which icecc`);
1003 $cxxCommand = $ccCommand;
1005 $ccCommand = File::Spec->catfile($qnxHost, "usr", "bin", "qcc");
1006 $cxxCommand = $ccCommand;
1009 if ($ENV{"CCWRAP"}) {
1010 $ccCommand = $ENV{"CCWRAP"};
1011 push @cmakeExtraOptions, "-DCMAKE_C_COMPILER_ARG1=qcc";
1012 push @cmakeExtraOptions, "-DCMAKE_CXX_COMPILER_ARG1=qcc";
1015 push @cmakeExtraOptions, "-DCMAKE_SKIP_RPATH='ON'" if isDarwin();
1016 push @cmakeExtraOptions, "-DPUBLIC_BUILD=1" if $ENV{"PUBLIC_BUILD"};
1017 push @cmakeExtraOptions, "-DENABLE_GLES2=1" unless $ENV{"DISABLE_GLES2"};
1019 my @includeSystemDirectories;
1020 push @includeSystemDirectories, File::Spec->catdir($stageInc, "grskia", "skia");
1021 push @includeSystemDirectories, File::Spec->catdir($stageInc, "grskia");
1022 push @includeSystemDirectories, File::Spec->catdir($stageInc, "harfbuzz");
1023 push @includeSystemDirectories, File::Spec->catdir($stageInc, "imf");
1024 push @includeSystemDirectories, $stageInc;
1025 push @includeSystemDirectories, File::Spec->catdir($stageInc, "browser", "platform");
1026 push @includeSystemDirectories, File::Spec->catdir($stageInc, "browser", "qsk");
1027 push @includeSystemDirectories, File::Spec->catdir($stageInc, "ots");
1030 push @cxxFlags, "-Wl,-rpath-link,$stageLib";
1031 push @cxxFlags, "-Wl,-rpath-link," . File::Spec->catfile($stageUsrLib, "torch-webkit");
1032 push @cxxFlags, "-Wl,-rpath-link,$stageUsrLib";
1033 push @cxxFlags, "-L$stageLib";
1034 push @cxxFlags, "-L$stageUsrLib";
1036 if ($ENV{"PROFILE"}) {
1037 push @cmakeExtraOptions, "-DPROFILING=1";
1038 push @cxxFlags, "-p";
1042 push @cmakeArgs, '-DCMAKE_SYSTEM_NAME="QNX"';
1043 push @cmakeArgs, "-DCMAKE_SYSTEM_PROCESSOR=\"$cpuDir\"";
1044 push @cmakeArgs, '-DCMAKE_SYSTEM_VERSION="1"';
1045 push @cmakeArgs, "-DCMAKE_C_COMPILER=\"$ccCommand\"";
1046 push @cmakeArgs, "-DCMAKE_CXX_COMPILER=\"$cxxCommand\"";
1047 push @cmakeArgs, "-DCMAKE_C_FLAGS=\"-Vgcc_nto${cpu} -g @cxxFlags\"";
1048 push @cmakeArgs, "-DCMAKE_CXX_FLAGS=\"-Vgcc_nto${cpu}_cpp-ne -g -lang-c++ @cxxFlags\"";
1050 # We cannot use CMAKE_INCLUDE_PATH since this describes the search path for header files in user directories.
1051 # And the QNX system headers are in user directories on the host OS (i.e. they aren't installed in the host OS's
1052 # system header search path). So, we need to inform g++ that these user directories (@includeSystemDirectories)
1053 # are to be taken as the host OS's system header directories when building our port.
1055 # Also, we cannot use CMAKE_SYSTEM_INCLUDE_PATH since that will override the entire system header path.
1056 # So, we define the additional system include paths in ADDITIONAL_SYSTEM_INCLUDE_PATH. This list will
1057 # be processed in OptionsBlackBerry.cmake.
1058 push @cmakeArgs, '-DADDITIONAL_SYSTEM_INCLUDE_PATH="' . join(';', @includeSystemDirectories) . '"';
1060 # FIXME: Make this more general purpose such that we can pass a list of directories and files.
1061 push @cmakeArgs, '-DTHIRD_PARTY_ICU_DIR="' . File::Spec->catdir($stageInc, "unicode") . '"';
1062 push @cmakeArgs, '-DTHIRD_PARTY_UNICODE_FILE="' . File::Spec->catfile($stageInc, "unicode.h") . '"';
1064 push @cmakeArgs, "-DCMAKE_LIBRARY_PATH=\"$stageLib;$stageUsrLib\"";
1065 push @cmakeArgs, '-DCMAKE_AR="' . File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ar") . '"';
1066 push @cmakeArgs, '-DCMAKE_RANLIB="' . File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ranlib") . '"';
1067 push @cmakeArgs, '-DCMAKE_LD="'. File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ld") . '"';
1068 push @cmakeArgs, '-DCMAKE_LINKER="' . File::Spec->catfile($qnxHost, "usr", "bin", "nto${buSuffix}-ld") . '"';
1069 push @cmakeArgs, "-DECLIPSE_CDT4_GENERATE_SOURCE_PROJECT=TRUE";
1070 push @cmakeArgs, '-G"Eclipse CDT4 - Unix Makefiles"';
1071 push @cmakeArgs, @cmakeExtraOptions;
1075 sub determineIsEfl()
1077 return if defined($isEfl);
1078 $isEfl = checkForArgumentAndRemoveFromARGV("--efl");
1093 sub determineIsGtk()
1095 return if defined($isGtk);
1096 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
1105 sub determineIsWinCE()
1107 return if defined($isWinCE);
1108 $isWinCE = checkForArgumentAndRemoveFromARGV("--wince");
1119 return if defined($isWx);
1120 $isWx = checkForArgumentAndRemoveFromARGV("--wx");
1128 foreach my $opt (@ARGV) {
1129 if ($opt =~ /^--wx-args/i ) {
1130 @ARGV = grep(!/^--wx-args/i, @ARGV);
1132 $rawWxArgs =~ s/--wx-args=//i;
1135 @wxArgs = split(/,/, $rawWxArgs);
1140 # Determine if this is debian, ubuntu, linspire, or something similar.
1143 return -e "/etc/debian_version";
1148 return -e "/etc/fedora-release";
1153 determineIsChromium();
1154 determineIsChromiumAndroid();
1155 return $isChromium || $isChromiumAndroid;
1158 sub determineIsChromium()
1160 return if defined($isChromium);
1161 $isChromium = checkForArgumentAndRemoveFromARGV("--chromium");
1163 $forceChromiumUpdate = checkForArgumentAndRemoveFromARGV("--force-update");
1167 sub isChromiumAndroid()
1169 determineIsChromiumAndroid();
1170 return $isChromiumAndroid;
1173 sub determineIsChromiumAndroid()
1175 return if defined($isChromiumAndroid);
1176 $isChromiumAndroid = checkForArgumentAndRemoveFromARGV("--chromium-android");
1179 sub isChromiumMacMake()
1181 determineIsChromiumMacMake();
1182 return $isChromiumMacMake;
1185 sub determineIsChromiumMacMake()
1187 return if defined($isChromiumMacMake);
1189 my $hasUpToDateMakefile = 0;
1190 if (-e 'Makefile.chromium') {
1191 unless (-e 'Source/WebKit/chromium/WebKit.xcodeproj') {
1192 $hasUpToDateMakefile = 1;
1194 $hasUpToDateMakefile = stat('Makefile.chromium')->mtime > stat('Source/WebKit/chromium/WebKit.xcodeproj')->mtime;
1197 $isChromiumMacMake = isDarwin() && $hasUpToDateMakefile;
1200 sub isChromiumNinja()
1202 determineIsChromiumNinja();
1203 return $isChromiumNinja;
1206 sub determineIsChromiumNinja()
1208 return if defined($isChromiumNinja);
1210 my $config = configuration();
1212 my $hasUpToDateNinjabuild = 0;
1213 if (-e "out/$config/build.ninja") {
1214 my $statNinja = stat("out/$config/build.ninja")->mtime;
1217 if (-e 'Source/WebKit/chromium/WebKit.xcodeproj') {
1218 $statXcode = stat('Source/WebKit/chromium/WebKit.xcodeproj')->mtime;
1222 if (-e 'Makefile.chromium') {
1223 $statMake = stat('Makefile.chromium')->mtime;
1226 $hasUpToDateNinjabuild = $statNinja > $statXcode && $statNinja > $statMake;
1228 $isChromiumNinja = $hasUpToDateNinjabuild;
1231 sub forceChromiumUpdate()
1233 determineIsChromium();
1234 return $forceChromiumUpdate;
1239 determineIsWinCairo();
1243 sub determineIsWinCairo()
1245 return if defined($isWinCairo);
1246 $isWinCairo = checkForArgumentAndRemoveFromARGV("--wincairo");
1251 return ($^O eq "cygwin") || 0;
1256 return isWindows() || isCygwin() || isMsys();
1259 sub determineWinVersion()
1261 return if $winVersion;
1263 if (!isAnyWindows()) {
1268 my $versionString = `cmd /c ver`;
1269 $versionString =~ /(\d)\.(\d)\.(\d+)/;
1280 determineWinVersion();
1286 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 1 && winVersion()->{build} == 7600;
1289 sub isWindowsVista()
1291 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 0;
1296 return isAnyWindows() && winVersion()->{major} == 5 && winVersion()->{minor} == 1;
1301 return ($^O eq "darwin") || 0;
1306 return ($^O eq "MSWin32") || 0;
1311 return ($^O eq "msys") || 0;
1316 return ($^O eq "linux") || 0;
1321 return ($^O eq "freebsd") || 0;
1326 return $Config{archname} =~ /^arm-/;
1329 sub isCrossCompilation()
1332 $compiler = $ENV{'CC'} if (defined($ENV{'CC'}));
1333 if ($compiler =~ /gcc/) {
1334 my $compiler_options = `$compiler -v 2>&1`;
1335 my @host = $compiler_options =~ m/--host=(.*?)\s/;
1336 my @target = $compiler_options =~ m/--target=(.*?)\s/;
1338 return ($host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]);
1345 return !(isQt() or isGtk() or isWx() or isChromium() or isEfl() or isWinCE() or isBlackBerry());
1348 sub isAppleMacWebKit()
1350 return isAppleWebKit() && isDarwin();
1353 sub isAppleWinWebKit()
1355 return isAppleWebKit() && (isCygwin() || isWindows());
1358 sub isPerianInstalled()
1360 if (!isAppleWebKit()) {
1364 if (-d "/Library/QuickTime/Perian.component") {
1368 if (-d "$ENV{HOME}/Library/QuickTime/Perian.component") {
1375 sub determineNmPath()
1379 if (isAppleMacWebKit()) {
1380 $nmPath = `xcrun -find nm`;
1383 $nmPath = "nm" if !$nmPath;
1392 sub determineOSXVersion()
1394 return if $osXVersion;
1401 my $version = `sw_vers -productVersion`;
1402 my @splitVersion = split(/\./, $version);
1403 @splitVersion >= 2 or die "Invalid version $version";
1405 "major" => $splitVersion[0],
1406 "minor" => $splitVersion[1],
1407 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
1413 determineOSXVersion();
1419 return isDarwin() && osXVersion()->{"minor"} == 6;
1424 return isDarwin() && osXVersion()->{"minor"} == 7;
1429 return $ENV{'OS'} eq 'Windows_NT';
1432 sub shouldTargetWebProcess
1434 determineShouldTargetWebProcess();
1435 return $shouldTargetWebProcess;
1438 sub determineShouldTargetWebProcess
1440 return if defined($shouldTargetWebProcess);
1441 $shouldTargetWebProcess = checkForArgumentAndRemoveFromARGV("--target-web-process");
1446 determineDebugger();
1450 sub determineDebugger
1452 return if defined($debugger);
1453 if (checkForArgumentAndRemoveFromARGV("--use-lldb")) {
1460 sub appendToEnvironmentVariableList
1462 my ($environmentVariableName, $value) = @_;
1464 if (defined($ENV{$environmentVariableName})) {
1465 $ENV{$environmentVariableName} .= ":" . $value;
1467 $ENV{$environmentVariableName} = $value;
1471 sub setUpGuardMallocIfNeeded
1477 if (!defined($shouldUseGuardMalloc)) {
1478 $shouldUseGuardMalloc = checkForArgumentAndRemoveFromARGV("--guard-malloc");
1481 if ($shouldUseGuardMalloc) {
1482 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", "/usr/lib/libgmalloc.dylib");
1486 sub relativeScriptsDir()
1488 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel($FindBin::Bin, getcwd()), "");
1489 if ($scriptDir eq "") {
1497 my $relativeScriptsPath = relativeScriptsDir();
1498 if (isGtk() || isQt() || isWx() || isEfl() || isWinCE()) {
1499 return "$relativeScriptsPath/run-launcher";
1500 } elsif (isAppleWebKit()) {
1501 return "$relativeScriptsPath/run-safari";
1508 return "GtkLauncher";
1510 return "QtTestBrowser";
1513 } elsif (isAppleWebKit()) {
1516 return "EWebLauncher";
1517 } elsif (isWinCE()) {
1518 return "WinCELauncher";
1522 sub checkRequiredSystemConfig
1525 chomp(my $productVersion = `sw_vers -productVersion`);
1526 if (eval "v$productVersion" lt v10.4) {
1527 print "*************************************************************\n";
1528 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
1529 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
1530 print "*************************************************************\n";
1532 my $xcodebuildVersionOutput = `xcodebuild -version`;
1533 my $devToolsCoreVersion = ($xcodebuildVersionOutput =~ /DevToolsCore-(\d+)/) ? $1 : undef;
1534 my $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : undef;
1535 if (!$devToolsCoreVersion && !$xcodeVersion
1536 || $devToolsCoreVersion && $devToolsCoreVersion < 747
1537 || $xcodeVersion && eval "v$xcodeVersion" lt v2.3) {
1538 print "*************************************************************\n";
1539 print "Xcode Version 2.3 or later is required to build WebKit.\n";
1540 print "You have an earlier version of Xcode, thus the build will\n";
1541 print "most likely fail. The latest Xcode is available from the web:\n";
1542 print "http://developer.apple.com/tools/xcode\n";
1543 print "*************************************************************\n";
1545 } elsif (isGtk() or isQt() or isWx() or isEfl()) {
1546 my @cmds = qw(flex bison gperf);
1548 foreach my $cmd (@cmds) {
1549 push @missing, $cmd if not commandExists($cmd);
1553 my $list = join ", ", @missing;
1554 die "ERROR: $list missing but required to build WebKit.\n";
1557 # Win32 and other platforms may want to check for minimum config
1560 sub determineWindowsSourceDir()
1562 return if $windowsSourceDir;
1563 $windowsSourceDir = sourceDir();
1564 chomp($windowsSourceDir = `cygpath -w '$windowsSourceDir'`) if isCygwin();
1567 sub windowsSourceDir()
1569 determineWindowsSourceDir();
1570 return $windowsSourceDir;
1573 sub windowsLibrariesDir()
1575 return windowsSourceDir() . "\\WebKitLibraries\\win";
1578 sub windowsOutputDir()
1580 return windowsSourceDir() . "\\WebKitBuild";
1583 sub setupAppleWinEnv()
1585 return unless isAppleWinWebKit();
1587 if (isWindowsNT()) {
1588 my $restartNeeded = 0;
1589 my %variablesToSet = ();
1591 # FIXME: We should remove this explicit version check for cygwin once we stop supporting Cygwin 1.7.9 or older versions.
1592 # https://bugs.webkit.org/show_bug.cgi?id=85791
1593 my $currentCygwinVersion = version->parse(`uname -r`);
1594 my $firstCygwinVersionWithoutTTYSupport = version->parse("1.7.10");
1595 if ($currentCygwinVersion < $firstCygwinVersionWithoutTTYSupport) {
1596 # Setting the environment variable 'CYGWIN' to 'tty' makes cygwin enable extra support (i.e., termios)
1597 # for UNIX-like ttys in the Windows console
1598 $variablesToSet{CYGWIN} = "tty" unless $ENV{CYGWIN};
1601 # Those environment variables must be set to be able to build inside Visual Studio.
1602 $variablesToSet{WEBKITLIBRARIESDIR} = windowsLibrariesDir() unless $ENV{WEBKITLIBRARIESDIR};
1603 $variablesToSet{WEBKITOUTPUTDIR} = windowsOutputDir() unless $ENV{WEBKITOUTPUTDIR};
1605 foreach my $variable (keys %variablesToSet) {
1606 print "Setting the Environment Variable '" . $variable . "' to '" . $variablesToSet{$variable} . "'\n\n";
1607 system qw(regtool -s set), '\\HKEY_CURRENT_USER\\Environment\\' . $variable, $variablesToSet{$variable};
1608 $restartNeeded ||= $variable eq "WEBKITLIBRARIESDIR" || $variable eq "WEBKITOUTPUTDIR";
1611 if ($restartNeeded) {
1612 print "Please restart your computer before attempting to build inside Visual Studio.\n\n";
1615 if (!$ENV{'WEBKITLIBRARIESDIR'}) {
1616 print "Warning: You must set the 'WebKitLibrariesDir' environment variable\n";
1617 print " to be able build WebKit from within Visual Studio.\n";
1618 print " Make sure that 'WebKitLibrariesDir' points to the\n";
1619 print " 'WebKitLibraries/win' directory, not the 'WebKitLibraries/' directory.\n\n";
1621 if (!$ENV{'WEBKITOUTPUTDIR'}) {
1622 print "Warning: You must set the 'WebKitOutputDir' environment variable\n";
1623 print " to be able build WebKit from within Visual Studio.\n\n";
1628 sub setupCygwinEnv()
1630 return if !isCygwin() && !isWindows();
1631 return if $vcBuildPath;
1634 my $programFilesPath = $ENV{'PROGRAMFILES(X86)'} || $ENV{'PROGRAMFILES'} || "C:\\Program Files";
1635 if ($ENV{'VSINSTALLDIR'}) {
1636 $vsInstallDir = $ENV{'VSINSTALLDIR'};
1638 $vsInstallDir = File::Spec->catdir($programFilesPath, "Microsoft Visual Studio 8");
1640 chomp($vsInstallDir = `cygpath "$vsInstallDir"`) if isCygwin();
1641 $vcBuildPath = File::Spec->catfile($vsInstallDir, qw(Common7 IDE devenv.com));
1642 if (-e $vcBuildPath) {
1643 # Visual Studio is installed; we can use pdevenv to build.
1644 # FIXME: Make pdevenv work with non-Cygwin Perl.
1645 $vcBuildPath = File::Spec->catfile(sourceDir(), qw(Tools Scripts pdevenv)) if isCygwin();
1647 # Visual Studio not found, try VC++ Express
1648 $vcBuildPath = File::Spec->catfile($vsInstallDir, qw(Common7 IDE VCExpress.exe));
1649 if (! -e $vcBuildPath) {
1650 print "*************************************************************\n";
1651 print "Cannot find '$vcBuildPath'\n";
1652 print "Please execute the file 'vcvars32.bat' from\n";
1653 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
1654 print "to setup the necessary environment variables.\n";
1655 print "*************************************************************\n";
1658 $willUseVCExpressWhenBuilding = 1;
1661 my $qtSDKPath = File::Spec->catdir($programFilesPath, "QuickTime SDK");
1662 if (0 && ! -e $qtSDKPath) {
1663 print "*************************************************************\n";
1664 print "Cannot find '$qtSDKPath'\n";
1665 print "Please download the QuickTime SDK for Windows from\n";
1666 print "http://developer.apple.com/quicktime/download/\n";
1667 print "*************************************************************\n";
1671 unless ($ENV{WEBKITLIBRARIESDIR}) {
1672 $ENV{'WEBKITLIBRARIESDIR'} = File::Spec->catdir($sourceDir, "WebKitLibraries", "win");
1673 chomp($ENV{WEBKITLIBRARIESDIR} = `cygpath -wa '$ENV{WEBKITLIBRARIESDIR}'`) if isCygwin();
1676 print "Building results into: ", baseProductDir(), "\n";
1677 print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
1678 print "WEBKITLIBRARIESDIR is set to: ", $ENV{"WEBKITLIBRARIESDIR"}, "\n";
1681 sub dieIfWindowsPlatformSDKNotInstalled
1683 my $registry32Path = "/proc/registry/";
1684 my $registry64Path = "/proc/registry64/";
1685 my $windowsPlatformSDKRegistryEntry = "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1";
1687 # FIXME: It would be better to detect whether we are using 32- or 64-bit Windows
1688 # and only check the appropriate entry. But for now we just blindly check both.
1689 return if (-e $registry32Path . $windowsPlatformSDKRegistryEntry) || (-e $registry64Path . $windowsPlatformSDKRegistryEntry);
1691 print "*************************************************************\n";
1692 print "Cannot find registry entry '$windowsPlatformSDKRegistryEntry'.\n";
1693 print "Please download and install the Microsoft Windows Server 2003 R2\n";
1694 print "Platform SDK from <http://www.microsoft.com/downloads/details.aspx?\n";
1695 print "familyid=0baf2b35-c656-4969-ace8-e4c0c0716adb&displaylang=en>.\n\n";
1696 print "Then follow step 2 in the Windows section of the \"Installing Developer\n";
1697 print "Tools\" instructions at <http://www.webkit.org/building/tools.html>.\n";
1698 print "*************************************************************\n";
1702 sub copyInspectorFrontendFiles
1704 my $productDir = productDir();
1705 my $sourceInspectorPath = sourceDir() . "/Source/WebCore/inspector/front-end/";
1706 my $inspectorResourcesDirPath = $ENV{"WEBKITINSPECTORRESOURCESDIR"};
1708 if (!defined($inspectorResourcesDirPath)) {
1709 $inspectorResourcesDirPath = "";
1712 if (isAppleMacWebKit()) {
1713 $inspectorResourcesDirPath = $productDir . "/WebCore.framework/Resources/inspector";
1714 } elsif (isAppleWinWebKit()) {
1715 $inspectorResourcesDirPath = $productDir . "/WebKit.resources/inspector";
1716 } elsif (isQt() || isGtk()) {
1717 my $prefix = $ENV{"WebKitInstallationPrefix"};
1718 $inspectorResourcesDirPath = (defined($prefix) ? $prefix : "/usr/share") . "/webkit-1.0/webinspector";
1720 my $prefix = $ENV{"WebKitInstallationPrefix"};
1721 $inspectorResourcesDirPath = (defined($prefix) ? $prefix : "/usr/share") . "/ewebkit/webinspector";
1724 if (! -d $inspectorResourcesDirPath) {
1725 print "*************************************************************\n";
1726 print "Cannot find '$inspectorResourcesDirPath'.\n" if (defined($inspectorResourcesDirPath));
1727 print "Make sure that you have built WebKit first.\n" if (! -d $productDir || defined($inspectorResourcesDirPath));
1728 print "Optionally, set the environment variable 'WebKitInspectorResourcesDir'\n";
1729 print "to point to the directory that contains the WebKit Inspector front-end\n";
1730 print "files for the built WebCore framework.\n";
1731 print "*************************************************************\n";
1735 if (isAppleMacWebKit()) {
1736 my $sourceLocalizedStrings = sourceDir() . "/Source/WebCore/English.lproj/localizedStrings.js";
1737 my $destinationLocalizedStrings = $productDir . "/WebCore.framework/Resources/English.lproj/localizedStrings.js";
1738 system "ditto", $sourceLocalizedStrings, $destinationLocalizedStrings;
1741 return system "rsync", "-aut", "--exclude=/.DS_Store", "--exclude=*.re2js", "--exclude=.svn/", !isQt() ? "--exclude=/WebKit.qrc" : "", $sourceInspectorPath, $inspectorResourcesDirPath;
1744 sub buildXCodeProject($$@)
1746 my ($project, $clean, @extraOptions) = @_;
1749 push(@extraOptions, "-alltargets");
1750 push(@extraOptions, "clean");
1753 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
1756 sub usingVisualStudioExpress()
1759 return $willUseVCExpressWhenBuilding;
1762 sub buildVisualStudioProject
1764 my ($project, $clean) = @_;
1767 my $config = configurationForVisualStudio();
1769 dieIfWindowsPlatformSDKNotInstalled() if $willUseVCExpressWhenBuilding;
1771 chomp($project = `cygpath -w "$project"`) if isCygwin();
1773 my $action = "/build";
1778 my @command = ($vcBuildPath, $project, $action, $config);
1780 print join(" ", @command), "\n";
1781 return system @command;
1784 sub downloadWafIfNeeded
1786 # get / update waf if needed
1787 my $waf = "$sourceDir/Tools/waf/waf";
1788 my $wafURL = 'http://wxwebkit.kosoftworks.com/downloads/deps/waf';
1790 my $result = system "curl -o $waf $wafURL";
1797 my ($project, $shouldClean, @options) = @_;
1799 # set the PYTHONPATH for waf
1800 my $pythonPath = $ENV{'PYTHONPATH'};
1801 if (!defined($pythonPath)) {
1804 my $sourceDir = sourceDir();
1805 my $newPythonPath = "$sourceDir/Tools/waf/build:$pythonPath";
1807 $newPythonPath = `cygpath --mixed --path $newPythonPath`;
1809 $ENV{'PYTHONPATH'} = $newPythonPath;
1811 print "Building $project\n";
1813 my $wafCommand = "$sourceDir/Tools/waf/waf";
1814 if ($ENV{'WXWEBKIT_WAF'}) {
1815 $wafCommand = $ENV{'WXWEBKIT_WAF'};
1818 $wafCommand = `cygpath --windows "$wafCommand"`;
1822 return system $wafCommand, "uninstall", "clean", "distclean";
1825 return system $wafCommand, 'configure', 'build', 'install', @options;
1828 sub retrieveQMakespecVar
1831 my $varname = $_[1];
1833 my $varvalue = undef;
1834 #print "retrieveMakespecVar " . $mkspec . ", " . $varname . "\n";
1837 open SPEC, "<$mkspec" or return $varvalue;
1839 if ($_ =~ /\s*include\((.+)\)/) {
1840 # open the included mkspec
1841 my $oldcwd = getcwd();
1842 (my $volume, my $directories, my $file) = File::Spec->splitpath($mkspec);
1843 my $newcwd = "$volume$directories";
1844 chdir $newcwd if $newcwd;
1845 $varvalue = retrieveQMakespecVar($1, $varname);
1847 } elsif ($_ =~ /$varname\s*=\s*([^\s]+)/) {
1856 sub qtMakeCommand($)
1858 my ($qmakebin) = @_;
1859 chomp(my $mkspec = `$qmakebin -query QMAKE_MKSPECS`);
1860 $mkspec .= "/default";
1861 my $compiler = retrieveQMakespecVar("$mkspec/qmake.conf", "QMAKE_CC");
1863 #print "default spec: " . $mkspec . "\n";
1864 #print "compiler found: " . $compiler . "\n";
1866 if ($compiler && $compiler eq "cl") {
1873 sub autotoolsFlag($$)
1875 my ($flag, $feature) = @_;
1876 my $prefix = $flag ? "--enable" : "--disable";
1878 return $prefix . '-' . $feature;
1881 sub getMD5HashForFile($)
1885 open(FILE_CONTENTS, $file);
1887 # Read the whole file.
1889 while (<FILE_CONTENTS>) {
1893 close(FILE_CONTENTS);
1895 return md5_hex($contents);
1898 sub runAutogenForAutotoolsProjectIfNecessary($@)
1900 my ($dir, $prefix, $sourceDir, $project, @buildArgs) = @_;
1902 my $argumentsFile = "previous-autogen-arguments.txt";
1903 if (-e "GNUmakefile") {
1904 # Just assume that build-jsc will never be used to reconfigure JSC. Later
1905 # we can go back and make this more complicated if the demand is there.
1906 if ($project ne "WebKit") {
1910 # We only run autogen.sh again if the arguments passed have changed.
1911 if (!mustReRunAutogen($sourceDir, $argumentsFile, @buildArgs)) {
1916 print "Calling autogen.sh in " . $dir . "\n\n";
1917 print "Installation prefix directory: $prefix\n" if(defined($prefix));
1919 # Only for WebKit, write the autogen.sh arguments to a file so that we can detect
1920 # when they change and automatically re-run it.
1921 if ($project eq 'WebKit') {
1922 open(AUTOTOOLS_ARGUMENTS, ">$argumentsFile");
1923 print AUTOTOOLS_ARGUMENTS join(" ", @buildArgs);
1924 close(AUTOTOOLS_ARGUMENTS);
1927 # Make the path relative since it will appear in all -I compiler flags.
1928 # Long argument lists cause bizarre slowdowns in libtool.
1929 my $relSourceDir = File::Spec->abs2rel($sourceDir) || ".";
1931 # Compiler options to keep floating point values consistent
1932 # between 32-bit and 64-bit architectures. The options are also
1933 # used on Chromium build.
1934 determineArchitecture();
1935 if ($architecture ne "x86_64" && !isARM()) {
1936 $ENV{'CXXFLAGS'} = "-march=pentium4 -msse2 -mfpmath=sse " . ($ENV{'CXXFLAGS'} || "");
1939 # Prefix the command with jhbuild run.
1940 unshift(@buildArgs, "$relSourceDir/autogen.sh");
1941 unshift(@buildArgs, "$sourceDir/Tools/gtk/run-with-jhbuild");
1942 if (system(@buildArgs) ne 0) {
1943 die "Calling autogen.sh failed!\n";
1947 sub getJhbuildPath()
1949 return join('/', baseProductDir(), "Dependencies");
1952 sub jhbuildConfigurationChanged()
1954 foreach my $file (qw(jhbuildrc.md5sum jhbuild.modules.md5sum)) {
1955 my $path = join('/', getJhbuildPath(), $file);
1960 # Get the md5 sum of the file we're testing, look in the right platform directory.
1961 $file =~ m/(.+)\.md5sum/;
1962 my $platformDir = isEfl() ? 'efl' : 'gtk';
1963 my $actualFile = join('/', $sourceDir, 'Tools', $platformDir, $1);
1964 my $currentSum = getMD5HashForFile($actualFile);
1966 # Get our previous record.
1967 open(PREVIOUS_MD5, $path);
1968 chomp(my $previousSum = <PREVIOUS_MD5>);
1969 close(PREVIOUS_MD5);
1971 if ($previousSum ne $currentSum) {
1977 sub saveJhbuildMd5() {
1978 my $platform = isEfl() ? 'efl' : 'gtk';
1979 # Save md5sum for jhbuild-related files.
1980 foreach my $file (qw(jhbuildrc jhbuild.modules)) {
1981 my $source = join('/', $sourceDir, "Tools", $platform, $file);
1982 my $destination = join('/', getJhbuildPath(), $file);
1983 open(SUM, ">$destination" . ".md5sum");
1984 print SUM getMD5HashForFile($source);
1989 sub cleanJhbuild() {
1990 # If the configuration changed, dependencies may have been removed.
1991 # Since we lack a granular way of uninstalling those we wipe out the
1992 # jhbuild root and start from scratch.
1993 my $jhbuildPath = getJhbuildPath();
1994 if (system("rm -rf $jhbuildPath/Root") ne 0) {
1995 die "Cleaning jhbuild root failed!";
1998 my $platform = isEfl() ? 'efl' : 'gtk';
1999 if (system("perl $sourceDir/Tools/jhbuild/jhbuild-wrapper --$platform clean") ne 0) {
2000 die "Cleaning jhbuild modules failed!";
2004 sub mustReRunAutogen($@)
2006 my ($sourceDir, $filename, @currentArguments) = @_;
2008 if (! -e $filename) {
2012 open(AUTOTOOLS_ARGUMENTS, $filename);
2013 chomp(my $previousArguments = <AUTOTOOLS_ARGUMENTS>);
2014 close(AUTOTOOLS_ARGUMENTS);
2016 # We only care about the WebKit2 argument when we are building WebKit itself.
2017 # build-jsc never passes --enable-webkit2, so if we didn't do this, autogen.sh
2018 # would run for every single build on the bots, since it runs both build-webkit
2020 my $joinedCurrentArguments = join(" ", @currentArguments);
2021 if ($previousArguments ne $joinedCurrentArguments) {
2022 print "Previous autogen arguments were: $previousArguments\n\n";
2023 print "New autogen arguments are: $joinedCurrentArguments\n";
2030 sub buildAutotoolsProject($@)
2032 my ($project, $clean, @buildParams) = @_;
2035 my $dir = productDir();
2036 my $config = passedConfiguration() || configuration();
2039 # Use rm to clean the build directory since distclean may miss files
2040 if ($clean && -d $dir) {
2041 system "rm", "-rf", "$dir";
2045 File::Path::mkpath($dir) or die "Failed to create build directory " . $dir
2047 chdir $dir or die "Failed to cd into " . $dir . "\n";
2054 my $makeArgs = $ENV{"WebKitMakeArguments"} || "";
2055 for my $i (0 .. $#buildParams) {
2056 my $opt = $buildParams[$i];
2057 if ($opt =~ /^--makeargs=(.*)/i ) {
2058 $makeArgs = $makeArgs . " " . $1;
2059 } elsif ($opt =~ /^--prefix=(.*)/i ) {
2062 push @buildArgs, $opt;
2066 # Automatically determine the number of CPUs for make only
2067 # if make arguments haven't already been specified.
2068 if ($makeArgs eq "") {
2069 $makeArgs = "-j" . numberOfCPUs();
2072 # WebKit is the default target, so we don't need to specify anything.
2073 if ($project eq "JavaScriptCore") {
2074 $makeArgs .= " jsc";
2075 } elsif ($project eq "WTF") {
2076 $makeArgs .= " libWTF.la";
2079 $prefix = $ENV{"WebKitInstallationPrefix"} if !defined($prefix);
2080 push @buildArgs, "--prefix=" . $prefix if defined($prefix);
2082 # Check if configuration is Debug.
2083 my $debug = $config =~ m/debug/i;
2085 push @buildArgs, "--enable-debug";
2087 push @buildArgs, "--disable-debug";
2090 # Enable unstable features when building through build-webkit.
2091 push @buildArgs, "--enable-unstable-features";
2093 # We might need to update jhbuild dependencies.
2095 if (jhbuildConfigurationChanged()) {
2100 if (checkForArgumentAndRemoveFromArrayRef("--update-gtk", \@buildArgs)) {
2105 # Force autogen to run, to catch the possibly updated libraries.
2106 system("rm -f previous-autogen-arguments.txt");
2108 system("perl", "$sourceDir/Tools/Scripts/update-webkitgtk-libs") == 0 or die $!;
2113 # If GNUmakefile exists, don't run autogen.sh unless its arguments
2114 # have changed. The makefile should be smart enough to track autotools
2115 # dependencies and re-run autogen.sh when build files change.
2116 runAutogenForAutotoolsProjectIfNecessary($dir, $prefix, $sourceDir, $project, @buildArgs);
2118 my $gtkScriptsPath = "$sourceDir/Tools/gtk";
2119 my $runWithJhbuild = "$gtkScriptsPath/run-with-jhbuild";
2120 if (system("$runWithJhbuild $make $makeArgs") ne 0) {
2121 die "\nFailed to build WebKit using '$make'!\n";
2126 if ($project eq 'WebKit' && !isCrossCompilation()) {
2127 my @docGenerationOptions = ($runWithJhbuild, "$gtkScriptsPath/generate-gtkdoc", "--skip-html");
2128 push(@docGenerationOptions, productDir());
2130 if (system(@docGenerationOptions)) {
2131 die "\n gtkdoc did not build without warnings\n";
2138 sub jhbuildWrapperPrefixIfNeeded()
2141 return File::Spec->catfile(sourceDir(), "Tools", "efl", "run-with-jhbuild");
2146 sub removeCMakeCache()
2148 my $cacheFilePath = File::Spec->catdir(baseProductDir(), configuration(), "CMakeCache.txt");
2149 unlink($cacheFilePath) if -e $cacheFilePath;
2152 sub generateBuildSystemFromCMakeProject
2154 my ($port, $prefixPath, @cmakeArgs, $additionalCMakeArgs) = @_;
2155 my $config = configuration();
2156 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
2157 File::Path::mkpath($buildPath) unless -d $buildPath;
2158 my $originalWorkingDirectory = getcwd();
2159 chdir($buildPath) or die;
2162 push @args, "-DPORT=\"$port\"";
2163 push @args, "-DCMAKE_INSTALL_PREFIX=\"$prefixPath\"" if $prefixPath;
2164 push @args, "-DSHARED_CORE=ON" if isEfl() && $ENV{"ENABLE_DRT"};
2165 if ($config =~ /release/i) {
2166 push @args, "-DCMAKE_BUILD_TYPE=Release";
2167 } elsif ($config =~ /debug/i) {
2168 push @args, "-DCMAKE_BUILD_TYPE=Debug";
2170 # if ENABLE(TIZEN_WEBKIT_EFL_DRT)
2171 push @args, "-DSHARED_CORE=ON";
2173 push @args, @cmakeArgs if @cmakeArgs;
2174 push @args, $additionalCMakeArgs if $additionalCMakeArgs;
2176 push @args, '"' . sourceDir() . '"';
2178 # Compiler options to keep floating point values consistent
2179 # between 32-bit and 64-bit architectures.
2180 determineArchitecture();
2181 if ($architecture ne "x86_64" && !isARM()) {
2182 $ENV{'CXXFLAGS'} = "-march=pentium4 -msse2 -mfpmath=sse " . ($ENV{'CXXFLAGS'} || "");
2185 if (isEfl() && jhbuildConfigurationChanged()) {
2187 system("perl", "$sourceDir/Tools/Scripts/update-webkitefl-libs") == 0 or die $!;
2194 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
2195 # parsed for shell metacharacters.
2196 my $wrapper = jhbuildWrapperPrefixIfNeeded() . " ";
2197 my $returnCode = system($wrapper . "cmake @args");
2199 chdir($originalWorkingDirectory);
2203 sub buildCMakeGeneratedProject($)
2205 my ($makeArgs) = @_;
2206 my $config = configuration();
2207 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
2208 if (! -d $buildPath) {
2209 die "Must call generateBuildSystemFromCMakeProject() before building CMake project.";
2211 my @args = ("--build", $buildPath, "--config", $config);
2212 push @args, ("--", $makeArgs) if $makeArgs;
2214 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
2215 # parsed for shell metacharacters. In particular, $makeArgs may contain such metacharacters.
2216 my $wrapper = jhbuildWrapperPrefixIfNeeded() . " ";
2217 return system($wrapper . "cmake @args");
2220 sub cleanCMakeGeneratedProject()
2222 my $config = configuration();
2223 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
2224 if (-d $buildPath) {
2225 return system("cmake", "--build", $buildPath, "--config", $config, "--target", "clean");
2230 sub buildCMakeProjectOrExit($$$$@)
2232 my ($clean, $port, $prefixPath, $makeArgs, @cmakeArgs) = @_;
2235 exit(exitStatus(cleanCMakeGeneratedProject())) if $clean;
2237 $returnCode = exitStatus(generateBuildSystemFromCMakeProject($port, $prefixPath, @cmakeArgs));
2238 exit($returnCode) if $returnCode;
2239 $returnCode = exitStatus(buildCMakeGeneratedProject($makeArgs));
2240 exit($returnCode) if $returnCode;
2244 sub cmakeBasedPortArguments()
2246 return blackberryCMakeArguments() if isBlackBerry();
2247 return ('-DCMAKE_WINCE_SDK="STANDARDSDK_500 (ARMV4I)"') if isWinCE();
2251 sub cmakeBasedPortName()
2253 return "BlackBerry" if isBlackBerry();
2254 return "Efl" if isEfl();
2255 return "WinCE" if isWinCE();
2261 my ($prompt, $default) = @_;
2262 my $defaultValue = $default ? "[$default]" : "";
2263 print "$prompt $defaultValue: ";
2264 chomp(my $input = <STDIN>);
2265 return $input ? $input : $default;
2268 sub buildQMakeProjects
2270 my ($projects, $clean, @buildParams) = @_;
2275 my $make = qtMakeCommand($qmakebin);
2279 for my $i (0 .. $#buildParams) {
2280 my $opt = $buildParams[$i];
2281 if ($opt =~ /^--qmake=(.*)/i ) {
2283 } elsif ($opt =~ /^--qmakearg=(.*)/i ) {
2284 push @buildArgs, $1;
2285 } elsif ($opt =~ /^--makeargs=(.*)/i ) {
2287 } elsif ($opt =~ /^--install-headers=(.*)/i ) {
2288 $installHeaders = $1;
2289 } elsif ($opt =~ /^--install-libs=(.*)/i ) {
2292 push @buildArgs, $opt;
2296 # Automatically determine the number of CPUs for make only if this make argument haven't already been specified.
2297 if ($make eq "make" && $makeargs !~ /-j\s*\d+/i && (!defined $ENV{"MAKEFLAGS"} || ($ENV{"MAKEFLAGS"} !~ /-j\s*\d+/i ))) {
2298 $makeargs .= " -j" . numberOfCPUs();
2301 my $qmakepath = File::Spec->catfile(sourceDir(), "Tools", "qmake");
2304 $qmakecommand = "(set QMAKEPATH=$qmakepath) && $qmakebin";
2306 $qmakecommand = "QMAKEPATH=$qmakepath $qmakebin";
2309 my $config = configuration();
2310 push @buildArgs, "INSTALL_HEADERS=" . $installHeaders if defined($installHeaders);
2311 push @buildArgs, "INSTALL_LIBS=" . $installLibs if defined($installLibs);
2313 my $passedConfig = passedConfiguration() || "";
2314 if ($passedConfig =~ m/debug/i) {
2315 push @buildArgs, "CONFIG-=release";
2316 push @buildArgs, "CONFIG+=debug";
2317 } elsif ($passedConfig =~ m/release/i) {
2318 push @buildArgs, "CONFIG+=release";
2319 push @buildArgs, "CONFIG-=debug";
2320 } elsif ($passedConfig) {
2321 die "Build type $passedConfig is not supported with --qt.\n";
2323 push @buildArgs, "CONFIG-=debug_and_release" if ($passedConfig && isDarwin());
2325 my $originalCwd = getcwd();
2326 my $dir = File::Spec->canonpath(productDir());
2327 File::Path::mkpath($dir);
2328 chdir $dir or die "Failed to cd into " . $dir . "\n";
2330 my %defines = qtFeatureDefaults(\@buildArgs, \$qconfigs);
2332 my $svnRevision = currentSVNRevision();
2336 my $pathToDefinesCache = File::Spec->catfile($dir, ".webkit.config");
2337 my $pathToOldDefinesFile = File::Spec->catfile($dir, "defaults.txt");
2339 # FIXME: Get rid of .webkit.config and defaults.txt and move all the logic to .qmake.cache
2341 # Ease transition to new build layout
2342 if (-e $pathToOldDefinesFile) {
2343 print "Old build layout detected";
2344 $buildHint = "clean";
2345 } elsif (-e $pathToDefinesCache && open(DEFAULTS, $pathToDefinesCache)) {
2346 my %previousDefines;
2347 while (<DEFAULTS>) {
2348 if ($_ =~ m/(\S+)=(\S+)/gi) {
2349 $previousDefines{$1} = $2;
2354 $previousDefines{"SVN_REVISION"} = "unknown" if not exists $previousDefines{"SVN_REVISION"};
2356 if ($svnRevision ne $previousDefines{"SVN_REVISION"}) {
2357 print "Last built revision was " . $previousDefines{"SVN_REVISION"} .
2358 ", now at revision $svnRevision. Full incremental build needed.\n";
2360 $buildHint = "incremental";
2363 # Don't confuse the should-we-clean heuristics below
2364 delete($previousDefines{"SVN_REVISION"});
2366 my @uniqueDefineNames = keys %{ +{ map { $_, 1 } (keys %defines, keys %previousDefines) } };
2367 foreach my $define (@uniqueDefineNames) {
2368 if (! exists $previousDefines{$define}) {
2369 print "Feature $define added";
2370 $buildHint = "clean";
2374 if (! exists $defines{$define}) {
2375 print "Feature $define removed";
2376 $buildHint = "clean";
2380 if ($defines{$define} != $previousDefines{$define}) {
2381 print "Feature $define changed ($previousDefines{$define} -> $defines{$define})";
2382 $buildHint = "clean";
2387 # Missing build cache suggests we had a broken build after a clean,
2388 # so we assume we have to do an incremental build just in case.
2389 $buildHint = "incremental";
2392 if ($buildHint eq "clean") {
2393 print ", clean build needed!\n";
2394 # FIXME: This STDIN/STDOUT check does not work on the bots. Disable until it does.
2395 # if (! -t STDIN || ( &promptUser("Would you like to clean the build directory?", "yes") eq "yes")) {
2397 File::Path::rmtree($dir);
2398 File::Path::mkpath($dir);
2399 chdir $dir or die "Failed to cd into " . $dir . "\n";
2402 # Still trigger an incremental build
2403 $buildHint = "incremental";
2406 if ($buildHint eq "incremental") {
2407 my $qmakeDefines = "DEFINES +=";
2408 foreach my $key (sort keys %defines) {
2409 $qmakeDefines .= " \\\n $key=$defines{$key}";
2411 open(QMAKE_CACHE, ">.qmake.cache") or die "Cannot create .qmake.cache!\n";
2412 print QMAKE_CACHE "CONFIG += webkit_configured $qconfigs\n";
2413 print QMAKE_CACHE $qmakeDefines."\n";
2417 # Save config up-front so we can detect changes to the build config even
2418 # when the user re-configures after aborting the build.
2419 open(DEFAULTS, ">$pathToDefinesCache");
2420 print DEFAULTS "# These defines were set when building WebKit last time\n";
2421 foreach my $key (sort keys %defines) {
2422 print DEFAULTS "$key=$defines{$key}\n";
2428 my $makefile = File::Spec->catfile($dir, "Makefile");
2429 if (! -e $makefile) {
2430 push @buildArgs, "-after OVERRIDE_SUBDIRS=\"@{$projects}\"" if @{$projects};
2432 push @buildArgs, File::Spec->catfile(sourceDir(), "WebKit.pro");
2433 my $command = "$qmakecommand @buildArgs";
2434 print "Calling '$command' in " . $dir . "\n\n";
2435 print "Installation headers directory: $installHeaders\n" if(defined($installHeaders));
2436 print "Installation libraries directory: $installLibs\n" if(defined($installLibs));
2438 $result = system "$command";
2440 die "Failed to setup build environment using $qmakebin!\n";
2444 my $command = "$make $makeargs";
2445 $command =~ s/\s+$//;
2448 $command = "$command distclean";
2449 } elsif ($buildHint eq "incremental") {
2450 $command = "$command incremental";
2453 print "Calling '$command' in " . $dir . "\n\n";
2454 $result = system $command;
2459 # Now that the build completed successfully we can save the SVN revision
2460 open(DEFAULTS, ">>$pathToDefinesCache");
2461 print DEFAULTS "SVN_REVISION=$svnRevision\n";
2463 } elsif ($buildHint eq "" && exitStatus($result)) {
2464 my $exitCode = exitStatus($result);
2465 my $failMessage = <<EOF;
2467 ===== BUILD FAILED ======
2469 The build failed with exit code $exitCode. This may have been because you
2471 - added an #include to a source/header
2472 - added a Q_OBJECT macro to a class
2473 - added a new resource to a qrc file
2475 as dependencies are not automatically re-computed for local developer builds.
2476 You may try computing dependencies manually by running 'make qmake' in:
2480 or passing --makeargs="qmake" to build-webkit.
2482 =========================
2485 print "$failMessage";
2493 my ($project, $clean, @buildArgs) = @_;
2495 if ($project ne "WebKit" and $project ne "JavaScriptCore" and $project ne "WTF") {
2496 die "Unsupported project: $project. Supported projects: WebKit, JavaScriptCore, WTF\n";
2499 return buildAutotoolsProject($project, $clean, @buildArgs);
2502 sub buildChromiumMakefile($$@)
2504 my ($target, $clean, @options) = @_;
2506 return system qw(rm -rf out);
2508 my $config = configuration();
2509 my $numCpus = numberOfCPUs();
2512 $makeArgs = $1 if /^--makeargs=(.*)/i;
2514 $makeArgs = "-j$numCpus" if not $makeArgs;
2515 my $command .= "make -fMakefile.chromium $makeArgs BUILDTYPE=$config $target";
2518 return system $command;
2521 sub buildChromiumNinja($$@)
2523 # rm -rf out requires rerunning gyp, so don't support --clean for now.
2524 my ($target, @options) = @_;
2525 my $config = configuration();
2528 $makeArgs = $1 if /^--makeargs=(.*)/i;
2532 $command .= "ninja -C out/$config $target $makeArgs";
2535 return system $command;
2538 sub buildChromiumVisualStudioProject($$)
2540 my ($projectPath, $clean) = @_;
2542 my $config = configuration();
2543 my $action = "/build";
2544 $action = "/clean" if $clean;
2546 # Find Visual Studio installation.
2548 my $programFilesPath = $ENV{'PROGRAMFILES'} || "C:\\Program Files";
2549 if ($ENV{'VSINSTALLDIR'}) {
2550 $vsInstallDir = $ENV{'VSINSTALLDIR'};
2552 $vsInstallDir = "$programFilesPath/Microsoft Visual Studio 8";
2554 $vsInstallDir =~ s,\\,/,g;
2555 $vsInstallDir = `cygpath "$vsInstallDir"` if isCygwin();
2556 chomp $vsInstallDir;
2557 $vcBuildPath = "$vsInstallDir/Common7/IDE/devenv.com";
2558 if (! -e $vcBuildPath) {
2559 # Visual Studio not found, try VC++ Express
2560 $vcBuildPath = "$vsInstallDir/Common7/IDE/VCExpress.exe";
2561 if (! -e $vcBuildPath) {
2562 print "*************************************************************\n";
2563 print "Cannot find '$vcBuildPath'\n";
2564 print "Please execute the file 'vcvars32.bat' from\n";
2565 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
2566 print "to setup the necessary environment variables.\n";
2567 print "*************************************************************\n";
2572 # Create command line and execute it.
2573 my @command = ($vcBuildPath, $projectPath, $action, $config);
2574 print "Building results into: ", baseProductDir(), "\n";
2575 print join(" ", @command), "\n";
2576 return system @command;
2579 sub buildChromium($@)
2581 my ($clean, @options) = @_;
2583 # We might need to update DEPS or re-run GYP if things have changed.
2584 if (checkForArgumentAndRemoveFromArrayRef("--update-chromium", \@options)) {
2585 system("perl", "Tools/Scripts/update-webkit-chromium", "--force") == 0 or die $!;
2589 if (isDarwin() && !isChromiumAndroid() && !isChromiumMacMake() && !isChromiumNinja()) {
2590 # Mac build - builds the root xcode project.
2591 $result = buildXCodeProject("Source/WebKit/chromium/All", $clean, "-configuration", configuration(), @options);
2592 } elsif (isCygwin() || isWindows()) {
2593 # Windows build - builds the root visual studio solution.
2594 $result = buildChromiumVisualStudioProject("Source/WebKit/chromium/All.sln", $clean);
2595 } elsif (isChromiumNinja()) {
2596 $result = buildChromiumNinja("all", $clean, @options);
2597 } elsif (isLinux() || isChromiumAndroid() || isChromiumMacMake()) {
2598 # Linux build - build using make.
2599 $result = buildChromiumMakefile("all", $clean, @options);
2601 print STDERR "This platform is not supported by chromium.\n";
2606 sub chromiumInstall64BitAndroidLinkerIfNeeded
2608 my ($androidNdkRoot) = @_;
2610 # Resolve the toolchain version through glob().
2611 my $linkerDirPrefix = glob("$androidNdkRoot/toolchains/arm-linux-androideabi-*/prebuilt/linux-x86");
2613 my $linkerDirname1 = "$linkerDirPrefix/bin";
2614 my $linkerBasename1 = "arm-linux-androideabi-ld";
2615 my $linkerDirname2 = "$linkerDirPrefix/arm-linux-androideabi/bin";
2616 my $linkerBasename2 = "ld";
2617 my $newLinker = "arm-linux-androideabi-ld.e4df3e0a5bb640ccfa2f30ee67fe9b3146b152d6";
2619 # Do not continue if the new linker is not (yet) available.
2620 if (! -e "third_party/aosp/$newLinker") {
2624 chromiumReplaceAndroidLinkerIfNeeded($linkerDirname1, $linkerBasename1, $newLinker);
2625 chromiumReplaceAndroidLinkerIfNeeded($linkerDirname2, $linkerBasename2, $newLinker);
2628 sub chromiumReplaceAndroidLinkerIfNeeded
2630 my ($linkerDirname, $linkerBasename, $newLinker) = @_;
2632 # If the destination directory does not exist, or the linker has already
2633 # been installed, replacing it will not be necessary.
2634 if (! -d "$linkerDirname" || -e "$linkerDirname/$newLinker") {
2638 print "Installing 64-bit Android linker in $linkerDirname..\n";
2639 system("cp", "third_party/aosp/$newLinker", "$linkerDirname/$newLinker");
2640 system("mv", "$linkerDirname/$linkerBasename", "$linkerDirname/$linkerBasename.orig");
2641 system("ln", "-s", "$newLinker", "$linkerDirname/$linkerBasename");
2643 if (! -e "$linkerDirname/$newLinker") {
2644 print "Unable to copy the linker.\n";
2649 sub appleApplicationSupportPath
2651 open INSTALL_DIR, "</proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Apple\ Inc./Apple\ Application\ Support/InstallDir";
2652 my $path = <INSTALL_DIR>;
2653 $path =~ s/[\r\n\x00].*//;
2656 my $unixPath = `cygpath -u '$path'`;
2661 sub setPathForRunningWebKitApp
2665 if (isAppleWinWebKit()) {
2666 $env->{PATH} = join(':', productDir(), dirname(installedSafariPath()), appleApplicationSupportPath(), $env->{PATH} || "");
2668 my $qtLibs = `$qmakebin -query QT_INSTALL_LIBS`;
2669 $qtLibs =~ s/[\n|\r]$//g;
2670 $env->{PATH} = join(';', $qtLibs, productDir() . "/lib", $env->{PATH} || "");
2674 sub printHelpAndExitForRunAndDebugWebKitAppIfNeeded
2676 return unless checkForArgumentAndRemoveFromARGV("--help");
2678 my ($includeOptionsForDebugging) = @_;
2681 Usage: @{[basename($0)]} [options] [args ...]
2682 --help Show this help message
2683 --no-saved-state Disable application resume for the session on Mac OS 10.7
2684 --guard-malloc Enable Guard Malloc (Mac OS X only)
2687 if ($includeOptionsForDebugging) {
2689 --target-web-process Debug the web process
2697 sub argumentsForRunAndDebugMacWebKitApp()
2700 push @args, ("-ApplePersistenceIgnoreState", "YES") if !isSnowLeopard() && checkForArgumentAndRemoveFromArrayRef("--no-saved-state", \@args);
2704 sub runMacWebKitApp($;$)
2706 my ($appPath, $useOpenCommand) = @_;
2707 my $productDir = productDir();
2708 print "Starting @{[basename($appPath)]} with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2709 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2710 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2712 setUpGuardMallocIfNeeded();
2714 if (defined($useOpenCommand) && $useOpenCommand == USE_OPEN_COMMAND) {
2715 return system("open", "-W", "-a", $appPath, "--args", argumentsForRunAndDebugMacWebKitApp());
2717 if (architecture()) {
2718 return system "arch", "-" . architecture(), $appPath, argumentsForRunAndDebugMacWebKitApp();
2720 return system { $appPath } $appPath, argumentsForRunAndDebugMacWebKitApp();
2723 sub execMacWebKitAppForDebugging($)
2726 my $architectureSwitch;
2727 my $argumentsSeparator;
2729 if (debugger() eq "lldb") {
2730 $architectureSwitch = "--arch";
2731 $argumentsSeparator = "--";
2732 } elsif (debugger() eq "gdb") {
2733 $architectureSwitch = "-arch";
2734 $argumentsSeparator = "--args";
2736 die "Unknown debugger $debugger.\n";
2739 my $debuggerPath = `xcrun -find $debugger`;
2740 chomp $debuggerPath;
2741 die "Can't find the $debugger executable.\n" unless -x $debuggerPath;
2743 my $productDir = productDir();
2744 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
2745 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2747 setUpGuardMallocIfNeeded();
2749 my @architectureFlags = ($architectureSwitch, architecture());
2750 if (!shouldTargetWebProcess()) {
2751 print "Starting @{[basename($appPath)]} under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2752 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $appPath, argumentsForRunAndDebugMacWebKitApp() or die;
2754 my $webProcessShimPath = File::Spec->catfile($productDir, "WebProcessShim.dylib");
2755 my $webProcessPath = File::Spec->catdir($productDir, "WebProcess.app");
2756 my $webKit2ExecutablePath = File::Spec->catfile($productDir, "WebKit2.framework", "WebKit2");
2758 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", $webProcessShimPath);
2760 print "Starting WebProcess under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2761 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $webProcessPath, $webKit2ExecutablePath, "-type", "webprocess", "-client-executable", $appPath or die;
2767 if (isAppleMacWebKit()) {
2769 execMacWebKitAppForDebugging(safariPath());
2772 if (isAppleWinWebKit()) {
2774 my $productDir = productDir();
2775 chomp($ENV{WEBKITNIGHTLY} = `cygpath -wa "$productDir"`);
2776 my $safariPath = safariPath();
2777 chomp($safariPath = `cygpath -wa "$safariPath"`);
2778 return system { $vcBuildPath } $vcBuildPath, "/debugexe", "\"$safariPath\"", @ARGV;
2781 return 1; # Unsupported platform; can't debug Safari on this platform.
2787 if (isAppleMacWebKit()) {
2788 return runMacWebKitApp(safariPath());
2791 if (isAppleWinWebKit()) {
2793 my $productDir = productDir();
2794 my $webKitLauncherPath = File::Spec->catfile(productDir(), "WebKit.exe");
2795 return system { $webKitLauncherPath } $webKitLauncherPath, @ARGV;
2798 return 1; # Unsupported platform; can't run Safari on this platform.
2803 if (isAppleMacWebKit()) {
2804 return runMacWebKitApp(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2810 sub debugMiniBrowser
2812 if (isAppleMacWebKit()) {
2813 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2819 sub runWebKitTestRunner
2821 if (isAppleMacWebKit()) {
2822 return runMacWebKitApp(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2824 my $productDir = productDir();
2825 my $injectedBundlePath = "$productDir/Libraries/.libs/libTestRunnerInjectedBundle";
2826 print "Starting WebKitTestRunner with TEST_RUNNER_INJECTED_BUNDLE_FILENAME set to point to $injectedBundlePath.\n";
2827 $ENV{TEST_RUNNER_INJECTED_BUNDLE_FILENAME} = $injectedBundlePath;
2828 my @args = ("$productDir/Programs/WebKitTestRunner", @ARGV);
2829 return system {$args[0] } @args;
2835 sub debugWebKitTestRunner
2837 if (isAppleMacWebKit()) {
2838 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2844 sub runTestWebKitAPI
2846 if (isAppleMacWebKit()) {
2847 return runMacWebKitApp(File::Spec->catfile(productDir(), "TestWebKitAPI"));
2853 sub readRegistryString
2855 my ($valueName) = @_;
2856 chomp(my $string = `regtool --wow32 get "$valueName"`);
2860 sub writeRegistryString
2862 my ($valueName, $string) = @_;
2864 my $error = system "regtool", "--wow32", "set", "-s", $valueName, $string;
2866 # On Windows Vista/7 with UAC enabled, regtool will fail to modify the registry, but will still
2867 # return a successful exit code. So we double-check here that the value we tried to write to the
2868 # registry was really written.
2869 return !$error && readRegistryString($valueName) eq $string;