How to access preprocessor macros from build script?

Hi,


I want to make a build script that takes different actions based on a preprocessor macro. For example, I tried to write it this way:


if [ "${myFlag}" = "1" ]; then


Where "myFlag" is a preprocessor macro that I defined in the build settings.


It doesn't appear to work the way I wrote it. Is there a way to do this?

Replies

Did you try omitting the braces?

You need to omit the braces.


When you say "preprocessor macros", are you setting up a user-defined environment build setting, or are you actually assigning values to the "Preprocessor Macros" build setting? If it's the latter, I don't think pre-processor macro definitions are available to run scripts except through the GCC_PREPROCESSOR_MACROS environment variable which is set from the build settings. If you are setting the value for "myflag" in the build settings via the GCC_PREPROCESSOR_MACROS (the "Preprocessor Macros" build setting), you'll have to parse the whole macro definition to find "myflag"


You can set user-defined environment variables for Xcode via .xcconfig files (look up "xcconfig" files in Xcode documentation, and/or the Internet).