
# Use: PBX  Target : Project ;
rule PBX
{
    PBXBuild all         : "$(2)" "$(1)" build ;
    PBXBuild build       : "$(2)" "$(1)" build ;
    PBXBuild installsrc  : "$(2)" "$(1)" installsrc ;
    PBXBuild installhdrs : "$(2)" "$(1)" installhdrs ;
    PBXBuild install     : "$(2)" "$(1)" install ;
    PBXBuild clean       : "$(2)" "$(1)" clean ;
}

actions PBX
{
}

# Use: PBXBuild Action : Project Target Action;
rule PBXBuild
{
    ALWAYS "$(1)" ;
    NOTFILE "$(2[2])" ;
    NOTFILE "$(2[3])" ;
    
    # When this jam script is called, these variables are set in the environment (PB checkbox)
    # However, xcodebuild won't inherit these values from us, so we pass them in on the command line...

    # Note that since xcodebuild doesn't inherit variables from the environment, it wouldn't help
    # to call xcodebuild directly since you would still need to pass variables on the command line.
    # This method at least avoids replication of the following variable manipulation:

    # We copy BUILT_PRODUCTS_DIR because otherwise it gets mangled by xcodebuild
    
    ENVIRONMENT = ;
    if $(DSTROOT) != ""                 { ENVIRONMENT += "DSTROOT=$(DSTROOT)" ; }
    if $(OBJROOT) != ""                 { ENVIRONMENT += "OBJROOT=$(OBJROOT)" ; }
    if $(SYMROOT) != ""                 { ENVIRONMENT += "SYMROOT=$(SYMROOT)" ; }
    if $(BUILT_PRODUCTS_DIR) != ""      { ENVIRONMENT += "BUILT_PRODUCTS_DIR=$(BUILT_PRODUCTS_DIR)" ; }
    if $(SUBLIBROOTS) != ""             { ENVIRONMENT += "SUBLIBROOTS=$(SUBLIBROOTS)" ; }
    if $(RC_XBS) != ""                  { ENVIRONMENT += "RC_XBS=$(RC_XBS)" ; }
    if $(RC_JASPER) != ""               { ENVIRONMENT += "RC_JASPER=$(RC_JASPER)" ; }
    if $(RC_CFLAGS) != ""               { ENVIRONMENT += "RC_CFLAGS=$(RC_CFLAGS)" ; }
    if $(RC_NONARCH_CFLAGS) != ""       { ENVIRONMENT += "RC_NONARCH_CFLAGS=$(RC_NONARCH_CFLAGS)" ; }
    if $(RC_ARCHS) != ""                { ENVIRONMENT += "RC_ARCHS=$(RC_ARCHS)" ; }
    if $(RC_hppa) != ""                 { ENVIRONMENT += "RC_hppa=$(RC_hppa)" ; }
    if $(RC_i386) != ""                 { ENVIRONMENT += "RC_i386=$(RC_i386)" ; }
    if $(RC_m68k) != ""                 { ENVIRONMENT += "RC_m68k=$(RC_m68k)" ; }
    if $(RC_ppc) != ""                  { ENVIRONMENT += "RC_ppc=$(RC_ppc)" ; }
    if $(RC_ppc64) != ""                { ENVIRONMENT += "RC_ppc64=$(RC_ppc64)" ; }
    if $(RC_sparc) != ""                { ENVIRONMENT += "RC_sparc=$(RC_sparc)" ; }
    if $(RC_OS) != ""                   { ENVIRONMENT += "RC_OS=$(RC_OS)" ; }
    if $(RC_RELEASE) != ""              { ENVIRONMENT += "RC_RELEASE=$(RC_RELEASE)" ; }
    if $(RC_ProjectName) != ""          { ENVIRONMENT += "RC_ProjectName=$(RC_ProjectName)" ; }
    if $(RC_ProjectSourceVersion) != "" { ENVIRONMENT += "RC_ProjectSourceVersion=$(RC_ProjectSourceVersion)" ; }
    if $(RC_ProjectBuildVersion) != ""  { ENVIRONMENT += "RC_ProjectBuildVersion=$(RC_ProjectBuildVersion)" ; }
    if $(RC_ReleaseStatus) != ""        { ENVIRONMENT += "RC_ReleaseStatus=$(RC_ReleaseStatus)" ; }
    if $(NEXT_ROOT) != ""               { ENVIRONMENT += "NEXT_ROOT=$(NEXT_ROOT)" ; }
    if $(OPTIMIZATION_CFLAGS) != ""     { ENVIRONMENT += "OPTIMIZATION_CFLAGS=$(OPTIMIZATION_CFLAGS)" ; }
    if $(OTHER_CFLAGS) != ""            { ENVIRONMENT += "OTHER_CFLAGS=$(OTHER_CFLAGS)" ; }
    if $(OTHER_CPLUSPLUSFLAGS) != ""    { ENVIRONMENT += "OTHER_CPLUSPLUSFLAGS=$(OTHER_CPLUSPLUSFLAGS)" ; }
    if $(INSTALL_MODE_FLAG) != ""       { ENVIRONMENT += "INSTALL_MODE_FLAG=$(INSTALL_MODE_FLAG)" ; }
    if $(FRAMEWORK_SEARCH_PATHS) != ""  { ENVIRONMENT += "FRAMEWORK_SEARCH_PATHS=$(FRAMEWORK_SEARCH_PATHS)" ; }
} 

actions PBXBuild
{
    cd "$(2[1]:D)" && xcodebuild "$(2[3])" -target "$(2[2])" "SRCROOT=$(2[1]:D)" "$(ENVIRONMENT)"
}
