blob: a7cdedf5427416bd5915f3ca858a5cf34e0bb889 [file] [log] [blame]
mitz@apple.com24e143e2012-05-07 01:41:09 +00001#!/usr/bin/perl -w
2
dbates@webkit.orgf56e08c2016-03-25 16:05:22 +00003# Copyright (C) 2005-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
dbates@webkit.orgf56e08c2016-03-25 16:05:22 +000040determineXcodeSDK();
commit-queue@webkit.org1a7076e2016-03-02 01:43:03 +000041
fpizlo@apple.com2d771832014-01-31 00:41:51 +000042my $programName = basename($0);
43my $usage = <<EOF;
44Usage: $programName [options]
45 --help Show this help message
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +000046 --[no-]wksi Toggle copying WebKitSystemInterface drops (default: $wksi)
commit-queue@webkit.org64b963282014-08-08 19:20:19 +000047 --clean Clean the libraries (default: $clean)
fpizlo@apple.com895703e2014-02-08 02:11:22 +000048 --[no-]use-full-lib-paths Toggle using full library paths
dbates@webkit.orgfda2d732014-12-20 00:15:15 +000049 --sdk=<sdk> Use a specific Xcode SDK
50 --device Use the current iphoneos.internal SDK (iOS only)
51 --simulator Use the current iphonesimulator SDK (iOS only)
mrowe@apple.come0e5cea2014-05-03 01:15:47 +000052 --osx-version=<version> Set the OS X version to use when deciding what to copy.
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000053 --[no-]force Toggle forcing the copy - i.e. ignoring timestamps (default: $force)
fpizlo@apple.com2d771832014-01-31 00:41:51 +000054EOF
55
56GetOptions(
57 'help' => \$showHelp,
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +000058 'wksi!' => \$wksi,
commit-queue@webkit.org64b963282014-08-08 19:20:19 +000059 'clean' => \$clean,
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000060 'use-full-lib-paths!' => \$useFullLibPaths,
mrowe@apple.come0e5cea2014-05-03 01:15:47 +000061 'osx-version=s' => \$osxVersion,
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000062 'force!' => \$force
fpizlo@apple.com2d771832014-01-31 00:41:51 +000063);
64
65if ($showHelp) {
66 print STDERR $usage;
67 exit 1;
68}
69
mitz@apple.comfedfb312012-05-09 07:46:28 +000070my $productDir = shift @ARGV;
fpizlo@apple.com895703e2014-02-08 02:11:22 +000071if ($productDir) {
72 $productDir = File::Spec->rel2abs($productDir);
73} else {
ddkilzer@apple.com7c175aa2014-05-07 05:18:07 +000074 $productDir = $ENV{BUILT_PRODUCTS_DIR} || productDir();
fpizlo@apple.com895703e2014-02-08 02:11:22 +000075}
mitz@apple.com24e143e2012-05-07 01:41:09 +000076
bfulgham@apple.com6d17b502015-10-30 17:05:58 +000077if (!isIOSWebKit() && !$osxVersion &&!isAnyWindows()) {
mrowe@apple.come0e5cea2014-05-03 01:15:47 +000078 $osxVersion = `sw_vers -productVersion | cut -d. -f-2`;
79 chomp($osxVersion);
80}
81
mitz@apple.com24e143e2012-05-07 01:41:09 +000082chdirWebKit();
83
dbates@webkit.orgfda2d732014-12-20 00:15:15 +000084sub executeRanlib($)
85{
86 my ($library) = @_;
87 my @args;
88 push @args, ("-sdk", xcodeSDK()) if xcodeSDK();
89 push @args, "ranlib";
90 push @args, "-no_warning_for_no_symbols" if isIOSWebKit();
91 system("xcrun", @args, $library) == 0 or die;
fpizlo@apple.com54c843a2014-03-14 22:39:06 +000092}
oliver@apple.comea771492013-07-25 03:58:38 +000093
94sub unpackIfNecessary
95{
96 my ($targetDir, $sampleFile, $package, $hasLibraries) = @_;
fpizlo@apple.com03d945b2014-02-12 04:06:42 +000097 if ($force || !-e $sampleFile || -M $sampleFile > -M $package) {
oliver@apple.comea771492013-07-25 03:58:38 +000098 print "Unpacking $package into $targetDir\n";
99 (system("tar -C $targetDir -xmf $package") == 0) or die;
100 if ($hasLibraries) {
101 foreach my $library (`tar -tf $package`) {
102 chomp $library;
103 print " Ranlib $library\n";
dbates@webkit.orgfda2d732014-12-20 00:15:15 +0000104 executeRanlib($targetDir . "/" . $library);
oliver@apple.comea771492013-07-25 03:58:38 +0000105 }
106 }
oliver@apple.comf0c513f2013-07-25 03:58:53 +0000107 return 1;
oliver@apple.comea771492013-07-25 03:58:38 +0000108 }
oliver@apple.comf0c513f2013-07-25 03:58:53 +0000109 return 0;
mitz@apple.com24e143e2012-05-07 01:41:09 +0000110}
111
oliver@apple.comea771492013-07-25 03:58:38 +0000112sub dittoHeaders
113{
114 my ($srcHeader, $header) = @_;
fpizlo@apple.com03d945b2014-02-12 04:06:42 +0000115 if ($force || !-e $header || -M $header > -M $srcHeader) {
oliver@apple.comea771492013-07-25 03:58:38 +0000116 print "Updating $header\n";
117 (system("ditto", $srcHeader, $header) == 0) or die;
118 }
119}
120
dbates@webkit.org25812f42015-10-08 23:34:08 +0000121if ($clean) {
122 print "Cleaning.\n";
123 (system("rm", "-rf", File::Spec->catfile($productDir, "usr", "local", "include", "WebKitSystemInterface.h")) == 0) or die;
dbates@webkit.org25812f42015-10-08 23:34:08 +0000124 unlink glob "$productDir/libWebKitSystemInterface*" or die if glob "$productDir/libWebKitSystemInterface*";
125 unlink glob "$productDir/usr/local/lib/libWebKitSystemInterface*" or die if glob "$productDir/usr/local/lib/libWebKitSystemInterface*";
dbates@webkit.org25812f42015-10-08 23:34:08 +0000126 unlink glob "$productDir/libLTO*" or die if glob "$productDir/libLTO*";
127}
128
fpizlo@apple.comd7630ae2014-01-31 21:26:26 +0000129if ($wksi) {
fpizlo@apple.com42a73a92014-02-05 21:44:26 +0000130 (system("mkdir", "-p", "$productDir/usr/local/include") == 0) or die;
fpizlo@apple.com895703e2014-02-08 02:11:22 +0000131
132 my $libraryDir = $useFullLibPaths ? "$productDir/usr/local/lib" : $productDir;
133 (system("mkdir", "-p", $libraryDir) == 0) or die;
fpizlo@apple.com42a73a92014-02-05 21:44:26 +0000134
dbates@webkit.org8261c7e2014-12-20 00:17:37 +0000135 my @librariesToCopy;
136 if (isIOSWebKit()) {
137 push(@librariesToCopy, (
dbates@webkit.orgdab64802016-08-16 22:20:05 +0000138 "libWebKitSystemInterfaceIOSDevice9.a",
139 "libWebKitSystemInterfaceIOSSimulator9.a",
dbates@webkit.org06e81912016-09-07 19:28:01 +0000140 "libWebKitSystemInterfaceIOSDevice10.a",
141 "libWebKitSystemInterfaceIOSSimulator10.a",
dbates@webkit.org8261c7e2014-12-20 00:17:37 +0000142 ));
143 } else {
144 push(@librariesToCopy, (
lforschler@apple.com3676a922015-08-13 23:26:57 +0000145 "libWebKitSystemInterfaceYosemite.a",
lforschler@apple.com8f5cf6c2016-06-14 16:40:47 +0000146 "libWebKitSystemInterfaceElCapitan.a",
147 "libWebKitSystemInterfaceOSX10.12.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