1 ################################################################################
3 # httpd.cygclass - functions for building Apache HTTP Server mod_* modules
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/httpd.cygclass
28 # The Apache Web Server is an HTTP server which can be extended through
29 # plugins, known as DSOs, to support all sorts of tasks, scripting languages,
30 # and more. DSOs use the ".so" extension, even on platforms which use DLLs.
32 # The purpose of httpd.cygclass is to provide functions and definitions
33 # for building DSOs for the Cygwin Apache HTTP Server packages. Cygwin packages
34 # doing so should use the "httpd-" prefix before the canonical package name.
35 # Because there is no consistent DSO source buildsystem, src_compile and
36 # src_install must be defined yourself.
38 # Apache module source packages do not have a single system. Some packages
42 # NAME="httpd-mod_clamav"
46 # SUMMARY="ClamAV filter module for Apache HTTP Server"
47 # DESCRIPTION="mod_clamav is an Apache HTTP Server filter which scans the content
48 # delivered by the proxy module (mod_proxy) for viruses using the Clamav
49 # virus scanning engine."
50 # HOMEPAGE="http://software.othello.ch/mod_clamav/"
51 # LICENSE="GPL-2.0-only"
52 # SRC_URI="http://software.othello.ch/mod_clamav/mod_clamav-${VERSION}.tar.gz"
53 # SRC_DIR="mod_clamav-${VERSION}"
54 # PATCH_URI="0.22-cygwin-layout.patch"
65 # dohttpdmod mod_clamav
66 # dohttpdconf ${S}/sample.conf ${S}/safepatterns.conf
69 # Other simple module just ship the sources without a build system:
73 # NAME="httpd-mod_geoip"
77 # SUMMARY="Apache HTTP Server GeoIP module"
78 # DESCRIPTION="mod_geoip2 is an Apache HTTP Server module for finding the country and
79 # city that a web request originated from. It uses the GeoIP library and
80 # database to perform the lookup."
81 # HOMEPAGE="https://dev.maxmind.com/geoip/legacy/mod_geoip2/"
82 # LICENSE="Apache-1.1"
83 # SRC_URI="https://github.com/maxmind/geoip-api-mod_geoip2/archive/v${VERSION}.tar.gz"
84 # SRC_DIR="geoip-api-mod_geoip2-${VERSION}"
89 # httpd_apxs_compile *.c -lGeoIP
94 # dohttpdmod mod_geoip.la
100 # httpd-devel, libapr1-devel, libaprutil1-devel
105 # cross-compiling is not (yet?) supported
106 __cross_compiling_error
108 case ${PN} in httpd-mod_*)
109 ORIG_PN=${ORIG_PN:-${PN#httpd-}}
110 ORIG_P=${ORIG_PN}-${PV}
111 #****o* httpd.cygclass/CATEGORY (httpd)
115 #****o* httpd.cygclass/SUMMARY (httpd)
117 SUMMARY="Apache HTTP Server ${PN#httpd-mod_} module"
121 HTTPD_MOD_NAME=${HTTPD_MOD_NAME:-${PN#httpd-}}
123 #****d* httpd.cygclass/HTTPD_APXS
125 # Path to apxs(1), the APache eXtenSion tool.
127 HTTPD_APXS=/usr/bin/apxs
129 check_prog_req ${HTTPD_APXS} httpd-devel
131 #****d* httpd.cygclass/HTTPD
133 # Path to the Apache HTTP Server.
135 HTTPD=/usr/sbin/httpd
137 #****d* httpd.cygclass/HTTPD_VERSION
139 # Full version of the Apache HTTP Server.
141 HTTPD_VERSION=$(${HTTPD} -v | cut -d ' ' -f 3 | cut -d / -f 2)
143 #****d* httpd.cygclass/HTTPD_INCLUDEDIR
145 # Location of Apache HTTP Server headers.
147 HTTPD_INCLUDEDIR="$(${HTTPD_APXS} -q INCLUDEDIR 2>/dev/null)" # /usr/include/httpd
149 #****d* httpd.cygclass/HTTPD_LIBEXECDIR
151 # Installation path for Apache HTTP Server DSOs.
153 HTTPD_LIBEXECDIR="$(${HTTPD_APXS} -q LIBEXECDIR 2>/dev/null)" # /usr/lib/httpd/modules
155 #****d* httpd.cygclass/HTTPD_SYSCONFDIR
157 # Installation path for Apache HTTP Server configuration files.
159 HTTPD_SYSCONFDIR="$(${HTTPD_APXS} -q SYSCONFDIR 2>/dev/null).d" # /etc/httpd/conf.d
161 #****d* httpd.cygclass/HTTPD_SYSCONFMODULESDIR
163 # Installation path for Apache HTTP Server LoadModule directives
165 HTTPD_SYSCONFMODULESDIR="$(${HTTPD_APXS} -q SYSCONFDIR 2>/dev/null).modules.d" # /etc/httpd/conf.modules.d
167 #****d* httpd.cygclass/HTTPD_CFLAGS
169 # Compile flags for building Apache HTTP Server DSOs.
171 HTTPD_CFLAGS="-I${HTTPD_INCLUDEDIR} $(${HTTPD_APXS} -q CFLAGS 2>/dev/null)"
173 #****d* httpd.cygclass/HTTPD_LIBS
175 # Link flags for building Apache HTTP Server DSOs.
177 # This is Cygwin specific due to the linking requirements of PE/COFF DLLs.
181 DEPS_PATH="${DEPS_PATH}${DEPS_PATH+:}/usr/sbin:${HTTPD_LIBEXECDIR}"
183 #****d* httpd.cygclass/APR_VERSION
185 # Major version of APR libraries used by the Apache HTTP Server.
187 case ${HTTPD_VERSION:0:3} in
188 2.4) APR_VERSION=1 ;;
189 *) error "Don't know anything about Apache HTTP Server ${HTTPD_VERSION}" ;;
192 #****d* httpd.cygclass/APR_CONFIG
194 # Path to matching APR_VERSION-specific apr-config script
197 #****d* httpd.cygclass/APU_CONFIG
199 # Path to matching APR_VERSION-specific apu-config script
202 case ${APR_VERSION} in
203 1) APR_CONFIG=/usr/bin/apr-${APR_VERSION}-config
204 APU_CONFIG=/usr/bin/apu-${APR_VERSION}-config
206 *) error "Illegal value ${APR_VERSION} for APR_VERSION" ;;
209 check_prog_req ${APR_CONFIG##*/} libapr${APR_VERSION}-devel
210 check_prog_req ${APU_CONFIG##*/} libaprutil${APR_VERSION}-devel
212 #****d* httpd.cygclass/APR_CFLAGS
214 # Compile flags for building against APR libraries
216 APR_CFLAGS="$(${APU_CONFIG} --includes) $(${APR_CONFIG} --cppflags --includes)"
218 #****d* httpd.cygclass/APR_LIBS
220 # Link flags for building against APR libraries
222 APR_LIBS="$(${APU_CONFIG} --link-ld) $(${APR_CONFIG} --link-ld --libs)"
224 #****d* httpd.cygclass/APR_LIBTOOL
226 # Path to libtool script used by APR-dependent packages
228 APR_LIBTOOL="$(${APR_CONFIG} --apr-libtool)"
230 # Make HTTPD_* contain all required flags
231 HTTPD_CFLAGS+=" ${APR_CFLAGS}"
232 HTTPD_LIBS+=" ${APR_LIBS}"
234 if check_prog apreq2-config
237 #****d* httpd.cygclass/APREQ2_CONFIG
239 # Path to apreq2-config script
241 APREQ2_CONFIG=/usr/bin/apreq2-config
243 #****d* httpd.cygclass/APREQ2_CFLAGS
245 # Compile flags for building against libapreq2
249 APREQ2_CFLAGS="$(${APREQ2_CONFIG} --includes)"
251 #****d* httpd.cygclass/APREQ2_LIBS
253 # Link flags for building against libapreq2
257 APREQ2_LIBS="$(${APREQ2_CONFIG} --link-ld)"
259 fi # check_prog apreq2-config #
261 #****C* httpd.cygclass/httpd_mod_compile
263 # httpd_mod_compile [CONFIGURE_FLAGS]
265 # Build a DSO which uses an autoconf/libtool buildsystem by calling cygconf
266 # and cygmake with some Apache-specific flags. Arguments, if any, are passed
267 # as configure flags.
269 # This is very generic and may not work in all cases.
271 httpd_mod_compile() {
272 if ! defined HTTPD_MOD_NAME
274 error "define HTTPD_MOD_NAME before calling httpd_mod_compile"
278 --with-apxs=${HTTPD_APXS} \
279 --with-apr-config=${APR_CONFIG} \
283 ${HTTPD_MOD_NAME}_la_CPPFLAGS="${HTTPD_CFLAGS}" \
284 ${HTTPD_MOD_NAME}_la_LDFLAGS="-module -avoid-version -no-undefined -shrext .so" \
285 ${HTTPD_MOD_NAME}_la_LIBADD="${HTTPD_LIBS}"
288 #****C* httpd.cygclass/httpd_apxs_compile
290 # httpd_apxs_compile [CFLAGS] SOURCES [LIBS]
292 # Uses HTTPD_APXS to build a DSO from one or more .c source files which ship
293 # without their own build system.
295 # - CFLAGS -- Additional CFLAGS required for compiling this DSO.
296 # - SOURCES -- One or more .c sources.
297 # - LIBS -- Additional libraries required for linking this DSO. Must be last.
299 httpd_apxs_compile() {
300 if ! defined HTTPD_MOD_NAME
302 error "define HTTPD_MOD_NAME before calling httpd_apxs_compile"
305 ${HTTPD_APXS} -c -o ${HTTPD_MOD_NAME}.la -Wc,"${CFLAGS}" "${@:-*.c}" \
306 || error "httpd_apxs_compile failed"
309 #****I* httpd.cygclass/dohttpdconf
311 # dohttpdconf CONF_FILE [CONF_FILE] ...
313 # Installs additional Apache configuration files.
315 # All files passed to dohttpdconf will be concenated into one file named
316 # HTTPD_MOD_NAME.conf. Therefore, this must only be called once.
321 dodir ${HTTPD_SYSCONFDIR}
327 cat ${f} >> ${D}${HTTPD_SYSCONFDIR}/${HTTPD_MOD_NAME}.conf
332 #****I* httpd.cygclass/dohttpdmod
334 # dohttpdmod DSO [DSO] ...
336 # Installs one or more DSOs into $D/HTTPD_LIBEXECDIR. DSOs are usually
337 # a .la libtool library (whether build with httpd_mod_compile or httpd_apxs_compile),
338 # but may also be a .so DLL if built without libtool.
343 dodir ${HTTPD_LIBEXECDIR}
348 ${mod}) mod=${mod}.la ;;
354 error "dohttpdmod: ${mod}: File not found"
359 __doinstall 0755 ${mod} ${HTTPD_LIBEXECDIR} \
360 || error "install ${mod} failed"
361 [ -f ${D}${HTTPD_LIBEXECDIR}/${modf%.la}.so ] \
362 || error "install ${mod} was incorrectly linked, ${modf%.la}.so not found"
363 rm -f ${D}${HTTPD_LIBEXECDIR}/${modf%.*}.{a,dll.a,la}
366 __doinstall 0755 ${mod} ${HTTPD_LIBEXECDIR} \
367 || error "install ${mod} failed"
369 *) error "dohttpdmod: ${mod##*/}: Unknown file type"
374 #****I* httpd.cygclass/httpd_loadmodules
378 # Creates a LoadModule configuration snippet in HTTPD_SYSCONFMODULESDIR.
379 # This means that users need not do anything more than install the package in
380 # order to enable the DSO. For modules which require further configuration,
381 # create a complete file and use dohttpdconf to install it.
383 httpd_loadmodules() {
384 local dso imp mod sym
386 dodir ${HTTPD_SYSCONFMODULESDIR}
388 for mod in ${D}${HTTPD_LIBEXECDIR}/*.so
396 sym=$(nm ${imp} 2>/dev/null | sed -n -e 's|.* I __nm_${ARCH_i686+_}\(.*_module\)$|\1|p')
401 sym=$(nm -C ${mod} 2>/dev/null | sed -n -e 's|.* D \(.*_module\)$|\1|p')
407 mod_*) sym=${dso:4}_module ;;
408 cyg*|lib*) sym=${dso:3}_module ;;
412 if ! ${OBJDUMP} -p ${mod} 2> /dev/null | grep -q "\] ${sym}$"
414 error "Cannot determine module symbol name for ${mod##*/}"
417 cat >> ${D}${HTTPD_SYSCONFMODULESDIR}/${dso}.conf <<-_EOF
418 LoadModule ${sym} modules/${mod##*/}
424 readonly -f httpd_mod_compile httpd_apxs_compile dohttpdconf \
425 dohttpdmod httpd_loadmodules