profiles/arch/arm64: Unmask py3.8+3.9
[gentoo.git] / net-print / cups / cups-9999.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python2_7 )
7
8 inherit autotools flag-o-matic linux-info xdg multilib-minimal pam systemd toolchain-funcs
9
10 MY_PV="${PV/_rc/rc}"
11 MY_PV="${MY_PV/_beta/b}"
12 MY_P="${PN}-${MY_PV}"
13
14 if [[ ${PV} == *9999 ]]; then
15         inherit git-r3
16         EGIT_REPO_URI="https://github.com/apple/cups.git"
17         if [[ ${PV} != 9999 ]]; then
18                 EGIT_BRANCH=branch-${PV/.9999}
19         fi
20 else
21         #SRC_URI="https://github.com/apple/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
22         SRC_URI="https://github.com/apple/cups/releases/download/v${MY_PV}/${MY_P}-source.tar.gz"
23         if [[ "${PV}" != *_beta* ]] && [[ "${PV}" != *_rc* ]] ; then
24                 KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86 ~m68k-mint"
25         fi
26 fi
27
28 DESCRIPTION="The Common Unix Printing System"
29 HOMEPAGE="https://www.cups.org/"
30
31 LICENSE="Apache-2.0"
32 SLOT="0"
33 IUSE="acl dbus debug kerberos lprng-compat pam selinux +ssl static-libs systemd +threads usb X xinetd zeroconf"
34
35 CDEPEND="
36         app-text/libpaper
37         sys-libs/zlib
38         acl? (
39                 kernel_linux? (
40                         sys-apps/acl
41                         sys-apps/attr
42                 )
43         )
44         dbus? ( >=sys-apps/dbus-1.6.18-r1[${MULTILIB_USEDEP}] )
45         kerberos? ( >=virtual/krb5-0-r1[${MULTILIB_USEDEP}] )
46         !lprng-compat? ( !net-print/lprng )
47         pam? ( sys-libs/pam )
48         ssl? ( >=net-libs/gnutls-2.12.23-r6:0=[${MULTILIB_USEDEP}] )
49         systemd? ( sys-apps/systemd )
50         usb? ( virtual/libusb:1 )
51         X? ( x11-misc/xdg-utils )
52         xinetd? ( sys-apps/xinetd )
53         zeroconf? ( >=net-dns/avahi-0.6.31-r2[${MULTILIB_USEDEP}] )
54 "
55
56 DEPEND="${CDEPEND}"
57 BDEPEND="
58         acct-group/lp
59         acct-group/lpadmin
60         >=virtual/pkgconfig-0-r1[${MULTILIB_USEDEP}]
61 "
62
63 RDEPEND="${CDEPEND}
64         acct-group/lp
65         acct-group/lpadmin
66         selinux? ( sec-policy/selinux-cups )
67 "
68
69 PDEPEND=">=net-print/cups-filters-1.0.43"
70
71 REQUIRED_USE="
72         usb? ( threads )
73 "
74
75 # upstream includes an interactive test which is a nono for gentoo
76 RESTRICT="test"
77
78 # systemd-socket.patch from Fedora
79 PATCHES=(
80         "${FILESDIR}/${PN}-2.2.6-fix-install-perms.patch"
81         "${FILESDIR}/${PN}-1.4.4-nostrip.patch"
82         "${FILESDIR}/${PN}-2.0.2-rename-systemd-service-files.patch"
83         "${FILESDIR}/${PN}-2.0.1-xinetd-installation-fix.patch"
84 )
85
86 MULTILIB_CHOST_TOOLS=(
87         /usr/bin/cups-config
88 )
89
90 S="${WORKDIR}/${MY_P}"
91
92 pkg_setup() {
93         #enewgroup lp -> acct-group/lp
94         # user lp already provided by baselayout
95         #enewuser lp -1 -1 -1 lp
96         #enewgroup lpadmin 106
97
98         if use kernel_linux; then
99                 linux-info_pkg_setup
100                 if  ! linux_config_exists; then
101                         ewarn "Can't check the linux kernel configuration."
102                         ewarn "You might have some incompatible options enabled."
103                 else
104                         # recheck that we don't have usblp to collide with libusb; this should now work in most cases (bug 501122)
105                         if use usb; then
106                                 if linux_chkconfig_present USB_PRINTER; then
107                                         elog "Your USB printers will be managed via libusb. In case you run into problems, "
108                                         elog "please try disabling USB_PRINTER support in your kernel or blacklisting the"
109                                         elog "usblp kernel module."
110                                         elog "Alternatively, just disable the usb useflag for cups (your printer will still work)."
111                                 fi
112                         else
113                                 #here we should warn user that he should enable it so he can print
114                                 if ! linux_chkconfig_present USB_PRINTER; then
115                                         ewarn "If you plan to use USB printers you should enable the USB_PRINTER"
116                                         ewarn "support in your kernel."
117                                         ewarn "Please enable it:"
118                                         ewarn "    CONFIG_USB_PRINTER=y"
119                                         ewarn "in /usr/src/linux/.config or"
120                                         ewarn "    Device Drivers --->"
121                                         ewarn "        USB support  --->"
122                                         ewarn "            [*] USB Printer support"
123                                         ewarn "Alternatively, enable the usb useflag for cups and use the libusb code."
124                                 fi
125                         fi
126                 fi
127         fi
128 }
129
130 src_prepare() {
131         default
132
133         # Remove ".SILENT" rule for verbose output (bug 524338).
134         sed 's#^.SILENT:##g' -i "${S}"/Makedefs.in || die "sed failed"
135
136         # Fix install-sh, posix sh does not have 'function'.
137         sed 's#function gzipcp#gzipcp()#g' -i "${S}/install-sh"
138
139         # Do not add -Werror even for live ebuilds
140         sed '/WARNING_OPTIONS/s@-Werror@@' \
141                 -i config-scripts/cups-compiler.m4 || die
142
143         AT_M4DIR=config-scripts eaclocal
144         eautoconf
145
146         # custom Makefiles
147         multilib_copy_sources
148 }
149
150 multilib_src_configure() {
151         export DSOFLAGS="${LDFLAGS}"
152
153         einfo LINGUAS=\"${LINGUAS}\"
154
155         # explicitly specify compiler wrt bug 524340
156         #
157         # need to override KRB5CONFIG for proper flags
158         # https://github.com/apple/cups/issues/4423
159         local myeconfargs=(
160                 CC="$(tc-getCC)"
161                 CXX="$(tc-getCXX)"
162                 KRB5CONFIG="${EPREFIX}"/usr/bin/${CHOST}-krb5-config
163                 --libdir="${EPREFIX}"/usr/$(get_libdir)
164                 --localstatedir="${EPREFIX}"/var
165                 --with-exe-file-perm=755
166                 --with-rundir="${EPREFIX}"/run/cups
167                 --with-cups-user=lp
168                 --with-cups-group=lp
169                 --with-docdir="${EPREFIX}"/usr/share/cups/html
170                 --with-languages="${LINGUAS}"
171                 --with-system-groups=lpadmin
172                 --with-xinetd="${EPREFIX}"/etc/xinetd.d
173                 $(multilib_native_use_enable acl)
174                 $(use_enable dbus)
175                 $(use_enable debug)
176                 $(use_enable debug debug-guards)
177                 $(use_enable debug debug-printfs)
178                 $(use_enable kerberos gssapi)
179                 $(multilib_native_use_enable pam)
180                 $(use_enable static-libs static)
181                 $(use_enable threads)
182                 $(use_enable ssl gnutls)
183                 $(use_enable systemd)
184                 $(multilib_native_use_enable usb libusb)
185                 $(use_enable zeroconf avahi)
186                 --disable-dnssd
187                 $(multilib_is_native_abi && echo --enable-libpaper || echo --disable-libpaper)
188         )
189
190         if tc-is-static-only; then
191                 myeconfargs+=(
192                         --disable-shared
193                 )
194         fi
195
196         econf "${myeconfargs[@]}"
197
198         # install in /usr/libexec always, instead of using /usr/lib/cups, as that
199         # makes more sense when facing multilib support.
200         sed -i -e "s:SERVERBIN.*:SERVERBIN = \"\$\(BUILDROOT\)${EPREFIX}/usr/libexec/cups\":" Makedefs || die
201         sed -i -e "s:#define CUPS_SERVERBIN.*:#define CUPS_SERVERBIN \"${EPREFIX}/usr/libexec/cups\":" config.h || die
202         sed -i -e "s:cups_serverbin=.*:cups_serverbin=\"${EPREFIX}/usr/libexec/cups\":" cups-config || die
203
204         # additional path corrections needed for prefix, see bug 597728
205         sed \
206                 -e "s:ICONDIR.*:ICONDIR = ${EPREFIX}/usr/share/icons:" \
207                 -e "s:INITDIR.*:INITDIR = ${EPREFIX}/etc:" \
208                 -e "s:DBUSDIR.*:DBUSDIR = ${EPREFIX}/etc/dbus-1:" \
209                 -e "s:MENUDIR.*:MENUDIR = ${EPREFIX}/usr/share/applications:" \
210                 -i Makedefs || die
211 }
212
213 multilib_src_compile() {
214         if multilib_is_native_abi; then
215                 default
216         else
217                 emake libs
218         fi
219 }
220
221 multilib_src_test() {
222         multilib_is_native_abi && default
223 }
224
225 multilib_src_install() {
226         if multilib_is_native_abi; then
227                 emake BUILDROOT="${D}" install
228         else
229                 emake BUILDROOT="${D}" install-libs install-headers
230                 dobin cups-config
231         fi
232 }
233
234 multilib_src_install_all() {
235         dodoc {CHANGES,CREDITS,README}.md
236
237         # move the default config file to docs
238         dodoc "${ED}"/etc/cups/cupsd.conf.default
239         rm -f "${ED}"/etc/cups/cupsd.conf.default
240
241         # clean out cups init scripts
242         rm -rf "${ED}"/etc/{init.d/cups,rc*,pam.d/cups}
243
244         # install our init script
245         local neededservices=(
246                 $(usex zeroconf avahi-daemon '')
247                 $(usex dbus dbus '')
248         )
249         [[ -n ${neededservices[@]} ]] && neededservices="need ${neededservices[@]}"
250         cp "${FILESDIR}"/cupsd.init.d-r3 "${T}"/cupsd || die
251         sed -i \
252                 -e "s/@neededservices@/${neededservices}/" \
253                 "${T}"/cupsd || die
254         doinitd "${T}"/cupsd
255
256         # install our pam script
257         pamd_mimic_system cups auth account
258
259         if use xinetd ; then
260                 # correct path
261                 sed -i \
262                         -e "s:server = .*:server = /usr/libexec/cups/daemon/cups-lpd:" \
263                         "${ED}"/etc/xinetd.d/cups-lpd || die
264                 # it is safer to disable this by default, bug #137130
265                 grep -w 'disable' "${ED}"/etc/xinetd.d/cups-lpd || \
266                         { sed -i -e "s:}:\tdisable = yes\n}:" "${ED}"/etc/xinetd.d/cups-lpd || die ; }
267                 # write permission for file owner (root), bug #296221
268                 fperms u+w /etc/xinetd.d/cups-lpd
269         else
270                 # always configure with --with-xinetd= and clean up later,
271                 # bug #525604
272                 rm -rf "${ED}"/etc/xinetd.d
273         fi
274
275         keepdir /usr/libexec/cups/driver /usr/share/cups/{model,profiles} \
276                 /var/log/cups /var/spool/cups/tmp
277
278         keepdir /etc/cups/{interfaces,ppd,ssl}
279
280         if ! use X ; then
281                 rm -r "${ED}"/usr/share/applications || die
282         fi
283
284         # create /etc/cups/client.conf, bug #196967 and #266678
285         echo "ServerName ${EPREFIX}/run/cups/cups.sock" >> "${ED}"/etc/cups/client.conf
286
287         # the following file is now provided by cups-filters:
288         rm -r "${ED}"/usr/share/cups/banners || die
289
290         # the following are created by the init script
291         rm -r "${ED}"/var/cache/cups || die
292         rm -r "${ED}"/run || die
293
294         # for the special case of running lprng and cups together, bug 467226
295         if use lprng-compat ; then
296                 rm -fv "${ED}"/usr/bin/{lp*,cancel}
297                 rm -fv "${ED}"/usr/sbin/lp*
298                 rm -fv "${ED}"/usr/share/man/man1/{lp*,cancel*}
299                 rm -fv "${ED}"/usr/share/man/man8/lp*
300                 ewarn "Not installing lp... binaries, since the lprng-compat useflag is set."
301                 ewarn "Unless you plan to install an exotic server setup, you most likely"
302                 ewarn "do not want this. Disable the useflag then and all will be fine."
303         fi
304 }
305
306 pkg_preinst() {
307         xdg_pkg_preinst
308 }
309
310 pkg_postinst() {
311         # Update desktop file database and gtk icon cache (bug 370059)
312         xdg_pkg_postinst
313
314         local v
315
316         for v in ${REPLACING_VERSIONS}; do
317                 if ! ver_test ${v} -ge 2.2.2-r2 ; then
318                         echo
319                         ewarn "The cupsd init script switched to using pidfiles. Shutting down"
320                         ewarn "cupsd will fail the next time. To fix this, please run once as root"
321                         ewarn "   killall cupsd ; /etc/init.d/cupsd zap ; /etc/init.d/cupsd start"
322                         echo
323                         break
324                 fi
325         done
326
327         for v in ${REPLACING_VERSIONS}; do
328                 echo
329                 elog "For information about installing a printer and general cups setup"
330                 elog "take a look at: https://wiki.gentoo.org/wiki/Printing"
331                 echo
332                 break
333         done
334 }
335
336 pkg_postrm() {
337         # Update desktop file database and gtk icon cache (bug 370059)
338         xdg_pkg_postrm
339 }