6 # bsd.apache.mk - Apache related macros.
7 # Author: Clement Laforet <clement@FreeBSD.org>
8 # Author: Olli Hauer <ohauer@FreeBSD.org>
10 # Please view me with 4 column tabs!
12 # =========================================================================
13 # Parameter APACHE_PORT (user controlled):
15 # The parameter APACHE_PORT can be used in /etc/make.conf to
16 # overwrite the default apache port.
18 # This parameter should never be used in the Makefile of a port!
20 # Example entry in /etc/make.conf:
21 # APACHE_PORT= www/apache22
23 # To get a list of "possible" valid values execute the command:
24 # $> egrep 'apache[12]' ports/www/Makefile | awk '{print "www/" $3}'
26 # =========================================================================
28 # This script will be included if one of the following parameter
29 # is defined in the Makefile of the port
31 # USE_APACHE - Set apache and apxs as build and run dependency
32 # USE_APACHE_BUILD - Set apache and apxs as build dependency
33 # USE_APACHE_RUN - Set apache and apxs as run dependency
35 # The following example is representative of all three possible
39 # USE_APACHE= 22 # specify exact version
40 # USE_APACHE= 22+ # specify [min] version, no [max] version
41 # USE_APACHE= 22-24 # specify [min]-[max] range
42 # USE_APACHE= -22 # specify [max] version, no [min] version
45 # - If "+" is specified and no apache is installed, then
46 # ${DEFAULT_APACHE_VERSION} will be used.
48 # - Valid version numbers are specified in the variable
49 # APACHE_SUPPORTED_VERSION below
51 # - The following values for USE_APACHE are reserverd and only valid
52 # in apache-server ports!
53 # USE_APACHE= common22
56 # The following variables can be used (ro) in ports Makefile
57 # =========================================================================
62 # - DEFAULT_APACHE_VERSION
65 # Parameters for building third party apache modules:
66 # =========================================================================
67 # - AP_FAST_BUILD # automatic module build
69 # - AP_GENPLIST # automatic PLIST generation plus add
70 # # the module disabled into httpd.conf
71 # # (only if no pkg-plist exist)
73 # - MODULENAME # default: ${PORTNAME}
74 # - SHORTMODNAME # default: ${MODULENAME:S/mod_//}
75 # - SRC_FILE # default: ${MODULENAME}.c
79 .if !defined(Apache_Pre_Include)
81 Apache_Pre_Include= bsd.apache.mk
83 DEFAULT_APACHE_VERSION= 22
84 APACHE_SUPPORTED_VERSION= 22 24 # preferred version first
87 _ERROR_MSG= : Error from bsd.apache.mk.
90 # Keep apache version in ascending order!
91 # The "+" sign is only valid as last sign, not between
92 # two versions or in combination with range!
93 .if defined(USE_APACHE) && !empty(USE_APACHE)
94 . if ${USE_APACHE:Mcommon*} != ""
95 AP_PORT_IS_SERVER= yes
96 . elif ${USE_APACHE:C/\-//:S/^22//:S/^24//:C/\+$//} == ""
97 AP_PORT_IS_MODULE= yes
98 . if ${USE_APACHE:C/\-//:S/^22//:S/^24//} == "+"
102 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
104 # Catch unknown apache versions and silly USE_APACHE constructs
105 . if empty(AP_PORT_IS_SERVER) && empty(AP_PORT_IS_MODULE)
106 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
108 # Catch USE_APACHE [min]-[max]+
109 . if defined(AP_PLUS) && ${USE_APACHE:C/[.+0-9]//g} == "-"
110 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
112 .elif defined(USE_APACHE)
113 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( no version specified )
114 .endif # defined(USE_APACHE)
116 # ===============================================================
117 .if defined(AP_PORT_IS_SERVER)
118 # MFC TODO: remove this check
119 # used only by www/cakephp* ports
120 .if defined(SLAVE_PORT_MODULES)
121 DEFAULT_MODULES_CATEGORIES+= SLAVE_PORT
122 ALL_MODULES_CATEGORIES+= SLAVE_PORT
126 .for category in ${DEFAULT_MODULES_CATEGORIES}
127 DEFAULT_MODULES+= ${${category}_MODULES}
130 .for category in ${ALL_MODULES_CATEGORIES}
131 AVAILABLE_MODULES+= ${${category}_MODULES}
134 # detect invalid lowercase params in make.conf
135 # keep this check until end of 2012
136 .if defined(WITH_STATIC_MODULES) && ${WITH_STATIC_MODULES:M[a-z]*}
137 IGNORE= lowercase WITH_STATIC_MODULES="${WITH_STATIC_MODULES}"\
138 detected (make.conf), they shoud be UPPERCASE
141 # Setting "@comment " as default.
142 .for module in ${AVAILABLE_MODULES:O}
143 ${module}_PLIST_SUB= "@comment "
144 _DISABLE_MODULES+= --disable-${module:tl}
148 # dirty hacks to make sure all modules are disabled before we select them
149 .if ${USE_APACHE:Mcommon2*}
150 CONFIGURE_ARGS+= ${_DISABLE_MODULES:O:u}
154 .for module in ${AVAILABLE_MODULES}
155 . if ${PORT_OPTIONS:M${module}}
156 _APACHE_MODULES+= ${module}
158 WITHOUT_MODULES+= ${module}
162 .if !defined(WITH_STATIC_APACHE)
165 CONFIGURE_ARGS+= --enable-so
167 CONFIGURE_ARGS+= --disable-so
168 WITH_ALL_STATIC_MODULES= yes
171 .if ${PORT_OPTIONS:MSUEXEC}
172 _APACHE_MODULES+= ${SUEXEC_MODULES}
173 SUEXEC_CONFARGS= with-suexec
175 # SUEXEC_DOCROOT should exist
176 SUEXEC_DOCROOT?= ${PREFIX}/www/data
177 #SUEXEC_DOCROOT?= ${WWWDIR}
178 SUEXEC_USERDIR?= public_html
179 # avoid duplicate search paths
180 .if ${LOCALBASE} == ${PREFIX}
181 SUEXEC_SAFEPATH?= ${LOCALBASE}/bin:/usr/bin:/bin
183 SUEXEC_SAFEPATH?= ${PREFIX}/bin:${LOCALBASE}/bin:/usr/bin:/bin
185 SUEXEC_LOGFILE?= /var/log/httpd-suexec.log
188 SUEXEC_CALLER?= ${WWWOWN}
189 CONFIGURE_ARGS+= --${SUEXEC_CONFARGS}-caller=${SUEXEC_CALLER} \
190 --${SUEXEC_CONFARGS}-uidmin=${SUEXEC_UIDMIN} \
191 --${SUEXEC_CONFARGS}-gidmin=${SUEXEC_GIDMIN} \
192 --${SUEXEC_CONFARGS}-userdir="${SUEXEC_USERDIR}" \
193 --${SUEXEC_CONFARGS}-docroot="${SUEXEC_DOCROOT}" \
194 --${SUEXEC_CONFARGS}-safepath="${SUEXEC_SAFEPATH}" \
195 --${SUEXEC_CONFARGS}-logfile="${SUEXEC_LOGFILE}" \
196 --${SUEXEC_CONFARGS}-bin="${PREFIX}/sbin/suexec"
198 . if defined(WITH_SUEXEC_UMASK)
199 CONFIGURE_ARGS+= --${SUEXEC_CONFARGS}-umask=${SUEXEC_UMASK}
203 .if !defined(WITHOUT_MODULES)
204 APACHE_MODULES= ${_APACHE_MODULES}
206 .for module in ${_APACHE_MODULES:O:u}
207 . if !${WITHOUT_MODULES:M${module}}
208 APACHE_MODULES+= ${module}
213 .if defined(WITH_STATIC_MODULES)
214 . for module in ${APACHE_MODULES}
215 . if ${WITH_STATIC_MODULES:M${module}}
216 _CONFIGURE_ARGS+= --enable-${module:tl}
218 _CONFIGURE_ARGS+= --enable-${module:tl}=shared
221 CONFIGURE_ARGS+= ${_CONFIGURE_ARGS:O}
222 .elif defined(WITH_STATIC_APACHE) || defined(WITH_ALL_STATIC_MODULES)
223 WITH_STATIC_MODULES= ${APACHE_MODULES}
224 CONFIGURE_ARGS+= --enable-modules="${APACHE_MODULES:O:tl}"
226 CONFIGURE_ARGS+= --enable-mods-shared="${APACHE_MODULES:O:tl}"
229 # ====================================
230 # start pkg-plist adjustments
231 .if defined(WITH_STATIC_MODULES)
232 .for module in ${APACHE_MODULES}
233 . if !${WITH_STATIC_MODULES:M${module}}
234 _SHARED_MODULES+= ${module}
238 SHARED_MODULES= ${_SHARED_MODULES}
239 .elif !defined(WITH_ALL_STATIC_MODULES)
240 SHARED_MODULES= ${APACHE_MODULES}
243 .for module in ${SHARED_MODULES}
244 ${module}_PLIST_SUB= ""
247 .for module in ${AVAILABLE_MODULES:O:u}
248 PLIST_SUB+= MOD_${module}=${${module}_PLIST_SUB}
251 # pkg-plist workaround STATIC support
252 .if ${PORT_OPTIONS:MSUEXEC}
253 PLIST_SUB+= SUEXEC=""
255 PLIST_SUB+= SUEXEC="@comment "
258 .if ${PORT_OPTIONS:MLOG_FORENSIC}
259 PLIST_SUB+= FORENSIC=""
261 PLIST_SUB+= FORENSIC="@comment "
264 # end pkg-plist adjustments
266 #### End of AP_PORT_IS_SERVER ####
268 # ===============================================================
269 .elif defined(AP_PORT_IS_MODULE) || defined(USE_APACHE_RUN) || defined(USE_APACHE_BUILD)
270 APXS?= ${LOCALBASE}/sbin/apxs
271 HTTPD?= ${LOCALBASE}/sbin/httpd
273 MODULENAME?= ${PORTNAME}
274 SHORTMODNAME?= ${MODULENAME:S/mod_//}
275 SRC_FILE?= ${MODULENAME}.c
278 _APACHE_VERSION!= ${HTTPD} -V | ${SED} -ne 's/^Server version: Apache\/\([0-9]\)\.\([0-9]*\).*/\1\2/p'
279 # XXX see mod_perl-2.0.6/Changes
280 # Apache 2.4 and onwards doesn't require linking the MPM module
281 # directly in the httpd binary anymore. APXS lost the MPM_NAME query,
282 # so we can't assume a given MPM anymore.
283 . if ${_APACHE_VERSION} <= 22
284 APACHE_MPM!= ${APXS} -q MPM_NAME
286 .elif defined(APACHE_PORT)
287 _APACHE_VERSION!= ${ECHO_CMD} ${APACHE_PORT} | ${SED} -ne 's,.*/apache\([0-9]*\).*,\1,p'
290 .if defined(USE_APACHE)
291 _USE_APACHE:= ${USE_APACHE}
292 .elif defined(USE_APACHE_BUILD)
293 _USE_APACHE:= ${USE_APACHE_BUILD}
294 .elif defined(USE_APACHE_RUN)
295 _USE_APACHE:= ${USE_APACHE_RUN}
298 _APACHE_VERSION_CHECK:= ${_USE_APACHE:C/^([1-9][0-9])$/\1-\1/}
299 _APACHE_VERSION_MINIMUM_TMP:= ${_APACHE_VERSION_CHECK:C/([1-9][0-9])[-+].*/\1/}
300 _APACHE_VERSION_MINIMUM:= ${_APACHE_VERSION_MINIMUM_TMP:M[1-9][0-9]}
301 _APACHE_VERSION_MAXIMUM_TMP:= ${_APACHE_VERSION_CHECK:C/.*-([1-9][0-9])/\1/}
302 _APACHE_VERSION_MAXIMUM:= ${_APACHE_VERSION_MAXIMUM_TMP:M[1-9][0-9]}
304 .if defined(_APACHE_VERSION)
305 # Validate Apache version whether it meets USE_APACHE version restriction.
306 . if !empty(_APACHE_VERSION_MINIMUM) && (${_APACHE_VERSION} < ${_APACHE_VERSION_MINIMUM})
307 _APACHE_VERSION_NONSUPPORTED= ${_APACHE_VERSION_MINIMUM} at least
308 . elif !empty(_APACHE_VERSION_MAXIMUM) && (${_APACHE_VERSION} > ${_APACHE_VERSION_MAXIMUM})
309 _APACHE_VERSION_NONSUPPORTED= ${_APACHE_VERSION_MAXIMUM} at most
312 . if defined(_APACHE_VERSION_NONSUPPORTED) && !defined(AP_IGNORE_VERSION_CHECK)
313 BROKEN= ${_ERROR_MSG} apache${_APACHE_VERSION} is installed (or APACHE_PORT is defined) and port requires apache${_APACHE_VERSION_NONSUPPORTED}
315 .else # defined(_APACHE_VERSION)
316 . for ver in ${APACHE_SUPPORTED_VERSION}
318 . if !defined(_APACHE_VERSION) && \
319 !(!empty(_APACHE_VERSION_MINIMUM) && ( ${__VER} < ${_APACHE_VERSION_MINIMUM} )) && \
320 !(!empty(_APACHE_VERSION_MAXIMUM) && ( ${__VER} > ${_APACHE_VERSION_MAXIMUM} ))
321 _APACHE_VERSION= ${ver}
324 .endif # defined(_APACHE_VERSION)
326 APACHE_VERSION:= ${_APACHE_VERSION}
329 APXS_PREFIX!= ${APXS} -q prefix 2> /dev/null || echo NULL
330 . if ${APXS_PREFIX} == NULL
331 IGNORE= : Your apache does not support DSO modules
333 . if defined(AP_GENPLIST) && ${APXS_PREFIX} != ${PREFIX}
334 IGNORE?= PREFIX must be equal to APXS_PREFIX.
338 .if ${APACHE_VERSION} >= 22
340 APACHEMODDIR= libexec/apache${APACHE_VERSION}
341 APACHEINCLUDEDIR=include/apache${APACHE_VERSION}
342 APACHEETCDIR= etc/apache${APACHE_VERSION}
343 APACHE_PORT?= www/apache${APACHE_VERSION}
346 PLIST_SUB+= APACHEMODDIR="${APACHEMODDIR}" \
347 APACHEINCLUDEDIR="${APACHEINCLUDEDIR}" \
348 APACHEETCDIR="${APACHEETCDIR}"
350 APACHE_PKGNAMEPREFIX= ap${APACHE_VERSION}-
351 .if defined(AP_FAST_BUILD)
352 PKGNAMEPREFIX?= ${APACHE_PKGNAMEPREFIX}
355 .if defined(USE_APACHE) || defined(USE_APACHE_BUILD)
356 BUILD_DEPENDS+= ${APXS}:${PORTSDIR}/${APACHE_PORT}
359 .if defined(USE_APACHE) || defined(USE_APACHE_RUN)
360 RUN_DEPENDS+= ${APXS}:${PORTSDIR}/${APACHE_PORT}
363 PLIST_SUB+= AP_NAME="${SHORTMODNAME}"
364 PLIST_SUB+= AP_MODULE="${MODULENAME}.so"
366 .if defined(AP_GENPLIST)
367 PLIST?= ${WRKDIR}/ap-plist
371 AP_EXTRAS+= -I ${AP_INC}
374 AP_EXTRAS+= -L ${AP_LIB}
377 .endif # End of AP_PORT_IS_SERVER / AP_PORT_IS_MOULE
378 .endif # End of !Apache_Pre_Include
380 # ===============================================================
381 .if defined(_POSTMKINCLUDED) && !defined(Apache_Post_Include)
382 Apache_Post_Include= bsd.apache.mk
384 .if defined(USE_APACHE_RUN) && !empty(USE_APACHE_RUN)
385 . if ${USE_APACHE_RUN:C/\-//:S/^22//:S/^24//:C/\+$//} != ""
386 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_RUN ( ${USE_APACHE_RUN} )
388 .elif defined(USE_APACHE_RUN)
389 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_RUN ( no valid version specified )
392 .if defined(USE_APACHE_BUILD) && !empty(USE_APACHE_BUILD)
393 . if ${USE_APACHE_BUILD:C/\-//:S/^22//:S/^24//:C/\+$//} != ""
394 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_BUILD ( ${USE_APACHE_BUILD} )
396 .elif defined(USE_APACHE_BUILD)
397 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_BUILD ( no valid version specified )
400 # Check if USE_APACHE(_BUILD|_RUN) are mixed together
401 .if defined(USE_APACHE) && ( defined(USE_APACHE_BUILD) || defined(USE_APACHE_RUN) )
402 IGNORE= ${_ERROR_MSG} specify only one of: USE_APACHE USE_APACHE_BUILD USE_APACHE_RUN
403 .elif defined(USE_APACHE_BUILD) && defined(USE_APACHE_RUN)
404 IGNORE= ${_ERROR_MSG} use USE_APACHE instead of USE_APACHE_BUILD and USE_APACHE_RUN together
407 .if defined(NO_BUILD) && defined(USE_APACHE)
408 BROKEN= If NO_BUILD is used, then USE_APACHE_RUN is sufficient. Please fix your Makefile
411 .if defined(AP_PORT_IS_SERVER)
412 .if !target(print-closest-mirrors)
413 print-closest-mirrors:
414 @${ECHO_MSG} -n "Fetching list of nearest mirror: " >&2
415 @MIRRORS=`${FETCH_CMD} -T 30 -qo - http://www.apache.org/dyn/closer.cgi/httpd/ 2> /dev/null\
416 | ${GREP} /httpd/ | ${SED} 's/.*href="\(.*\)"><str.*/\1/g' | \
417 ${HEAD} -7 | ${TAIL} -6` ; \
418 ${ECHO_MSG} done >&2; if [ "x$$MIRRORS" != "x" ]; then \
419 ${ECHO_MSG} -n "MASTER_SITE_APACHE_HTTPD?= ";\
420 ${ECHO_MSG} $$MIRRORS; else \
421 ${ECHO_MSG} "No mirrors found!">&2 ; fi
424 .if !target(show-modules)
426 .if !empty(APACHE_MODULES)
427 .for module in ${AVAILABLE_MODULES}
428 @${PRINTF} "%-20s : " ${module}
429 . if ${APACHE_MODULES:M${module}}
430 @${ECHO} -n "enabled "
431 . if !empty(WITH_STATIC_MODULES) && ${WITH_STATIC_MODULES:M${module}}
432 @${ECHO_CMD} " (static)"
434 @${ECHO_CMD} "(shared)"
437 @${ECHO_CMD} disabled
441 .for module in ${AVAILABLE_MODULES}
442 @${PRINTF} "%-20s : disabled\n" ${module}
447 .elif defined(AP_PORT_IS_MODULE)
449 .if defined(AP_MODENABLE)
454 PLIST_SUB+= AP_MOD_EN="${AP_MOD_EN}"
456 .if defined(AP_FAST_BUILD)
457 .if !target(ap-gen-plist)
459 .if defined(AP_GENPLIST)
460 . if !exists(${PLIST})
461 @${ECHO} "===> Generating apache plist"
463 @${ECHO} "@unexec ${SED} -i '' -E '/LoadModule[[:blank:]]+%%AP_NAME%%_module/d' %D/%%APACHEETCDIR%%/httpd.conf" >> ${PLIST}
464 @${ECHO} "%%APACHEMODDIR%%/%%AP_MODULE%%" >> ${PLIST}
465 @${ECHO} "@exec %D/sbin/apxs -e ${AP_MOD_EN} -n %%AP_NAME%% %D/%F" >> ${PLIST}
466 @${ECHO} "@unexec echo \"Don't forget to remove all ${MODULENAME}-related directives in your httpd.conf\"">> ${PLIST}
473 .if !target(do-build)
474 do-build: ap-gen-plist
475 @cd ${WRKSRC} && ${APXS} -c ${AP_EXTRAS} -o ${MODULENAME}.${AP_BUILDEXT} ${SRC_FILE}
478 .if !target(do-install)
480 . if defined(NO_STAGE)
481 @${APXS} -i ${AP_MOD_EN} -n ${SHORTMODNAME} ${WRKSRC}/${MODULENAME}.${AP_BUILDEXT}
483 @${MKDIR} ${STAGEDIR}${PREFIX}/${APACHEMODDIR}
484 @${APXS} -S LIBEXECDIR=${STAGEDIR}${PREFIX}/${APACHEMODDIR} -i -n ${SHORTMODNAME} ${WRKSRC}/${MODULENAME}.${AP_BUILDEXT}
487 .endif # defined(AP_FAST_BUILD)
488 .endif # defined(AP_PORT_IS_MODULE)
489 .endif # defined(_POSTMKINCLUDED) && !defined(Apache_Post_Include)