apache-module.eclass 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. # Copyright 1999-2011 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: apache-module.eclass
  4. # @MAINTAINER:
  5. # apache-devs@gentoo.org
  6. # @BLURB: Provides a common set of functions for apache modules
  7. # @DESCRIPTION:
  8. # This eclass handles apache modules in a sane way.
  9. #
  10. # To make use of this eclass simply call one of the need/want_apache functions
  11. # described in depend.apache.eclass. Make sure you use the need/want_apache call
  12. # after you have defined DEPEND and RDEPEND. Also note that you can not rely on
  13. # the automatic RDEPEND=DEPEND that portage does if you use this eclass.
  14. #
  15. # See Bug 107127 for more information.
  16. #
  17. # @EXAMPLE:
  18. #
  19. # Here is a simple example of an ebuild for mod_foo:
  20. #
  21. # @CODE
  22. # APACHE2_MOD_CONF="42_mod_foo"
  23. # APACHE2_MOD_DEFINE="FOO"
  24. # need_apache2
  25. # @CODE
  26. #
  27. # A more complicated example for a module with non-standard locations:
  28. #
  29. # @CODE
  30. # APXS2_S="${S}/apache22/src"
  31. # APACHE2_MOD_FILE="${APXS2_S}/${PN}.so"
  32. # APACHE2_MOD_CONF="42_${PN}"
  33. # APACHE2_MOD_DEFINE="FOO"
  34. # DOCFILES="docs/*.html"
  35. # need_apache2_2
  36. # @CODE
  37. #
  38. # A basic module configuration which just loads the module into apache:
  39. #
  40. # @CODE
  41. # <IfDefine FOO>
  42. # LoadModule foo_module modules/mod_foo.so
  43. # </IfDefine>
  44. # @CODE
  45. inherit depend.apache
  46. # ==============================================================================
  47. # PUBLIC VARIABLES
  48. # ==============================================================================
  49. # @VARIABLE: APXS2_S
  50. # @DESCRIPTION:
  51. # Path to temporary build directory. (Defaults to `${S}/src' if it exists,
  52. # `${S}' otherwise)
  53. # @VARIABLE: APXS2_ARGS
  54. # @DESCRIPTION:
  55. # Arguments to pass to the apxs tool. (Defaults to `-c ${PN}.c')
  56. # @VARIABLE: APACHE2_EXECFILES
  57. # @DESCRIPTION:
  58. # List of files that will be installed into ${APACHE_MODULE_DIR} beside
  59. # ${APACHE2_MOD_FILE}. In addition, this function also sets the executable
  60. # permission on those files.
  61. # @VARIABLE: APACHE2_MOD_CONF
  62. # @DESCRIPTION:
  63. # Module configuration file installed by src_install (minus the .conf suffix and
  64. # relative to ${FILESDIR}).
  65. # @VARIABLE: APACHE2_MOD_DEFINE
  66. # @DESCRIPTION:
  67. # Name of define (e.g. FOO) to use in conditional loading of the installed
  68. # module/its config file, multiple defines should be space separated.
  69. # @VARIABLE: APACHE2_MOD_FILE
  70. # @DESCRIPTION:
  71. # Name of the module that src_install installs minus the .so suffix. (Defaults
  72. # to `${APXS2_S}/.libs/${PN}.so')
  73. # @VARIABLE: APACHE2_VHOST_CONF
  74. # @DESCRIPTION:
  75. # Virtual host configuration file installed by src_install (minus the .conf
  76. # suffix and relative to ${FILESDIR}).
  77. # @VARIABLE: DOCFILES
  78. # @DESCRIPTION:
  79. # If the exported src_install() is being used, and ${DOCFILES} is non-zero, some
  80. # sed-fu is applied to split out html documentation (if any) from normal
  81. # documentation, and dodoc'd or dohtml'd.
  82. # ==============================================================================
  83. # INTERNAL FUNCTIONS
  84. # ==============================================================================
  85. # Internal function to construct the default ${APXS2_S} path if required.
  86. apache_cd_dir() {
  87. debug-print-function $FUNCNAME $*
  88. local CD_DIR="${APXS2_S}"
  89. if [[ -z "${CD_DIR}" ]] ; then
  90. if [[ -d "${S}/src" ]] ; then
  91. CD_DIR="${S}/src"
  92. else
  93. CD_DIR="${S}"
  94. fi
  95. fi
  96. debug-print $FUNCNAME "CD_DIR=${CD_DIR}"
  97. echo "${CD_DIR}"
  98. }
  99. # Internal function to construct the default ${APACHE2_MOD_FILE} if required.
  100. apache_mod_file() {
  101. debug-print-function $FUNCNAME $*
  102. local MOD_FILE="${APACHE2_MOD_FILE:-$(apache_cd_dir)/.libs/${PN}.so}"
  103. debug-print $FUNCNAME "MOD_FILE=${MOD_FILE}"
  104. echo "${MOD_FILE}"
  105. }
  106. # Internal function for picking out html files from ${DOCFILES}. It takes an
  107. # optional first argument `html'; if the first argument is equals `html', only
  108. # html files are returned, otherwise normal (non-html) docs are returned.
  109. apache_doc_magic() {
  110. debug-print-function $FUNCNAME $*
  111. local DOCS=
  112. if [[ -n "${DOCFILES}" ]] ; then
  113. if [[ "x$1" == "xhtml" ]] ; then
  114. DOCS="`echo ${DOCFILES} | sed -e 's/ /\n/g' | sed -e '/^[^ ]*.html$/ !d'`"
  115. else
  116. DOCS="`echo ${DOCFILES} | sed 's, *[^ ]*\+.html, ,g'`"
  117. fi
  118. fi
  119. debug-print $FUNCNAME "DOCS=${DOCS}"
  120. echo "${DOCS}"
  121. }
  122. # ==============================================================================
  123. # EXPORTED FUNCTIONS
  124. # ==============================================================================
  125. # @FUNCTION: apache-module_src_compile
  126. # @DESCRIPTION:
  127. # The default action is to call ${APXS} with the value of ${APXS2_ARGS}. If a
  128. # module requires a different build setup than this, use ${APXS} in your own
  129. # src_compile routine.
  130. apache-module_src_compile() {
  131. debug-print-function $FUNCNAME $*
  132. local CD_DIR=$(apache_cd_dir)
  133. cd "${CD_DIR}" || die "cd ${CD_DIR} failed"
  134. APXS2_ARGS="${APXS2_ARGS:--c ${PN}.c}"
  135. ${APXS} ${APXS2_ARGS} || die "${APXS} ${APXS2_ARGS} failed"
  136. }
  137. # @FUNCTION: apache-module_src_install
  138. # @DESCRIPTION:
  139. # This installs the files into apache's directories. The module is installed
  140. # from a directory chosen as above (apache_cd_dir). In addition, this function
  141. # can also set the executable permission on files listed in
  142. # ${APACHE2_EXECFILES}. The configuration file name is listed in
  143. # ${APACHE2_MOD_CONF} without the .conf extensions, so if you configuration is
  144. # 55_mod_foo.conf, APACHE2_MOD_CONF would be 55_mod_foo. ${DOCFILES} contains
  145. # the list of files you want filed as documentation.
  146. apache-module_src_install() {
  147. debug-print-function $FUNCNAME $*
  148. local CD_DIR=$(apache_cd_dir)
  149. pushd "${CD_DIR}" >/dev/null || die "cd ${CD_DIR} failed"
  150. local MOD_FILE=$(apache_mod_file)
  151. exeinto "${APACHE_MODULESDIR}"
  152. doexe ${MOD_FILE} || die "internal ebuild error: '${MOD_FILE}' not found"
  153. [[ -n "${APACHE2_EXECFILES}" ]] && doexe ${APACHE2_EXECFILES}
  154. if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
  155. insinto "${APACHE_MODULES_CONFDIR}"
  156. set -- ${APACHE2_MOD_CONF}
  157. newins "${FILESDIR}/${1}.conf" "$(basename ${2:-$1}).conf" \
  158. || die "internal ebuild error: '${FILESDIR}/${1}.conf' not found"
  159. fi
  160. if [[ -n "${APACHE2_VHOST_CONF}" ]] ; then
  161. insinto "${APACHE_VHOSTS_CONFDIR}"
  162. set -- ${APACHE2_VHOST_CONF}
  163. newins "${FILESDIR}/${1}.conf" "$(basename ${2:-$1}).conf " \
  164. || die "internal ebuild error: '${FILESDIR}/${1}.conf' not found"
  165. fi
  166. cd "${S}"
  167. if [[ -n "${DOCFILES}" ]] ; then
  168. local OTHER_DOCS=$(apache_doc_magic)
  169. local HTML_DOCS=$(apache_doc_magic html)
  170. [[ -n "${OTHER_DOCS}" ]] && dodoc ${OTHER_DOCS}
  171. [[ -n "${HTML_DOCS}" ]] && dohtml ${HTML_DOCS}
  172. fi
  173. popd >/dev/null
  174. }
  175. # @FUNCTION: apache-module_pkg_postinst
  176. # @DESCRIPTION:
  177. # This prints out information about the installed module and how to enable it.
  178. apache-module_pkg_postinst() {
  179. debug-print-function $FUNCNAME $*
  180. if [[ -n "${APACHE2_MOD_DEFINE}" ]] ; then
  181. local my_opts="-D ${APACHE2_MOD_DEFINE// / -D }"
  182. einfo
  183. einfo "To enable ${PN}, you need to edit your /etc/conf.d/apache2 file and"
  184. einfo "add '${my_opts}' to APACHE2_OPTS."
  185. einfo
  186. fi
  187. if [[ -n "${APACHE2_MOD_CONF}" ]] ; then
  188. set -- ${APACHE2_MOD_CONF}
  189. einfo
  190. einfo "Configuration file installed as"
  191. einfo " ${APACHE_MODULES_CONFDIR}/$(basename ${2:-$1}).conf"
  192. einfo "You may want to edit it before turning the module on in /etc/conf.d/apache2"
  193. einfo
  194. fi
  195. }
  196. EXPORT_FUNCTIONS src_compile src_install pkg_postinst