Gentoo Archives: gentoo-dev

From: jonas.licht@××××××××××××××.de
To: gentoo-dev@l.g.o
Cc: Jonas Licht <jonas.licht@××××××××××××××.de>
Subject: [gentoo-dev] [PATCH v2 2/3] Add nginx-module.eclass
Date: Sun, 28 Feb 2021 17:36:59
Message-Id: 20210228173615.12685-3-jonas.licht@fem.tu-ilmenau.de
In Reply to: [gentoo-dev] [PATCH v2 0/3] Version 2 by jonas.licht@fem.tu-ilmenau.de
1 From: Jonas Licht <jonas.licht@××××××××××××××.de>
2
3 Signed-off-by: Jonas Licht <jonas.licht@××××××××××××××.de>
4 ---
5 eclass/nginx-module.eclass | 72 ++++++++++++++++++++++++++++++++++++++
6 1 file changed, 72 insertions(+)
7 create mode 100644 eclass/nginx-module.eclass
8
9 diff --git a/eclass/nginx-module.eclass b/eclass/nginx-module.eclass
10 new file mode 100644
11 index 00000000000..d9f9bbdb89c
12 --- /dev/null
13 +++ b/eclass/nginx-module.eclass
14 @@ -0,0 +1,72 @@
15 +# Copyright 2021 Gentoo Authors
16 +# Distributed under the terms of the GNU General Public License v2
17 +
18 +# @ECLASS: nginx-module.eclass
19 +# @MAINTAINER:
20 +# Jonas Licht <jonas.licht@×××××.com>
21 +# @AUTHOR:
22 +# Jonas Licht <jonas.licht@×××××.com>
23 +# @BLURB: Provide a set of functions to build nginx dynamic modules.
24 +# @DESCRIPTION:
25 +# Eclass to make dynamic nginx modules.
26 +# As these modules are hardly build against one nginx version we use version cut to indicate the nginx version too.
27 +# The first three parts of the version must represent the nginx version,
28 +# the remaining part displays the module version.
29 +#
30 +# To build a nginx module the whole nginx source code is needed,
31 +# therfore we set the SRC_URI to the nginx source archive.
32 +# The module archive must be added with SRC_URI+=
33 +
34 +case ${EAPI:-0} in
35 + 7) ;;
36 + *) die "This eclass only supports EAPI 7" ;;
37 +esac
38 +
39 +# @ECLASS-VARIABLE: NGINX_PV
40 +# @DESCRIPTION:
41 +# Uses version cut of the first three parts of the version to determine the nginx version providing the module.
42 +# This version is used for SRC_URI, BDPEND and compiling process.
43 +NGINX_PV=$(ver_cut 1-3)
44 +
45 +# @ECLASS-VARIABLE: MODULE_PV
46 +# @DESCRIPTION:
47 +# Uses version cut to get the version of the module.
48 +# Variable can be used for SRC_URI of the nginx module.
49 +MODULE_PV=$(ver_cut 4-)
50 +
51 +BDPEND="=www-servers/nginx-${NGINX_PV}:="
52 +SRC_URI="https://nginx.org/download/nginx-${NGINX_PV}.tar.gz"
53 +
54 +S="${WORKDIR}/nginx-${NGINX_PV}"
55 +
56 +EXPORT_FUNCTIONS src_configure src_compile src_install
57 +
58 +# @FUNCTION: nginx-module_src_configure
59 +# @USAGE: [additional-args]
60 +# @DESCRIPTION:
61 +# Parses the configure from the original nginx binary by exicution 'nginx -V' and adds the package as dynamic module.
62 +nginx-module_src_configure() {
63 + if [ $(grep -c "\.[[:space:]]auto/module" "${WORKDIR}/${PN}-${MODULE_PV}/config") -eq 0 ]; then
64 + die "module uses old unsupported static config file syntax: https://www.nginx.com/resources/wiki/extending/converting/"
65 + fi
66 + #grep nginx configure from nginx -V add drop all other external modules
67 + NGINX_ORIGIN_CONFIGURE=$(nginx -V 2>&1 | grep "configure arguments:" | cut -d: -f2 | sed "s/--add-module=\([^\s]\)*\s/ /")
68 + ./configure ${NGINX_ORIGIN_CONFIGURE} --add-dynamic-module="../${PN}-${MODULE_PV}" "$@" || die "configure failed"
69 +}
70 +
71 +# @FUNCTION: nginx-module_src_compile
72 +# @USAGE: [additional-args]
73 +# @DESCRIPTION:
74 +# Runs 'make modules' to only build our package module.
75 +nginx-module_src_compile() {
76 + emake modules "$@"
77 +}
78 +
79 +# @FUNCTION: nginx-module_src_install
80 +# @DESCRIPTION:
81 +# Parses the module config file to get the so file name and install the shared object file to '/usr/$(get_libdir)/nginx/modules'
82 +nginx-module_src_install() {
83 + NGINX_MODULE_NAME=$(grep ${WORKDIR}/${PN}-${MODULE_PV}/config -e "ngx_addon_name" | cut -d= -f2)
84 + exeinto /usr/$(get_libdir)/nginx/modules
85 + doexe ${S}/objs/${NGINX_MODULE_NAME}.so
86 +}
87 --
88 2.26.2