/core/externals/google-toolbox-for-mac/BuildScripts/PListCompiler.sh

http://macfuse.googlecode.com/ · Shell · 70 lines · 29 code · 12 blank · 29 comment · 3 complexity · dcb833f99b0051fb89d0daad5a25663d MD5 · raw file

  1. #!/bin/bash
  2. # PlistCompiler.sh
  3. # Copyright 2010 Google Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may not
  6. # use this file except in compliance with the License. You may obtain a copy
  7. # of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations under
  15. # the License.
  16. # Takes a file (usually with a suffix of .plistsrc) and "compiles it" using
  17. # the gcc preprocessor.
  18. # The best way to use PlistCompiler is to add a custom build rule to your target
  19. # in Xcode with the following settings:
  20. # Process: "Source files with names matching:" "*.plistsrc"
  21. # using: "Custom script:"
  22. # "Path/to/PlistCompiler/relative/to/${SRCROOT}'
  23. # with output files:
  24. # ${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${INPUT_FILE_BASE}.plist
  25. # You can control the include paths by setting the
  26. # GTM_PLIST_COMPILER_INCLUDE_PATHS environment variable to a colon delimited
  27. # path string. It defaults to "."
  28. set -o errexit
  29. set -o nounset
  30. PWD=$(pwd)
  31. GTM_PLIST_COMPILER_INCLUDE_PATHS=${GTM_PLIST_COMPILER_INCLUDE_PATHS:=${PWD}}
  32. if [[ $# -ne 2 && $# -ne 0 ]] ; then
  33. echo "usage: ${0} INPUT OUTPUT" >&2
  34. exit 1
  35. fi
  36. if [[ $# -eq 2 ]] ; then
  37. SCRIPT_INPUT_FILE="${1}"
  38. SCRIPT_OUTPUT_FILE="${2}"
  39. else
  40. SCRIPT_INPUT_FILE="${INPUT_FILE_PATH}"
  41. SCRIPT_OUTPUT_FILE="${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${INPUT_FILE_BASE}.plist"
  42. fi
  43. # Split up the passed in include paths
  44. SaveIFS=$IFS
  45. IFS=":"
  46. declare -a SPLIT_INCLUDE_PATHS
  47. for a in ${GTM_PLIST_COMPILER_INCLUDE_PATHS};
  48. do
  49. SPLIT_INCLUDE_PATHS[${#SPLIT_INCLUDE_PATHS[@]}]=-I
  50. SPLIT_INCLUDE_PATHS[${#SPLIT_INCLUDE_PATHS[@]}]="${a}"
  51. done
  52. IFS=$SaveIFS
  53. NAME=$(basename $0)
  54. TEMP=$(mktemp -t "${NAME}")
  55. # run gcc and strip out lines starting with # that the preprocessor leaves behind.
  56. gcc ${SPLIT_INCLUDE_PATHS[@]} -E -x c "${SCRIPT_INPUT_FILE}" -o "${TEMP}"
  57. sed 's/^#.*//g' "${TEMP}" > "${SCRIPT_OUTPUT_FILE}"
  58. rm -f "${TEMP}"