dev-cpp/pangomm: stable 2.42.1 for hppa, bug #717144
[gentoo.git] / www-servers / uwsgi / uwsgi-2.0.17.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=5
5
6 PYTHON_COMPAT=( python2_7 python3_6 )
7 PYTHON_REQ_USE="threads(+)"
8
9 RUBY_OPTIONAL="yes"
10 USE_RUBY="ruby23 ruby24"
11
12 PHP_EXT_INI="no"
13 PHP_EXT_NAME="dummy"
14 PHP_EXT_OPTIONAL_USE="php"
15 USE_PHP="php7-2 php7-3 php7-4" # deps must be registered separately below
16
17 MY_P="${P/_/-}"
18
19 inherit apache-module eutils flag-o-matic multilib pax-utils php-ext-source-r2 python-r1 ruby-ng versionator
20
21 DESCRIPTION="uWSGI server for Python web applications"
22 HOMEPAGE="http://projects.unbit.it/uwsgi/"
23 SRC_URI="https://github.com/unbit/uwsgi/archive/${PV}.tar.gz -> ${P}.tar.gz"
24
25 LICENSE="GPL-2"
26 SLOT="0"
27 KEYWORDS="amd64 x86 ~amd64-linux"
28
29 UWSGI_PLUGINS_STD=( ping cache carbon nagios rpc rrdtool
30         http ugreen signal syslog rsyslog
31         router_{uwsgi,redirect,basicauth,rewrite,http,cache,static,memcached,redis,hash,expires,metrics}
32         {core,fast,raw,ssl}router
33         redislog mongodblog log{file,socket}
34         spooler cheaper_busyness symcall
35         transformation_{chunked,gzip,offload,tofile}
36         zergpool )
37 UWSGI_PLUGINS_OPT=( alarm_{curl,xmpp} clock_{monotonic,realtime} curl_cron
38         dumbloop echo emperor_{amqp,pg,zeromq} forkptyrouter
39         geoip graylog2 legion_cache_fetch ldap log{crypto,pipe} notfound pam
40         rados router_{access,radius,spnego,xmldir}
41         sqlite ssi stats_pusher_statsd
42         systemd_logger transformation_toupper tuntap webdav xattr xslt zabbix )
43
44 LANG_SUPPORT_SIMPLE=( cgi perl ) # plugins which can be built in the main build process
45 LANG_SUPPORT_EXTENDED=( go lua php python python-asyncio python-gevent ruby )
46
47 # plugins to be ignored (for now):
48 # cheaper_backlog2: example plugin
49 # coroae: TODO
50 # cplusplus: partially example code, needs explicit class
51 # dummy: no idea
52 # example: example plugin
53 # exception_log: example plugin
54 # *java*: TODO
55 # v8: TODO
56 # matheval: TODO
57 IUSE="apache2 +caps debug +embedded expat jemalloc json libressl +pcre +routing selinux +ssl +xml yajl yaml zeromq"
58
59 for plugin in ${UWSGI_PLUGINS_STD[@]}; do IUSE="${IUSE} +uwsgi_plugins_${plugin}"; done
60 for plugin in ${UWSGI_PLUGINS_OPT[@]}; do IUSE="${IUSE} uwsgi_plugins_${plugin}"; done
61 IUSE="${IUSE} ${LANG_SUPPORT_SIMPLE[@]} ${LANG_SUPPORT_EXTENDED[@]}"
62
63 REQUIRED_USE="|| ( ${LANG_SUPPORT_SIMPLE[@]} ${LANG_SUPPORT_EXTENDED[@]} )
64         uwsgi_plugins_logcrypto? ( ssl )
65         uwsgi_plugins_sslrouter? ( ssl )
66         routing? ( pcre )
67         uwsgi_plugins_emperor_zeromq? ( zeromq )
68         uwsgi_plugins_forkptyrouter? ( uwsgi_plugins_corerouter )
69         uwsgi_plugins_router_xmldir? ( xml !expat )
70         python? ( ${PYTHON_REQUIRED_USE} )
71         python-asyncio? ( || ( $(python_gen_useflags -3) ) python-gevent )
72         python-gevent? ( python )
73         expat? ( xml )"
74
75 # util-linux is required for libuuid when requesting zeromq support
76 # Order:
77 # 1. Unconditional
78 # 2. General features
79 # 3. Plugins
80 # 4. Language/app support
81 CDEPEND="sys-libs/zlib
82         caps? ( sys-libs/libcap )
83         json? ( !yajl? ( dev-libs/jansson )
84                 yajl? ( dev-libs/yajl ) )
85         pcre? ( dev-libs/libpcre:3 )
86         ssl? (
87                 !libressl? ( dev-libs/openssl:0 )
88                 libressl? ( dev-libs/libressl )
89         )
90         xml? ( !expat? ( dev-libs/libxml2 )
91                 expat? ( dev-libs/expat ) )
92         yaml? ( dev-libs/libyaml )
93         zeromq? ( net-libs/zeromq sys-apps/util-linux )
94         uwsgi_plugins_alarm_curl? ( net-misc/curl )
95         uwsgi_plugins_alarm_xmpp? ( net-libs/gloox )
96         uwsgi_plugins_curl_cron? ( net-misc/curl )
97         uwsgi_plugins_emperor_pg? ( dev-db/postgresql:= )
98         uwsgi_plugins_geoip? ( dev-libs/geoip )
99         uwsgi_plugins_ldap? ( net-nds/openldap )
100         uwsgi_plugins_pam? ( sys-libs/pam )
101         uwsgi_plugins_sqlite? ( dev-db/sqlite:3 )
102         uwsgi_plugins_rados? ( sys-cluster/ceph )
103         uwsgi_plugins_router_access? ( sys-apps/tcp-wrappers )
104         uwsgi_plugins_router_spnego? ( virtual/krb5 )
105         uwsgi_plugins_systemd_logger? ( sys-apps/systemd )
106         uwsgi_plugins_webdav? ( dev-libs/libxml2 )
107         uwsgi_plugins_xslt? ( dev-libs/libxslt )
108         go? ( sys-devel/gcc:=[go] )
109         lua? ( dev-lang/lua:= )
110         perl? ( dev-lang/perl:= )
111         php? (
112                 php_targets_php7-2? ( dev-lang/php:7.2[embed] )
113                 php_targets_php7-3? ( dev-lang/php:7.3[embed] )
114                 php_targets_php7-4? ( dev-lang/php:7.4[embed] )
115         )
116         python? ( ${PYTHON_DEPS} )
117         python-gevent? ( >=dev-python/gevent-1.2.1[${PYTHON_USEDEP}] )
118         ruby? ( $(ruby_implementations_depend) )"
119 DEPEND="${CDEPEND}
120         virtual/pkgconfig"
121 RDEPEND="${CDEPEND}
122         selinux? ( sec-policy/selinux-uwsgi )
123         uwsgi_plugins_rrdtool? ( net-analyzer/rrdtool )"
124
125 want_apache2
126
127 S="${WORKDIR}/${MY_P}"
128 APXS2_S="${S}/apache2"
129 APACHE2_MOD_CONF="42_mod_uwsgi-r2 42_mod_uwsgi"
130
131 # FIXME: is this patch still useful?
132 PATCHES=(
133         "${FILESDIR}/2.0.14-php-plugin.patch"
134 )
135
136 src_unpack() {
137         default
138 }
139
140 pkg_setup() {
141         python_setup
142         use ruby && ruby-ng_pkg_setup
143         depend.apache_pkg_setup
144 }
145
146 src_prepare() {
147         default
148
149         sed -i \
150                 -e "s|'-O2', ||" \
151                 -e "s|'-Werror', ||" \
152                 -e "s|uc.get('plugin_dir')|uc.get('plugin_build_dir')|" \
153                 uwsgiconfig.py || die "sed failed"
154
155         sed -i \
156                 -e "s|/lib|/$(get_libdir)|" \
157                 plugins/php/uwsgiplugin.py || die "sed failed"
158 }
159
160 src_configure() {
161         local embedded_plugins=()
162         local plugins=()
163         local malloc_impl="libc"
164         local json="false"
165         local xml="false"
166
167         for p in ${UWSGI_PLUGINS_STD[@]} ${UWSGI_PLUGINS_OPT[@]} ; do
168                 use uwsgi_plugins_${p} && embedded_plugins+=("${p}")
169         done
170         for p in ${LANG_SUPPORT_SIMPLE[@]} ; do
171                 use ${p} && plugins+=("${p}")
172         done
173
174         # do not embed any plugins
175         if ! use embedded; then
176                 plugins=( ${plugins[@]} ${embedded_plugins[@]} )
177                 embedded_plugins=()
178         fi
179
180         # flatten the arrays
181         plugins=${plugins[@]}
182         embedded_plugins=${embedded_plugins[@]}
183
184         # rename some of the use flags, language plugins are always real plugins
185         plugins="${plugins/perl/psgi}"
186         plugins="${plugins/sqlite/sqlite3}"
187         embedded_plugins="${embedded_plugins/sqlite/sqlite3}"
188
189         # override defaults as requested by the user
190         if use xml; then
191                 use expat && xml="expat" || xml="libxml2"
192         fi
193         if use json; then
194                 use yajl && json="yajl" || json="jansson"
195         fi
196         use jemalloc && malloc_impl="jemalloc"
197
198         # prepare the buildconf for gentoo
199         cp "${FILESDIR}"/gentoo.buildconf buildconf/gentoo.ini || die
200         sed -i \
201                 -e "s|VAR_XML|${xml}|" \
202                 -e "s|VAR_YAML|$(usex yaml libyaml true)|" \
203                 -e "s|VAR_JSON|${json}|" \
204                 -e "s|VAR_SSL|$(usex ssl true false)|" \
205                 -e "s|VAR_PCRE|$(usex pcre true false)|" \
206                 -e "s|VAR_ZMQ|$(usex zeromq true false)|" \
207                 -e "s|VAR_ROUTING|$(usex routing true false)|" \
208                 -e "s|VAR_DEBUG|$(usex debug true false)|" \
209                 -e "s|VAR_MALLOC|${malloc_impl}|" \
210                 -e "s|VAR_PLUGINS|${plugins// /, }|" \
211                 -e "s|VAR_PLUGIN_DIR|${EPREFIX}/usr/$(get_libdir)/uwsgi|" \
212                 -e "s|VAR_BUILD_DIR|${T}/plugins|" \
213                 -e "s|VAR_EMBEDDED|${embedded_plugins// /, }|" \
214                 buildconf/gentoo.ini || die "sed failed"
215
216         if ! use caps; then
217                 sed -i -e 's|sys/capability.h|DISABLED|' uwsgiconfig.py || die "sed failed"
218         fi
219
220         if ! use zeromq; then
221                 sed -i -e 's|uuid/uuid.h|DISABLED|' uwsgiconfig.py || die "sed failed"
222         fi
223
224         if use uwsgi_plugins_emperor_pg ; then
225                 PGPV="$(best_version dev-db/postgresql)"
226                 PGSLOT="$(get_version_component_range 1-2 ${PGPV##dev-db/postgresql-})"
227                 sed -i \
228                         -e "s|pg_config|pg_config${PGSLOT/.}|" \
229                         plugins/emperor_pg/uwsgiplugin.py || die "sed failed"
230         fi
231 }
232
233 each_ruby_compile() {
234         cd "${WORKDIR}/${MY_P}" || die "sed failed"
235
236         UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rack gentoo rack_${RUBY##*/} || die "building plugin for ${RUBY} failed"
237         UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/fiber gentoo fiber_${RUBY##*/}|| die "building fiber plugin for ${RUBY} failed"
238         UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rbthreads gentoo rbthreads_${RUBY##*/}|| die "building rbthreads plugin for ${RUBY} failed"
239 }
240
241 python_compile_plugins() {
242         local EPYV
243         local PYV
244         EPYV=${EPYTHON/.}
245         PYV=${EPYV/python}
246
247         ${PYTHON} uwsgiconfig.py --plugin plugins/python gentoo ${EPYV} || die "building plugin for ${EPYTHON} failed"
248
249         if use python-asyncio ; then
250                 if [[ "${PYV}" == "34" || "${PYV}" == "35" ]] ; then
251                         ${PYTHON} uwsgiconfig.py --plugin plugins/asyncio gentoo asyncio${PYV} || die "building plugin for asyncio-support in ${EPYTHON} failed"
252                 fi
253         fi
254
255         if use python-gevent ; then
256                 ${PYTHON} uwsgiconfig.py --plugin plugins/gevent gentoo gevent${PYV} || die "building plugin for gevent-support in ${EPYTHON} failed"
257         fi
258 }
259
260 python_install_symlinks() {
261         dosym uwsgi /usr/bin/uwsgi_${EPYTHON/.}
262 }
263
264 src_compile() {
265         mkdir -p "${T}/plugins" || die
266
267         python uwsgiconfig.py --build gentoo || die "building uwsgi failed"
268
269         if use go ; then
270                 python uwsgiconfig.py --plugin plugins/gccgo gentoo || die "building plugin for go failed"
271         fi
272
273         if use lua ; then
274                 # setting the name for the pkg-config file to lua, since we don't have
275                 # slotted lua
276                 UWSGICONFIG_LUAPC="lua" python uwsgiconfig.py --plugin plugins/lua gentoo || die "building plugin for lua failed"
277         fi
278
279         if use php ; then
280                 for s in $(php_get_slots); do
281                         UWSGICONFIG_PHPDIR="/usr/$(get_libdir)/${s}" python uwsgiconfig.py --plugin plugins/php gentoo ${s/.} || die "building plugin for ${s} failed"
282                 done
283         fi
284
285         if use python ; then
286                 python_foreach_impl python_compile_plugins
287         fi
288
289         if use ruby ; then
290                 ruby-ng_src_compile
291         fi
292
293         if use apache2 ; then
294                 for m in proxy_uwsgi Ruwsgi uwsgi ; do
295                         APXS2_ARGS="-c mod_${m}.c"
296                         apache-module_src_compile
297                 done
298         fi
299 }
300
301 src_install() {
302         dobin uwsgi
303         pax-mark m "${D}"/usr/bin/uwsgi
304
305         insinto /usr/$(get_libdir)/uwsgi
306         doins "${T}/plugins"/*.so
307
308         use cgi && dosym uwsgi /usr/bin/uwsgi_cgi
309         use go && dosym uwsgi /usr/bin/uwsgi_go
310         use lua && dosym uwsgi /usr/bin/uwsgi_lua
311         use perl && dosym uwsgi /usr/bin/uwsgi_psgi
312
313         if use php ; then
314                 for s in $(php_get_slots); do
315                         dosym uwsgi /usr/bin/uwsgi_${s/.}
316                 done
317         fi
318
319         if use python ; then
320                 python_foreach_impl python_install_symlinks
321                 python_foreach_impl python_domodule uwsgidecorators.py
322         fi
323
324         if use apache2; then
325                 for m in proxy_uwsgi Ruwsgi uwsgi ; do
326                         APACHE2_MOD_FILE="${APXS2_S}/.libs/mod_${m}.so"
327                         apache-module_src_install
328                 done
329         fi
330
331         newinitd "${FILESDIR}"/uwsgi.initd-r7 uwsgi
332         newconfd "${FILESDIR}"/uwsgi.confd-r4 uwsgi
333         keepdir /etc/"${PN}".d
334         use uwsgi_plugins_spooler && keepdir /var/spool/"${PN}"
335 }
336
337 pkg_postinst() {
338         if use apache2 ; then
339                 elog "Three Apache modules have been installed: mod_proxy_uwsgi, mod_uwsgi and mod_Ruwsgi."
340                 elog "You can enable them with -D PROXY_UWSGI, -DUWSGI or -DRUWSGI in /etc/conf.d/apache2."
341                 elog "mod_uwsgi and mod_Ruwsgi have the same configuration interface and define the same symbols."
342                 elog "Therefore you can enable only one of them at a time."
343                 elog "mod_uwsgi is commercially supported by Unbit and stable but a bit hacky."
344                 elog "mod_Ruwsgi is newer and more Apache-API friendly but not commercially supported."
345                 elog "mod_proxy_uwsgi is a proxy module, considered stable and is now the recommended module."
346         fi
347
348         elog "Append the following options to the uwsgi call to load the respective language plugin:"
349         use cgi    && elog "  '--plugins cgi' for cgi"
350         use lua    && elog "  '--plugins lua' for lua"
351         use perl   && elog "  '--plugins psgi' for perl"
352
353         if use php ; then
354                 for s in $(php_get_slots); do
355                         elog "  '--plugins ${s/.}' for ${s}"
356                 done
357         fi
358
359         python_pkg_postinst() {
360                 local EPYV
361                 local PYV
362                 EPYV=${EPYTHON/.}
363                 PYV=${EPYV/python}
364
365                 elog " "
366                 elog "  '--plugins ${EPYV}' for ${EPYTHON}"
367                 if use python-asyncio ; then
368                         if [[ ${EPYV} == python34 ]] ; then
369                                 elog "  '--plugins ${EPYV},asyncio${PYV}' for asyncio support in ${EPYTHON}"
370                         else
371                                 elog "  (asyncio is only supported in python3.4)"
372                         fi
373                 fi
374                 if use python-gevent ; then
375                         elog "  '--plugins ${EPYV},gevent${PYV}' for gevent support in ${EPYTHON}"
376                 fi
377         }
378
379         use python && python_foreach_impl python_pkg_postinst
380
381         if use ruby ; then
382                 for ruby in $(ruby_get_use_implementations) ; do
383                         elog "  '--plugins rack_${ruby/.}' for ${ruby}"
384                         elog "  '--plugins fiber_${ruby/.}' for ${ruby} fibers"
385                         elog "  '--plugins rbthreads_${ruby/.}' for ${ruby} rbthreads"
386                 done
387         fi
388 }