# $NetBSD$

BUILTIN_PKG:=	openldap-client

BUILTIN_FIND_FILES_VAR:=	H_OPENLDAP
BUILTIN_FIND_FILES.H_OPENLDAP=	/usr/include/ldap_features.h

.include "../../mk/buildlink3/bsd.builtin.mk"

###
### Determine if there is a built-in implementation of the package and
### set IS_BUILTIN.<pkg> appropriately ("yes" or "no").
###
.if !defined(IS_BUILTIN.openldap-client)
IS_BUILTIN.openldap-client-client=	no
.  if empty(H_OPENLDAP:M__nonexistent__) && empty(H_OPENLDAP:M${LOCALBASE}/*)
IS_BUILTIN.openldap-client=	yes
.  endif
.endif
MAKEVARS+=	IS_BUILTIN.openldap-client

###
### If there is a built-in implementation, then set BUILTIN_PKG.<pkg> to
### a package name to represent the built-in package.
###
.if !defined(BUILTIN_PKG.openldap-client) && \
    !empty(IS_BUILTIN.openldap-client:M[yY][eE][sS]) && \
    empty(H_OPENLDAP:M__nonexistent__)
BUILTIN_VERSION.openldap-client!=	\
	${AWK} '/\#define[ 	]*_?LDAP_VENDOR_VERSION_MAJOR[ 	]/ {printf $$3"."; } \
	/\#define[ 	]*_?LDAP_VENDOR_VERSION_MINOR[ 	]/ {printf $$3"."; } \
	/\#define[ 	]*_?LDAP_VENDOR_VERSION_PATCH[ 	]/ {print $$3; }' ${H_OPENLDAP}
BUILTIN_PKG.openldap-client=	openldap-client-${BUILTIN_VERSION.openldap-client}
.endif
MAKEVARS+=	BUILTIN_PKG.openldap-client

###
### Determine whether we should use the built-in implementation if it
### exists, and set USE_BUILTIN.<pkg> appropriate ("yes" or "no").
###
.if !defined(USE_BUILTIN.openldap-client)
.  if ${PREFER.openldap-client} == "pkgsrc"
USE_BUILTIN.openldap-client=	no
.  else
USE_BUILTIN.openldap-client=	${IS_BUILTIN.openldap-client}
.    if defined(BUILTIN_PKG.openldap-client) && \
        !empty(IS_BUILTIN.openldap-client:M[yY][eE][sS])
USE_BUILTIN.openldap-client=	yes
.      for _dep_ in ${BUILDLINK_API_DEPENDS.openldap-client}
.        if !empty(USE_BUILTIN.openldap-client:M[yY][eE][sS])
USE_BUILTIN.openldap-client!=							\
	if ${PKG_ADMIN} pmatch ${_dep_:Q} ${BUILTIN_PKG.openldap-client:Q}; then \
		${ECHO} yes;						\
	else								\
		${ECHO} no;						\
	fi
.        endif
.      endfor
.    endif
.  endif  # PREFER.openldap-client
.endif
MAKEVARS+=	USE_BUILTIN.openldap-client