1 # Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
2 # Copyright (C) 2009 Google Inc. All rights reserved.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 # its contributors may be used to endorse or promote products derived
15 # from this software without specific prior written permission.
17 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # Module to share code to get to WebKit directories.
42 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
45 @EXPORT = qw(&chdirWebKit &baseProductDir &productDir &XcodeOptions &XcodeOptionString &XcodeOptionStringNoConfig &passedConfiguration &setConfiguration &safariPath &checkFrameworks ¤tSVNRevision);
54 my @baseProductDirOption;
56 my $configurationForVisualStudio;
57 my $configurationProductDir;
59 my $currentSVNRevision;
63 my %qtFeatureDefaults;
68 my $isInspectorFrontend;
70 # Variables for Win32 support
75 # Defined in VCSUtils.
78 sub determineSourceDir
81 $sourceDir = $FindBin::Bin;
82 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
84 # walks up path checking each directory to see if it is the main WebKit project dir,
85 # defined by containing JavaScriptCore, WebCore, and WebKit
86 until ((-d "$sourceDir/JavaScriptCore" && -d "$sourceDir/WebCore" && -d "$sourceDir/WebKit") || (-d "$sourceDir/Internal" && -d "$sourceDir/OpenSource"))
88 if ($sourceDir !~ s|/[^/]+$||) {
89 die "Could not find top level webkit directory above source directory using FindBin.\n";
93 $sourceDir = "$sourceDir/OpenSource" if -d "$sourceDir/OpenSource";
100 $thisPerl .= $Config{_exe} unless $thisPerl =~ m/$Config{_exe}$/i;
105 # used for scripts which are stored in a non-standard location
111 sub determineBaseProductDir
113 return if defined $baseProductDir;
114 determineSourceDir();
116 if (isAppleMacWebKit()) {
117 # Silently remove ~/Library/Preferences/xcodebuild.plist which can
118 # cause build failure. The presence of
119 # ~/Library/Preferences/xcodebuild.plist can prevent xcodebuild from
120 # respecting global settings such as a custom build products directory
121 # (<rdar://problem/5585899>).
122 my $personalPlistFile = $ENV{HOME} . "/Library/Preferences/xcodebuild.plist";
123 if (-e $personalPlistFile) {
124 unlink($personalPlistFile) || die "Could not delete $personalPlistFile: $!";
127 open PRODUCT, "defaults read com.apple.Xcode PBXApplicationwideBuildSettings 2> " . File::Spec->devnull() . " |" or die;
128 $baseProductDir = join '', <PRODUCT>;
131 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
132 undef $baseProductDir unless $baseProductDir =~ /^\//;
134 if (!defined($baseProductDir)) {
135 open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> " . File::Spec->devnull() . " |" or die;
136 $baseProductDir = <PRODUCT>;
138 if ($baseProductDir) {
139 chomp $baseProductDir;
140 undef $baseProductDir unless $baseProductDir =~ /^\//;
143 } elsif (isSymbian()) {
144 # Shadow builds are not supported on Symbian
145 $baseProductDir = $sourceDir;
148 if (!defined($baseProductDir)) { # Port-spesific checks failed, use default
149 $baseProductDir = $ENV{"WEBKITOUTPUTDIR"} || "$sourceDir/WebKitBuild";
152 if (isGit() && isGitBranchBuild()) {
153 my $branch = gitBranch();
154 $baseProductDir = "$baseProductDir/$branch";
157 if (isAppleMacWebKit()) {
158 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
159 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
160 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
161 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
162 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
163 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir");
167 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
169 $ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
172 if (isAppleWinWebKit()) {
173 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
174 chomp $unixBuildPath;
175 $baseProductDir = $unixBuildPath;
179 sub setBaseProductDir($)
181 ($baseProductDir) = @_;
184 sub determineConfiguration
186 return if defined $configuration;
187 determineBaseProductDir();
188 if (open CONFIGURATION, "$baseProductDir/Configuration") {
189 $configuration = <CONFIGURATION>;
192 if ($configuration) {
193 chomp $configuration;
194 # compatibility for people who have old Configuration files
195 $configuration = "Release" if $configuration eq "Deployment";
196 $configuration = "Debug" if $configuration eq "Development";
198 $configuration = "Release";
202 sub determineArchitecture
204 return if defined $architecture;
205 # make sure $architecture is defined for non-apple-mac builds
207 return unless isAppleMacWebKit();
209 determineBaseProductDir();
210 if (open ARCHITECTURE, "$baseProductDir/Architecture") {
211 $architecture = <ARCHITECTURE>;
217 if (isTiger() or isLeopard()) {
218 $architecture = `arch`;
220 my $supports64Bit = `sysctl -n hw.optional.x86_64`;
221 chomp $supports64Bit;
222 $architecture = $supports64Bit ? 'x86_64' : `arch`;
230 my ($productDir) = @_;
232 $jscName .= "_debug" if (isCygwin() && ($configuration eq "Debug"));
233 return "$productDir/$jscName";
236 sub argumentsForConfiguration()
238 determineConfiguration();
239 determineArchitecture();
242 push(@args, '--debug') if $configuration eq "Debug";
243 push(@args, '--release') if $configuration eq "Release";
244 push(@args, '--32-bit') if $architecture ne "x86_64";
245 push(@args, '--qt') if isQt();
246 push(@args, '--symbian') if isSymbian();
247 push(@args, '--gtk') if isGtk();
248 push(@args, '--wx') if isWx();
249 push(@args, '--chromium') if isChromium();
250 push(@args, '--inspector-frontend') if isInspectorFrontend();
254 sub determineConfigurationForVisualStudio
256 return if defined $configurationForVisualStudio;
257 determineConfiguration();
258 $configurationForVisualStudio = $configuration;
259 return unless $configuration eq "Debug";
261 chomp(my $dir = `cygpath -ua '$ENV{WEBKITLIBRARIESDIR}'`);
262 $configurationForVisualStudio = "Debug_Internal" if -f "$dir/bin/CoreFoundation_debug.dll";
265 sub determineConfigurationProductDir
267 return if defined $configurationProductDir;
268 determineBaseProductDir();
269 determineConfiguration();
270 if (isAppleWinWebKit() && !isWx()) {
271 $configurationProductDir = "$baseProductDir/bin";
273 # [Gtk] We don't have Release/Debug configurations in straight
274 # autotool builds (non build-webkit). In this case and if
275 # WEBKITOUTPUTDIR exist, use that as our configuration dir. This will
276 # allows us to run run-webkit-tests without using build-webkit.
277 if ($ENV{"WEBKITOUTPUTDIR"} && isGtk()) {
278 $configurationProductDir = "$baseProductDir";
280 $configurationProductDir = "$baseProductDir/$configuration";
285 sub setConfigurationProductDir($)
287 ($configurationProductDir) = @_;
290 sub determineCurrentSVNRevision
292 return if defined $currentSVNRevision;
293 determineSourceDir();
294 $currentSVNRevision = svnRevisionForDirectory($sourceDir);
295 return $currentSVNRevision;
301 determineSourceDir();
302 chdir $sourceDir or die;
307 determineBaseProductDir();
308 return $baseProductDir;
313 determineSourceDir();
319 determineConfigurationProductDir();
320 return $configurationProductDir;
325 my $productDir = productDir();
326 $productDir .= "/JavaScriptCore" if isQt();
327 $productDir .= "/$configuration" if (isQt() && isWindows());
328 $productDir .= "/Programs" if isGtk();
335 determineConfiguration();
336 return $configuration;
339 sub configurationForVisualStudio()
341 determineConfigurationForVisualStudio();
342 return $configurationForVisualStudio;
345 sub currentSVNRevision
347 determineCurrentSVNRevision();
348 return $currentSVNRevision;
353 determineBaseProductDir();
354 determineConfiguration();
355 determineArchitecture();
356 return (@baseProductDirOption, "-configuration", $configuration, "ARCHS=$architecture");
359 sub XcodeOptionString
361 return join " ", XcodeOptions();
364 sub XcodeOptionStringNoConfig
366 return join " ", @baseProductDirOption;
369 sub XcodeCoverageSupportOptions()
371 my @coverageSupportOptions = ();
372 push @coverageSupportOptions, "GCC_GENERATE_TEST_COVERAGE_FILES=YES";
373 push @coverageSupportOptions, "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES";
374 push @coverageSupportOptions, "EXTRA_LINK= \$(EXTRA_LINK) -ftest-coverage -fprofile-arcs";
375 push @coverageSupportOptions, "OTHER_CFLAGS= \$(OTHER_CFLAGS) -DCOVERAGE -MD";
376 push @coverageSupportOptions, "OTHER_LDFLAGS=\$(OTHER_LDFLAGS) -ftest-coverage -fprofile-arcs -framework AppKit";
377 return @coverageSupportOptions;
380 my $passedConfiguration;
381 my $searchedForPassedConfiguration;
382 sub determinePassedConfiguration
384 return if $searchedForPassedConfiguration;
385 $searchedForPassedConfiguration = 1;
387 my $isWinCairo = checkForArgumentAndRemoveFromARGV("--cairo-win32");
389 for my $i (0 .. $#ARGV) {
391 if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
392 splice(@ARGV, $i, 1);
393 $passedConfiguration = "Debug";
394 $passedConfiguration .= "_Cairo" if ($isWinCairo && isCygwin());
397 if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
398 splice(@ARGV, $i, 1);
399 $passedConfiguration = "Release";
400 $passedConfiguration .= "_Cairo" if ($isWinCairo && isCygwin());
403 if ($opt =~ /^--profil(e|ing)$/i) {
404 splice(@ARGV, $i, 1);
405 $passedConfiguration = "Profiling";
406 $passedConfiguration .= "_Cairo" if ($isWinCairo && isCygwin());
410 $passedConfiguration = undef;
413 sub passedConfiguration
415 determinePassedConfiguration();
416 return $passedConfiguration;
423 if (my $config = shift @_) {
424 $configuration = $config;
428 determinePassedConfiguration();
429 $configuration = $passedConfiguration if $passedConfiguration;
433 my $passedArchitecture;
434 my $searchedForPassedArchitecture;
435 sub determinePassedArchitecture
437 return if $searchedForPassedArchitecture;
438 $searchedForPassedArchitecture = 1;
440 for my $i (0 .. $#ARGV) {
442 if ($opt =~ /^--32-bit$/i) {
443 splice(@ARGV, $i, 1);
444 if (isAppleMacWebKit()) {
445 $passedArchitecture = `arch`;
446 chomp $passedArchitecture;
451 $passedArchitecture = undef;
454 sub passedArchitecture
456 determinePassedArchitecture();
457 return $passedArchitecture;
462 determineArchitecture();
463 return $architecture;
468 if (my $arch = shift @_) {
469 $architecture = $arch;
473 determinePassedArchitecture();
474 $architecture = $passedArchitecture if $passedArchitecture;
478 sub safariPathFromSafariBundle
480 my ($safariBundle) = @_;
482 return "$safariBundle/Contents/MacOS/Safari" if isAppleMacWebKit();
483 return $safariBundle if isAppleWinWebKit();
486 sub installedSafariPath
490 if (isAppleMacWebKit()) {
491 $safariBundle = "/Applications/Safari.app";
492 } elsif (isAppleWinWebKit()) {
493 $safariBundle = `"$configurationProductDir/FindSafari.exe"`;
494 $safariBundle =~ s/[\r\n]+$//;
495 $safariBundle = `cygpath -u '$safariBundle'`;
496 $safariBundle =~ s/[\r\n]+$//;
497 $safariBundle .= "Safari.exe";
500 return safariPathFromSafariBundle($safariBundle);
506 # Use WEBKIT_SAFARI environment variable if present.
507 my $safariBundle = $ENV{WEBKIT_SAFARI};
508 if (!$safariBundle) {
509 determineConfigurationProductDir();
510 # Use Safari.app in product directory if present (good for Safari development team).
511 if (isAppleMacWebKit() && -d "$configurationProductDir/Safari.app") {
512 $safariBundle = "$configurationProductDir/Safari.app";
513 } elsif (isAppleWinWebKit()) {
514 my $path = "$configurationProductDir/Safari.exe";
515 my $debugPath = "$configurationProductDir/Safari_debug.exe";
517 if (configurationForVisualStudio() =~ /Debug/ && -x $debugPath) {
518 $safariBundle = $debugPath;
520 $safariBundle = $path;
523 if (!$safariBundle) {
524 return installedSafariPath();
527 my $safariPath = safariPathFromSafariBundle($safariBundle);
528 die "Can't find executable at $safariPath.\n" if isAppleMacWebKit() && !-x $safariPath;
532 sub builtDylibPathForName
534 my $libraryName = shift;
535 determineConfigurationProductDir();
537 return "$configurationProductDir/$libraryName";
540 $libraryName = "QtWebKit";
541 if (isDarwin() and -d "$configurationProductDir/lib/$libraryName.framework") {
542 return "$configurationProductDir/lib/$libraryName.framework/$libraryName";
543 } elsif (isWindows()) {
544 my $mkspec = `qmake -query QMAKE_MKSPECS`;
545 $mkspec =~ s/[\n|\r]$//g;
546 my $qtMajorVersion = retrieveQMakespecVar("$mkspec/qconfig.pri", "QT_MAJOR_VERSION");
547 if (not $qtMajorVersion) {
548 $qtMajorVersion = "";
550 return "$configurationProductDir/lib/$libraryName$qtMajorVersion.dll";
552 return "$configurationProductDir/lib/lib$libraryName.so";
556 return "$configurationProductDir/libwxwebkit.dylib";
559 return "$configurationProductDir/$libraryName/../.libs/libwebkit-1.0.so";
561 if (isAppleMacWebKit()) {
562 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
564 if (isAppleWinWebKit()) {
565 if ($libraryName eq "JavaScriptCore") {
566 return "$baseProductDir/lib/$libraryName.lib";
568 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
572 die "Unsupported platform, can't determine built library locations.";
575 # Check to see that all the frameworks are built.
576 sub checkFrameworks # FIXME: This is a poor name since only the Mac calls built WebCore a Framework.
578 return if isCygwin();
579 my @frameworks = ("JavaScriptCore", "WebCore");
580 push(@frameworks, "WebKit") if isAppleMacWebKit(); # FIXME: This seems wrong, all ports should have a WebKit these days.
581 for my $framework (@frameworks) {
582 my $path = builtDylibPathForName($framework);
583 die "Can't find built framework at \"$path\".\n" unless -e $path;
587 sub isInspectorFrontend()
589 determineIsInspectorFrontend();
590 return $isInspectorFrontend;
593 sub determineIsInspectorFrontend()
595 return if defined($isInspectorFrontend);
596 $isInspectorFrontend = checkForArgumentAndRemoveFromARGV("--inspector-frontend");
607 determineIsSymbian();
611 sub qtFeatureDefaults()
613 determineQtFeatureDefaults();
614 return %qtFeatureDefaults;
617 sub determineQtFeatureDefaults()
619 return if %qtFeatureDefaults;
620 my $originalCwd = getcwd();
621 chdir File::Spec->catfile(sourceDir(), "WebCore");
622 my $defaults = `qmake CONFIG+=compute_defaults 2>&1`;
625 while ($defaults =~ m/(\S*?)=(.*?)( |$)/gi) {
626 $qtFeatureDefaults{$1}=$2;
630 sub checkForArgumentAndRemoveFromARGV
632 my $argToCheck = shift;
633 foreach my $opt (@ARGV) {
634 if ($opt =~ /^$argToCheck$/i ) {
635 @ARGV = grep(!/^$argToCheck$/i, @ARGV);
644 return if defined($isQt);
646 # Allow override in case QTDIR is not set.
647 if (checkForArgumentAndRemoveFromARGV("--qt")) {
652 # The presence of QTDIR only means Qt if --gtk is not on the command-line
653 if (isGtk() || isWx()) {
658 $isQt = defined($ENV{'QTDIR'});
661 sub determineIsSymbian()
663 return if defined($isSymbian);
665 if (checkForArgumentAndRemoveFromARGV("--symbian")) {
670 $isSymbian = defined($ENV{'EPOCROOT'});
681 return if defined($isGtk);
682 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
693 return if defined($isWx);
694 $isWx = checkForArgumentAndRemoveFromARGV("--wx");
702 foreach my $opt (@ARGV) {
703 if ($opt =~ /^--wx-args/i ) {
704 @ARGV = grep(!/^--wx-args/i, @ARGV);
706 $rawWxArgs =~ s/--wx-args=//i;
709 @wxArgs = split(/,/, $rawWxArgs);
714 # Determine if this is debian, ubuntu, linspire, or something similar.
717 return -e "/etc/debian_version";
722 return -e "/etc/fedora-release";
727 determineIsChromium();
731 sub determineIsChromium()
733 return if defined($isChromium);
734 $isChromium = checkForArgumentAndRemoveFromARGV("--chromium");
739 return ($^O eq "cygwin") || 0;
744 return ($^O eq "darwin") || 0;
749 return ($^O eq "MSWin32") || 0;
754 return ($^O eq "msys") || 0;
759 return ($^O eq "linux") || 0;
764 return !(isQt() or isGtk() or isWx() or isChromium());
767 sub isAppleMacWebKit()
769 return isAppleWebKit() && isDarwin();
772 sub isAppleWinWebKit()
774 return isAppleWebKit() && isCygwin();
777 sub isPerianInstalled()
779 if (!isAppleWebKit()) {
783 if (-d "/Library/QuickTime/Perian.component") {
787 if (-d "$ENV{HOME}/Library/QuickTime/Perian.component") {
794 sub determineOSXVersion()
796 return if $osXVersion;
803 my $version = `sw_vers -productVersion`;
804 my @splitVersion = split(/\./, $version);
805 @splitVersion >= 2 or die "Invalid version $version";
807 "major" => $splitVersion[0],
808 "minor" => $splitVersion[1],
809 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
815 determineOSXVersion();
821 return isDarwin() && osXVersion()->{"minor"} == 4;
826 return isDarwin() && osXVersion()->{"minor"} == 5;
831 return isDarwin() && osXVersion()->{"minor"} == 6;
836 return $ENV{'OS'} eq 'Windows_NT';
839 sub relativeScriptsDir()
841 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel(dirname($0), getcwd()), "");
842 if ($scriptDir eq "") {
850 my $relativeScriptsPath = relativeScriptsDir();
851 if (isGtk() || isQt() || isWx()) {
852 return "$relativeScriptsPath/run-launcher";
853 } elsif (isAppleWebKit()) {
854 return "$relativeScriptsPath/run-safari";
861 return "GtkLauncher";
866 } elsif (isAppleWebKit()) {
871 sub checkRequiredSystemConfig
874 chomp(my $productVersion = `sw_vers -productVersion`);
875 if ($productVersion lt "10.4") {
876 print "*************************************************************\n";
877 print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
878 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
879 print "*************************************************************\n";
881 my $xcodeVersion = `xcodebuild -version`;
882 if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 747) {
883 print "*************************************************************\n";
884 print "Xcode Version 2.3 or later is required to build WebKit.\n";
885 print "You have an earlier version of Xcode, thus the build will\n";
886 print "most likely fail. The latest Xcode is available from the web:\n";
887 print "http://developer.apple.com/tools/xcode\n";
888 print "*************************************************************\n";
890 } elsif (isGtk() or isQt() or isWx()) {
891 my @cmds = qw(flex bison gperf);
893 foreach my $cmd (@cmds) {
894 if (not `$cmd --version`) {
899 my $list = join ", ", @missing;
900 die "ERROR: $list missing but required to build WebKit.\n";
903 # Win32 and other platforms may want to check for minimum config
906 sub determineWindowsSourceDir()
908 return if $windowsSourceDir;
909 my $sourceDir = sourceDir();
910 chomp($windowsSourceDir = `cygpath -w '$sourceDir'`);
913 sub windowsSourceDir()
915 determineWindowsSourceDir();
916 return $windowsSourceDir;
919 sub windowsLibrariesDir()
921 return windowsSourceDir() . "\\WebKitLibraries\\win";
924 sub windowsOutputDir()
926 return windowsSourceDir() . "\\WebKitBuild";
929 sub setupAppleWinEnv()
931 return unless isAppleWinWebKit();
934 my $restartNeeded = 0;
935 my %variablesToSet = ();
937 # Setting the environment variable 'CYGWIN' to 'tty' makes cygwin enable extra support (i.e., termios)
938 # for UNIX-like ttys in the Windows console
939 $variablesToSet{CYGWIN} = "tty" unless $ENV{CYGWIN};
941 # Those environment variables must be set to be able to build inside Visual Studio.
942 $variablesToSet{WEBKITLIBRARIESDIR} = windowsLibrariesDir() unless $ENV{WEBKITLIBRARIESDIR};
943 $variablesToSet{WEBKITOUTPUTDIR} = windowsOutputDir() unless $ENV{WEBKITOUTPUTDIR};
945 foreach my $variable (keys %variablesToSet) {
946 print "Setting the Environment Variable '" . $variable . "' to '" . $variablesToSet{$variable} . "'\n\n";
947 system qw(regtool -s set), '\\HKEY_CURRENT_USER\\Environment\\' . $variable, $variablesToSet{$variable};
948 $restartNeeded ||= $variable eq "WEBKITLIBRARIESDIR" || $variable eq "WEBKITOUTPUTDIR";
951 if ($restartNeeded) {
952 print "Please restart your computer before attempting to build inside Visual Studio.\n\n";
955 if (!$ENV{'WEBKITLIBRARIESDIR'}) {
956 print "Warning: You must set the 'WebKitLibrariesDir' environment variable\n";
957 print " to be able build WebKit from within Visual Studio.\n";
958 print " Make sure that 'WebKitLibrariesDir' points to the\n";
959 print " 'WebKitLibraries/win' directory, not the 'WebKitLibraries/' directory.\n\n";
961 if (!$ENV{'WEBKITOUTPUTDIR'}) {
962 print "Warning: You must set the 'WebKitOutputDir' environment variable\n";
963 print " to be able build WebKit from within Visual Studio.\n\n";
970 return if !isCygwin();
971 return if $vcBuildPath;
974 my $programFilesPath = $ENV{'PROGRAMFILES'} || "C:\\Program Files";
975 if ($ENV{'VSINSTALLDIR'}) {
976 $vsInstallDir = $ENV{'VSINSTALLDIR'};
978 $vsInstallDir = "$programFilesPath/Microsoft Visual Studio 8";
980 $vsInstallDir = `cygpath "$vsInstallDir"`;
982 $vcBuildPath = "$vsInstallDir/Common7/IDE/devenv.com";
983 if (-e $vcBuildPath) {
984 # Visual Studio is installed; we can use pdevenv to build.
985 $vcBuildPath = File::Spec->catfile(sourceDir(), qw(WebKitTools Scripts pdevenv));
987 # Visual Studio not found, try VC++ Express
988 $vcBuildPath = "$vsInstallDir/Common7/IDE/VCExpress.exe";
989 if (! -e $vcBuildPath) {
990 print "*************************************************************\n";
991 print "Cannot find '$vcBuildPath'\n";
992 print "Please execute the file 'vcvars32.bat' from\n";
993 print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
994 print "to setup the necessary environment variables.\n";
995 print "*************************************************************\n";
1000 my $qtSDKPath = "$programFilesPath/QuickTime SDK";
1001 if (0 && ! -e $qtSDKPath) {
1002 print "*************************************************************\n";
1003 print "Cannot find '$qtSDKPath'\n";
1004 print "Please download the QuickTime SDK for Windows from\n";
1005 print "http://developer.apple.com/quicktime/download/\n";
1006 print "*************************************************************\n";
1010 chomp($ENV{'WEBKITLIBRARIESDIR'} = `cygpath -wa "$sourceDir/WebKitLibraries/win"`) unless $ENV{'WEBKITLIBRARIESDIR'};
1012 $windowsTmpPath = `cygpath -w /tmp`;
1013 chomp $windowsTmpPath;
1014 print "Building results into: ", baseProductDir(), "\n";
1015 print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
1016 print "WEBKITLIBRARIESDIR is set to: ", $ENV{"WEBKITLIBRARIESDIR"}, "\n";
1019 sub copyInspectorFrontendFiles
1021 my $productDir = productDir();
1022 my $sourceInspectorPath = sourceDir() . "/WebCore/inspector/front-end/";
1023 my $inspectorResourcesDirPath = $ENV{"WEBKITINSPECTORRESOURCESDIR"};
1025 if (!defined($inspectorResourcesDirPath)) {
1026 $inspectorResourcesDirPath = "";
1029 if (isAppleMacWebKit()) {
1030 $inspectorResourcesDirPath = $productDir . "/WebCore.framework/Resources/inspector";
1031 } elsif (isAppleWinWebKit()) {
1032 $inspectorResourcesDirPath = $productDir . "/WebKit.resources/inspector";
1033 } elsif (isQt() || isGtk()) {
1034 my $prefix = $ENV{"WebKitInstallationPrefix"};
1035 $inspectorResourcesDirPath = (defined($prefix) ? $prefix : "/usr/share") . "/webkit-1.0/webinspector";
1038 if (! -d $inspectorResourcesDirPath) {
1039 print "*************************************************************\n";
1040 print "Cannot find '$inspectorResourcesDirPath'.\n" if (defined($inspectorResourcesDirPath));
1041 print "Make sure that you have built WebKit first.\n" if (! -d $productDir || defined($inspectorResourcesDirPath));
1042 print "Optionally, set the environment variable 'WebKitInspectorResourcesDir'\n";
1043 print "to point to the directory that contains the WebKit Inspector front-end\n";
1044 print "files for the built WebCore framework.\n";
1045 print "*************************************************************\n";
1048 return system "rsync", "-aut", "--exclude=/.DS_Store", "--exclude=.svn/", !isQt() ? "--exclude=/WebKit.qrc" : "", $sourceInspectorPath, $inspectorResourcesDirPath;
1051 sub buildXCodeProject($$@)
1053 my ($project, $clean, @extraOptions) = @_;
1056 push(@extraOptions, "-alltargets");
1057 push(@extraOptions, "clean");
1060 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
1063 sub buildVisualStudioProject
1065 my ($project, $clean) = @_;
1068 my $config = configurationForVisualStudio();
1070 chomp(my $winProjectPath = `cygpath -w "$project"`);
1072 my $action = "/build";
1077 my @command = ($vcBuildPath, $winProjectPath, $action, $config);
1079 print join(" ", @command), "\n";
1080 return system @command;
1083 sub downloadWafIfNeeded
1085 # get / update waf if needed
1086 my $waf = "$sourceDir/WebKitTools/wx/waf";
1087 my $wafURL = 'http://wxwebkit.wxcommunity.com/downloads/deps/waf';
1089 my $result = system "curl -o $waf $wafURL";
1096 my ($project, $shouldClean, @options) = @_;
1098 # set the PYTHONPATH for waf
1099 my $pythonPath = $ENV{'PYTHONPATH'};
1100 if (!defined($pythonPath)) {
1103 my $sourceDir = sourceDir();
1104 my $newPythonPath = "$sourceDir/WebKitTools/wx/build:$pythonPath";
1106 $newPythonPath = `cygpath --mixed --path $newPythonPath`;
1108 $ENV{'PYTHONPATH'} = $newPythonPath;
1110 print "Building $project\n";
1112 my $wafCommand = "$sourceDir/WebKitTools/wx/waf";
1113 if ($ENV{'WXWEBKIT_WAF'}) {
1114 $wafCommand = $ENV{'WXWEBKIT_WAF'};
1117 $wafCommand = `cygpath --windows "$wafCommand"`;
1121 return system $wafCommand, "clean", "distclean";
1124 return system $wafCommand, 'configure', 'build', 'install', @options;
1127 sub retrieveQMakespecVar
1130 my $varname = $_[1];
1132 my $varvalue = undef;
1133 #print "retrieveMakespecVar " . $mkspec . ", " . $varname . "\n";
1136 open SPEC, "<$mkspec" or return $varvalue;
1138 if ($_ =~ /\s*include\((.+)\)/) {
1139 # open the included mkspec
1140 my $oldcwd = getcwd();
1141 (my $volume, my $directories, my $file) = File::Spec->splitpath($mkspec);
1142 my $newcwd = "$volume$directories";
1143 chdir $newcwd if $newcwd;
1144 $varvalue = retrieveQMakespecVar($1, $varname);
1146 } elsif ($_ =~ /$varname\s*=\s*([^\s]+)/) {
1155 sub qtMakeCommand($)
1157 my ($qmakebin) = @_;
1158 chomp(my $mkspec = `$qmakebin -query QMAKE_MKSPECS`);
1159 $mkspec .= "/default";
1160 my $compiler = retrieveQMakespecVar("$mkspec/qmake.conf", "QMAKE_CC");
1162 #print "default spec: " . $mkspec . "\n";
1163 #print "compiler found: " . $compiler . "\n";
1165 if ($compiler eq "cl") {
1172 sub autotoolsFlag($$)
1174 my ($flag, $feature) = @_;
1175 my $prefix = $flag ? "--enable" : "--disable";
1177 return $prefix . '-' . $feature;
1180 sub buildAutotoolsProject($@)
1182 my ($clean, @buildParams) = @_;
1185 my $dir = productDir();
1186 my $config = passedConfiguration() || configuration();
1187 my $prefix = $ENV{"WebKitInstallationPrefix"};
1190 my $makeArgs = $ENV{"WebKitMakeArguments"} || "";
1191 for my $i (0 .. $#buildParams) {
1192 my $opt = $buildParams[$i];
1193 if ($opt =~ /^--makeargs=(.*)/i ) {
1194 $makeArgs = $makeArgs . " " . $1;
1196 push @buildArgs, $opt;
1200 push @buildArgs, "--prefix=" . $prefix if defined($prefix);
1202 # check if configuration is Debug
1203 if ($config =~ m/debug/i) {
1204 push @buildArgs, "--enable-debug";
1206 push @buildArgs, "--disable-debug";
1209 # Use rm to clean the build directory since distclean may miss files
1210 if ($clean && -d $dir) {
1211 system "rm", "-rf", "$dir";
1215 system "mkdir", "-p", "$dir";
1217 die "Failed to create build directory " . $dir;
1221 chdir $dir or die "Failed to cd into " . $dir . "\n";
1225 #$result = system $make, "distclean";
1229 print "Calling configure in " . $dir . "\n\n";
1230 print "Installation directory: $prefix\n" if(defined($prefix));
1232 # Make the path relative since it will appear in all -I compiler flags.
1233 # Long argument lists cause bizarre slowdowns in libtool.
1234 my $relSourceDir = File::Spec->abs2rel($sourceDir);
1235 $relSourceDir = "." if !$relSourceDir;
1237 $result = system "$relSourceDir/autogen.sh", @buildArgs;
1239 die "Failed to setup build environment using 'autotools'!\n";
1242 $result = system "$make $makeArgs";
1244 die "\nFailed to build WebKit using '$make'!\n";
1251 sub buildQMakeProject($@)
1253 my ($clean, @buildParams) = @_;
1255 my @buildArgs = ("-r");
1257 my $qmakebin = "qmake"; # Allow override of the qmake binary from $PATH
1259 for my $i (0 .. $#buildParams) {
1260 my $opt = $buildParams[$i];
1261 if ($opt =~ /^--qmake=(.*)/i ) {
1263 } elsif ($opt =~ /^--qmakearg=(.*)/i ) {
1264 push @buildArgs, $1;
1265 } elsif ($opt =~ /^--makeargs=(.*)/i ) {
1268 push @buildArgs, $opt;
1272 my $make = qtMakeCommand($qmakebin);
1273 my $config = configuration();
1274 my $prefix = $ENV{"WebKitInstallationPrefix"};
1275 my $dir = File::Spec->canonpath(baseProductDir());
1276 $dir = File::Spec->catfile($dir, $config) unless isSymbian();
1277 File::Path::mkpath($dir);
1278 chdir $dir or die "Failed to cd into " . $dir . "\n";
1280 print "Generating derived sources\n\n";
1282 my @dsQmakeArgs = @buildArgs;
1283 push @dsQmakeArgs, "-r";
1284 push @dsQmakeArgs, sourceDir() . "/DerivedSources.pro";
1285 push @dsQmakeArgs, "-o Makefile.DerivedSources";
1286 print "Calling '$qmakebin @dsQmakeArgs' in " . $dir . "\n\n";
1287 my $result = system "$qmakebin @dsQmakeArgs";
1289 die "Failed while running $qmakebin to generate derived sources!\n";
1292 my $dsMakefile = "Makefile.DerivedSources";
1294 # Iterate over different source directories manually to workaround a problem with qmake+extraTargets+s60
1295 for my $subdir ("JavaScriptCore", "WebCore", "WebKit/qt/Api") {
1296 print "Calling '$make $makeargs -f $dsMakefile generated_files' in " . $dir . "/$subdir\n\n";
1297 if ($make eq "nmake") {
1298 my $subdirWindows = $subdir;
1299 $subdirWindows =~ s:/:\\:g;
1300 $result = system "pushd $subdirWindows && $make $makeargs -f $dsMakefile generated_files && popd";
1302 $result = system "$make $makeargs -C $subdir -f $dsMakefile generated_files";
1305 die "Failed to generate ${subdir}'s derived sources!\n";
1309 push @buildArgs, "OUTPUT_DIR=" . baseProductDir() . "/$config";
1310 push @buildArgs, sourceDir() . "/WebKit.pro";
1311 if ($config =~ m/debug/i) {
1312 push @buildArgs, "CONFIG-=release";
1313 push @buildArgs, "CONFIG+=debug";
1315 my $passedConfig = passedConfiguration() || "";
1316 if (!isDarwin() || $passedConfig =~ m/release/i) {
1317 push @buildArgs, "CONFIG+=release";
1318 push @buildArgs, "CONFIG-=debug";
1320 push @buildArgs, "CONFIG+=debug";
1321 push @buildArgs, "CONFIG+=debug_and_release";
1325 print "Calling '$qmakebin @buildArgs' in " . $dir . "\n\n";
1326 print "Installation directory: $prefix\n" if(defined($prefix));
1328 $result = system "$qmakebin @buildArgs";
1330 die "Failed to setup build environment using $qmakebin!\n";
1334 print "Calling '$make $makeargs distclean' in " . $dir . "\n\n";
1335 $result = system "$make $makeargs distclean";
1336 } elsif (isSymbian()) {
1337 print "\n\nWebKit is now configured for building, but you have to make\n";
1338 print "a choice about the target yourself. To start the build run:\n\n";
1339 print " make release-armv5|debug-winscw|etc.\n\n";
1341 print "Calling '$make $makeargs' in " . $dir . "\n\n";
1342 $result = system "$make $makeargs";
1349 sub buildQMakeQtProject($$@)
1351 my ($project, $clean, @buildArgs) = @_;
1353 return buildQMakeProject($clean, @buildArgs);
1356 sub buildGtkProject($$@)
1358 my ($project, $clean, @buildArgs) = @_;
1360 if ($project ne "WebKit") {
1361 die "The Gtk port builds JavaScriptCore, WebCore and WebKit in one shot! Only call it for 'WebKit'.\n";
1364 return buildAutotoolsProject($clean, @buildArgs);
1367 sub buildChromiumMakefile($$$)
1369 my ($dir, $target, $clean) = @_;
1372 return system qw(rm -rf out);
1374 my $config = configuration();
1375 my @command = ("make", "-j4", "BUILDTYPE=$config", $target);
1376 print join(" ", @command) . "\n";
1377 return system @command;
1380 sub buildChromiumVisualStudioProject($$)
1382 my ($projectPath, $clean) = @_;
1384 my $config = configuration();
1385 my $action = "/build";
1386 $action = "/clean" if $clean;
1388 # Find Visual Studio installation.
1390 my $programFilesPath = $ENV{'PROGRAMFILES'} || "C:\\Program Files";
1391 if ($ENV{'VSINSTALLDIR'}) {
1392 $vsInstallDir = $ENV{'VSINSTALLDIR'};
1394 $vsInstallDir = "$programFilesPath/Microsoft Visual Studio 8";
1396 $vsInstallDir = `cygpath "$vsInstallDir"` if isCygwin();
1397 chomp $vsInstallDir;
1398 $vcBuildPath = "$vsInstallDir/Common7/IDE/devenv.com";
1400 # Create command line and execute it.
1401 my @command = ($vcBuildPath, $projectPath, $action, $config);
1402 print "Building results into: ", baseProductDir(), "\n";
1403 print join(" ", @command), "\n";
1404 return system @command;
1407 sub buildChromium($@)
1409 my ($clean, @options) = @_;
1413 # Mac build - builds the root xcode project.
1414 $result = buildXCodeProject("WebKit/chromium/WebKit", $clean, (@options));
1415 } elsif (isCygwin() || isWindows()) {
1416 # Windows build - builds the root visual studio solution.
1417 $result = buildChromiumVisualStudioProject("WebKit/chromium/WebKit.sln", $clean);
1418 } elsif (isLinux()) {
1419 # Linux build - build using make.
1420 $ result = buildChromiumMakefile("WebKit/chromium/", "all", $clean);
1422 print STDERR "This platform is not supported by chromium.\n";
1427 sub appleApplicationSupportPath
1429 open INSTALL_DIR, "</proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Apple\ Inc./Apple\ Application\ Support/InstallDir";
1430 my $path = <INSTALL_DIR>;
1431 $path =~ s/[\r\n\x00].*//;
1434 my $unixPath = `cygpath -u '$path'`;
1439 sub setPathForRunningWebKitApp
1443 if (isAppleWinWebKit()) {
1444 $env->{PATH} = join(':', productDir(), dirname(installedSafariPath()), appleApplicationSupportPath(), $env->{PATH} || "");
1446 my $qtLibs = `qmake -query QT_INSTALL_LIBS`;
1447 $qtLibs =~ s/[\n|\r]$//g;
1448 $env->{PATH} = join(';', $qtLibs, productDir() . "/lib", $env->{PATH} || "");
1454 my ($debugger) = @_;
1456 if (isAppleMacWebKit()) {
1457 return system "$FindBin::Bin/gdb-safari", @ARGV if $debugger;
1459 my $productDir = productDir();
1460 print "Starting Safari with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
1461 $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
1462 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
1463 if (!isTiger() && architecture()) {
1464 return system "arch", "-" . architecture(), safariPath(), @ARGV;
1466 return system safariPath(), @ARGV;
1470 if (isAppleWinWebKit()) {
1471 my $script = "run-webkit-nightly.cmd";
1472 my $result = system "cp", "$FindBin::Bin/$script", productDir();
1473 return $result if $result;
1478 my $debuggerFlag = $debugger ? "/debugger" : "";
1479 $result = system "cmd", "/c", "call $script $debuggerFlag";