Gentoo Archives: gentoo-dev

From: Adrian Schollmeyer <nex@××××××.de>
To: gentoo-dev@l.g.o
Cc: jonas.licht@××××××××××××××.de, nex+b-g-o@××××××.de
Subject: [gentoo-dev] [PATCH v3 2/3] Add nginx-module.eclass
Date: Tue, 24 Jan 2023 15:52:39
Message-Id: 20230124155156.12178-3-nex@nexadn.de
In Reply to: [gentoo-dev] [RFC] www-nginx/ category and nginx-module.eclass for nginx modules by Adrian Schollmeyer
1 From: Jonas Licht <jonas.licht@××××××××××××××.de>
2
3 Signed-off-by: Adrian Schollmeyer <nex+b-g-o@××××××.de>
4 Signed-off-by: Jonas Licht <jonas.licht@××××××××××××××.de>
5 ---
6 eclass/nginx-module.eclass | 90 ++++++++++++++++++++++++++++++++++++++
7 1 file changed, 90 insertions(+)
8 create mode 100644 eclass/nginx-module.eclass
9
10 diff --git a/eclass/nginx-module.eclass b/eclass/nginx-module.eclass
11 new file mode 100644
12 index 00000000000..aa25977cdc5
13 --- /dev/null
14 +++ b/eclass/nginx-module.eclass
15 @@ -0,0 +1,90 @@
16 +# Copyright 2021-2023 Gentoo Authors
17 +# Distributed under the terms of the GNU General Public License v2
18 +
19 +# @ECLASS: nginx-module.eclass
20 +# @MAINTAINER:
21 +# Jonas Licht <jonas.licht@×××××.com>
22 +# @AUTHOR:
23 +# Jonas Licht <jonas.licht@×××××.com>
24 +# @BLURB: Provide a set of functions to build nginx dynamic modules.
25 +# @DESCRIPTION:
26 +# Eclass to make dynamic nginx modules.
27 +# As these modules are built against one particular nginx version.
28 +# The nginx version is encoded in PV as the first three version components,
29 +# while the rest of PV represent's the module's upstream version.
30 +#
31 +# To build an nginx module the whole nginx source code is needed.
32 +# Therefore SRC_URI is set to the nginx source archive.
33 +# Ebuilds using this eclass thus must use SRC_URI+= instead of
34 +# SRC_URI=.
35 +
36 +case ${EAPI:-0} in
37 + 7|8) ;;
38 + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
39 +esac
40 +
41 +inherit toolchain-funcs
42 +
43 +# @ECLASS_VARIABLE: NGINX_PV
44 +# @PRE_INHERIT
45 +# @DESCRIPTION:
46 +# Version of www-apps/nginx to build against.
47 +# Default is the first three components of PV.
48 +: "${NGINX_PV:=$(ver_cut 1-3)}"
49 +
50 +# @ECLASS_VARIABLE: MODULE_PV
51 +# @PRE_INHERIT
52 +# @DESCRIPTION:
53 +# Module version minus the www-apps/nginx version.
54 +# Default is all components of PV starting with the 4th component.
55 +: "${MODULE_PV=$(ver_cut 4-)}"
56 +
57 +# @ECLASS_VARIABLE: MODULE_SOURCE
58 +# @DESCRIPTION:
59 +# Path to the unpacked source directory of the module.
60 +# Defaults to '${WORKDIR}/${PN}-${MODULE_PV}', mimicking the default value of S.
61 +: "${MODULE_SOURCE:="${WORKDIR}/${PN}-${MODULE_PV}"}"
62 +
63 +BDEPEND="~www-servers/nginx-${NGINX_PV}:="
64 +SRC_URI="https://nginx.org/download/nginx-${NGINX_PV}.tar.gz"
65 +
66 +S="${WORKDIR}/nginx-${NGINX_PV}"
67 +
68 +EXPORT_FUNCTIONS src_configure src_compile src_install
69 +
70 +# @FUNCTION: nginx-module_src_configure
71 +# @USAGE: [additional-args]
72 +# @DESCRIPTION:
73 +# Parses the configure from the original nginx binary by executing 'nginx -V' and
74 +# adds the package as dynamic module.
75 +nginx-module_src_configure() {
76 + if [ "$(grep -c "\.[[:space:]]auto/module" "${MODULE_SOURCE}/config")" -eq 0 ]; then
77 + die "module uses old unsupported static config file syntax: https://www.nginx.com/resources/wiki/extending/converting/"
78 + fi
79 + #grep nginx configure from nginx -V add drop all other external modules
80 + NGINX_ORIGIN_CONFIGURE=$(nginx -V 2>&1 | grep "configure arguments:" | cut -d: -f2 | sed "s/--add-module=\([^\s]\)*\s/ /")
81 + # shellcheck disable=SC2086
82 + ./configure ${NGINX_ORIGIN_CONFIGURE} --add-dynamic-module="${MODULE_SOURCE}" "$@" || die "configure failed"
83 +}
84 +
85 +# @FUNCTION: nginx-module_src_compile
86 +# @USAGE: [additional-args]
87 +# @DESCRIPTION:
88 +# Runs 'make modules' to only build our package module.
89 +nginx-module_src_compile() {
90 + # https://bugs.gentoo.org/286772
91 + export LANG=C LC_ALL=C
92 + emake modules "$@" CC="$(tc-getCC)" LINK="$(tc-getCC) ${LDFLAGS}" OTHERLDFLAGS="${LDFLAGS}"
93 +}
94 +
95 +# @FUNCTION: nginx-module_src_install
96 +# @DESCRIPTION:
97 +# Parses the module config file to get the shared object file name and install the file to the nginx module directory.
98 +nginx-module_src_install() {
99 + einstalldocs
100 +
101 + local NGINX_MODULE_NAME
102 + NGINX_MODULE_NAME=$(grep "${MODULE_SOURCE}/config" -e "ngx_addon_name" | cut -d= -f2)
103 + exeinto /usr/$(get_libdir)/nginx/modules
104 + doexe objs/${NGINX_MODULE_NAME}.so
105 +}
106 --
107 2.38.2