PageRenderTime 14ms CodeModel.GetById 10ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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