Intermediates = "$(BUILT_PRODUCTS_DIR)/Kerberos5.intermediates" ;
IntermediateBuild = "$(Intermediates)/build" ;
Sources = "$(SRCROOT)/../../Kerberos5/Sources" ;

Reconf = "$(Sources)/util/reconf" ;
Configure = "$(Sources)/configure" ;
Makefile = "$(IntermediateBuild)/Makefile" ;
MakeStamp = "$(IntermediateBuild)/make.stamp" ;

# Assemble CFLAGS
CONFIGURE_CFLAGS = "-fno-common -include /usr/include/TargetConditionals.h -DUSE_PASSWORD_SERVER" ;
if $(RC_CFLAGS)      != "" { CONFIGURE_CFLAGS = "$(CONFIGURE_CFLAGS) $(RC_CFLAGS)" ;      }
if $(CFLAGS)         != "" { CONFIGURE_CFLAGS = "$(CONFIGURE_CFLAGS) $(CFLAGS)" ;         }
if $(OTHER_CFLAGS)   != "" { CONFIGURE_CFLAGS = "$(CONFIGURE_CFLAGS) $(OTHER_CFLAGS)" ;   }
if $(WARNING_CFLAGS) != "" { CONFIGURE_CFLAGS = "$(CONFIGURE_CFLAGS) $(WARNING_CFLAGS)" ; }
CONFIGURE_CFLAGS = "CFLAGS=$(CONFIGURE_CFLAGS)" ;

# Assemble LDFLAGS
CONFIGURE_LDFLAGS = "-Wl,-search_paths_first" ;
if $(LDFLAGS) != "" { CONFIGURE_LDFLAGS = "$(LDFLAGS) $(CONFIGURE_LDFLAGS)" ;  }
CONFIGURE_LDFLAGS = "LDFLAGS=$(CONFIGURE_LDFLAGS:)" ;

#
# Note: in this jam script we have separated the dependency tree from the 
# actual scripts.  This is so that CVS checkouts trigger a rebuild but the jam
# script doesn't need to know how the reconf and configure scripts work.
#

# Reconf <configure> : <configure.in>
rule Reconf
{
    DEPENDS "$(1)" : "$(1).in" "$(Reconf)" ;
}
actions Reconf
{
    cd "$(Sources)" && /bin/sh "$(Reconf)" -f
}

# Configure <makefile> : <configure>
rule Configure
{
    DEPENDS "$(1)" : "$(2)" ;
    Reconf "$(2)" : "$(2).in" ;
    Clean.Remove clean "$(1:D)" ;
}
actions Configure
{
    mkdir -p "$(1:D)"
    cd "$(1:D)" && /bin/sh "$(2)" --prefix=/usr --localstatedir=/var/db "$(CONFIGURE_CFLAGS)" "$(CONFIGURE_LDFLAGS)" || rm -f "$(1)"
}

# Make <stamp file> : <makefile>
rule Make
{
    DEPENDS "$(1)" : "$(2)" ;
    Configure "$(2)" : "$(Configure)" ;
    Clean.Remove clean "$(1)" ;
}
actions Make
{
    mkdir -p "$(1:D)"
    cd "$(1:D)" && make && touch "$(1)" && echo "### HAPPINESS ###"
}

# InstallProgram <destination executable> : <source executable>
rule InstallProgram
{
    DEPENDS "$(1)" : "$(2)" ;
    DEPENDS "$(2)" : "$(MakeStamp)" ;
    Clean.Remove clean "$(1)" ;
}
actions InstallProgram
{
    mkdir -p "$(1:D)"
    /usr/bin/install -c -s "$(2)" "$(1)" 
}

# InstallFile <destination file> : <source file>
rule InstallFile
{
    DEPENDS "$(1)" : "$(2)" ;
    DEPENDS "$(2)" : "$(MakeStamp)" ;
    Clean.Remove clean "$(1)" ;
}
actions InstallFile
{
    mkdir -p "$(1:D)"
    /usr/bin/install -c -m 644 "$(2)" "$(1)" 
}

Make "$(MakeStamp)" : "$(Makefile)" ;

InstallProgram "$(DSTROOT)/usr/sbin/kadmin"          : "$(IntermediateBuild)/kadmin/cli/kadmin" ;
InstallProgram "$(DSTROOT)/usr/sbin/kadmin.local"    : "$(IntermediateBuild)/kadmin/cli/kadmin.local" ;
InstallProgram "$(DSTROOT)/usr/sbin/kadmind"         : "$(IntermediateBuild)/kadmin/server/kadmind" ;
InstallProgram "$(DSTROOT)/usr/sbin/ktutil"          : "$(IntermediateBuild)/kadmin/ktutil/ktutil" ;
InstallProgram "$(DSTROOT)/usr/sbin/kdb5_util"       : "$(IntermediateBuild)/kadmin/dbutil/kdb5_util" ;
InstallProgram "$(DSTROOT)/usr/sbin/kprop"           : "$(IntermediateBuild)/slave/kprop" ;
InstallProgram "$(DSTROOT)/usr/sbin/kpropd"          : "$(IntermediateBuild)/slave/kpropd" ;
InstallProgram "$(DSTROOT)/usr/sbin/krb524d"         : "$(IntermediateBuild)/krb524/krb524d" ;
InstallProgram "$(DSTROOT)/usr/sbin/krb5kdc"         : "$(IntermediateBuild)/kdc/krb5kdc" ;
InstallProgram "$(DSTROOT)/usr/bin/krb5-config"      : "$(IntermediateBuild)/krb5-config" ;
                  
InstallFile "$(DSTROOT)/usr/share/man/man1/kerberos.1"     : "$(SRCROOT)/../../Kerberos5/Sources/gen-manpages/kerberos.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man5/kdc.conf.5"     : "$(SRCROOT)/../../Kerberos5/Sources/config-files/kdc.conf.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man5/krb5.conf.5"    : "$(SRCROOT)/../../Kerberos5/Sources/config-files/krb5.conf.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/kadmin.8"       : "$(SRCROOT)/../../Kerberos5/Sources/kadmin/cli/kadmin.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/kadmin.local.8" : "$(SRCROOT)/../../Kerberos5/Sources/kadmin/cli/kadmin.local.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/kadmind.8"      : "$(SRCROOT)/../../Kerberos5/Sources/kadmin/server/kadmind.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/ktutil.8"       : "$(SRCROOT)/../../Kerberos5/Sources/kadmin/ktutil/ktutil.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/kdb5_util.8"    : "$(SRCROOT)/../../Kerberos5/Sources/kadmin/dbutil/kdb5_util.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/kprop.8"        : "$(SRCROOT)/../../Kerberos5/Sources/slave/kprop.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/kpropd.8"       : "$(SRCROOT)/../../Kerberos5/Sources/slave/kpropd.M" ;
InstallFile "$(DSTROOT)/usr/share/man/man8/krb5kdc.8"      : "$(SRCROOT)/../../Kerberos5/Sources/kdc/krb5kdc.M" ;


DEPENDS all     : "$(MakeStamp)" ;

DEPENDS install : all 
                  "$(DSTROOT)/usr/sbin/kadmin"
                  "$(DSTROOT)/usr/sbin/kadmin.local"
                  "$(DSTROOT)/usr/sbin/kadmind"
                  "$(DSTROOT)/usr/sbin/kdb5_util"
                  "$(DSTROOT)/usr/sbin/kprop"
                  "$(DSTROOT)/usr/sbin/kpropd"
                  "$(DSTROOT)/usr/sbin/krb524d"
                  "$(DSTROOT)/usr/sbin/krb5kdc"
                  "$(DSTROOT)/usr/sbin/ktutil"
                  "$(DSTROOT)/usr/bin/krb5-config"
                  
                  "$(DSTROOT)/usr/share/man/man1/kerberos.1"
                  "$(DSTROOT)/usr/share/man/man5/kdc.conf.5"
                  "$(DSTROOT)/usr/share/man/man5/krb5.conf.5"
                  "$(DSTROOT)/usr/share/man/man8/kadmin.8"
                  "$(DSTROOT)/usr/share/man/man8/kadmin.local.8"
                  "$(DSTROOT)/usr/share/man/man8/kadmind.8"
                  "$(DSTROOT)/usr/share/man/man8/kdb5_util.8"
                  "$(DSTROOT)/usr/share/man/man8/kprop.8"
                  "$(DSTROOT)/usr/share/man/man8/kpropd.8"
                  "$(DSTROOT)/usr/share/man/man8/krb5kdc.8"
                  "$(DSTROOT)/usr/share/man/man8/ktutil.8" ;
                  
DEPENDS installhdrs : all ;
