blob: e840fcead19ebf04614fff53e445c52cf658b0e8 [file] [log] [blame]
mitz@apple.com24e143e2012-05-07 01:41:09 +00001#!/usr/bin/perl -w
2
fpizlo@apple.comef5e13652016-02-18 00:11:21 +00003# Copyright (C) 2005, 2008, 2010, 2011, 2012, 2013, 2014, 2016 Apple Inc. All rights reserved.
mitz@apple.com24e143e2012-05-07 01:41:09 +00004#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8#
9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
16# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
19# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26use strict;
fpizlo@apple.com895703e2014-02-08 02:11:22 +000027use File::Spec;
mitz@apple.com24e143e2012-05-07 01:41:09 +000028use FindBin;
fpizlo@apple.com2d771832014-01-31 00:41:51 +000029use Getopt::Long qw(:config pass_through);
mitz@apple.com24e143e2012-05-07 01:41:09 +000030use lib $FindBin::Bin;
31use webkitdirs;
32
fpizlo@apple.com2d771832014-01-31 00:41:51 +000033my $showHelp = 0;
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +000034my $wksi = 0;
commit-queue@webkit.org64b963282014-08-08 19:20:19 +000035my $clean = 0;
fpizlo@apple.com895703e2014-02-08 02:11:22 +000036my $useFullLibPaths = 0;
mrowe@apple.come0e5cea2014-05-03 01:15:47 +000037my $osxVersion;
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000038my $force = 0;
fpizlo@apple.com2d771832014-01-31 00:41:51 +000039
commit-queue@webkit.org1a7076e2016-03-02 01:43:03 +000040# Pops off --sdk=<SDK Name> from the argument list so --sdk is not taken as the productDir.
41willUseIOSDeviceSDK();
42
fpizlo@apple.com2d771832014-01-31 00:41:51 +000043my $programName = basename($0);
44my $usage = <<EOF;
45Usage: $programName [options]
46 --help Show this help message
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +000047 --[no-]wksi Toggle copying WebKitSystemInterface drops (default: $wksi)
commit-queue@webkit.org64b963282014-08-08 19:20:19 +000048 --clean Clean the libraries (default: $clean)
fpizlo@apple.com895703e2014-02-08 02:11:22 +000049 --[no-]use-full-lib-paths Toggle using full library paths
dbates@webkit.orgfda2d732014-12-20 00:15:15 +000050 --sdk=<sdk> Use a specific Xcode SDK
51 --device Use the current iphoneos.internal SDK (iOS only)
52 --simulator Use the current iphonesimulator SDK (iOS only)
mrowe@apple.come0e5cea2014-05-03 01:15:47 +000053 --osx-version=<version> Set the OS X version to use when deciding what to copy.
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000054 --[no-]force Toggle forcing the copy - i.e. ignoring timestamps (default: $force)
fpizlo@apple.com2d771832014-01-31 00:41:51 +000055EOF
56
57GetOptions(
58 'help' => \$showHelp,
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +000059 'wksi!' => \$wksi,
commit-queue@webkit.org64b963282014-08-08 19:20:19 +000060 'clean' => \$clean,
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000061 'use-full-lib-paths!' => \$useFullLibPaths,
mrowe@apple.come0e5cea2014-05-03 01:15:47 +000062 'osx-version=s' => \$osxVersion,
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000063 'force!' => \$force
fpizlo@apple.com2d771832014-01-31 00:41:51 +000064);
65
66if ($showHelp) {
67 print STDERR $usage;
68 exit 1;
69}
70
mitz@apple.comfedfb312012-05-09 07:46:28 +000071my $productDir = shift @ARGV;
fpizlo@apple.com895703e2014-02-08 02:11:22 +000072if ($productDir) {
73 $productDir = File::Spec->rel2abs($productDir);
74} else {
ddkilzer@apple.com7c175aa2014-05-07 05:18:07 +000075 $productDir = $ENV{BUILT_PRODUCTS_DIR} || productDir();
fpizlo@apple.com895703e2014-02-08 02:11:22 +000076}
mitz@apple.com24e143e2012-05-07 01:41:09 +000077
bfulgham@apple.com6d17b502015-10-30 17:05:58 +000078if (!isIOSWebKit() && !$osxVersion &&!isAnyWindows()) {
mrowe@apple.come0e5cea2014-05-03 01:15:47 +000079 $osxVersion = `sw_vers -productVersion | cut -d. -f-2`;
80 chomp($osxVersion);
81}
82
mitz@apple.com24e143e2012-05-07 01:41:09 +000083chdirWebKit();
84
dbates@webkit.orgfda2d732014-12-20 00:15:15 +000085sub executeRanlib($)
86{
87 my ($library) = @_;
88 my @args;
89 push @args, ("-sdk", xcodeSDK()) if xcodeSDK();
90 push @args, "ranlib";
91 push @args, "-no_warning_for_no_symbols" if isIOSWebKit();
92 system("xcrun", @args, $library) == 0 or die;
fpizlo@apple.com54c843a2014-03-14 22:39:06 +000093}
oliver@apple.comea771492013-07-25 03:58:38 +000094
95sub unpackIfNecessary
96{
97 my ($targetDir, $sampleFile, $package, $hasLibraries) = @_;
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000098 if ($force || !-e $sampleFile || -M $sampleFile > -M $package) {
oliver@apple.comea771492013-07-25 03:58:38 +000099 print "Unpacking $package into $targetDir\n";
100 (system("tar -C $targetDir -xmf $package") == 0) or die;
101 if ($hasLibraries) {
102 foreach my $library (`tar -tf $package`) {
103 chomp $library;
104 print " Ranlib $library\n";
dbates@webkit.orgfda2d732014-12-20 00:15:15 +0000105 executeRanlib($targetDir . "/" . $library);
oliver@apple.comea771492013-07-25 03:58:38 +0000106 }
107 }
oliver@apple.comf0c513f2013-07-25 03:58:53 +0000108 return 1;
oliver@apple.comea771492013-07-25 03:58:38 +0000109 }
oliver@apple.comf0c513f2013-07-25 03:58:53 +0000110 return 0;
mitz@apple.com24e143e2012-05-07 01:41:09 +0000111}
112
oliver@apple.comea771492013-07-25 03:58:38 +0000113sub dittoHeaders
114{
115 my ($srcHeader, $header) = @_;
fpizlo@apple.com03d945b2014-02-12 04:06:42 +0000116 if ($force || !-e $header || -M $header > -M $srcHeader) {
oliver@apple.comea771492013-07-25 03:58:38 +0000117 print "Updating $header\n";
118 (system("ditto", $srcHeader, $header) == 0) or die;
119 }
120}
121
dbates@webkit.org25812f42015-10-08 23:34:08 +0000122if ($clean) {
123 print "Cleaning.\n";
124 (system("rm", "-rf", File::Spec->catfile($productDir, "usr", "local", "include", "WebKitSystemInterface.h")) == 0) or die;
dbates@webkit.org25812f42015-10-08 23:34:08 +0000125 unlink glob "$productDir/libWebKitSystemInterface*" or die if glob "$productDir/libWebKitSystemInterface*";
126 unlink glob "$productDir/usr/local/lib/libWebKitSystemInterface*" or die if glob "$productDir/usr/local/lib/libWebKitSystemInterface*";
dbates@webkit.org25812f42015-10-08 23:34:08 +0000127 unlink glob "$productDir/libLTO*" or die if glob "$productDir/libLTO*";
128}
129
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +0000130if ($wksi) {
fpizlo@apple.com42a73a92014-02-05 21:44:26 +0000131 (system("mkdir", "-p", "$productDir/usr/local/include") == 0) or die;
fpizlo@apple.com895703e2014-02-08 02:11:22 +0000132
133 my $libraryDir = $useFullLibPaths ? "$productDir/usr/local/lib" : $productDir;
134 (system("mkdir", "-p", $libraryDir) == 0) or die;
fpizlo@apple.com42a73a92014-02-05 21:44:26 +0000135
dbates@webkit.org8261c7e2014-12-20 00:17:37 +0000136 my @librariesToCopy;
137 if (isIOSWebKit()) {
138 push(@librariesToCopy, (
dbates@webkit.org69d2ef82015-09-25 06:58:25 +0000139 "libWebKitSystemInterfaceIOSDevice9.0.a",
140 "libWebKitSystemInterfaceIOSSimulator9.0.a",
dbates@webkit.org7d33ba42016-01-26 18:40:25 +0000141 "libWebKitSystemInterfaceIOSDevice9.2.a",
142 "libWebKitSystemInterfaceIOSSimulator9.2.a",
dbates@webkit.org8261c7e2014-12-20 00:17:37 +0000143 ));
144 } else {
145 push(@librariesToCopy, (
lforschler@apple.com3676a922015-08-13 23:26:57 +0000146 "libWebKitSystemInterfaceYosemite.a",
147 "libWebKitSystemInterfaceElCapitan.a"
dbates@webkit.org8261c7e2014-12-20 00:17:37 +0000148 ));
149 }
150
dbates@webkit.orgfda2d732014-12-20 00:15:15 +0000151 foreach my $libraryName (@librariesToCopy) {
152 my $sourceLibrary = "WebKitLibraries/" . $libraryName;
153 my $targetLibrary = "$libraryDir/" . $libraryName;
154 if ($force || !-e $targetLibrary || -M $targetLibrary > -M $sourceLibrary) {
155 print "Updating $targetLibrary\n";
156 (system("ditto", $sourceLibrary, $targetLibrary) == 0) or die;
157 executeRanlib($targetLibrary);
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +0000158 }
159 }
160
161 dittoHeaders("WebKitLibraries/WebKitSystemInterface.h", "$productDir/usr/local/include/WebKitSystemInterface.h");
162}
163
dbates@webkit.org25812f42015-10-08 23:34:08 +0000164sub fileContains
165{
166 my ($filename, $string) = @_;
167 open my $fileHandle, '<', $filename or die;
168 while (<$fileHandle>) {
169 return 1 if /^$string$/;
dbates@webkit.org8261c7e2014-12-20 00:17:37 +0000170 }
dbates@webkit.org25812f42015-10-08 23:34:08 +0000171 return 0;
172}
173
174sub isContentOfFileEqualToString($$)
175{
176 my ($filename, $string) = @_;
177 open my $fileHandle, '<', $filename or die;
178 binmode $fileHandle;
179 my $contents = <$fileHandle>;
180 return $contents eq $string;
181}
182