initial import
[vuplus_webkit] / Source / WebCore / WebCore.gyp / mac / adjust_visibility.sh
1 #!/bin/sh
2
3 #
4 # Copyright (C) 2009 Google Inc. All rights reserved.
5
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are
8 # met:
9
10 #     * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 #     * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following disclaimer
14 # in the documentation and/or other materials provided with the
15 # distribution.
16 #     * Neither the name of Google Inc. nor the names of its
17 # contributors may be used to endorse or promote products derived from
18 # this software without specific prior written permission.
19
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #
32
33 # usage: adjust_visibility.sh INPUT OUTPUT WORK_DIR
34 #
35 # Transforms a static library at INPUT by marking all of its symbols
36 # private_extern.  The output is placed at OUTPUT.  WORK_DIR is used as a
37 # scratch directory, which need not exist before this script is invoked,
38 # and which will be left behind when the script exits.
39
40 set -e
41
42 if [ $# -ne 3 ] ; then
43   echo "usage: ${0} INPUT OUTPUT WORK_DIR" >& 2
44   exit 1
45 fi
46
47 INPUT="${1}"
48 OUTPUT="${2}"
49 WORK_DIR="${3}"
50
51 # Start with a clean slate.
52 rm -f "${OUTPUT}"
53 rm -rf "${WORK_DIR}"
54 mkdir -p "${WORK_DIR}"
55
56 # ar doesn't operate on fat files.  Figure out what architectures are
57 # involved.
58 ARCHS=$(file "${INPUT}" | sed -Ene 's/^.*\(for architecture (.+)\):.*$/\1/p')
59 if [ -z "${ARCHS}" ] ; then
60   ARCHS=self
61 fi
62
63 OUTPUT_NAME="output.a"
64
65 for ARCH in ${ARCHS} ; do
66   # Get a thin version of fat input by running lipo.  If the input is already
67   # thin, just copy it into place.  The extra copy isn't strictly necessary
68   # but it simplifies the script.
69   ARCH_DIR="${WORK_DIR}/${ARCH}"
70   mkdir -p "${ARCH_DIR}"
71   INPUT_NAME=input.a
72   ARCH_INPUT="${ARCH_DIR}/${INPUT_NAME}"
73   if [ "${ARCHS}" = "self" ] ; then
74     cp "${INPUT}" "${ARCH_INPUT}"
75   else
76     lipo -thin "${ARCH}" "${INPUT}" -output "${ARCH_INPUT}"
77   fi
78
79   # Change directories to extract the archive to ensure correct pathnames.
80   (cd "${ARCH_DIR}" && ar -x "${INPUT_NAME}")
81
82   # libWebKitSystemInterfaceLeopard.a's cuDbUtils.o references a few symbols
83   # that are not defined in any framework in OS X 10.5. If it's linked into a
84   # libwebkit.dylib with -Wl,-all_load, linking to libwebkit.dylib will result
85   # in these unresolved symbols:
86   # __ZN8Security12KeychainCore6Schema22X509CrlSchemaIndexListE$non_lazy_ptr
87   # __ZN8Security12KeychainCore6Schema23X509CrlSchemaIndexCountE$non_lazy_ptr
88   # __ZN8Security12KeychainCore6Schema26X509CrlSchemaAttributeListE$non_lazy_ptr
89   # __ZN8Security12KeychainCore6Schema27X509CrlSchemaAttributeCountE$non_lazy_ptr
90   # Since nothing in cuDbUtils.o is needed, just remove it.
91   rm "${ARCH_DIR}"/cuDbUtils.o
92
93   # Use ld -r to relink each object that was in the archive.  Providing an
94   # empty -exported_symbols_list will transform all symbols to private_extern;
95   # these symbols are retained with -keep_private_externs.
96   for OBJECT in "${ARCH_DIR}/"*.o ; do
97     NEW_OBJECT="${OBJECT}.new"
98     ld -o "${NEW_OBJECT}" -r "${OBJECT}" \
99         -exported_symbols_list /dev/null -keep_private_externs
100     mv "${NEW_OBJECT}" "${OBJECT}"
101   done
102
103   # Build an architecture-specific archive from the modified object files.
104   ARCH_OUTPUT="${ARCH_DIR}/${OUTPUT_NAME}"
105   (cd "${ARCH_DIR}" && ar -rc "${OUTPUT_NAME}" *.o)
106   ranlib "${ARCH_OUTPUT}"
107
108   # Toss the object files out now that they're in the archive.
109   rm -f "${ARCH_DIR}/"*.o
110 done
111
112 # Create a fat archive from the architecture-specific archives if needed.
113 # If the input was thin, leave the output thin by copying the only output
114 # archive to the destination.
115 if [ "${ARCHS}" = "self" ] ; then
116   cp "${WORK_DIR}/self/${OUTPUT_NAME}" "${OUTPUT}"
117 else
118   lipo -create -output "${OUTPUT}" "${WORK_DIR}/"*"/${OUTPUT_NAME}"
119 fi