# LinkHeader <Link> : <Source>
rule LinkHeader
{
    NOTFILE "$(2)" ;
    Clean clean "$(1)" ;
}
actions LinkHeader
{
    mkdir -p  "$(1:D)"
    ln -sf "$(2)" "$(1)"
}

# LinkHeader <Copy> : <Source>
rule CopyHeader
{
    DEPENDS "$(1)" : "$(2)" ;
    Clean.Remove clean : "$(1)" ;
}
actions CopyHeader
{
    mkdir -p "$(1:D)"
    cp -fRP "$(2)" "$(1)"
}


# UsrInclude <Target> : <SourceDir> <CompatHeadersDir> ;
rule UsrInclude 
{
    SOURCE_HEADERS = "$(2[1])" ;
    COMPAT_HEADERS = "$(2[2])" ;

    # generate the headers
    DEPENDS "$(1)" : "$(COMPAT_HEADERS)/kerberosIV/des.h"
                     "$(COMPAT_HEADERS)/kerberosIV/krb.h"
                     "$(COMPAT_HEADERS)/kerberosIV/krb_err.h"
                     "$(COMPAT_HEADERS)/des.h"
                     "$(COMPAT_HEADERS)/krb.h"
                     "$(COMPAT_HEADERS)/com_err.h"
                     "$(COMPAT_HEADERS)/profile.h"
                     "$(COMPAT_HEADERS)/krb5.h"
                     "$(COMPAT_HEADERS)/gssapi/gssapi.h"
                     "$(COMPAT_HEADERS)/gssapi/gssapi_krb5.h"
                     "$(COMPAT_HEADERS)/gssapi/gssapi_generic.h" ;

    CopyHeader "$(COMPAT_HEADERS)/kerberosIV/des.h"        : "$(SOURCE_HEADERS)/kerberosIV/des.h" ;
    CopyHeader "$(COMPAT_HEADERS)/kerberosIV/krb.h"        : "$(SOURCE_HEADERS)/kerberosIV/krb.h" ;
    CopyHeader "$(COMPAT_HEADERS)/kerberosIV/krb_err.h"    : "$(SOURCE_HEADERS)/kerberosIV/krb_err.h" ;
    CopyHeader "$(COMPAT_HEADERS)/com_err.h"               : "$(SOURCE_HEADERS)/com_err.h" ;
    CopyHeader "$(COMPAT_HEADERS)/profile.h"               : "$(SOURCE_HEADERS)/profile.h" ;
    CopyHeader "$(COMPAT_HEADERS)/krb5.h"                  : "$(SOURCE_HEADERS)/krb5.h" ;
    CopyHeader "$(COMPAT_HEADERS)/gssapi/gssapi.h"         : "$(SOURCE_HEADERS)/gssapi/gssapi.h" ;
    CopyHeader "$(COMPAT_HEADERS)/gssapi/gssapi_krb5.h"    : "$(SOURCE_HEADERS)/gssapi/gssapi_krb5.h" ;
    CopyHeader "$(COMPAT_HEADERS)/gssapi/gssapi_generic.h" : "$(SOURCE_HEADERS)/gssapi/gssapi_generic.h" ;
    
    # symlink the krb4 and des headers from kerberosIV
    LinkHeader "$(COMPAT_HEADERS)/des.h" : "kerberosIV/des.h" ;
    LinkHeader "$(COMPAT_HEADERS)/krb.h" : "kerberosIV/krb.h" ;
}

UsrInclude all     : "$(BUILT_PRODUCTS_DIR)/Kerberos5.intermediates/include" "$(BUILT_PRODUCTS_DIR)" ;
UsrInclude install : "$(BUILT_PRODUCTS_DIR)/Kerberos5.intermediates/include" "$(DSTROOT)/usr/include" ;

NOCARE installhdrs ;
NOTFILE installhdrs ;
