blob: c26b9fb492bf95715fd6a3a915f91cb2d7326794 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001#!/bin/bash
2
3# Copyright (c) 2008 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This is a handy wrapper script that figures out how to call the strip
8# utility (strip_save_dsym in this case), if it even needs to be called at all,
9# and then does it. This script should be called by a post-link phase in
10# targets that might generate Mach-O executables, dynamic libraries, or
11# loadable bundles.
12#
13# An example "Strip If Needed" build phase placed after "Link Binary With
14# Libraries" would do:
15# exec "${XCODEPROJ_DEPTH}/build/mac/strip_from_xcode"
16
17if [ "${CONFIGURATION}" != "Release" ] ; then
18 # Only strip in release mode.
19 exit 0
20fi
21
22declare -a FLAGS
23
24# MACH_O_TYPE is not set for a command-line tool, so check PRODUCT_TYPE too.
25# Weird.
26if [ "${MACH_O_TYPE}" = "mh_execute" ] || \
27 [ "${PRODUCT_TYPE}" = "com.apple.product-type.tool" ] ; then
28 # Strip everything (no special flags). No-op.
29 true
30elif [ "${MACH_O_TYPE}" = "mh_dylib" ] || \
31 [ "${MACH_O_TYPE}" = "mh_bundle" ]; then
32 # Strip debugging symbols and local symbols
33 FLAGS[${#FLAGS[@]}]=-S
34 FLAGS[${#FLAGS[@]}]=-x
35elif [ "${MACH_O_TYPE}" = "staticlib" ] ; then
36 # Don't strip static libraries.
37 exit 0
38else
39 # Warn, but don't treat this as an error.
40 echo $0: warning: unrecognized MACH_O_TYPE ${MACH_O_TYPE}
41 exit 0
42fi
43
44if [ -n "${STRIPFLAGS}" ] ; then
45 # Pick up the standard STRIPFLAGS Xcode setting, used for "Additional Strip
46 # Flags".
47 for stripflag in "${STRIPFLAGS}" ; do
48 FLAGS[${#FLAGS[@]}]="${stripflag}"
49 done
50fi
51
52if [ -n "${CHROMIUM_STRIP_SAVE_FILE}" ] ; then
53 # An Xcode project can communicate a file listing symbols to saved in this
54 # environment variable by setting it as a build setting. This isn't a
55 # standard Xcode setting. It's used in preference to STRIPFLAGS to
56 # eliminate quoting ambiguity concerns.
57 FLAGS[${#FLAGS[@]}]=-s
58 FLAGS[${#FLAGS[@]}]="${CHROMIUM_STRIP_SAVE_FILE}"
59fi
60
61exec "$(dirname ${0})/strip_save_dsym" "${FLAGS[@]}" \
62 "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}"