1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 python3_{5,6,7} pypy )
7 PYTHON_REQ_USE="threads(+)"
10 USE_RUBY="ruby23 ruby24 ruby25"
14 PHP_EXT_OPTIONAL_USE="php"
15 USE_PHP="php5-6 php7-1 php7-2 php7-3" # deps must be registered separately below
19 inherit eapi7-ver eutils flag-o-matic multilib pax-utils php-ext-source-r3 python-r1 ruby-ng
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"
27 KEYWORDS="~amd64 ~arm ~x86 ~amd64-linux"
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}
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 )
44 LANG_SUPPORT_SIMPLE=( cgi mono perl ) # plugins which can be built in the main build process
45 LANG_SUPPORT_EXTENDED=( go lua php pypy python python_asyncio python_gevent ruby )
47 # plugins to be ignored (for now):
48 # cheaper_backlog2: example plugin
50 # cplusplus: partially example code, needs explicit class
52 # example: example plugin
53 # exception_log: example plugin
57 IUSE="apache2 +caps debug +embedded expat jemalloc json libressl +pcre +routing selinux +ssl +xml yajl yaml zeromq"
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[@]}"
63 REQUIRED_USE="|| ( ${LANG_SUPPORT_SIMPLE[@]} ${LANG_SUPPORT_EXTENDED[@]} )
64 uwsgi_plugins_logcrypto? ( ssl )
65 uwsgi_plugins_sslrouter? ( ssl )
67 uwsgi_plugins_emperor_zeromq? ( zeromq )
68 uwsgi_plugins_forkptyrouter? ( uwsgi_plugins_corerouter )
69 uwsgi_plugins_router_xmldir? ( xml !expat )
70 pypy? ( python_targets_python2_7 )
71 python? ( ${PYTHON_REQUIRED_USE} )
72 python_asyncio? ( || ( $(python_gen_useflags -3) ) )
73 python_gevent? ( python )
76 # util-linux is required for libuuid when requesting zeromq support
81 # 4. Language/app support
84 caps? ( sys-libs/libcap )
86 !yajl? ( dev-libs/jansson )
87 yajl? ( dev-libs/yajl )
89 pcre? ( dev-libs/libpcre:3 )
91 !libressl? ( dev-libs/openssl:0= )
92 libressl? ( dev-libs/libressl )
95 !expat? ( dev-libs/libxml2 )
96 expat? ( dev-libs/expat )
98 yaml? ( dev-libs/libyaml )
99 zeromq? ( net-libs/zeromq sys-apps/util-linux )
100 uwsgi_plugins_alarm_curl? ( net-misc/curl )
101 uwsgi_plugins_alarm_xmpp? ( net-libs/gloox )
102 uwsgi_plugins_curl_cron? ( net-misc/curl )
103 uwsgi_plugins_emperor_pg? ( dev-db/postgresql:= )
104 uwsgi_plugins_geoip? ( dev-libs/geoip )
105 uwsgi_plugins_ldap? ( net-nds/openldap )
106 uwsgi_plugins_pam? ( sys-libs/pam )
107 uwsgi_plugins_sqlite? ( dev-db/sqlite:3 )
108 uwsgi_plugins_rados? ( sys-cluster/ceph )
109 uwsgi_plugins_router_access? ( sys-apps/tcp-wrappers )
110 uwsgi_plugins_router_spnego? ( virtual/krb5 )
111 uwsgi_plugins_systemd_logger? ( sys-apps/systemd )
112 uwsgi_plugins_webdav? ( dev-libs/libxml2 )
113 uwsgi_plugins_xslt? ( dev-libs/libxslt )
114 go? ( sys-devel/gcc:=[go] )
115 lua? ( dev-lang/lua:= )
116 mono? ( dev-lang/mono:= )
117 perl? ( dev-lang/perl:= )
119 php_targets_php5-6? ( dev-lang/php:5.6[embed] )
120 php_targets_php7-1? ( dev-lang/php:7.1[embed] )
121 php_targets_php7-2? ( dev-lang/php:7.2[embed] )
122 php_targets_php7-3? ( dev-lang/php:7.3[embed] )
124 pypy? ( dev-python/pypy )
125 python? ( ${PYTHON_DEPS} )
126 python_asyncio? ( virtual/python-greenlet[${PYTHON_USEDEP}] )
127 python_gevent? ( >=dev-python/gevent-1.3.5[${PYTHON_USEDEP}] )
128 ruby? ( $(ruby_implementations_depend) )"
132 selinux? ( sec-policy/selinux-uwsgi )
133 uwsgi_plugins_rrdtool? ( net-analyzer/rrdtool )"
135 S="${WORKDIR}/${MY_P}"
138 echo ${PYTHON_USEDEP}
144 use ruby && ruby-ng_pkg_setup
152 -e "s|'-Werror', ||" \
153 -e "s|uc.get('plugin_dir')|uc.get('plugin_build_dir')|" \
154 uwsgiconfig.py || die "sed failed"
157 -e "s|/lib|/$(get_libdir)|" \
158 plugins/php/uwsgiplugin.py || die "sed failed"
162 local embedded_plugins=()
164 local malloc_impl="libc"
168 for p in ${UWSGI_PLUGINS_STD[@]} ${UWSGI_PLUGINS_OPT[@]} ; do
169 use uwsgi_plugins_${p} && embedded_plugins+=("${p}")
171 for p in ${LANG_SUPPORT_SIMPLE[@]} ; do
172 use ${p} && plugins+=("${p}")
175 # do not embed any plugins
176 if ! use embedded; then
177 plugins=( ${plugins[@]} ${embedded_plugins[@]} )
182 plugins=${plugins[@]}
183 embedded_plugins=${embedded_plugins[@]}
185 # rename some of the use flags, language plugins are always real plugins
186 plugins="${plugins/perl/psgi}"
187 plugins="${plugins/sqlite/sqlite3}"
188 embedded_plugins="${embedded_plugins/sqlite/sqlite3}"
190 # override defaults as requested by the user
192 use expat && xml="expat" || xml="libxml2"
195 use yajl && json="yajl" || json="jansson"
197 use jemalloc && malloc_impl="jemalloc"
199 # prepare the buildconf for gentoo
200 cp "${FILESDIR}"/gentoo.buildconf buildconf/gentoo.ini || die
202 -e "s|VAR_XML|${xml}|" \
203 -e "s|VAR_YAML|$(usex yaml libyaml true)|" \
204 -e "s|VAR_JSON|${json}|" \
205 -e "s|VAR_SSL|$(usex ssl true false)|" \
206 -e "s|VAR_PCRE|$(usex pcre true false)|" \
207 -e "s|VAR_ZMQ|$(usex zeromq true false)|" \
208 -e "s|VAR_ROUTING|$(usex routing true false)|" \
209 -e "s|VAR_DEBUG|$(usex debug true false)|" \
210 -e "s|VAR_MALLOC|${malloc_impl}|" \
211 -e "s|VAR_PLUGINS|${plugins// /, }|" \
212 -e "s|VAR_PLUGIN_DIR|${EPREFIX}/usr/$(get_libdir)/uwsgi|" \
213 -e "s|VAR_BUILD_DIR|${T}/plugins|" \
214 -e "s|VAR_EMBEDDED|${embedded_plugins// /, }|" \
215 buildconf/gentoo.ini || die "sed failed"
218 sed -i -e 's|sys/capability.h|DISABLED|' uwsgiconfig.py || die "sed failed"
221 if ! use zeromq; then
222 sed -i -e 's|uuid/uuid.h|DISABLED|' uwsgiconfig.py || die "sed failed"
225 if use uwsgi_plugins_emperor_pg ; then
226 PGPV="$(best_version dev-db/postgresql)"
227 PGSLOT="$(ver_cut 1-2 ${PGPV##dev-db/postgresql-})"
229 -e "s|pg_config|pg_config${PGSLOT/.}|" \
230 plugins/emperor_pg/uwsgiplugin.py || die "sed failed"
234 each_ruby_compile() {
235 cd "${WORKDIR}/${MY_P}" || die "sed failed"
237 UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rack gentoo rack_${RUBY##*/} || die "building plugin for ${RUBY} failed"
238 UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/fiber gentoo fiber_${RUBY##*/}|| die "building fiber plugin for ${RUBY} failed"
239 UWSGICONFIG_RUBYPATH="${RUBY}" python uwsgiconfig.py --plugin plugins/rbthreads gentoo rbthreads_${RUBY##*/}|| die "building rbthreads plugin for ${RUBY} failed"
242 python_compile_plugins() {
248 if [[ ${EPYTHON} == pypy* ]]; then
249 einfo "skipping because pypy is not meant to build plugins on its own"
253 ${PYTHON} uwsgiconfig.py --plugin plugins/python gentoo ${EPYV} || die "building plugin for ${EPYTHON} failed"
255 if use python_asyncio ; then
256 if [[ "${PYV}" != "27" ]] ; then
257 ${PYTHON} uwsgiconfig.py --plugin plugins/asyncio gentoo asyncio${PYV} || die "building plugin for asyncio-support in ${EPYTHON} failed"
261 if use python_gevent ; then
262 ${PYTHON} uwsgiconfig.py --plugin plugins/gevent gentoo gevent${PYV} || die "building plugin for gevent-support in ${EPYTHON} failed"
265 if use python_gevent || use python_asyncio; then
266 ${PYTHON} uwsgiconfig.py --plugin plugins/greenlet gentoo greenlet${PYV} || die "building plugin for greenlet-support in ${EPYTHON} failed"
270 if [[ "${PYV}" == "27" ]] ; then
271 # TODO: do some proper patching ? The wiki didn't help... I gave up for now.
272 # QA: RWX --- --- usr/lib64/uwsgi/pypy_plugin.so
273 append-ldflags -Wl,-z,noexecstack
274 ${PYTHON} uwsgiconfig.py --plugin plugins/pypy gentoo pypy || die "building plugin for pypy-support in ${EPYTHON} failed"
279 python_install_symlinks() {
280 dosym uwsgi /usr/bin/uwsgi_${EPYTHON/.}
284 mkdir -p "${T}/plugins" || die
286 python uwsgiconfig.py --build gentoo || die "building uwsgi failed"
289 python uwsgiconfig.py --plugin plugins/gccgo gentoo || die "building plugin for go failed"
293 # setting the name for the pkg-config file to lua, since we don't have
295 UWSGICONFIG_LUAPC="lua" python uwsgiconfig.py --plugin plugins/lua gentoo || die "building plugin for lua failed"
299 for s in $(php_get_slots); do
300 UWSGICONFIG_PHPDIR="/usr/$(get_libdir)/${s}" python uwsgiconfig.py --plugin plugins/php gentoo ${s/.} || die "building plugin for ${s} failed"
305 python_foreach_impl python_compile_plugins
315 pax-mark m "${D}"/usr/bin/uwsgi
317 insinto /usr/$(get_libdir)/uwsgi
318 doins "${T}/plugins"/*.so
320 use cgi && dosym uwsgi /usr/bin/uwsgi_cgi
321 use go && dosym uwsgi /usr/bin/uwsgi_go
322 use lua && dosym uwsgi /usr/bin/uwsgi_lua
323 use mono && dosym uwsgi /usr/bin/uwsgi_mono
324 use perl && dosym uwsgi /usr/bin/uwsgi_psgi
327 for s in $(php_get_slots); do
328 dosym uwsgi /usr/bin/uwsgi_${s/.}
333 python_foreach_impl python_install_symlinks
334 python_foreach_impl python_domodule uwsgidecorators.py
337 newinitd "${FILESDIR}"/uwsgi.initd-r7 uwsgi
338 newconfd "${FILESDIR}"/uwsgi.confd-r4 uwsgi
339 keepdir /etc/"${PN}".d
340 use uwsgi_plugins_spooler && keepdir /var/spool/"${PN}"
344 if use apache2 ; then
345 ewarn "As reported on bug #650776 [1], Apache module mod_proxy_uwsgi"
346 ewarn "is being transferred to upstream Apache since 2.4.30, see [2]."
347 ewarn "We therefore do not build them any more."
348 ewarn " [1] https://bugs.gentoo.org/650776"
349 ewarn " [2] https://github.com/unbit/uwsgi/issues/1636"
352 elog "Append the following options to the uwsgi call to load the respective language plugin:"
353 use cgi && elog " '--plugins cgi' for cgi"
354 use lua && elog " '--plugins lua' for lua"
355 use mono && elog " '--plugins mono' for mono"
356 use perl && elog " '--plugins psgi' for perl"
359 for s in $(php_get_slots); do
360 elog " '--plugins ${s/.}' for ${s}"
364 python_pkg_postinst() {
370 if [[ ${EPYTHON} == pypy* ]] ; then
371 elog " '--plugins pypy' for pypy"
376 elog " '--plugins ${EPYV}' for ${EPYTHON}"
377 if use python_asyncio ; then
378 if [[ ${EPYV} == python34 ]] ; then
379 elog " '--plugins ${EPYV},asyncio${PYV}' for asyncio support in ${EPYTHON}"
381 elog " (asyncio is only supported in python3.4)"
384 if use python_gevent ; then
385 elog " '--plugins ${EPYV},gevent${PYV}' for gevent support in ${EPYTHON}"
389 use python && python_foreach_impl python_pkg_postinst
392 for ruby in $(ruby_get_use_implementations) ; do
393 elog " '--plugins rack_${ruby/.}' for ${ruby}"
394 elog " '--plugins fiber_${ruby/.}' for ${ruby} fibers"
395 elog " '--plugins rbthreads_${ruby/.}' for ${ruby} rbthreads"