Subject: pkg/22547: New apache.mk, similar to java-vm.mk
To: None <gnats-bugs@gnats.netbsd.org>
From: Eric Haszlakiewicz <erh@nimenees.com>
List: netbsd-bugs
Date: 08/19/2003 14:58:35
>Number:         22547
>Category:       pkg
>Synopsis:       It's not possible to write an apache module package for any apache.
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 19 19:59:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Eric Haszlakiewicz
>Release:        NetBSD 1.6W
>Organization:
>Environment:
System: NetBSD diana.nimenees.com 1.6W NetBSD 1.6W (DIANA) #1: Tue Aug 5 16:20:11 CDT 2003 root@poe.nimenees.com:/usr/build/DIANA i386
Architecture: i386
Machine: i386
>Description:
	The way that the apache web servers are handled doesn't work very well
when trying to create a module package that will work with either version.
For instance, notice that there are two php4 modules, one for apache13
and one for apache2.  It should be possible to have a single package that
just uses whatever version of apache is installed.
>How-To-Repeat:
>Fix:
	Here is an apache.mk to put in pkgsrc/mk that works similar to
the java-vm.mk.  Instead of .including .../apache/buildlink2.mk or
.../apache2/buildlink2.mk a package should include this and it will
depend on whatever happens to be installed.  PKG_APACHE_DEFAULT can
be set to define what to install is apache is not yet installed.
Package makefiles can specify which versions they can build against.

A review of this would be great, since I haven't done a whole lot
with pkgsrc.

# $NetBSD: $
#
# This Makefile fragment handles Apache dependencies and make variables,
# and is meant to be included by packages that require Apache either at
# build-time or at run-time.  apache.mk will:
#
#	* set PKG_APACHE to the name of the apache web serverused
#
#	* add a full dependency on the apache server
#
#   * optionally add a full dependency on apr
#
# The available user variables are:
#
# PKG_APACHE_DEFAULT is a user-settable variable whose value is the default
#	apache server to use.  Possible values are apache13, apache2 and apache6
#
# The available makefile variables are:
#
# USE_APACHE13 is used to note that the package requires the Apache13 server. 
#	It's undefined by default, but may be set to "yes".
#
# USE_APACHE2 is used to note that the package requires the Apache2 server.
#	It's undefined by default, but may be set to "yes".
#
# USE_APACHE6 is used to note that the package requires the Apache6 server.
#	It's undefined by default, but may be set to "yes".
#
# PKG_APACHE_ACCEPTED is a package-settable list of servers that may be used as
#	possible dependencies for the package.  Possible values are the same as
#   for PKG_APACHE_DEFAULT.  This overrides any of the USE_APACHE settings.
#
# USE_APR is used to note that the package requires the Apache Portable
#   runtime to build and execute.  This is only takes effect if apache2
#   is chosen (by this file) as the web server to use.  This adds a full
#   dependency on apr.
#

.if !defined(APACHE_MK)
APACHE_MK=	# defined

.include "../../mk/bsd.prefs.mk"

PKG_APACHE_DEFAULT?=	# empty

_PKG_APACHES?=	apache13 apache2 apache6

.if defined(PKG_APACHE_ACCEPTED)
.    for _ap_ in ${PKG_APACHE_ACCEPTED}
.        if !empty(_PKG_APACHES:M${_ap_})
           _PKG_APACHE_ACCEPTED+=${PKG_APACHE_ACCEPTED:M${_ap_}}
.        endif
.    endfor
.endif

.if defined(USE_APACHE2) && !empty(USE_APACHE2:M[yY][eE][sS])
_PKG_APACHE_ACCEPTED?=		apache2
.elif defined(USE_APACHE13) && !empty(USE_APACHE13:M[yY][eE][sS])
_PKG_APACHE_ACCEPTED?=		apache13
.elif defined(USE_APACHE6) && !empty(USE_APACHE6:M[yY][eE][sS])
_PKG_APACHE_ACCEPTED?=		apache6
.endif

_PKG_APACHE_ACCEPTED?=	${_PKG_APACHES}

# Set the default apache for this platform.
#
.if !empty(PKG_APACHE_DEFAULT)
_PKG_APACHE_DEFAULT=	${PKG_APACHE_DEFAULT}
.endif
.if !defined(_PKG_APACHE_DEFAULT)
_PKG_APACHE_DEFAULT?=	apache13
.endif

