#!/bin/bash

source debian/vars.sh

# Kerberos setup
test -f $_root_sysconfdir/profile.d/krb5-devel.sh && source $_root_sysconfdir/profile.d/krb5-devel.sh
test -f $_root_sysconfdir/profile.d/krb5.sh && source $_root_sysconfdir/profile.d/krb5.sh
GSSDIR=$(krb5-config --prefix)
# SSL setup, probably legacy-only, but shouldn't hurt -- Rex
export PKG_CONFIG_PATH="/opt/cpanel/ea-openssl11/lib/pkgconfig/"
export EXTRACFLAGS="$EXTRACFLAGS $(pkg-config --cflags openssl 2>/dev/null)"
# $RPM_OPT_FLAGS
export EXTRACFLAGS="$EXTRACFLAGS -fPIC $RPM_OPT_FLAGS"
# jorton added these, I'll assume he knows what he's doing. :) -- Rex
export EXTRACFLAGS="$EXTRACFLAGS -fno-strict-aliasing"
export EXTRACFLAGS="$EXTRACFLAGS -Wno-pointer-sign"
export EXTRALDFLAGS="$EXTRALDFLAGS $(pkg-config --libs openssl 2>/dev/null) -Wl,-rpath,/opt/cpanel/ea-openssl11/lib"
# MOAR fun: '-Wl,--build-id=uuid'
# This is complex, so bear with me.  Whenever a library or executable is
# linked in Linux, a .build_id is generated and added to the ELF.  This
# .build_id is also shadow linked to a file in /usr/lib.   In all cases the
# .build_id is a cryptographic signature (sha1 hash) of the binaries contents
# and perhaps "seed".  But in the case of libc-client, we build for each
# version of PHP, and just put the library inside the PHP directory namespace,
# but the libraries are binarily identical (at the time of the hash).  So we
# were getting conflicts when we installed the library on multiple versions of
# PHP as both rpm's owned the .build_id file.  So I am telling the linker
# instead of using the normal sha1 hash, to instead use a random uuid, so each
# version of this library will have a different build_id.  Now further
# consideration, the normal form of this would be -Wl,--build-id,uuid, but for
# some reason that form works perfectly for any of the arguments that use a
# single dash, but does not work for the double hash type.  So I did it
# without the comma, and it is treating that as instead of a parameter, value
# but as a single entity on the linker command line.  Man I am getting a
# headache.
export EXTRALDFLAGS="$EXTRALDFLAGS $(pkg-config --libs openssl 2>/dev/null) '-Wl,--build-id=uuid'"
echo -e "y\ny" | \
make  lnp \
IP=6 \
EXTRACFLAGS="$EXTRACFLAGS" \
EXTRALDFLAGS="$EXTRALDFLAGS" \
EXTRAAUTHENTICATORS=gss \
SPECIALS="GSSDIR=${GSSDIR} LOCKPGM=$_root_sbindir/mlock SSLCERTS=$ssldir/certs SSLDIR=/opt/cpanel/ea-openssl11 SSLINCLUDE=/opt/cpanel/ea-openssl11/include SSLKEYS=$ssldir/private SSLLIB=/opt/cpanel/ea-openssl11/lib" \
SPECIALS="GSSDIR=${GSSDIR} LOCKPGM=$_root_sbindir/mlock SSLCERTS=$ssldir/certs SSLINCLUDE=/usr/include/openssl SSLKEYS=$ssldir/private" \
SSLTYPE=unix \
CCLIENTLIB=$pwd/c-client/$shlibname \
SHLIBBASE=$soname \
SHLIBNAME=$shlibname
