Home | History | Annotate | Download | only in Scripts
      1 #!/usr/bin/perl -w
      2 
      3 # Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
      4 # Copyright (C) 2009 Google Inc. All rights reserved.
      5 # Copyright (C) 2010 moiji-mobile.com All rights reserved.
      6 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
      7 #
      8 # Redistribution and use in source and binary forms, with or without
      9 # modification, are permitted provided that the following conditions
     10 # are met:
     11 #
     12 # 1.  Redistributions of source code must retain the above copyright
     13 #     notice, this list of conditions and the following disclaimer. 
     14 # 2.  Redistributions in binary form must reproduce the above copyright
     15 #     notice, this list of conditions and the following disclaimer in the
     16 #     documentation and/or other materials provided with the distribution. 
     17 # 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     18 #     its contributors may be used to endorse or promote products derived
     19 #     from this software without specific prior written permission. 
     20 #
     21 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     22 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     23 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     24 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     25 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     26 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31 
     32 # Build script wrapper for the WebKit Open Source Project.
     33 
     34 use strict;
     35 use File::Basename;
     36 use File::Find;
     37 use File::Spec;
     38 use FindBin;
     39 use Getopt::Long qw(:config pass_through);
     40 use lib $FindBin::Bin;
     41 use webkitdirs;
     42 use webkitperl::features;
     43 use POSIX;
     44 
     45 sub cMakeArgsFromFeatures();
     46 sub checkForJavaSDK();
     47 sub formatBuildTime($);
     48 sub writeCongrats();
     49 
     50 my $originalWorkingDirectory = getcwd();
     51 chdirWebKit();
     52 
     53 my $showHelp = 0;
     54 my $clean = 0;
     55 my $useGYP = 0;
     56 my $minimal = 0;
     57 my $v8 = 0;
     58 my $installHeaders;
     59 my $installLibs;
     60 my $prefixPath;
     61 my $makeArgs = "";
     62 my $noWebKit2 = 0;
     63 my $startTime = time();
     64 
     65 my (
     66     $threeDCanvasSupport,
     67     $threeDRenderingSupport,
     68     $accelerated2dCanvasSupport,
     69     $blobSupport,
     70     $channelMessagingSupport,
     71     $clientBasedGeolocationSupport,
     72     $coverageSupport,
     73     $databaseSupport,
     74     $datagridSupport,
     75     $datalistSupport,
     76     $dataTransferItemsSupport,
     77     $deviceOrientationSupport,
     78     $directoryUploadSupport,
     79     $domStorageSupport,
     80     $eventsourceSupport,
     81     $fileSystemSupport,
     82     $filtersSupport,
     83     $fullscreenAPISupport,
     84     $geolocationSupport,
     85     $iconDatabaseSupport,
     86     $imageResizerSupport,
     87     $indexedDatabaseSupport,
     88     $inputSpeechSupport,
     89     $javaScriptDebuggerSupport,
     90     $linkPrefetchSupport,
     91     $mathmlSupport,
     92     $mediaStatisticsSupport,
     93     $mediaStreamSupport,
     94     $meterTagSupport,
     95     $netscapePluginSupport,
     96     $notificationsSupport,
     97     $offlineWebApplicationSupport,
     98     $orientationEventsSupport,
     99     $pageVisibilityApiSupport,
    100     $progressTagSupport,
    101     $quotaSupport,
    102     $registerProtocolHandlerSupport,
    103     $sharedWorkersSupport,
    104     $svgSupport,
    105     $svgAnimationSupport,
    106     $svgAsImageSupport,
    107     $svgDOMObjCBindingsSupport,
    108     $svgFontsSupport,
    109     $svgForeignObjectSupport,
    110     $svgUseSupport,
    111     $systemMallocSupport,
    112     $tiledBackingStoreSupport,
    113     $touchEventsSupport,
    114     $videoSupport,
    115     $wcssSupport,
    116     $webAudioSupport,
    117     $webInspectorSupport,
    118     $webSocketsSupport,
    119     $webTimingSupport,
    120     $wmlSupport,
    121     $workersSupport,
    122     $xhtmlmpSupport,
    123     $xpathSupport,
    124     $xsltSupport,
    125 );
    126 
    127 my @features = (
    128     { option => "3d-canvas", desc => "Toggle 3D canvas (WebGL) support",
    129       define => "ENABLE_WEBGL", default => (isAppleMacWebKit() && !isTiger() && !isLeopard()), value => \$threeDCanvasSupport },
    130 
    131     { option => "3d-rendering", desc => "Toggle 3D rendering support",
    132       define => "ENABLE_3D_RENDERING", default => (isAppleMacWebKit() && !isTiger()), value => \$threeDRenderingSupport },
    133 
    134     { option => "accelerated-2d-canvas", desc => "Toggle accelerated 2D canvas support",
    135       define => "ENABLE_ACCELERATED_2D_CANVAS", default => 0, value => \$accelerated2dCanvasSupport },
    136 
    137     { option => "blob", desc => "Toggle Blob support",
    138       define => "ENABLE_BLOB", default => (isAppleMacWebKit() || isGtk()), value => \$blobSupport },
    139 
    140     { option => "channel-messaging", desc => "Toggle MessageChannel and MessagePort support",
    141       define => "ENABLE_CHANNEL_MESSAGING", default => 1, value => \$channelMessagingSupport },
    142 
    143     { option => "client-based-geolocation", desc => "Toggle client-based Geolocation support",
    144       define => "ENABLE_CLIENT_BASED_GEOLOCATION", default => isAppleWebKit(), value => \$clientBasedGeolocationSupport },
    145 
    146     { option => "coverage", desc => "Toggle code coverage support",
    147       define => "", default => 0, value => \$coverageSupport },
    148 
    149     { option => "database", desc => "Toggle Database Support",
    150       define => "ENABLE_DATABASE", default => 1, value => \$databaseSupport },
    151 
    152     { option => "datagrid", desc => "Toggle Datagrid Support",
    153       define => "ENABLE_DATAGRID", default => 0, value => \$datagridSupport },
    154 
    155     { option => "datalist", desc => "Toggle HTML5 datalist support",
    156       define => "ENABLE_DATALIST", default => 1, value => \$datalistSupport },
    157 
    158     { option => "data-transfer-items", desc => "Toggle HTML5 data transfer items support",
    159       define => "ENABLE_DATA_TRANSFER_ITEMS", default => 0, value => \$dataTransferItemsSupport },
    160 
    161     { option => "device-orientation", desc => "Toggle DeviceOrientation support",
    162       define => "ENABLE_DEVICE_ORIENTATION", default => 0, value => \$deviceOrientationSupport },
    163 
    164     { option => "directory-upload", desc => "Toogle Directory upload support",
    165       define => "ENABLE_DIRECTORY_UPLOAD", default => 0, value => \$directoryUploadSupport },
    166 
    167     { option => "dom-storage", desc => "Toggle DOM Storage Support",
    168       define => "ENABLE_DOM_STORAGE", default => 1, value => \$domStorageSupport },
    169 
    170     { option => "eventsource", desc => "Toggle server-sent events support",
    171       define => "ENABLE_EVENTSOURCE", default => 1, value => \$eventsourceSupport },
    172 
    173     { option => "file-system", desc => "Toggle FileSystem support",
    174       define => "ENABLE_FILE_SYSTEM", default => 0, value => \$fileSystemSupport },
    175 
    176     { option => "filters", desc => "Toggle Filters support",
    177       define => "ENABLE_FILTERS", default => (isAppleWebKit() || isGtk() || isQt() || isEfl()), value => \$filtersSupport },
    178 
    179     { option => "fullscreen-api", desc => "Toggle Fullscreen API support",
    180       define => "ENABLE_FULLSCREEN_API", default => (isAppleMacWebKit() || isGtk()), value => \$fullscreenAPISupport },
    181 
    182     { option => "geolocation", desc => "Toggle Geolocation support",
    183       define => "ENABLE_GEOLOCATION", default => (isAppleWebKit() || isGtk()), value => \$geolocationSupport },
    184 
    185     { option => "icon-database", desc => "Toggle Icon database support",
    186       define => "ENABLE_ICONDATABASE", default => 1, value => \$iconDatabaseSupport },
    187 
    188     { option => "image-resizer", desc => "Toggle Image Resizer API support",
    189       define => "ENABLE_IMAGE_RESIZER", default => 0, value => \$imageResizerSupport },
    190 
    191     { option => "indexed-database", desc => "Toggle Indexed Database API support",
    192       define => "ENABLE_INDEXED_DATABASE", default => 0, value => \$indexedDatabaseSupport },
    193 
    194     { option => "input-speech", desc => "Speech Input API support",
    195       define => "ENABLE_INPUT_SPEECH", default => 0, value => \$inputSpeechSupport },
    196 
    197     { option => "inspector", desc => "Toggle Web Inspector support",
    198       define => "ENABLE_INSPECTOR", default => 1, value => \$webInspectorSupport },
    199 
    200     { option => "javascript-debugger", desc => "Toggle JavaScript Debugger/Profiler support",
    201       define => "ENABLE_JAVASCRIPT_DEBUGGER", default => 1, value => \$javaScriptDebuggerSupport },
    202 
    203     { option => "link-prefetch", desc => "Toggle pre fetching support",
    204       define => "ENABLE_LINK_PREFETCH", default => 0, value => \$linkPrefetchSupport },
    205 
    206     { option => "mathml", desc => "Toggle MathML support",
    207       define => "ENABLE_MATHML", default => 1, value => \$mathmlSupport },
    208 
    209     { option => "media-statistics", desc => "Toggle Media Statistics support",
    210       define => "ENABLE_MEDIA_STATISTICS", default => 0, value => \$mediaStatisticsSupport },
    211 
    212     { option => "media-stream", desc => "Toggle Media Stream API support (implies Blob support, currently Chromium only)",
    213       define => "ENABLE_MEDIA_STREAM", default => isChromium(), value => \$mediaStreamSupport },
    214 
    215     { option => "meter-tag", desc => "Meter Tag support",
    216       define => "ENABLE_METER_TAG", default => !isAppleWinWebKit(), value => \$meterTagSupport },
    217 
    218     { option => "netscape-plugin", desc => "Netscape Plugin support",
    219       define => "ENABLE_NETSCAPE_PLUGIN_API", default => !isEfl(), value => \$netscapePluginSupport },
    220 
    221     { option => "notifications", desc => "Toggle Desktop Notifications Support",
    222       define => "ENABLE_NOTIFICATIONS", default => 0, value => \$notificationsSupport },
    223 
    224     { option => "offline-web-applications", desc => "Toggle Offline Web Application Support",
    225       define => "ENABLE_OFFLINE_WEB_APPLICATIONS", default => 1, value => \$offlineWebApplicationSupport },
    226 
    227     { option => "orientation-events", desc => "Toggle Orientation Events support",
    228       define => "ENABLE_ORIENTATION_EVENTS", default => 0, value => \$orientationEventsSupport },
    229 
    230     { option => "page-visibility-api", desc => "Page Visibility API support",
    231       define => "ENABLE_PAGE_VISIBILITY_API", default => 0, value => \$pageVisibilityApiSupport },
    232 
    233     { option => "progress-tag", desc => "Progress Tag support",
    234       define => "ENABLE_PROGRESS_TAG", default => 1, value => \$progressTagSupport },
    235 
    236     { option => "quota", desc => "Toggle Quota support",
    237       define => "ENABLE_QUOTA", default => 0, value => \$quotaSupport },
    238 
    239     { option => "register-protocol-handler", desc => "Register Protocol Handler support",
    240       define => "ENABLE_REGISTER_PROTOCOL_HANDLER", default => 0, value => \$registerProtocolHandlerSupport },
    241 
    242     { option => "system-malloc", desc => "Toggle system allocator instead of TCmalloc",
    243       define => "USE_SYSTEM_MALLOC", default => 0, value => \$systemMallocSupport },
    244 
    245     { option => "shared-workers", desc => "Toggle SharedWorkers support",
    246       define => "ENABLE_SHARED_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$sharedWorkersSupport },
    247 
    248     { option => "svg", desc => "Toggle SVG support",
    249       define => "ENABLE_SVG", default => 1, value => \$svgSupport },
    250 
    251     { option => "svg-animation", desc => "Toggle SVG animation support (implies SVG support)",
    252       define => "ENABLE_SVG_ANIMATION", default => 1, value => \$svgAnimationSupport },
    253 
    254     { option => "svg-as-image", desc => "Toggle SVG as Image support (implies SVG support)",
    255       define => "ENABLE_SVG_AS_IMAGE", default => 1, value => \$svgAsImageSupport },
    256 
    257     { option => "svg-dom-objc-bindings", desc => "Toggle SVG DOM Objective-C bindings support (implies SVG support)",
    258       define => "ENABLE_SVG_DOM_OBJC_BINDINGS", default => isAppleMacWebKit(), value => \$svgDOMObjCBindingsSupport },
    259 
    260     { option => "svg-fonts", desc => "Toggle SVG fonts support (imples SVG support)",
    261       define => "ENABLE_SVG_FONTS", default => 1, value => \$svgFontsSupport },
    262 
    263     { option => "svg-foreign-object", desc => "Toggle SVG foreign object support (implies SVG support)",
    264       define => "ENABLE_SVG_FOREIGN_OBJECT", default => 1, value => \$svgForeignObjectSupport },
    265 
    266     { option => "svg-use", desc => "Toggle SVG use element support (implies SVG support)",
    267       define => "ENABLE_SVG_USE", default => 1, value => \$svgUseSupport },
    268 
    269     { option => "tiled-backing-store", desc => "Toggle Tiled Backing Store support",
    270       define => "ENABLE_TILED_BACKING_STORE", default => isQt(), value => \$tiledBackingStoreSupport },
    271 
    272     { option => "touch-events", desc => "Toggle Touch Events support",
    273       define => "ENABLE_TOUCH_EVENTS", default => isQt(), value => \$touchEventsSupport },
    274 
    275     { option => "video", desc => "Toggle Video support",
    276       define => "ENABLE_VIDEO", default => (isAppleWebKit() || isGtk()), value => \$videoSupport },
    277 
    278     { option => "wcss", desc => "Toggle WCSS support",
    279       define => "ENABLE_WCSS", default => 0, value => \$wcssSupport },
    280 
    281     { option => "web-audio", desc => "Toggle Web Audio support",
    282       define => "ENABLE_WEB_AUDIO", default => 0, value=> \$webAudioSupport },
    283 
    284     { option => "web-sockets", desc => "Toggle Web Sockets support",
    285       define => "ENABLE_WEB_SOCKETS", default => 1, value=> \$webSocketsSupport },
    286 
    287     { option => "web-timing", desc => "Toggle Web Timing support",
    288       define => "ENABLE_WEB_TIMING", default => 0, value=> \$webTimingSupport },
    289 
    290     { option => "wml", desc => "Toggle WML support",
    291       define => "ENABLE_WML", default => 0, value => \$wmlSupport },
    292 
    293     { option => "workers", desc => "Toggle Web Workers support",
    294       define => "ENABLE_WORKERS", default => (isAppleWebKit() || isGtk()), value => \$workersSupport },
    295 
    296     { option => "xhtmlmp", desc => "Toggle XHTML-MP support",
    297       define => "ENABLE_XHTMLMP", default => 0, value => \$xhtmlmpSupport },
    298 
    299     { option => "xpath", desc => "Toggle XPath support",
    300       define => "ENABLE_XPATH", default => 1, value => \$xpathSupport },
    301 
    302     { option => "xslt", desc => "Toggle XSLT support",
    303       define => "ENABLE_XSLT", default => 1, value => \$xsltSupport },
    304 );
    305 
    306 # Update defaults from Qt's project file
    307 if (isQt()) {
    308     # Take a sneek peek at the arguments, since we will need the qmake binary early
    309     # on to do profile parsing.
    310     foreach (@ARGV) {
    311         if (/^--qmake=(.*)/) {
    312             setQmakeBinaryPath($1);
    313         }
    314     }
    315     my %qtDefaults = qtFeatureDefaults();
    316     foreach (@features) {
    317         $_->{default} = $qtDefaults{$_->{define}} || 0;
    318     }
    319 }
    320 
    321 # Additional environment parameters
    322 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
    323 
    324 # Initialize values from defaults
    325 foreach (@ARGV) {
    326     if ($_ eq '--minimal') {
    327         $minimal = 1;
    328     } elsif ($_ eq '--v8') {
    329         $v8 = 1;
    330     }
    331 }
    332 
    333 # Initialize values from defaults
    334 foreach (@features) {
    335     ${$_->{value}} = ($_->{default} && !$minimal) || 0;
    336 }
    337 
    338 $svgSupport = $svgSupport || $svgAnimationSupport || $svgAsImageSupport
    339     || $svgDOMObjCBindingsSupport || $svgFontsSupport
    340     || $svgForeignObjectSupport || $svgUseSupport;
    341 
    342 $blobSupport = $blobSupport || $mediaStreamSupport;
    343 
    344 my $programName = basename($0);
    345 my $usage = <<EOF;
    346 Usage: $programName [options] [options to pass to build system]
    347   --help                            Show this help message
    348   --clean                           Cleanup the build directory
    349   --debug                           Compile in debug mode
    350   --gyp                             Use GYP-generated project files
    351   --dsym                            Change debugging format to dwarf-with-dsym (Mac only)
    352 
    353   --chromium                        Build the Chromium port on Mac/Win/Linux
    354   --efl                             Build the EFL port
    355   --gtk                             Build the GTK+ port
    356   --qt                              Build the Qt port
    357   --wincairo                        Build using Cairo (rather than CoreGraphics) on Windows
    358   --wince                           Build the WinCE port
    359 
    360   --inspector-frontend              Copy changes to the inspector front-end files to the build directory
    361 
    362   --install-headers=<path>          Set installation path for the headers (Qt only)
    363   --install-libs=<path>             Set installation path for the libraries (Qt only)
    364   --v8                              Use V8 as JavaScript engine (Qt only)
    365   -2                                build WebKit2 (Qt only)
    366 
    367   --prefix=<path>                   Set installation prefix to the given path (Gtk/Efl only)
    368   --makeargs=<arguments>            Optional Makefile flags
    369   --qmakearg=<arguments>            Optional qmake flags (Qt only, e.g. --qmakearg="CONFIG+=webkit2" to build WebKit2)
    370 
    371   --minimal                         No optional features, unless explicitly enabled.
    372 
    373 EOF
    374 
    375 my %options = (
    376     'help' => \$showHelp,
    377     'clean' => \$clean,
    378     'gyp' => \$useGYP,
    379     'install-headers=s' => \$installHeaders,
    380     'install-libs=s' => \$installLibs,
    381     'prefix=s' => \$prefixPath,
    382     'makeargs=s' => \$makeArgs,
    383     'minimal' => \$minimal,
    384     'v8' => \$v8,
    385     'no-webkit2' => \$noWebKit2,
    386 );
    387 
    388 # Build usage text and options list from features
    389 foreach (@features) {
    390     my $opt = sprintf("%-35s", "  --[no-]$_->{option}");
    391     $usage .= "$opt $_->{desc} (default: $_->{default})\n";
    392     $options{"$_->{option}!"} = $_->{value};
    393 }
    394 
    395 GetOptions(%options);
    396 
    397 if ($showHelp) {
    398    print STDERR $usage;
    399    exit 1;
    400 }
    401 
    402 checkRequiredSystemConfig();
    403 setConfiguration();
    404 
    405 my $productDir = productDir();
    406 
    407 # Remove Qt makefiles from productDir.
    408 # https://bugs.webkit.org/show_bug.cgi?id=54466
    409 File::Find::find(sub {unlink $File::Find::name if $File::Find::name =~ m/Makefile/;}, $productDir) if (isQt() && !isSymbian() && -e $productDir);
    410 
    411 # Remove 0 byte sized files from productDir after slave lost for Qt buildbots.
    412 File::Find::find(\&unlinkZeroFiles, $productDir) if (isQt() && !isSymbian() && -e $productDir);
    413 
    414 sub unlinkZeroFiles()
    415 {
    416     my $file = $File::Find::name;
    417     if (! -s $file) {
    418         unlink $file;
    419         print "0 byte sized file removed from build directory: $file\n";
    420     }
    421 }
    422 
    423 # Check that all the project directories are there.
    424 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
    425 
    426 for my $dir (@projects) {
    427     if (! -d $dir) {
    428         die "Error: No $dir directory found. Please do a fresh checkout.\n";
    429     }
    430 }
    431 
    432 if (!isQt() && !-d "WebKitLibraries") {
    433     die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
    434 }
    435 
    436 # Generate the generate project files from .gyp files
    437 if ($useGYP) {
    438     system("perl", "Tools/Scripts/generate-project-files") == 0 or die "Failed to run generate-project-files";
    439 }
    440 
    441 my @options = ();
    442 
    443 # enable autotool options accordingly
    444 if (isGtk()) {
    445     @options = @ARGV;
    446     foreach (@features) {
    447         push @options, autotoolsFlag(${$_->{value}}, $_->{option});
    448     }
    449 
    450     push @options, "--prefix=" . $prefixPath if defined($prefixPath);
    451     push @options, "--makeargs=" . $makeArgs if $makeArgs;
    452 } elsif (isAppleMacWebKit()) {
    453     checkForJavaSDK();
    454     push @options, XcodeOptions();
    455 
    456     sub option($$$)
    457     {
    458         my ($feature, $isEnabled, $defaultValue) = @_;
    459         return "" if $defaultValue == $isEnabled;
    460         return $feature . "=" . ($isEnabled ? $feature : "");
    461     }
    462 
    463     foreach (@features) {
    464         if ($_->{option} ne "coverage") {
    465             my $option = option($_->{define}, ${$_->{value}}, $_->{default});
    466             push @options, $option unless $option eq "";
    467         }
    468     }
    469 
    470     # Apple builds JavaScriptGlue, and only on the Mac.
    471     splice @projects, 1, 0, "Source/JavaScriptGlue";
    472 
    473     # ANGLE must come before WebCore
    474     splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
    475 
    476     # WebKit2 is only supported in SnowLeopard and later at present.
    477     push @projects, ("Source/WebKit2", "Tools/MiniBrowser") if osXVersion()->{"minor"} >= 6 and !$noWebKit2;
    478 
    479     # Copy library and header from WebKitLibraries to a findable place in the product directory.
    480     my @librariesToCopy = (
    481         "libWebKitSystemInterfaceTiger.a",
    482         "libWebKitSystemInterfaceLeopard.a",
    483         "libWebKitSystemInterfaceSnowLeopard.a",
    484         "libWebCoreSQLite3.a",
    485     );
    486     foreach my $libName (@librariesToCopy) {
    487         my $srcLib = "WebKitLibraries/" . $libName;
    488         my $lib = "$productDir/" . $libName;
    489         if (!-e $lib || -M $lib > -M $srcLib) {
    490             print "Updating $lib\n";
    491             system "ditto", $srcLib, $lib;
    492             system "ranlib", $lib;
    493         }
    494     }
    495 
    496     # FIXME: This code should be abstracted to not be copy/paste.
    497     my $srcHeader = "WebKitLibraries/WebKitSystemInterface.h";
    498     my $header = "$productDir/usr/local/include/WebKitSystemInterface.h";
    499     if (!-e $header || -M $header > -M $srcHeader) {
    500         print "Updating $header\n";
    501         system "mkdir", "-p", "$productDir/usr/local/include";
    502         system "ditto", $srcHeader, $header;
    503     }
    504 
    505     my $srcHeaderDir = "WebKitLibraries/WebCoreSQLite3";
    506     my $headerDir = "$productDir/WebCoreSQLite3";
    507     if (!-e $headerDir || -M $headerDir > -M $srcHeaderDir) {
    508         print "Updating $headerDir\n";
    509         system "ditto", $srcHeaderDir, $headerDir;
    510     }
    511 } elsif (isAppleWinWebKit()) {
    512     # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
    513     # Will fail if WebKitSupportLibrary.zip is not in source root.
    514     (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
    515     # Update Cairo Dependancies.
    516     if (isWinCairo()) {
    517         (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
    518     }
    519 } elsif (isQt()) {
    520     push @options, "--install-headers=" . $installHeaders if defined($installHeaders);
    521     push @options, "--install-libs=" . $installLibs if defined($installLibs);
    522     push @options, "--makeargs=" . $makeArgs if $makeArgs;
    523     push @options, "--qmakearg=CONFIG+=webkit2" if isWK2();
    524     @options = (@ARGV, @options);
    525 
    526     foreach (@features) {
    527         push @options, "DEFINES+=$_->{define}=${$_->{value}}" if ${$_->{value}} != $_->{default};
    528     }
    529 
    530     if ($minimal) {
    531         push @options, "CONFIG+=minimal";
    532     }
    533 
    534     if ($v8) {
    535         push @options, "CONFIG+=v8";
    536     }
    537 }
    538 
    539 # Force re-link of existing libraries if different than expected
    540 removeLibraryDependingOnFeature("WebCore", "SVG", $svgSupport);
    541 
    542 if (isInspectorFrontend()) {
    543     exit exitStatus(copyInspectorFrontendFiles());
    544 }
    545 
    546 if (isWx()) {
    547     downloadWafIfNeeded();
    548     @options = split(/ /, $makeArgs);
    549     @projects = ();
    550     my $result = buildWafProject('.', $clean, @options);
    551     exit exitStatus($result) if exitStatus($result);
    552 }
    553 
    554 if (isChromium()) {
    555     @options = @ARGV;
    556     # Chromium doesn't build by project directories.
    557     @projects = ();
    558     my $result = buildChromium($clean, @options);
    559     exit exitStatus($result) if exitStatus($result);
    560 }
    561 
    562 if (isEfl()) {
    563     # By default we build using all of the available CPUs.
    564     $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
    565     buildCMakeProjectOrExit($clean, "Efl", $prefixPath, $makeArgs, cMakeArgsFromFeatures());
    566 }
    567 
    568 if (isWinCE()) {
    569     buildCMakeProjectOrExit($clean, "WinCE", $prefixPath, $makeArgs, ("-DCMAKE_WINCE_SDK=\"STANDARDSDK_500 (ARMV4I)\"", cMakeArgsFromFeatures()));
    570 }
    571 
    572 # Build, and abort if the build fails.
    573 for my $dir (@projects) {
    574     chdir $dir or die;
    575     my $result = 0;
    576 
    577     # For Gtk and Qt the WebKit project builds all others
    578     if ((isGtk() || isQt()) && $dir ne "Source/WebKit") {
    579         chdirWebKit();
    580         next;
    581     }
    582 
    583     my $project = basename($dir);
    584     if (isGtk()) {
    585         $result = buildGtkProject($project, $clean,  @options);
    586     } elsif (isQt()) {
    587         #FIXME: $dir should probably be $project.
    588         $result = buildQMakeQtProject($dir, $clean, @options);
    589     } elsif (isAppleMacWebKit()) {
    590         my @local_options = @options;
    591         push @local_options, XcodeCoverageSupportOptions() if $coverageSupport && $project ne "ANGLE";
    592         my $useGYPProject = $useGYP && ($project =~ "WebCore|JavaScriptCore|JavaScriptGlue");
    593         my $projectPath = $useGYPProject ? "gyp/$project" : $project;
    594         $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
    595     } elsif (isAppleWinWebKit()) {
    596         if ($project eq "WebKit") {
    597             $result = buildVisualStudioProject("win/WebKit.vcproj/WebKit.sln", $clean);
    598         }
    599     }
    600     # Various build* calls above may change the CWD.
    601     chdirWebKit();
    602 
    603     if (exitStatus($result)) {
    604         my $scriptDir = relativeScriptsDir();
    605         if (usingVisualStudioExpress()) {
    606             # Visual Studio Express is so lame it can't stdout build failures.
    607             # So we find its logs and dump them to the console ourselves.
    608             system(File::Spec->catfile($scriptDir, "print-vse-failure-logs"));
    609         }
    610         if (isAppleWinWebKit()) {
    611             print "\n\n===== BUILD FAILED ======\n\n";
    612             print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
    613             my $baseProductDir = baseProductDir();
    614             print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
    615         }
    616         exit exitStatus($result);
    617     }
    618 }
    619 
    620 # Don't report the "WebKit is now built" message after a clean operation.
    621 exit if $clean;
    622 
    623 # Write out congratulations message.
    624 writeCongrats();
    625 
    626 exit 0;
    627 
    628 sub cMakeArgsFromFeatures()
    629 {
    630     my @args;
    631     foreach (@features) {
    632         my $featureName = $_->{define};
    633         if ($featureName) {
    634             my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
    635             push @args, "-D$featureName=$featureEnabled";
    636         }
    637     }
    638     return @args;
    639 }
    640 
    641 sub checkForJavaSDK()
    642 {
    643     my $jniHeader = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h";
    644     if (-e $jniHeader) {
    645         return;
    646     }
    647     print "\nCan't find required $jniHeader, build will fail.\n\n";
    648     print "After installing \"Java for Mac OS X 10.6 Update 3\", the Java Developer Package is required to build WebKit.\n";
    649     print "Please install the package from http://connect.apple.com (found under Downloads > Java).\n\n";
    650     print "For more information, see:\n";
    651     print "https://lists.webkit.org/pipermail/webkit-dev/2010-October/014867.html\n";
    652     print "https://webkit.org/building/tools.html\n\n";
    653     exit 1;
    654 }
    655 
    656 sub formatBuildTime($)
    657 {
    658     my ($buildTime) = @_;
    659 
    660     my $buildHours = int($buildTime / 3600);
    661     my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
    662     my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
    663 
    664     if ($buildHours) {
    665         return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
    666     }
    667     return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
    668 }
    669 
    670 sub writeCongrats()
    671 {
    672     my $launcherPath = launcherPath();
    673     my $launcherName = launcherName();
    674     my $endTime = time();
    675     my $buildTime = formatBuildTime($endTime - $startTime);
    676 
    677     print "\n";
    678     print "===========================================================\n";
    679     print " WebKit is now built ($buildTime). \n";
    680     if (!isChromium()) {
    681         print " To run $launcherName with this newly-built code, use the\n";
    682         print " \"$launcherPath\" script.\n";
    683     }
    684     print "===========================================================\n";
    685 }
    686