3 # bsd.apache.mk - Apache related macros.
4 # Author: Clement Laforet <clement@FreeBSD.org>
5 # Author: Olli Hauer <ohauer@FreeBSD.org>
7 # Please view me with 4 column tabs!
9 # =========================================================================
10 # Parameter APACHE_PORT (user controlled):
12 # The parameter APACHE_PORT can be used in /etc/make.conf to
13 # overwrite the default apache port.
15 # This parameter should never be used in the Makefile of a port!
17 # Example entry in /etc/make.conf:
18 # APACHE_PORT= www/apache22
20 # To get a list of "possible" valid values execute the command:
21 # $> egrep 'apache[12]' ports/www/Makefile | awk '{print "www/" $3}'
23 # =========================================================================
25 # This script will be included if one of the following parameter
26 # is defined in the Makefile of the port
28 # USE_APACHE - Set apache and apxs as build and run dependency
29 # USE_APACHE_BUILD - Set apache and apxs as build dependency
30 # USE_APACHE_RUN - Set apache and apxs as run dependency
32 # The following example is representative of all three possible
36 # USE_APACHE= 22 # specify exact version
37 # USE_APACHE= 22+ # specify [min] version, no [max] version
38 # USE_APACHE= 22-24 # specify [min]-[max] range
39 # USE_APACHE= -22 # specify [max] version, no [min] version
42 # - If "+" is specified and no apache is installed, then
43 # ${DEFAULT_APACHE_VERSION} will be used.
45 # - Valid version numbers are specified in the variable
46 # APACHE_SUPPORTED_VERSION below
48 # - The following values for USE_APACHE are reserverd and only valid
49 # in apache-server ports!
50 # USE_APACHE= common22
53 # The following variables can be used (ro) in ports Makefile
54 # =========================================================================
59 # - DEFAULT_APACHE_VERSION
62 # Parameters for building third party apache modules:
63 # =========================================================================
64 # - AP_FAST_BUILD # automatic module build
66 # - AP_GENPLIST # automatic PLIST generation plus add
67 # # the module disabled into httpd.conf
68 # # (only if no pkg-plist exist)
70 # - MODULENAME # default: ${PORTNAME}
71 # - SHORTMODNAME # default: ${MODULENAME:S/mod_//}
72 # - SRC_FILE # default: ${MODULENAME}.c
76 .if !defined(Apache_Pre_Include)
78 Apache_Pre_Include= bsd.apache.mk
80 .include "${PORTSDIR}/Mk/bsd.default-versions.mk"
82 .if defined(DEFAULT_APACHE_VER)
83 WARNING+= "DEFAULT_APACHE_VER is defined, consider using DEFAULT_VERSIONS=apache=${DEFAULT_APACHE_VER} instead"
86 DEFAULT_APACHE_VERSION?= ${APACHE_DEFAULT:S/.//}
87 APACHE_SUPPORTED_VERSION= 24 22 # preferred version first
90 _ERROR_MSG= : Error from bsd.apache.mk.
93 # Keep apache version in ascending order!
94 # The "+" sign is only valid as last sign, not between
95 # two versions or in combination with range!
96 .if defined(USE_APACHE) && !empty(USE_APACHE)
97 . if ${USE_APACHE:Mcommon*} != ""
98 AP_PORT_IS_SERVER= yes
99 . elif ${USE_APACHE:C/\-//:S/^22//:S/^24//:C/\+$//} == ""
100 AP_PORT_IS_MODULE= yes
101 . if ${USE_APACHE:C/\-//:S/^22//:S/^24//} == "+"
105 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
107 # Catch unknown apache versions and silly USE_APACHE constructs
108 . if empty(AP_PORT_IS_SERVER) && empty(AP_PORT_IS_MODULE)
109 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
111 # Catch USE_APACHE [min]-[max]+
112 . if defined(AP_PLUS) && ${USE_APACHE:C/[.+0-9]//g} == "-"
113 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
115 .elif defined(USE_APACHE)
116 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( no version specified )
117 .endif # defined(USE_APACHE)
119 # ===============================================================
120 .if defined(AP_PORT_IS_SERVER)
121 # MFC TODO: remove this check
122 # used only by www/cakephp* ports
123 .if defined(SLAVE_PORT_MODULES)
124 DEFAULT_MODULES_CATEGORIES+= SLAVE_PORT
125 ALL_MODULES_CATEGORIES+= SLAVE_PORT
129 .for category in ${DEFAULT_MODULES_CATEGORIES}
130 DEFAULT_MODULES+= ${${category}_MODULES}
133 .for category in ${ALL_MODULES_CATEGORIES}
134 AVAILABLE_MODULES+= ${${category}_MODULES}
137 # detect invalid lowercase params in make.conf
138 # keep this check until end of 2012
139 .if defined(WITH_STATIC_MODULES) && ${WITH_STATIC_MODULES:M[a-z]*}
140 IGNORE= lowercase WITH_STATIC_MODULES="${WITH_STATIC_MODULES}"\
141 detected (make.conf), they shoud be UPPERCASE
144 # Setting "@comment " as default.
145 .for module in ${AVAILABLE_MODULES:O}
146 ${module}_PLIST_SUB= "@comment "
147 _DISABLE_MODULES+= --disable-${module:tl}
151 # dirty hacks to make sure all modules are disabled before we select them
152 .if ${USE_APACHE:Mcommon2*}
153 CONFIGURE_ARGS+= ${_DISABLE_MODULES:O:u}
157 .for module in ${AVAILABLE_MODULES}
158 . if ${PORT_OPTIONS:M${module}}
159 _APACHE_MODULES+= ${module}
161 WITHOUT_MODULES+= ${module}
165 .if !defined(WITH_STATIC_APACHE)
168 CONFIGURE_ARGS+= --enable-so
170 CONFIGURE_ARGS+= --disable-so
171 WITH_ALL_STATIC_MODULES= yes
174 .if ${PORT_OPTIONS:MSUEXEC}
175 _APACHE_MODULES+= ${SUEXEC_MODULES}
176 SUEXEC_CONFARGS= with-suexec
178 # SUEXEC_DOCROOT should exist
179 SUEXEC_DOCROOT?= ${PREFIX}/www/data
180 #SUEXEC_DOCROOT?= ${WWWDIR}
181 SUEXEC_USERDIR?= public_html
182 # avoid duplicate search paths
183 .if ${LOCALBASE} == ${PREFIX}
184 SUEXEC_SAFEPATH?= ${LOCALBASE}/bin:/usr/bin:/bin
186 SUEXEC_SAFEPATH?= ${PREFIX}/bin:${LOCALBASE}/bin:/usr/bin:/bin
188 SUEXEC_LOGFILE?= /var/log/httpd-suexec.log
191 SUEXEC_CALLER?= ${WWWOWN}
192 CONFIGURE_ARGS+= --${SUEXEC_CONFARGS}-caller=${SUEXEC_CALLER} \
193 --${SUEXEC_CONFARGS}-uidmin=${SUEXEC_UIDMIN} \
194 --${SUEXEC_CONFARGS}-gidmin=${SUEXEC_GIDMIN} \
195 --${SUEXEC_CONFARGS}-userdir="${SUEXEC_USERDIR}" \
196 --${SUEXEC_CONFARGS}-docroot="${SUEXEC_DOCROOT}" \
197 --${SUEXEC_CONFARGS}-safepath="${SUEXEC_SAFEPATH}" \
198 --${SUEXEC_CONFARGS}-logfile="${SUEXEC_LOGFILE}" \
199 --${SUEXEC_CONFARGS}-bin="${PREFIX}/sbin/suexec"
201 . if defined(WITH_SUEXEC_UMASK)
202 CONFIGURE_ARGS+= --${SUEXEC_CONFARGS}-umask=${SUEXEC_UMASK}
206 .if !defined(WITHOUT_MODULES)
207 APACHE_MODULES= ${_APACHE_MODULES}
209 .for module in ${_APACHE_MODULES:O:u}
210 . if !${WITHOUT_MODULES:M${module}}
211 APACHE_MODULES+= ${module}
216 .if defined(WITH_STATIC_MODULES)
217 . for module in ${APACHE_MODULES}
218 . if ${WITH_STATIC_MODULES:M${module}}
219 _CONFIGURE_ARGS+= --enable-${module:tl}
221 _CONFIGURE_ARGS+= --enable-${module:tl}=shared
224 CONFIGURE_ARGS+= ${_CONFIGURE_ARGS:O}
225 .elif defined(WITH_STATIC_APACHE) || defined(WITH_ALL_STATIC_MODULES)
226 WITH_STATIC_MODULES= ${APACHE_MODULES}
227 CONFIGURE_ARGS+= --enable-modules="${APACHE_MODULES:O:tl}"
229 CONFIGURE_ARGS+= --enable-mods-shared="${APACHE_MODULES:O:tl}"
232 # ====================================
233 # start pkg-plist adjustments
234 .if defined(WITH_STATIC_MODULES)
235 .for module in ${APACHE_MODULES}
236 . if !${WITH_STATIC_MODULES:M${module}}
237 _SHARED_MODULES+= ${module}
241 SHARED_MODULES= ${_SHARED_MODULES}
242 .elif !defined(WITH_ALL_STATIC_MODULES)
243 SHARED_MODULES= ${APACHE_MODULES}
246 .for module in ${SHARED_MODULES}
247 ${module}_PLIST_SUB= ""
250 .for module in ${AVAILABLE_MODULES:O:u}
251 PLIST_SUB+= MOD_${module}=${${module}_PLIST_SUB}
254 # pkg-plist workaround STATIC support
255 .if ${PORT_OPTIONS:MSUEXEC}
256 PLIST_SUB+= SUEXEC=""
258 PLIST_SUB+= SUEXEC="@comment "
261 .if ${PORT_OPTIONS:MLOG_FORENSIC}
262 PLIST_SUB+= FORENSIC=""
264 PLIST_SUB+= FORENSIC="@comment "
267 # end pkg-plist adjustments
269 #### End of AP_PORT_IS_SERVER ####
271 # ===============================================================
272 .elif defined(AP_PORT_IS_MODULE) || defined(USE_APACHE_RUN) || defined(USE_APACHE_BUILD)
273 APXS?= ${LOCALBASE}/sbin/apxs
274 HTTPD?= ${LOCALBASE}/sbin/httpd
276 MODULENAME?= ${PORTNAME}
277 SHORTMODNAME?= ${MODULENAME:S/mod_//}
278 SRC_FILE?= ${MODULENAME}.c
281 _APACHE_VERSION!= ${HTTPD} -V | ${SED} -ne 's/^Server version: Apache\/\([0-9]\)\.\([0-9]*\).*/\1\2/p'
282 # XXX see mod_perl-2.0.6/Changes
283 # Apache 2.4 and onwards doesn't require linking the MPM module
284 # directly in the httpd binary anymore. APXS lost the MPM_NAME query,
285 # so we can't assume a given MPM anymore.
286 . if ${_APACHE_VERSION} <= 22
287 APACHE_MPM!= ${APXS} -q MPM_NAME
289 .elif defined(APACHE_PORT)
290 _APACHE_VERSION!= ${ECHO_CMD} ${APACHE_PORT} | ${SED} -ne 's,.*/apache\([0-9]*\).*,\1,p'
292 _APACHE_VERSION:= ${DEFAULT_APACHE_VERSION}
295 .if defined(USE_APACHE)
296 _USE_APACHE:= ${USE_APACHE}
297 .elif defined(USE_APACHE_BUILD)
298 _USE_APACHE:= ${USE_APACHE_BUILD}
299 .elif defined(USE_APACHE_RUN)
300 _USE_APACHE:= ${USE_APACHE_RUN}
303 _APACHE_VERSION_CHECK:= ${_USE_APACHE:C/^([1-9][0-9])$/\1-\1/}
304 _APACHE_VERSION_MINIMUM_TMP:= ${_APACHE_VERSION_CHECK:C/([1-9][0-9])[-+].*/\1/}
305 _APACHE_VERSION_MINIMUM:= ${_APACHE_VERSION_MINIMUM_TMP:M[1-9][0-9]}
306 _APACHE_VERSION_MAXIMUM_TMP:= ${_APACHE_VERSION_CHECK:C/.*-([1-9][0-9])/\1/}
307 _APACHE_VERSION_MAXIMUM:= ${_APACHE_VERSION_MAXIMUM_TMP:M[1-9][0-9]}
309 .if defined(_APACHE_VERSION)
310 # Validate Apache version whether it meets USE_APACHE version restriction.
311 . if !empty(_APACHE_VERSION_MINIMUM) && (${_APACHE_VERSION} < ${_APACHE_VERSION_MINIMUM})
312 _APACHE_VERSION_NONSUPPORTED= ${_APACHE_VERSION_MINIMUM} at least
313 . elif !empty(_APACHE_VERSION_MAXIMUM) && (${_APACHE_VERSION} > ${_APACHE_VERSION_MAXIMUM})
314 _APACHE_VERSION_NONSUPPORTED= ${_APACHE_VERSION_MAXIMUM} at most
317 . if defined(_APACHE_VERSION_NONSUPPORTED) && !defined(AP_IGNORE_VERSION_CHECK)
318 BROKEN= ${_ERROR_MSG} apache${_APACHE_VERSION} is installed (or APACHE_PORT is defined) and port requires apache${_APACHE_VERSION_NONSUPPORTED}
320 .else # defined(_APACHE_VERSION)
321 . for ver in ${APACHE_SUPPORTED_VERSION}
323 . if !defined(_APACHE_VERSION) && \
324 !(!empty(_APACHE_VERSION_MINIMUM) && ( ${__VER} < ${_APACHE_VERSION_MINIMUM} )) && \
325 !(!empty(_APACHE_VERSION_MAXIMUM) && ( ${__VER} > ${_APACHE_VERSION_MAXIMUM} ))
326 _APACHE_VERSION= ${ver}
329 .endif # defined(_APACHE_VERSION)
331 APACHE_VERSION:= ${_APACHE_VERSION}
334 APXS_PREFIX!= ${APXS} -q prefix 2> /dev/null || echo NULL
335 . if ${APXS_PREFIX} == NULL
336 IGNORE= : Your apache does not support DSO modules
338 . if defined(AP_GENPLIST) && ${APXS_PREFIX} != ${PREFIX}
339 IGNORE?= PREFIX must be equal to APXS_PREFIX.
344 APACHEMODDIR= libexec/apache${APACHE_VERSION}
345 APACHEINCLUDEDIR=include/apache${APACHE_VERSION}
346 APACHEETCDIR= etc/apache${APACHE_VERSION}
347 APACHE_PORT?= www/apache${APACHE_VERSION}
349 PLIST_SUB+= APACHEMODDIR="${APACHEMODDIR}" \
350 APACHEINCLUDEDIR="${APACHEINCLUDEDIR}" \
351 APACHEETCDIR="${APACHEETCDIR}" \
352 APACHE_VERSION="${APACHE_VERSION}"
354 SUB_LIST+= APACHEMODDIR="${APACHEMODDIR}" \
355 APACHEETCDIR="${APACHEETCDIR}" \
356 APACHE_VERSION="${APACHE_VERSION}"
358 APACHE_PKGNAMEPREFIX= ap${APACHE_VERSION}-
360 .if defined(AP_FAST_BUILD)
361 PKGNAMEPREFIX?= ${APACHE_PKGNAMEPREFIX}
364 .if defined(USE_APACHE) || defined(USE_APACHE_BUILD)
365 BUILD_DEPENDS+= ${APXS}:${PORTSDIR}/${APACHE_PORT}
368 .if defined(USE_APACHE) || defined(USE_APACHE_RUN)
369 RUN_DEPENDS+= ${APXS}:${PORTSDIR}/${APACHE_PORT}
372 PLIST_SUB+= AP_NAME="${SHORTMODNAME}"
373 PLIST_SUB+= AP_MODULE="${MODULENAME}.so"
375 .if defined(AP_GENPLIST)
376 PLIST?= ${WRKDIR}/ap-plist
380 AP_EXTRAS+= -I ${AP_INC}
383 AP_EXTRAS+= -L ${AP_LIB}
386 .endif # End of AP_PORT_IS_SERVER / AP_PORT_IS_MOULE
387 .endif # End of !Apache_Pre_Include
389 # ===============================================================
390 .if defined(_POSTMKINCLUDED) && !defined(Apache_Post_Include)
391 Apache_Post_Include= bsd.apache.mk
393 .if defined(USE_APACHE_RUN) && !empty(USE_APACHE_RUN)
394 . if ${USE_APACHE_RUN:C/\-//:S/^22//:S/^24//:C/\+$//} != ""
395 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_RUN ( ${USE_APACHE_RUN} )
397 .elif defined(USE_APACHE_RUN)
398 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_RUN ( no valid version specified )
401 .if defined(USE_APACHE_BUILD) && !empty(USE_APACHE_BUILD)
402 . if ${USE_APACHE_BUILD:C/\-//:S/^22//:S/^24//:C/\+$//} != ""
403 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_BUILD ( ${USE_APACHE_BUILD} )
405 .elif defined(USE_APACHE_BUILD)
406 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_BUILD ( no valid version specified )
409 # Check if USE_APACHE(_BUILD|_RUN) are mixed together
410 .if defined(USE_APACHE) && ( defined(USE_APACHE_BUILD) || defined(USE_APACHE_RUN) )
411 IGNORE= ${_ERROR_MSG} specify only one of: USE_APACHE USE_APACHE_BUILD USE_APACHE_RUN
412 .elif defined(USE_APACHE_BUILD) && defined(USE_APACHE_RUN)
413 IGNORE= ${_ERROR_MSG} use USE_APACHE instead of USE_APACHE_BUILD and USE_APACHE_RUN together
416 .if defined(NO_BUILD) && defined(USE_APACHE)
417 BROKEN= If NO_BUILD is used, then USE_APACHE_RUN is sufficient. Please fix your Makefile
420 .if defined(AP_PORT_IS_SERVER)
421 .if !target(print-closest-mirrors)
422 print-closest-mirrors:
423 @${ECHO_MSG} -n "Fetching list of nearest mirror: " >&2
424 @MIRRORS=`${FETCH_CMD} -T 30 -qo - http://www.apache.org/dyn/closer.cgi/httpd/ 2> /dev/null\
425 | ${GREP} /httpd/ | ${SED} 's/.*href="\(.*\)"><str.*/\1/g' | \
426 ${HEAD} -7 | ${TAIL} -6` ; \
427 ${ECHO_MSG} done >&2; if [ "x$$MIRRORS" != "x" ]; then \
428 ${ECHO_MSG} -n "MASTER_SITE_APACHE_HTTPD?= ";\
429 ${ECHO_MSG} $$MIRRORS; else \
430 ${ECHO_MSG} "No mirrors found!">&2 ; fi
433 .if !target(show-modules)
435 .if !empty(APACHE_MODULES)
436 .for module in ${AVAILABLE_MODULES}
437 @${PRINTF} "%-20s : " ${module}
438 . if ${APACHE_MODULES:M${module}}
439 @${ECHO} -n "enabled "
440 . if !empty(WITH_STATIC_MODULES) && ${WITH_STATIC_MODULES:M${module}}
441 @${ECHO_CMD} " (static)"
443 @${ECHO_CMD} "(shared)"
446 @${ECHO_CMD} disabled
450 .for module in ${AVAILABLE_MODULES}
451 @${PRINTF} "%-20s : disabled\n" ${module}
456 .elif defined(AP_PORT_IS_MODULE)
458 .if defined(AP_MODENABLE)
463 PLIST_SUB+= AP_MOD_EN="${AP_MOD_EN}"
465 .if defined(AP_FAST_BUILD)
466 .if !target(ap-gen-plist)
468 .if defined(AP_GENPLIST)
469 . if !exists(${PLIST})
470 @${ECHO} "===> Generating apache plist"
471 @${ECHO} "@unexec ${SED} -i '' -E '/LoadModule[[:blank:]]+%%AP_NAME%%_module/d' %D/%%APACHEETCDIR%%/httpd.conf" >> ${PLIST}
472 @${ECHO} "%%APACHEMODDIR%%/%%AP_MODULE%%" >> ${PLIST}
473 @${ECHO} "@exec %D/sbin/apxs -e ${AP_MOD_EN} -n %%AP_NAME%% %D/%F" >> ${PLIST}
474 @${ECHO} "@unexec echo \"Don't forget to remove all ${MODULENAME}-related directives in your httpd.conf\"">> ${PLIST}
481 .if !target(do-build)
482 do-build: ap-gen-plist
483 @cd ${WRKSRC} && ${APXS} -c ${AP_EXTRAS} -o ${MODULENAME}.${AP_BUILDEXT} ${SRC_FILE}
486 .if !target(do-install)
488 . if defined(NO_STAGE)
489 @${APXS} -i ${AP_MOD_EN} -n ${SHORTMODNAME} ${WRKSRC}/${MODULENAME}.${AP_BUILDEXT}
491 @${MKDIR} ${STAGEDIR}${PREFIX}/${APACHEMODDIR}
492 @${APXS} -S LIBEXECDIR=${STAGEDIR}${PREFIX}/${APACHEMODDIR} -i -n ${SHORTMODNAME} ${WRKSRC}/${MODULENAME}.${AP_BUILDEXT}
494 @${ECHO_MSG} "===> strip ${APACHEMODDIR}/${MODULENAME}.so"
495 @[ -e ${STAGEDIR}${PREFIX}/${APACHEMODDIR}/${MODULENAME}.so ] && ${STRIP_CMD} ${STAGEDIR}${PREFIX}/${APACHEMODDIR}/${MODULENAME}.so
497 @${ECHO_MSG} "===> DEBUG is set, will not strip ${APACHEMODDIR}/${MODULENAME}.so"
502 .endif # defined(AP_FAST_BUILD)
503 .endif # defined(AP_PORT_IS_SERVER / AP_PORT_IS_MODULE)
504 .endif # defined(_POSTMKINCLUDED) && !defined(Apache_Post_Include)