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 .include "${PORTSDIR}/Mk/bsd.default-versions.mk"
85 .if defined(DEFAULT_APACHE_VER)
86 WARNING+= "DEFAULT_APACHE_VER is defined, consider using DEFAULT_VERSIONS=apache=${DEFAULT_APACHE_VER} instead"
89 DEFAULT_APACHE_VERSION?= ${APACHE_DEFAULT:S/.//}
90 APACHE_SUPPORTED_VERSION= 22 24 # preferred version first
93 _ERROR_MSG= : Error from bsd.apache.mk.
96 # Keep apache version in ascending order!
97 # The "+" sign is only valid as last sign, not between
98 # two versions or in combination with range!
99 .if defined(USE_APACHE) && !empty(USE_APACHE)
100 . if ${USE_APACHE:Mcommon*} != ""
101 AP_PORT_IS_SERVER= yes
102 . elif ${USE_APACHE:C/\-//:S/^22//:S/^24//:C/\+$//} == ""
103 AP_PORT_IS_MODULE= yes
104 . if ${USE_APACHE:C/\-//:S/^22//:S/^24//} == "+"
108 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
110 # Catch unknown apache versions and silly USE_APACHE constructs
111 . if empty(AP_PORT_IS_SERVER) && empty(AP_PORT_IS_MODULE)
112 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
114 # Catch USE_APACHE [min]-[max]+
115 . if defined(AP_PLUS) && ${USE_APACHE:C/[.+0-9]//g} == "-"
116 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( ${USE_APACHE} )
118 .elif defined(USE_APACHE)
119 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE ( no version specified )
120 .endif # defined(USE_APACHE)
122 # ===============================================================
123 .if defined(AP_PORT_IS_SERVER)
124 # MFC TODO: remove this check
125 # used only by www/cakephp* ports
126 .if defined(SLAVE_PORT_MODULES)
127 DEFAULT_MODULES_CATEGORIES+= SLAVE_PORT
128 ALL_MODULES_CATEGORIES+= SLAVE_PORT
132 .for category in ${DEFAULT_MODULES_CATEGORIES}
133 DEFAULT_MODULES+= ${${category}_MODULES}
136 .for category in ${ALL_MODULES_CATEGORIES}
137 AVAILABLE_MODULES+= ${${category}_MODULES}
140 # detect invalid lowercase params in make.conf
141 # keep this check until end of 2012
142 .if defined(WITH_STATIC_MODULES) && ${WITH_STATIC_MODULES:M[a-z]*}
143 IGNORE= lowercase WITH_STATIC_MODULES="${WITH_STATIC_MODULES}"\
144 detected (make.conf), they shoud be UPPERCASE
147 # Setting "@comment " as default.
148 .for module in ${AVAILABLE_MODULES:O}
149 ${module}_PLIST_SUB= "@comment "
150 _DISABLE_MODULES+= --disable-${module:tl}
154 # dirty hacks to make sure all modules are disabled before we select them
155 .if ${USE_APACHE:Mcommon2*}
156 CONFIGURE_ARGS+= ${_DISABLE_MODULES:O:u}
160 .for module in ${AVAILABLE_MODULES}
161 . if ${PORT_OPTIONS:M${module}}
162 _APACHE_MODULES+= ${module}
164 WITHOUT_MODULES+= ${module}
168 .if !defined(WITH_STATIC_APACHE)
171 CONFIGURE_ARGS+= --enable-so
173 CONFIGURE_ARGS+= --disable-so
174 WITH_ALL_STATIC_MODULES= yes
177 .if ${PORT_OPTIONS:MSUEXEC}
178 _APACHE_MODULES+= ${SUEXEC_MODULES}
179 SUEXEC_CONFARGS= with-suexec
181 # SUEXEC_DOCROOT should exist
182 SUEXEC_DOCROOT?= ${PREFIX}/www/data
183 #SUEXEC_DOCROOT?= ${WWWDIR}
184 SUEXEC_USERDIR?= public_html
185 # avoid duplicate search paths
186 .if ${LOCALBASE} == ${PREFIX}
187 SUEXEC_SAFEPATH?= ${LOCALBASE}/bin:/usr/bin:/bin
189 SUEXEC_SAFEPATH?= ${PREFIX}/bin:${LOCALBASE}/bin:/usr/bin:/bin
191 SUEXEC_LOGFILE?= /var/log/httpd-suexec.log
194 SUEXEC_CALLER?= ${WWWOWN}
195 CONFIGURE_ARGS+= --${SUEXEC_CONFARGS}-caller=${SUEXEC_CALLER} \
196 --${SUEXEC_CONFARGS}-uidmin=${SUEXEC_UIDMIN} \
197 --${SUEXEC_CONFARGS}-gidmin=${SUEXEC_GIDMIN} \
198 --${SUEXEC_CONFARGS}-userdir="${SUEXEC_USERDIR}" \
199 --${SUEXEC_CONFARGS}-docroot="${SUEXEC_DOCROOT}" \
200 --${SUEXEC_CONFARGS}-safepath="${SUEXEC_SAFEPATH}" \
201 --${SUEXEC_CONFARGS}-logfile="${SUEXEC_LOGFILE}" \
202 --${SUEXEC_CONFARGS}-bin="${PREFIX}/sbin/suexec"
204 . if defined(WITH_SUEXEC_UMASK)
205 CONFIGURE_ARGS+= --${SUEXEC_CONFARGS}-umask=${SUEXEC_UMASK}
209 .if !defined(WITHOUT_MODULES)
210 APACHE_MODULES= ${_APACHE_MODULES}
212 .for module in ${_APACHE_MODULES:O:u}
213 . if !${WITHOUT_MODULES:M${module}}
214 APACHE_MODULES+= ${module}
219 .if defined(WITH_STATIC_MODULES)
220 . for module in ${APACHE_MODULES}
221 . if ${WITH_STATIC_MODULES:M${module}}
222 _CONFIGURE_ARGS+= --enable-${module:tl}
224 _CONFIGURE_ARGS+= --enable-${module:tl}=shared
227 CONFIGURE_ARGS+= ${_CONFIGURE_ARGS:O}
228 .elif defined(WITH_STATIC_APACHE) || defined(WITH_ALL_STATIC_MODULES)
229 WITH_STATIC_MODULES= ${APACHE_MODULES}
230 CONFIGURE_ARGS+= --enable-modules="${APACHE_MODULES:O:tl}"
232 CONFIGURE_ARGS+= --enable-mods-shared="${APACHE_MODULES:O:tl}"
235 # ====================================
236 # start pkg-plist adjustments
237 .if defined(WITH_STATIC_MODULES)
238 .for module in ${APACHE_MODULES}
239 . if !${WITH_STATIC_MODULES:M${module}}
240 _SHARED_MODULES+= ${module}
244 SHARED_MODULES= ${_SHARED_MODULES}
245 .elif !defined(WITH_ALL_STATIC_MODULES)
246 SHARED_MODULES= ${APACHE_MODULES}
249 .for module in ${SHARED_MODULES}
250 ${module}_PLIST_SUB= ""
253 .for module in ${AVAILABLE_MODULES:O:u}
254 PLIST_SUB+= MOD_${module}=${${module}_PLIST_SUB}
257 # pkg-plist workaround STATIC support
258 .if ${PORT_OPTIONS:MSUEXEC}
259 PLIST_SUB+= SUEXEC=""
261 PLIST_SUB+= SUEXEC="@comment "
264 .if ${PORT_OPTIONS:MLOG_FORENSIC}
265 PLIST_SUB+= FORENSIC=""
267 PLIST_SUB+= FORENSIC="@comment "
270 # end pkg-plist adjustments
272 #### End of AP_PORT_IS_SERVER ####
274 # ===============================================================
275 .elif defined(AP_PORT_IS_MODULE) || defined(USE_APACHE_RUN) || defined(USE_APACHE_BUILD)
276 APXS?= ${LOCALBASE}/sbin/apxs
277 HTTPD?= ${LOCALBASE}/sbin/httpd
279 MODULENAME?= ${PORTNAME}
280 SHORTMODNAME?= ${MODULENAME:S/mod_//}
281 SRC_FILE?= ${MODULENAME}.c
284 _APACHE_VERSION!= ${HTTPD} -V | ${SED} -ne 's/^Server version: Apache\/\([0-9]\)\.\([0-9]*\).*/\1\2/p'
285 # XXX see mod_perl-2.0.6/Changes
286 # Apache 2.4 and onwards doesn't require linking the MPM module
287 # directly in the httpd binary anymore. APXS lost the MPM_NAME query,
288 # so we can't assume a given MPM anymore.
289 . if ${_APACHE_VERSION} <= 22
290 APACHE_MPM!= ${APXS} -q MPM_NAME
292 .elif defined(APACHE_PORT)
293 _APACHE_VERSION!= ${ECHO_CMD} ${APACHE_PORT} | ${SED} -ne 's,.*/apache\([0-9]*\).*,\1,p'
295 _APACHE_VERSION:= ${DEFAULT_APACHE_VERSION}
298 .if defined(USE_APACHE)
299 _USE_APACHE:= ${USE_APACHE}
300 .elif defined(USE_APACHE_BUILD)
301 _USE_APACHE:= ${USE_APACHE_BUILD}
302 .elif defined(USE_APACHE_RUN)
303 _USE_APACHE:= ${USE_APACHE_RUN}
306 _APACHE_VERSION_CHECK:= ${_USE_APACHE:C/^([1-9][0-9])$/\1-\1/}
307 _APACHE_VERSION_MINIMUM_TMP:= ${_APACHE_VERSION_CHECK:C/([1-9][0-9])[-+].*/\1/}
308 _APACHE_VERSION_MINIMUM:= ${_APACHE_VERSION_MINIMUM_TMP:M[1-9][0-9]}
309 _APACHE_VERSION_MAXIMUM_TMP:= ${_APACHE_VERSION_CHECK:C/.*-([1-9][0-9])/\1/}
310 _APACHE_VERSION_MAXIMUM:= ${_APACHE_VERSION_MAXIMUM_TMP:M[1-9][0-9]}
312 .if defined(_APACHE_VERSION)
313 # Validate Apache version whether it meets USE_APACHE version restriction.
314 . if !empty(_APACHE_VERSION_MINIMUM) && (${_APACHE_VERSION} < ${_APACHE_VERSION_MINIMUM})
315 _APACHE_VERSION_NONSUPPORTED= ${_APACHE_VERSION_MINIMUM} at least
316 . elif !empty(_APACHE_VERSION_MAXIMUM) && (${_APACHE_VERSION} > ${_APACHE_VERSION_MAXIMUM})
317 _APACHE_VERSION_NONSUPPORTED= ${_APACHE_VERSION_MAXIMUM} at most
320 . if defined(_APACHE_VERSION_NONSUPPORTED) && !defined(AP_IGNORE_VERSION_CHECK)
321 BROKEN= ${_ERROR_MSG} apache${_APACHE_VERSION} is installed (or APACHE_PORT is defined) and port requires apache${_APACHE_VERSION_NONSUPPORTED}
323 .else # defined(_APACHE_VERSION)
324 . for ver in ${APACHE_SUPPORTED_VERSION}
326 . if !defined(_APACHE_VERSION) && \
327 !(!empty(_APACHE_VERSION_MINIMUM) && ( ${__VER} < ${_APACHE_VERSION_MINIMUM} )) && \
328 !(!empty(_APACHE_VERSION_MAXIMUM) && ( ${__VER} > ${_APACHE_VERSION_MAXIMUM} ))
329 _APACHE_VERSION= ${ver}
332 .endif # defined(_APACHE_VERSION)
334 APACHE_VERSION:= ${_APACHE_VERSION}
337 APXS_PREFIX!= ${APXS} -q prefix 2> /dev/null || echo NULL
338 . if ${APXS_PREFIX} == NULL
339 IGNORE= : Your apache does not support DSO modules
341 . if defined(AP_GENPLIST) && ${APXS_PREFIX} != ${PREFIX}
342 IGNORE?= PREFIX must be equal to APXS_PREFIX.
347 APACHEMODDIR= libexec/apache${APACHE_VERSION}
348 APACHEINCLUDEDIR=include/apache${APACHE_VERSION}
349 APACHEETCDIR= etc/apache${APACHE_VERSION}
350 APACHE_PORT?= www/apache${APACHE_VERSION}
352 PLIST_SUB+= APACHEMODDIR="${APACHEMODDIR}" \
353 APACHEINCLUDEDIR="${APACHEINCLUDEDIR}" \
354 APACHEETCDIR="${APACHEETCDIR}"
356 APACHE_PKGNAMEPREFIX= ap${APACHE_VERSION}-
357 .if defined(AP_FAST_BUILD)
358 PKGNAMEPREFIX?= ${APACHE_PKGNAMEPREFIX}
361 .if defined(USE_APACHE) || defined(USE_APACHE_BUILD)
362 BUILD_DEPENDS+= ${APXS}:${PORTSDIR}/${APACHE_PORT}
365 .if defined(USE_APACHE) || defined(USE_APACHE_RUN)
366 RUN_DEPENDS+= ${APXS}:${PORTSDIR}/${APACHE_PORT}
369 PLIST_SUB+= AP_NAME="${SHORTMODNAME}"
370 PLIST_SUB+= AP_MODULE="${MODULENAME}.so"
372 .if defined(AP_GENPLIST)
373 PLIST?= ${WRKDIR}/ap-plist
377 AP_EXTRAS+= -I ${AP_INC}
380 AP_EXTRAS+= -L ${AP_LIB}
383 .endif # End of AP_PORT_IS_SERVER / AP_PORT_IS_MOULE
384 .endif # End of !Apache_Pre_Include
386 # ===============================================================
387 .if defined(_POSTMKINCLUDED) && !defined(Apache_Post_Include)
388 Apache_Post_Include= bsd.apache.mk
390 .if defined(USE_APACHE_RUN) && !empty(USE_APACHE_RUN)
391 . if ${USE_APACHE_RUN:C/\-//:S/^22//:S/^24//:C/\+$//} != ""
392 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_RUN ( ${USE_APACHE_RUN} )
394 .elif defined(USE_APACHE_RUN)
395 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_RUN ( no valid version specified )
398 .if defined(USE_APACHE_BUILD) && !empty(USE_APACHE_BUILD)
399 . if ${USE_APACHE_BUILD:C/\-//:S/^22//:S/^24//:C/\+$//} != ""
400 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_BUILD ( ${USE_APACHE_BUILD} )
402 .elif defined(USE_APACHE_BUILD)
403 IGNORE= ${_ERROR_MSG} Illegal use of USE_APACHE_BUILD ( no valid version specified )
406 # Check if USE_APACHE(_BUILD|_RUN) are mixed together
407 .if defined(USE_APACHE) && ( defined(USE_APACHE_BUILD) || defined(USE_APACHE_RUN) )
408 IGNORE= ${_ERROR_MSG} specify only one of: USE_APACHE USE_APACHE_BUILD USE_APACHE_RUN
409 .elif defined(USE_APACHE_BUILD) && defined(USE_APACHE_RUN)
410 IGNORE= ${_ERROR_MSG} use USE_APACHE instead of USE_APACHE_BUILD and USE_APACHE_RUN together
413 .if defined(NO_BUILD) && defined(USE_APACHE)
414 BROKEN= If NO_BUILD is used, then USE_APACHE_RUN is sufficient. Please fix your Makefile
417 .if defined(AP_PORT_IS_SERVER)
418 .if !target(print-closest-mirrors)
419 print-closest-mirrors:
420 @${ECHO_MSG} -n "Fetching list of nearest mirror: " >&2
421 @MIRRORS=`${FETCH_CMD} -T 30 -qo - http://www.apache.org/dyn/closer.cgi/httpd/ 2> /dev/null\
422 | ${GREP} /httpd/ | ${SED} 's/.*href="\(.*\)"><str.*/\1/g' | \
423 ${HEAD} -7 | ${TAIL} -6` ; \
424 ${ECHO_MSG} done >&2; if [ "x$$MIRRORS" != "x" ]; then \
425 ${ECHO_MSG} -n "MASTER_SITE_APACHE_HTTPD?= ";\
426 ${ECHO_MSG} $$MIRRORS; else \
427 ${ECHO_MSG} "No mirrors found!">&2 ; fi
430 .if !target(show-modules)
432 .if !empty(APACHE_MODULES)
433 .for module in ${AVAILABLE_MODULES}
434 @${PRINTF} "%-20s : " ${module}
435 . if ${APACHE_MODULES:M${module}}
436 @${ECHO} -n "enabled "
437 . if !empty(WITH_STATIC_MODULES) && ${WITH_STATIC_MODULES:M${module}}
438 @${ECHO_CMD} " (static)"
440 @${ECHO_CMD} "(shared)"
443 @${ECHO_CMD} disabled
447 .for module in ${AVAILABLE_MODULES}
448 @${PRINTF} "%-20s : disabled\n" ${module}
453 .elif defined(AP_PORT_IS_MODULE)
455 .if defined(AP_MODENABLE)
460 PLIST_SUB+= AP_MOD_EN="${AP_MOD_EN}"
462 .if defined(AP_FAST_BUILD)
463 .if !target(ap-gen-plist)
465 .if defined(AP_GENPLIST)
466 . if !exists(${PLIST})
467 @${ECHO} "===> Generating apache plist"
469 @${ECHO} "@unexec ${SED} -i '' -E '/LoadModule[[:blank:]]+%%AP_NAME%%_module/d' %D/%%APACHEETCDIR%%/httpd.conf" >> ${PLIST}
470 @${ECHO} "%%APACHEMODDIR%%/%%AP_MODULE%%" >> ${PLIST}
471 @${ECHO} "@exec %D/sbin/apxs -e ${AP_MOD_EN} -n %%AP_NAME%% %D/%F" >> ${PLIST}
472 @${ECHO} "@unexec echo \"Don't forget to remove all ${MODULENAME}-related directives in your httpd.conf\"">> ${PLIST}
479 .if !target(do-build)
480 do-build: ap-gen-plist
481 @cd ${WRKSRC} && ${APXS} -c ${AP_EXTRAS} -o ${MODULENAME}.${AP_BUILDEXT} ${SRC_FILE}
484 .if !target(do-install)
486 . if defined(NO_STAGE)
487 @${APXS} -i ${AP_MOD_EN} -n ${SHORTMODNAME} ${WRKSRC}/${MODULENAME}.${AP_BUILDEXT}
489 @${MKDIR} ${STAGEDIR}${PREFIX}/${APACHEMODDIR}
490 @${APXS} -S LIBEXECDIR=${STAGEDIR}${PREFIX}/${APACHEMODDIR} -i -n ${SHORTMODNAME} ${WRKSRC}/${MODULENAME}.${AP_BUILDEXT}
492 @${ECHO_MSG} "===> strip ${APACHEMODDIR}/${MODULENAME}.so"
493 @[ -e ${STAGEDIR}${PREFIX}/${APACHEMODDIR}/${MODULENAME}.so ] && ${STRIP_CMD} ${STAGEDIR}${PREFIX}/${APACHEMODDIR}/${MODULENAME}.so
495 @${ECHO_MSG} "===> DEBUG is set, will not strip ${APACHEMODDIR}/${MODULENAME}.so"
499 .endif # defined(AP_FAST_BUILD)
500 .endif # defined(AP_PORT_IS_MODULE)
501 .endif # defined(_POSTMKINCLUDED) && !defined(Apache_Post_Include)