_APACHE_PKGBASE.apache13 = apache-1\*
_APACHE_PKGBASE.apache2 = apache-2\*
_APACHE_PKGBASE.apache6 = apache6

# Mark the acceptable apaches and check which apache packages are installed.
.for _ap_ in ${_PKG_APACHE_ACCEPTED}
_PKG_APACHE_OK.${_ap_}=	yes
_PKG_APACHE_INSTALLED.${_ap_}!= \
	if ${PKG_INFO} -qe ${_APACHE_PKGBASE.${_ap_}}; then		\
		${ECHO} yes;						\
	else								\
		${ECHO} no;						\
	fi
.endfor

# Use one of the installed apaches,...
#
.if !defined(_PKG_APACHE)
.  for _ap_ in ${_PKG_APACHE_ACCEPTED}
.    if !empty(_PKG_APACHE_INSTALLED.${_ap_}:M[yY][eE][sS])
_PKG_APACHE?=	${_ap_}
.    else
_PKG_APACHE_FIRSTACCEPTED?= ${_ap_}
.    endif
.  endfor
.endif
#
# ...otherwise, prefer the default one if it's accepted,...
#
.if !defined(_PKG_APACHE)
.  if defined(_PKG_APACHE_OK.${_PKG_APACHE_DEFAULT}) && \
      !empty(_PKG_APACHE_OK.${_PKG_APACHE_DEFAULT}:M[yY][eE][sS])
_PKG_APACHE=	${_PKG_APACHE_DEFAULT}
.  endif
.endif
#
# ...otherwise, just use the first accepted apache.
#
.if !defined(_PKG_APACHE)
.  if defined(_PKG_APACHE_FIRSTACCEPTED)
_PKG_APACHE=	${_PKG_APACHE_FIRSTACCEPTED}
.  endif
.endif
#
# If there are no acceptable apaches, then generate an error.
#
.if !defined(_PKG_APACHE)
# force an error
PKG_FAIL_REASON=	"no acceptable apache found"
_PKG_APACHE=		"none"
.endif

BUILDLINK_DEPENDS.apache13?=	apache-1.3*
BUILDLINK_DEPENDS.apache2?=		apache-2*
BUILDLINK_DEPENDS.apache6?=		apache6*

.if ${_PKG_APACHE} == "apache13"
_APACHE_PKGSRCDIR=  ../../www/apache
.elif ${_PKG_APACHE} == "apache2"
_APACHE_PKGSRCDIR=  ../../www/apache2
.elif ${_PKG_APACHE} == "apache6"
_APACHE_PKGSRCDIR=  ../../www/apache2
.endif

_APACHE_DEPENDENCY?=	${BUILDLINK_DEPENDS.${_PKG_JVM}}:${_APACHE_PKGSRCDIR}

# Add a runtime dependency on the apache server.
# This may or may not create an actual dependency depending on
# what the apache buildlink2.mk file does.
.if defined(_APACHE_PKGSRCDIR)
.if defined(USE_BUILDLINK2) && empty(USE_BUILDLINK2:M[nN][oO])
.  include "${_APACHE_PKGSRCDIR}/buildlink2.mk"
.else
DEPENDS+=		${_APACHE_DEPENDENCY}
.endif
.endif

# If we are building apache modules, then we might need a build-time
# dependency on apr, and the apache sources?
.if defined(USE_BUILDLINK2) && empty(USE_BUILDLINK2:M[nN][oO])
.    if defined(_APACHE_PKGSRCDIR)
.      include "${_APACHE_PKGSRCDIR}/buildlink2.mk"
.    endif
.else
BUILD_DEPENDS+=		${_APACHE_DEPENDENCY}
.endif

.if defined(USE_BUILDLINK2) && empty(USE_BUILDLINK2:M[nN][oO])
.    if ${_PKG_APACHE} == "apache2"
.        if defined(USE_APR) && !empty(USE_APR:M[yY][eE][sS])
.          include "../../devel/apr/buildlink2.mk"
.        endif
.    endif
.endif

# PKG_APACHE is a publicly readable variable containing the name of the server
#	we will be using.
#
PKG_APACHE:=		${_PKG_APACHE}
BUILD_DEFS+=		PKG_APACHE

.endif	# APACHE_MK
>Release-Note:
>Audit-Trail:
>Unformatted: