Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1 | #!/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 | |
| 17 | if [ "${CONFIGURATION}" != "Release" ] ; then |
| 18 | # Only strip in release mode. |
| 19 | exit 0 |
| 20 | fi |
| 21 | |
| 22 | declare -a FLAGS |
| 23 | |
| 24 | # MACH_O_TYPE is not set for a command-line tool, so check PRODUCT_TYPE too. |
| 25 | # Weird. |
| 26 | if [ "${MACH_O_TYPE}" = "mh_execute" ] || \ |
| 27 | [ "${PRODUCT_TYPE}" = "com.apple.product-type.tool" ] ; then |
| 28 | # Strip everything (no special flags). No-op. |
| 29 | true |
| 30 | elif [ "${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 |
| 35 | elif [ "${MACH_O_TYPE}" = "staticlib" ] ; then |
| 36 | # Don't strip static libraries. |
| 37 | exit 0 |
| 38 | else |
| 39 | # Warn, but don't treat this as an error. |
| 40 | echo $0: warning: unrecognized MACH_O_TYPE ${MACH_O_TYPE} |
| 41 | exit 0 |
| 42 | fi |
| 43 | |
| 44 | if [ -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 |
| 50 | fi |
| 51 | |
| 52 | if [ -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}" |
| 59 | fi |
| 60 | |
| 61 | exec "$(dirname ${0})/strip_save_dsym" "${FLAGS[@]}" \ |
| 62 | "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" |