1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
|
# Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
# its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Module to share code to get to WebKit directories.
use strict;
use warnings;
use FindBin;
use File::Basename;
use POSIX;
use VCSUtils;
BEGIN {
use Exporter ();
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw(&chdirWebKit &baseProductDir &productDir &XcodeOptions &XcodeOptionString &XcodeOptionStringNoConfig &passedConfiguration &setConfiguration &safariPath &checkFrameworks ¤tSVNRevision);
%EXPORT_TAGS = ( );
@EXPORT_OK = ();
}
our @EXPORT_OK;
my $baseProductDir;
my @baseProductDirOption;
my $configuration;
my $configurationForVisualStudio;
my $configurationProductDir;
my $sourceDir;
my $currentSVNRevision;
my $osXVersion;
my $isQt;
my $isGtk;
my $isWx;
my $forceRun64Bit;
# Variables for Win32 support
my $vcBuildPath;
my $windowsTmpPath;
sub determineSourceDir
{
return if $sourceDir;
$sourceDir = $FindBin::Bin;
$sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
# walks up path checking each directory to see if it is the main WebKit project dir,
# defined by containing JavaScriptCore, WebCore, and WebKit
until ((-d "$sourceDir/JavaScriptCore" && -d "$sourceDir/WebCore" && -d "$sourceDir/WebKit") || (-d "$sourceDir/Internal" && -d "$sourceDir/OpenSource"))
{
if ($sourceDir !~ s|/[^/]+$||) {
die "Could not find top level webkit directory above source directory using FindBin.\n";
}
}
$sourceDir = "$sourceDir/OpenSource" if -d "$sourceDir/OpenSource";
}
# used for scripts which are stored in a non-standard location
sub setSourceDir($)
{
($sourceDir) = @_;
}
sub determineBaseProductDir
{
return if defined $baseProductDir;
determineSourceDir();
if (isOSX()) {
open PRODUCT, "defaults read com.apple.Xcode PBXApplicationwideBuildSettings 2> /dev/null |" or die;
$baseProductDir = join '', <PRODUCT>;
close PRODUCT;
$baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
undef $baseProductDir unless $baseProductDir =~ /^\//;
if (!defined($baseProductDir)) {
open PRODUCT, "defaults read com.apple.Xcode PBXProductDirectory 2> /dev/null |" or die;
$baseProductDir = <PRODUCT>;
close PRODUCT;
if ($baseProductDir) {
chomp $baseProductDir;
undef $baseProductDir unless $baseProductDir =~ /^\//;
}
}
} else {
$baseProductDir = $ENV{"WEBKITOUTPUTDIR"};
if (isCygwin() && $baseProductDir) {
my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
chomp $unixBuildPath;
$baseProductDir = $unixBuildPath;
}
}
if ($baseProductDir && isOSX()) {
$baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
$baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
$baseProductDir =~ s|^~/|$ENV{HOME}/|;
die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
@baseProductDirOption = ();
}
if (!defined($baseProductDir)) {
$baseProductDir = "$sourceDir/WebKitBuild";
if (isGit() && isGitBranchBuild()) {
my $branch = gitBranch();
$baseProductDir = "$baseProductDir/$branch";
}
@baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir") if (isOSX());
if (isCygwin()) {
my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
chomp $dosBuildPath;
$ENV{"WEBKITOUTPUTDIR"} = $dosBuildPath;
}
}
}
sub setBaseProductDir($)
{
($baseProductDir) = @_;
}
sub determineConfiguration
{
return if defined $configuration;
determineBaseProductDir();
if (open CONFIGURATION, "$baseProductDir/Configuration") {
$configuration = <CONFIGURATION>;
close CONFIGURATION;
}
if ($configuration) {
chomp $configuration;
# compatibility for people who have old Configuration files
$configuration = "Release" if $configuration eq "Deployment";
$configuration = "Debug" if $configuration eq "Development";
} else {
$configuration = "Release";
}
}
sub determineConfigurationForVisualStudio
{
return if defined $configurationForVisualStudio;
determineConfiguration();
$configurationForVisualStudio = $configuration;
return unless $configuration eq "Debug";
setupCygwinEnv();
chomp(my $dir = `cygpath -ua '$ENV{WEBKITLIBRARIESDIR}'`);
$configurationForVisualStudio = "Debug_Internal" if -f "$dir/bin/CoreFoundation_debug.dll";
}
sub determineConfigurationProductDir
{
return if defined $configurationProductDir;
determineBaseProductDir();
if(isCygwin() && !isWx()) {
$configurationProductDir = "$baseProductDir/bin";
} else {
determineConfiguration();
$configurationProductDir = "$baseProductDir/$configuration";
}
}
sub setConfigurationProductDir($)
{
($configurationProductDir) = @_;
}
sub determineCurrentSVNRevision
{
return if defined $currentSVNRevision;
determineSourceDir();
my $svnInfo = `LC_ALL=C svn info $sourceDir | grep Revision:`;
($currentSVNRevision) = ($svnInfo =~ m/Revision: (\d+).*/g);
die "Unable to determine current SVN revision in $sourceDir" unless (defined $currentSVNRevision);
return $currentSVNRevision;
}
sub chdirWebKit
{
determineSourceDir();
chdir $sourceDir or die;
}
sub baseProductDir
{
determineBaseProductDir();
return $baseProductDir;
}
sub sourceDir
{
determineSourceDir();
return $sourceDir;
}
sub productDir
{
determineConfigurationProductDir();
return $configurationProductDir;
}
sub configuration()
{
determineConfiguration();
return $configuration;
}
sub configurationForVisualStudio()
{
determineConfigurationForVisualStudio();
return $configurationForVisualStudio;
}
sub currentSVNRevision
{
determineCurrentSVNRevision();
return $currentSVNRevision;
}
sub XcodeOptions
{
determineBaseProductDir();
determineConfiguration();
return (@baseProductDirOption, "-configuration", $configuration);
}
sub XcodeOptionString
{
return join " ", XcodeOptions();
}
sub XcodeOptionStringNoConfig
{
return join " ", @baseProductDirOption;
}
my $passedConfiguration;
my $searchedForPassedConfiguration;
sub determinePassedConfiguration
{
return if $searchedForPassedConfiguration;
$searchedForPassedConfiguration = 1;
for my $i (0 .. $#ARGV) {
my $opt = $ARGV[$i];
if ($opt =~ /^--debug$/i || $opt =~ /^--devel/i) {
splice(@ARGV, $i, 1);
$passedConfiguration = "Debug";
return;
}
if ($opt =~ /^--release$/i || $opt =~ /^--deploy/i) {
splice(@ARGV, $i, 1);
$passedConfiguration = "Release";
return;
}
}
$passedConfiguration = undef;
}
sub passedConfiguration
{
determinePassedConfiguration();
return $passedConfiguration;
}
sub setConfiguration
{
if (my $config = shift @_) {
$configuration = $config;
return;
}
determinePassedConfiguration();
$configuration = $passedConfiguration if $passedConfiguration;
}
sub safariPathFromSafariBundle
{
my ($safariBundle) = @_;
return "$safariBundle/Contents/MacOS/Safari" if isOSX();
return $safariBundle if isCygwin();
}
sub installedSafariPath
{
my $safariBundle;
if (isOSX()) {
$safariBundle = "/Applications/Safari.app";
} elsif (isCygwin()) {
$safariBundle = `"$configurationProductDir/FindSafari.exe"`;
$safariBundle =~ s/[\r\n]+$//;
$safariBundle = `cygpath -u '$safariBundle'`;
$safariBundle =~ s/[\r\n]+$//;
$safariBundle .= "Safari.exe";
}
return safariPathFromSafariBundle($safariBundle);
}
# Locate Safari.
sub safariPath
{
# Use WEBKIT_SAFARI environment variable if present.
my $safariBundle = $ENV{WEBKIT_SAFARI};
if (!$safariBundle) {
determineConfigurationProductDir();
# Use Safari.app in product directory if present (good for Safari development team).
if (isOSX() && -d "$configurationProductDir/Safari.app") {
$safariBundle = "$configurationProductDir/Safari.app";
} elsif (isCygwin() && -x "$configurationProductDir/bin/Safari.exe") {
$safariBundle = "$configurationProductDir/bin/Safari.exe";
} else {
return installedSafariPath();
}
}
my $safariPath = safariPathFromSafariBundle($safariBundle);
die "Can't find executable at $safariPath.\n" if isOSX() && !-x $safariPath;
return $safariPath;
}
sub builtDylibPathForName
{
my $framework = shift;
determineConfigurationProductDir();
if (isQt() or isGtk()) {
return "$configurationProductDir/$framework";
}
if (isOSX()) {
return "$configurationProductDir/$framework.framework/Versions/A/$framework";
}
if (isCygwin()) {
if ($framework eq "JavaScriptCore") {
return "$baseProductDir/lib/$framework.lib";
} else {
return "$baseProductDir/$framework.intermediate/$configuration/$framework.intermediate/$framework.lib";
}
}
die "Unsupported platform, can't determine built library locations.";
}
# Check to see that all the frameworks are built.
sub checkFrameworks
{
return if isCygwin();
my @frameworks = ("JavaScriptCore", "WebCore");
push(@frameworks, "WebKit") if isOSX();
for my $framework (@frameworks) {
my $path = builtDylibPathForName($framework);
die "Can't find built framework at \"$path\".\n" unless -x $path;
}
}
sub hasSVGSupport
{
return 0 if isCygwin();
my $path = shift;
if (isQt()) {
return 1;
}
if (isGtk() and $path =~ /WebCore/) {
$path .= "/../.libs/webkit-1.0.so";
}
my $hasSVGSupport = 0;
if (-e $path) {
open NM, "-|", "nm", $path or die;
while (<NM>) {
$hasSVGSupport = 1 if /SVGElement/;
}
close NM;
}
return $hasSVGSupport;
}
sub removeLibraryDependingOnSVG
{
my $frameworkName = shift;
my $shouldHaveSVG = shift;
my $path = builtDylibPathForName($frameworkName);
return unless -x $path;
my $hasSVG = hasSVGSupport($path);
system "rm -f $path" if ($shouldHaveSVG xor $hasSVG);
}
sub checkWebCoreSVGSupport
{
my $required = shift;
my $framework = "WebCore";
my $path = builtDylibPathForName($framework);
my $hasSVG = hasSVGSupport($path);
if ($required && !$hasSVG) {
die "$framework at \"$path\" does not include SVG Support, please run build-webkit --svg\n";
}
return $hasSVG;
}
sub isQt()
{
determineIsQt();
return $isQt;
}
sub checkArgv($)
{
my $argToCheck = shift;
foreach my $opt (@ARGV) {
if ($opt =~ /^$argToCheck/i ) {
@ARGV = grep(!/^$argToCheck/i, @ARGV);
return 1;
}
}
return 0;
}
sub determineIsQt()
{
return if defined($isQt);
# Allow override in case QTDIR is not set.
if (checkArgv("--qt")) {
$isQt = 1;
return;
}
# The presence of QTDIR only means Qt if --gtk is not on the command-line
if (isGtk()) {
$isQt = 0;
return;
}
$isQt = defined($ENV{'QTDIR'});
}
sub isGtk()
{
determineIsGtk();
return $isGtk;
}
sub determineIsGtk()
{
return if defined($isGtk);
if (checkArgv("--gtk")) {
$isGtk = 1;
} else {
$isGtk = 0;
}
}
sub isWx()
{
determineIsWx();
return $isWx;
}
sub determineIsWx()
{
return if defined($isWx);
if (checkArgv("--wx")) {
$isWx = 1;
} else {
$isWx = 0;
}
}
# Determine if this is debian, ubuntu, linspire, or something similar.
sub isDebianBased()
{
return -e "/etc/debian_version";
}
sub isCygwin()
{
return ($^O eq "cygwin") || 0;
}
sub isDarwin()
{
return ($^O eq "darwin") || 0;
}
# isOSX() only returns true for Apple's port, not for other ports that can be
# built/run on OS X.
sub isOSX()
{
return isDarwin() unless (isQt() or isGtk() or isWx());
return 0;
}
sub determineOSXVersion()
{
return if $osXVersion;
if (!isOSX()) {
$osXVersion = -1;
return;
}
my $version = `sw_vers -productVersion`;
my @splitVersion = split(/\./, $version);
@splitVersion >= 2 or die "Invalid version $version";
$osXVersion = {
"major" => $splitVersion[0],
"minor" => $splitVersion[1],
"subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
};
}
sub osXVersion()
{
determineOSXVersion();
return $osXVersion;
}
sub isTiger()
{
return isOSX() && osXVersion()->{"minor"} == 4;
}
sub isLeopard()
{
return isOSX() && osXVersion()->{"minor"} == 5;
}
sub relativeScriptsDir()
{
my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel(dirname($0), getcwd()), "");
if ($scriptDir eq "") {
$scriptDir = ".";
}
return $scriptDir;
}
sub launcherPath()
{
my $relativeScriptsPath = relativeScriptsDir();
if (isGtk() || isQt()) {
return "$relativeScriptsPath/run-launcher";
} elsif (isOSX() || isCygwin()) {
return "$relativeScriptsPath/run-safari";
}
}
sub launcherName()
{
if (isGtk()) {
return "GtkLauncher";
} elsif (isQt()) {
return "QtLauncher";
} elsif (isOSX() || isCygwin()) {
return "Safari";
}
}
sub checkRequiredSystemConfig
{
if (isOSX()) {
chomp(my $productVersion = `sw_vers -productVersion`);
if ($productVersion lt "10.4") {
print "*************************************************************\n";
print "Mac OS X Version 10.4.0 or later is required to build WebKit.\n";
print "You have " . $productVersion . ", thus the build will most likely fail.\n";
print "*************************************************************\n";
}
my $xcodeVersion = `xcodebuild -version`;
if ($xcodeVersion !~ /DevToolsCore-(\d+)/ || $1 < 747) {
print "*************************************************************\n";
print "Xcode Version 2.3 or later is required to build WebKit.\n";
print "You have an earlier version of Xcode, thus the build will\n";
print "most likely fail. The latest Xcode is available from the web:\n";
print "http://developer.apple.com/tools/xcode\n";
print "*************************************************************\n";
}
} elsif (isGtk() or isQt() or isWx()) {
my @cmds = qw(flex bison gperf);
my @missing = ();
foreach my $cmd (@cmds) {
if (not `$cmd --version`) {
push @missing, $cmd;
}
}
if (@missing) {
my $list = join ", ", @missing;
die "ERROR: $list missing but required to build WebKit.\n";
}
}
# Win32 and other platforms may want to check for minimum config
}
sub setupCygwinEnv()
{
return if !isCygwin();
return if $vcBuildPath;
my $programFilesPath = `cygpath "$ENV{'PROGRAMFILES'}"`;
chomp $programFilesPath;
$vcBuildPath = "$programFilesPath/Microsoft Visual Studio 8/Common7/IDE/devenv.com";
if (! -e $vcBuildPath) {
# VC++ not found, try VC++ Express
my $vsInstallDir;
if ($ENV{'VSINSTALLDIR'}) {
$vsInstallDir = $ENV{'VSINSTALLDIR'};
} else {
$programFilesPath = $ENV{'PROGRAMFILES'} || "C:\\Program Files";
$vsInstallDir = "$programFilesPath/Microsoft Visual Studio 8";
}
$vsInstallDir = `cygpath "$vsInstallDir"`;
chomp $vsInstallDir;
$vcBuildPath = "$vsInstallDir/Common7/IDE/VCExpress.exe";
if (! -e $vcBuildPath) {
print "*************************************************************\n";
print "Cannot find '$vcBuildPath'\n";
print "Please execute the file 'vcvars32.bat' from\n";
print "'$programFilesPath\\Microsoft Visual Studio 8\\VC\\bin\\'\n";
print "to setup the necessary environment variables.\n";
print "*************************************************************\n";
die;
}
}
my $qtSDKPath = "$programFilesPath/QuickTime SDK";
if (0 && ! -e $qtSDKPath) {
print "*************************************************************\n";
print "Cannot find '$qtSDKPath'\n";
print "Please download the QuickTime SDK for Windows from\n";
print "http://developer.apple.com/quicktime/download/\n";
print "*************************************************************\n";
die;
}
chomp($ENV{'WEBKITLIBRARIESDIR'} = `cygpath -wa "$sourceDir/WebKitLibraries/win"`) unless $ENV{'WEBKITLIBRARIESDIR'};
$windowsTmpPath = `cygpath -w /tmp`;
chomp $windowsTmpPath;
print "Building results into: ", baseProductDir(), "\n";
print "WEBKITOUTPUTDIR is set to: ", $ENV{"WEBKITOUTPUTDIR"}, "\n";
print "WEBKITLIBRARIESDIR is set to: ", $ENV{"WEBKITLIBRARIESDIR"}, "\n";
}
sub buildVisualStudioProject
{
my ($project, $clean) = @_;
setupCygwinEnv();
my $config = configurationForVisualStudio();
chomp(my $winProjectPath = `cygpath -w "$project"`);
my $command = "/build";
if ($clean) {
$command = "/clean";
}
print "$vcBuildPath $winProjectPath /build $config\n";
return system $vcBuildPath, $winProjectPath, $command, $config;
}
sub retrieveQMakespecVar
{
my $mkspec = $_[0];
my $varname = $_[1];
my $compiler = "unknown";
#print "retrieveMakespecVar " . $mkspec . ", " . $varname . "\n";
local *SPEC;
open SPEC, "<$mkspec" or return "make";
while (<SPEC>) {
if ($_ =~ /\s*include\((.+)\)/) {
# open the included mkspec
my $oldcwd = getcwd();
(my $volume, my $directories, my $file) = File::Spec->splitpath($mkspec);
chdir "$volume$directories";
$compiler = retrieveQMakespecVar($1, $varname);
chdir $oldcwd;
} elsif ($_ =~ /$varname\s*=\s*([^\s]+)/) {
$compiler = $1;
last;
}
}
close SPEC;
return $compiler;
}
sub qtMakeCommand($)
{
my ($qmakebin) = @_;
chomp(my $mkspec = `$qmakebin -query QMAKE_MKSPECS`);
$mkspec .= "/default";
my $compiler = retrieveQMakespecVar("$mkspec/qmake.conf", "QMAKE_CC");
#print "default spec: " . $mkspec . "\n";
#print "compiler found: " . $compiler . "\n";
if ($compiler eq "cl") {
return "nmake";
}
return "make";
}
sub autotoolsFlag($$)
{
my ($flag, $feature) = @_;
my $prefix = $flag ? "--enable" : "--disable";
return $prefix . '-' . $feature;
}
sub buildAutotoolsProject($@)
{
my ($clean, @buildArgs) = @_;
my $make = 'make';
my $dir = productDir();
my $config = passedConfiguration() || configuration();
my $prefix = $ENV{"WebKitInstallationPrefix"};
# check if configuration is Debug
if ($config =~ m/debug/i) {
push @buildArgs, "--enable-debug";
} else {
push @buildArgs, "--disable-debug";
}
if (! -d $dir) {
system "mkdir", "-p", "$dir";
if (! -d $dir) {
die "Failed to create build directory " . $dir;
}
}
chdir $dir or die "Failed to cd into " . $dir . "\n";
my $result;
if ($clean) {
$result = system $make, "distclean";
return 0;
}
print "Calling configure in " . $dir . "\n\n";
print "Installation directory: $prefix\n" if(defined($prefix));
$result = system "$sourceDir/autogen.sh", @buildArgs;
if ($result ne 0) {
die "Failed to setup build environment using 'autotools'!\n";
}
$result = system $make;
if ($result ne 0) {
die "\nFailed to build WebKit using '$make'!\n";
}
chdir ".." or die;
return $result;
}
sub buildQMakeProject($@)
{
my ($clean, @buildArgs) = @_;
push @buildArgs, "-r";
my $qmakebin = "qmake"; # Allow override of the qmake binary from $PATH
for my $i (0 .. $#ARGV) {
my $opt = $ARGV[$i];
if ($opt =~ /^--qmake=(.*)/i ) {
$qmakebin = $1;
} elsif ($opt =~ /^--qmakearg=(.*)/i ) {
push @buildArgs, $1;
}
}
my $make = qtMakeCommand($qmakebin);
my $config = configuration();
my $prefix = $ENV{"WebKitInstallationPrefix"};
push @buildArgs, "OUTPUT_DIR=" . baseProductDir() . "/$config";
push @buildArgs, sourceDir() . "/WebKit.pro";
if ($config =~ m/debug/i) {
push @buildArgs, "CONFIG-=release";
push @buildArgs, "CONFIG+=debug";
} else {
push @buildArgs, "CONFIG+=release";
push @buildArgs, "CONFIG-=debug";
}
my $dir = baseProductDir();
if (! -d $dir) {
system "mkdir", "-p", "$dir";
if (! -d $dir) {
die "Failed to create product directory " . $dir;
}
}
$dir = $dir . "/$config";
if (! -d $dir) {
system "mkdir", "-p", "$dir";
if (! -d $dir) {
die "Failed to create build directory " . $dir;
}
}
chdir $dir or die "Failed to cd into " . $dir . "\n";
print "Calling '$qmakebin @buildArgs' in " . $dir . "\n\n";
print "Installation directory: $prefix\n" if(defined($prefix));
my $result = system $qmakebin, @buildArgs;
if ($result ne 0) {
die "Failed to setup build environment using $qmakebin!\n";
}
if ($clean) {
$result = system "$make distclean";
} else {
$result = system "$make";
}
chdir ".." or die;
return $result;
}
sub buildQMakeQtProject($$)
{
my ($project, $clean) = @_;
my @buildArgs = ("CONFIG+=qt-port");
return buildQMakeProject($clean, @buildArgs);
}
sub buildGtkProject($$@)
{
my ($project, $clean, @buildArgs) = @_;
if ($project ne "WebKit") {
die "The Gtk port builds JavaScriptCore, WebCore and WebKit in one shot! Only call it for 'WebKit'.\n";
}
return buildAutotoolsProject($clean, @buildArgs);
}
sub setPathForRunningWebKitApp
{
my ($env) = @_;
return unless isCygwin();
$env->{PATH} = join(':', productDir(), dirname(installedSafariPath()), $env->{PATH} || "");
}
sub exitStatus($)
{
my ($returnvalue) = @_;
if ($^O eq "MSWin32") {
return $returnvalue >> 8;
}
return WEXITSTATUS($returnvalue);
}
sub runSafari
{
my ($debugger) = @_;
if (isOSX()) {
return system "$FindBin::Bin/gdb-safari", @ARGV if $debugger;
my $productDir = productDir();
print "Starting Safari with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
$ENV{DYLD_FRAMEWORK_PATH} = $productDir;
$ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
exportArchPreference();
if (!isTiger()) {
return system "arch", safariPath(), @ARGV;
} else {
return system safariPath(), @ARGV;
}
}
if (isCygwin()) {
my $script = "run-webkit-nightly.cmd";
my $result = system "cp", "$FindBin::Bin/$script", productDir();
return $result if $result;
my $cwd = getcwd();
chdir productDir();
my $debuggerFlag = $debugger ? "/debugger" : "";
$result = system "cmd", "/c", "call $script $debuggerFlag";
chdir $cwd;
return $result;
}
return 1;
}
sub setRun64Bit($)
{
($forceRun64Bit) = @_;
}
sub preferredArchitecture()
{
return unless isOSX();
my $currentArchitecture = `arch`;
chomp($currentArchitecture);
my $run64Bit = 0;
if (!defined($forceRun64Bit)) {
my $webKitPath = builtDylibPathForName("WebKit");
# The binary is 64-bit if one of the architectures it contains has "64" in the name
$run64Bit = `lipo -info "$webKitPath"` =~ /(are|architecture):.*64/;
}
if ($forceRun64Bit or $run64Bit) {
return ($currentArchitecture eq "i386") ? "x86_64" : "ppc64";
}
return $currentArchitecture;
}
sub exportArchPreference
{
$ENV{ARCHPREFERENCE} = preferredArchitecture() if isOSX();
}
1;
|