Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check GCC_PREPROCESSOR_DEFINITIONS parameters in a script

Tags:

bash

xcode

In the Build Settings of my project's target, I have preprocessor Macros configured as following:

Debug FILE_SHARE = 1
Adhoc FILE_SHARE = 1
Release FILE_SHARE = 2

I want to change the UIFileSharingEnabled flag based on those settings values in a script, something like the following:

#!/bin/bash
if [${buildSettings}/${GCC_PREPROCESSOR_DEFINITIONS}/${FILE_SHARE} = 1 ]; then
     /usr/libexec/PlistBuddy -c "Set :UIFileSharingEnabled YES" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
else
     usr/libexec/PlistBuddy -c "Set :UIFileSharingEnabled NO" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi

I know ${buildSettings}/${GCC_PREPROCESSOR_DEFINITIONS}/${FILE_SHARE} = 1 is the wrong syntax, but I cannot figure out what should be right syntax.

like image 731
jxyiliu Avatar asked Feb 25 '13 20:02

jxyiliu


1 Answers

The "User-Defined Build Settings" are also part of the environment when the run script is executed, so the following should work:

if [ ${FILE_SHARE} = 1 ]; then
/usr/libexec/PlistBuddy -c "Set :UIFileSharingEnabled YES" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
else
/usr/libexec/PlistBuddy -c "Set :UIFileSharingEnabled NO" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
fi

Edit: I have misread your question, the above answer applies to "User-Defined Build Settings", not to preprocessor macros.

The following script uses the regular expression matching feature of expr to extract the value of the FILE_SHARE preprocessor macro:

val=`expr "$GCC_PREPROCESSOR_DEFINITIONS" : ".*FILE_SHARE=\([0-9]*\)"`
if [ $val = 1 ]; then
...
else
...
fi
like image 117
Martin R Avatar answered Sep 21 '22 19:09

Martin R