app-misc/lirc: Enable py3.7
[gentoo.git] / app-misc / lirc / lirc-0.9.0-r6.ebuild
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=4
5
6 inherit eutils linux-mod linux-info systemd toolchain-funcs flag-o-matic autotools
7
8 DESCRIPTION="decode and send infra-red signals of many commonly used remote controls"
9 HOMEPAGE="http://www.lirc.org/"
10
11 MY_P=${PN}-${PV/_/}
12
13 if [[ "${PV/_pre/}" = "${PV}" ]]; then
14         SRC_URI="mirror://sourceforge/lirc/${MY_P}.tar.bz2"
15 else
16         SRC_URI="http://www.lirc.org/software/snapshots/${MY_P}.tar.bz2"
17 fi
18
19 LICENSE="GPL-2+"
20 SLOT="0"
21 KEYWORDS="amd64 ppc ppc64 x86"
22 IUSE="debug doc hardware-carrier transmitter static-libs X"
23
24 S="${WORKDIR}/${MY_P}"
25
26 RDEPEND="
27         X? (
28                 x11-libs/libX11
29                 x11-libs/libSM
30                 x11-libs/libICE
31         )
32         lirc_devices_alsa_usb? ( media-libs/alsa-lib )
33         lirc_devices_audio? ( >media-libs/portaudio-18 )
34         lirc_devices_irman? ( media-libs/libirman )"
35
36 # 2012-07-17, Ian Stakenvicius
37 # A helper script that scrapes out values for nearly all of the variables below
38 # from lirc's configure.ac is available at
39 # https://dev.gentoo.org/~axs/helper-for-lirc-iuse.sh
40
41 # This are drivers with names matching the
42 # parameter --with-driver=NAME
43 IUSE_LIRC_DEVICES_DIRECT="
44         all userspace accent act200l act220l
45         adaptec alsa_usb animax asusdh atilibusb
46         atiusb audio audio_alsa avermedia avermedia_vdomate
47         avermedia98 awlibusb bestbuy bestbuy2 breakoutbox
48         bte bw6130 caraca chronos commandir
49         cph06x creative creative_infracd
50         devinput digimatrix dsp dvico ea65 ene0100
51         exaudio flyvideo ftdi gvbctv5pci hauppauge
52         hauppauge_dvb hercules_smarttv_stereo i2cuser
53         igorplugusb iguanaIR imon imon_24g imon_knob
54         imon_lcd imon_pad imon_rsc irdeo irdeo_remote
55         irlink irman irreal it87 ite8709
56         knc_one kworld leadtek_0007 leadtek_0010
57         leadtek_pvr2000 livedrive_midi
58         livedrive_seq logitech macmini
59         mediafocusI mouseremote
60         mouseremote_ps2 mp3anywhere mplay nslu2
61         packard_bell parallel pcmak pcmak_usb
62         pctv pixelview_bt878 pixelview_pak
63         pixelview_pro provideo realmagic
64         remotemaster sa1100 samsung sasem sb0540 serial
65         silitek sir slinke streamzap tekram
66         tekram_bt829 tira ttusbir tuxbox tvbox udp uirt2
67         uirt2_raw usb_uirt_raw usbx wpc8769l zotac"
68
69 # drivers that need special handling and
70 # must have another name specified for
71 # parameter --with-driver=NAME
72 IUSE_LIRC_DEVICES_SPECIAL="
73         serial_igor_cesko
74         remote_wonder_plus xboxusb inputlirc"
75
76 IUSE_LIRC_DEVICES="${IUSE_LIRC_DEVICES_DIRECT} ${IUSE_LIRC_DEVICES_SPECIAL}"
77
78 # The following are lists which are used to provide ewarns on incompatibilities
79 # with the kernel:
80
81 #drivers that do not build kernel modules
82 NO_KMOD_BUILT_FOR_DEV="
83         accent bte creative creative_infracd devinput dsp ea65 exaudio
84         ftdi i2cuser irlink irreal livedrive_midi livedrive_seq logitech
85         mediafocusI mouseremote mouseremote_ps2 mp3anywhere mplay mplay2
86         pcmak pcmak_usb pctv realmagic remotemaster silitek tira tira_raw
87         tuxbox udp uirt2 uirt2_raw usb_uirt_raw usbx"
88
89 #drivers that build lirc_dev and so will conflict with kernel lirc_dev
90 LIRCDEV_BUILT_FOR_DEV="all
91         act200l act220l adaptec animax atiusb breakoutbox hauppauge
92         hauppauge_dvb hercules_smarttv_stereo igorplugusb imon imon_24g
93         imon_knob imon_lcd imon_pad imon_rsc irdeo irdeo_remote knc_one
94         leadtek_pvr2000 nslu2 packard_bell parallel pixelview_bt878
95         provideo sa1100 sasem serial sir tekram tekram_bt829 ttusbir
96         tvbox wpc8769l zotac"
97
98 #lirc_gpio drivers, which cannot be supported on kernel >= 2.6.22
99 LIRC_GPIO_DEV="
100         avermedia avermedia98 avermedia_vdomate bestbuy bestbuy2 chronos
101         cph03x cph06x flyvideo gvbctv5pci kworld leadtek_0007 leadtek_0010
102         pixelview_pak pixelview_pro"
103
104 #device-driver which use libusb
105 LIBUSB_USED_BY_DEV="
106         all atilibusb awlibusb sasem igorplugusb imon imon_lcd imon_pad
107         imon_rsc streamzap xboxusb irlink commandir"
108
109 for dev in ${LIBUSB_USED_BY_DEV}; do
110         DEPEND="${DEPEND} lirc_devices_${dev}? ( virtual/libusb:0 )"
111 done
112
113 # adding only compile-time depends
114 DEPEND="${RDEPEND} ${DEPEND}
115         virtual/linux-sources
116         lirc_devices_ftdi? ( dev-embedded/libftdi:0 )
117         lirc_devices_all? ( dev-embedded/libftdi:0 )"
118
119 # adding only run-time depends
120 RDEPEND="${RDEPEND}
121         lirc_devices_inputlirc? ( app-misc/inputlircd )
122         lirc_devices_iguanaIR? ( app-misc/iguanaIR )"
123
124 # add all devices to IUSE
125 # and ensure lirc_devices_all is not set alongside lirc_devices_*
126 REQUIRED_USE="lirc_devices_all? ("
127 for dev in ${IUSE_LIRC_DEVICES}; do
128         IUSE="${IUSE} lirc_devices_${dev}"
129         if [[ "${dev}" != "all" ]]; then
130                 REQUIRED_USE="${REQUIRED_USE} !lirc_devices_${dev}"
131         fi
132 done
133 REQUIRED_USE="${REQUIRED_USE} )"
134
135 add_device() {
136         local dev="${1}"
137         local desc="device ${dev}"
138         if [[ -n "${2}" ]]; then
139                 desc="${2}"
140         fi
141
142         # Bug #187418
143         if kernel_is ge 2 6 22 && [[ " ${LIRC_GPIO_DEV} " == *" ${dev} "* ]]; then
144                 eerror "${desc} uses lirc_gpio which fails with kernel 2.6.22 or above.  Not building."
145                 eerror "Use 'devinput' instead, or use 'userspace' along with in-kernel drivers"
146                 return 0
147         fi
148         : ${lirc_device_count:=0}
149         ((lirc_device_count++))
150
151         elog "Compiling support for ${desc}"
152
153         if [[ " ${LIRCDEV_BUILT_FOR_DEV} " == *" ${dev} "* ]] ; then
154                 if linux_chkconfig_present LIRC ; then
155                         ewarn "${desc} builds lirc_dev and CONFIG_LIRC is set in the kernel -- this may conflict."
156                 fi
157                 if ! linux_chkconfig_present MODULE_UNLOAD ; then
158                         ewarn "${desc} builds modules and CONFIG_MODULE_UNLOAD is unset in kernel."
159                         ewarn "You will need MODULE_UNLOAD support in your kernel."
160                 fi
161         fi
162         if [[ " ${NO_KMOD_BUILT_FOR_DEV} " == *" ${dev} "* ]] && ! linux_chkconfig_present IR_LIRC_CODEC ; then
163                 ewarn "${desc} builds no kernel module and CONFIG_IR_LIRC_CODEC is unset in kernel."
164         fi
165
166         if [[ ${lirc_device_count} -eq 2 ]] ; then
167                 ewarn
168                 ewarn "LIRC_DEVICES has more than one entry."
169                 ewarn "When selecting multiple devices for lirc to be supported,"
170                 ewarn "it can not be guaranteed that the drivers play nice together."
171                 ewarn "If this is not intended, then please adjust LIRC_DEVICES"
172                 ewarn "and re-emerge."
173                 ewarn
174         fi
175
176         MY_OPTS="${MY_OPTS} --with-driver=${dev}"
177 }
178
179 pkg_pretend() {
180         if [[ -n "${LIRC_OPTS}" ]] ; then
181                 ewarn
182                 ewarn "LIRC_OPTS is deprecated from lirc-0.8.0-r1 on."
183                 ewarn
184                 ewarn "Please use LIRC_DEVICES from now on."
185                 ewarn "e.g. LIRC_DEVICES=\"serial sir\""
186                 ewarn
187                 ewarn "Flags are now set per use-flags."
188                 ewarn "e.g. transmitter, hardware-carrier"
189
190                 local opt
191                 local unsupported_opts=""
192
193                 # test for allowed options for LIRC_OPTS
194                 for opt in ${LIRC_OPTS}; do
195                         case ${opt} in
196                                 --with-port=*|--with-irq=*|--with-timer=*|--with-tty=*)
197                                         MY_OPTS="${MY_OPTS} ${opt}"
198                                         ;;
199                                 *)
200                                         unsupported_opts="${unsupported_opts} ${opt}"
201                                         ;;
202                         esac
203                 done
204                 if [[ -n ${unsupported_opts} ]]; then
205                         eerror "These options are no longer allowed to be set"
206                         eerror "with LIRC_OPTS: ${unsupported_opts}"
207                         die "LIRC_OPTS is no longer supported, use LIRC_DEVICES."
208                 fi
209         fi
210 }
211
212 pkg_setup() {
213         linux-mod_pkg_setup
214
215         # set default configure options
216         MY_OPTS=""
217         LIRC_DRIVER_DEVICE="/dev/lirc0"
218
219         if use lirc_devices_all; then
220                 # compile in drivers for a lot of devices
221                 add_device all "a lot of devices"
222         else
223                 # compile in only requested drivers
224                 local dev
225                 for dev in ${IUSE_LIRC_DEVICES_DIRECT}; do
226                         if use lirc_devices_${dev}; then
227                                 add_device ${dev}
228                         fi
229                 done
230
231                 if use lirc_devices_remote_wonder_plus; then
232                         add_device atiusb "device Remote Wonder Plus (atiusb-based)"
233                 fi
234
235                 if use lirc_devices_serial_igor_cesko; then
236                         add_device serial "serial with Igor Cesko design"
237                         MY_OPTS="${MY_OPTS} --with-igor"
238                 fi
239
240                 if use lirc_devices_imon_pad; then
241                         ewarn "The imon_pad driver has incorporated the previous pad2keys patch"
242                         ewarn "and removed the pad2keys_active option for the lirc_imon module"
243                         ewarn "because it is always active."
244                         ewarn "If you have an older imon VFD device, you may need to add the module"
245                         ewarn "option display_type=1 to override autodetection and force VFD mode."
246                 fi
247
248                 if use lirc_devices_xboxusb; then
249                         add_device atiusb "device xboxusb"
250                 fi
251
252                 if [[ "${MY_OPTS}" == "" ]]; then
253                         if [[ "${PROFILE_ARCH}" == "xbox" ]]; then
254                                 # on xbox: use special driver
255                                 add_device atiusb "device xboxusb"
256                         else
257                                 # no driver requested
258                                 elog
259                                 elog "Compiling only the lirc-applications, but no drivers."
260                                 elog "Enable drivers with LIRC_DEVICES if you need them."
261                                 MY_OPTS="--with-driver=none"
262                         fi
263                 fi
264         fi
265
266         use hardware-carrier && MY_OPTS="${MY_OPTS} --without-soft-carrier"
267         use transmitter && MY_OPTS="${MY_OPTS} --with-transmitter"
268
269         einfo
270         einfo "lirc-configure-opts: ${MY_OPTS}"
271         elog  "Setting default lirc-device to ${LIRC_DRIVER_DEVICE}"
272
273         filter-flags -Wl,-O1
274 }
275
276 src_prepare() {
277         # Rip out dos CRLF
278         edos2unix contrib/lirc.rules
279
280         # Apply patches needed for some special device-types
281         use lirc_devices_audio || epatch "${FILESDIR}"/lirc-0.8.4-portaudio_check.patch
282         use lirc_devices_remote_wonder_plus && epatch "${FILESDIR}"/lirc-0.8.3_pre1-remotewonderplus.patch
283
284         # Apply fixes for kernel-2.6.39 and above
285         epatch "${FILESDIR}"/${P}-kernel-2.6.39-fixes.patch
286         # Slightly massaged upstream patch to fix kfifo issues >=2.6.38
287         # for bug 377033
288         epatch "${FILESDIR}"/${P}-atiusb_kfifo.patch
289         # Apply fixes for kernel-3.3 and above (bug 439538)
290         epatch "${FILESDIR}"/${P}-kernel-3.3.0-fixes.patch
291         # Apply fix for missing err() in usb.h for kernel 3.5+ (bug 444736)
292         epatch "${FILESDIR}"/${P}-kernel-3.5-err-fix.patch
293         # Apply fix for missing __devinit __devexit defines in kernel 3.8+ (bug 461532)
294         epatch "${FILESDIR}"/${P}-kernel-3.8-fixes.patch
295         # Add support for zotac remote, bug 342848
296         epatch "${FILESDIR}"/${P}-add-zotac-support.patch
297         # Use fixed font
298         epatch "${FILESDIR}"/${P}-fixed-font.patch
299
300         # Do not build drivers from the top-level Makefile
301         sed -i -e 's:\(SUBDIRS =\) drivers\(.*\):\1\2:' Makefile.am
302
303         # remove parallel driver on SMP systems
304         if linux_chkconfig_present SMP ; then
305                 sed -i -e "s:lirc_parallel\.o::" drivers/lirc_parallel/Makefile.am
306         fi
307
308         # Bug #187418 - only need this part for lirc_devices_all as others die in pkg_setup
309         if use lirc_devices_all && kernel_is ge 2 6 22 ; then
310                 ewarn "Disabling lirc_gpio driver as it does no longer work Kernel 2.6.22+"
311                 sed -i -e "s:lirc_gpio\.o::" drivers/lirc_gpio/Makefile.am
312         fi
313
314         # respect CFLAGS
315         sed -i -e 's:CFLAGS="-O2:CFLAGS=""\n#CFLAGS="-O2:' configure.ac
316
317         # setting default device-node
318         local f
319         for f in configure.ac acconfig.h; do
320                 [[ -f "$f" ]] && sed -i -e '/#define LIRC_DRIVER_DEVICE/d' "$f"
321         done
322         echo "#define LIRC_DRIVER_DEVICE \"${LIRC_DRIVER_DEVICE}\"" >> acconfig.h
323
324         sed -e "s/AM_CONFIG_HEADER/AC_CONFIG_HEADERS/" -i configure.ac || die # automake 1.13
325         eautoreconf
326 }
327
328 src_configure() {
329         econf \
330                 --localstatedir=/var \
331                 --with-syslog=LOG_DAEMON \
332                 --enable-sandboxed \
333                 --with-kerneldir="${KV_DIR}" \
334                 --with-moduledir="/lib/modules/${KV_FULL}/misc" \
335                 $(use_enable debug) \
336                 $(use_enable static-libs static) \
337                 $(use_with X x) \
338                 ${MY_OPTS} \
339                 ABI="${KERNEL_ABI}" \
340                 ARCH="$(tc-arch-kernel)"
341 }
342
343 src_compile() {
344         # force non-parallel make, Bug 196134 (confirmed valid for 0.9.0-r2)
345         emake -j1
346
347         MODULE_NAMES="lirc(misc:${S}/drivers)"
348         BUILD_TARGETS="all"
349         linux-mod_src_compile
350 }
351
352 src_install() {
353         emake DESTDIR="${D}" install
354         emake -C drivers DESTDIR="${D}" install
355
356         newinitd "${FILESDIR}"/lircd-0.8.6-r2 lircd
357         newinitd "${FILESDIR}"/lircmd lircmd
358         newconfd "${FILESDIR}"/lircd.conf.4 lircd
359
360         insinto /etc/modprobe.d/
361         newins "${FILESDIR}"/modprobed.lirc lirc.conf
362
363         newinitd "${FILESDIR}"/irexec-initd-0.8.6-r2 irexec
364         newconfd "${FILESDIR}"/irexec-confd irexec
365
366         systemd_dounit "${FILESDIR}"/irexec.service
367         systemd_dounit "${FILESDIR}"/lirc.service
368         systemd_dounit "${FILESDIR}"/lircm.service
369
370         if use doc ; then
371                 dohtml doc/html/*.html
372                 insinto /usr/share/doc/${PF}/images
373                 doins doc/images/*
374         fi
375
376         insinto /usr/share/lirc/remotes
377         doins -r remotes/*
378
379         keepdir /etc/lirc
380         if [[ -e "${D}"/etc/lirc/lircd.conf ]]; then
381                 newdoc "${D}"/etc/lirc/lircd.conf lircd.conf.example
382         fi
383
384         use static-libs || rm "${D}/usr/$(get_libdir)/liblirc_client.la"
385 }
386
387 pkg_preinst() {
388         linux-mod_pkg_preinst
389
390         local dir="${EROOT}/etc/modprobe.d"
391         if [[ -a "${dir}"/lirc && ! -a "${dir}"/lirc.conf ]]; then
392                 elog "Renaming ${dir}/lirc to lirc.conf"
393                 mv -f "${dir}/lirc" "${dir}/lirc.conf"
394         fi
395
396         # copy the first file that can be found
397         if [[ -f "${EROOT}"/etc/lirc/lircd.conf ]]; then
398                 cp "${EROOT}"/etc/lirc/lircd.conf "${T}"/lircd.conf
399         elif [[ -f "${EROOT}"/etc/lircd.conf ]]; then
400                 cp "${EROOT}"/etc/lircd.conf "${T}"/lircd.conf
401                 MOVE_OLD_LIRCD_CONF=1
402         elif [[ -f "${D}"/etc/lirc/lircd.conf ]]; then
403                 cp "${D}"/etc/lirc/lircd.conf "${T}"/lircd.conf
404         fi
405
406         # stop portage from touching the config file
407         if [[ -e "${D}"/etc/lirc/lircd.conf ]]; then
408                 rm -f "${D}"/etc/lirc/lircd.conf
409         fi
410 }
411
412 pkg_postinst() {
413         linux-mod_pkg_postinst
414
415         # copy config file to new location
416         # without portage knowing about it
417         # so it will not delete it on unmerge or ever touch it again
418         if [[ -e "${T}"/lircd.conf ]]; then
419                 cp "${T}"/lircd.conf "${EROOT}"/etc/lirc/lircd.conf
420                 if [[ "$MOVE_OLD_LIRCD_CONF" = "1" ]]; then
421                         elog "Moved /etc/lircd.conf to /etc/lirc/lircd.conf"
422                         rm -f "${EROOT}"/etc/lircd.conf
423                 fi
424         fi
425
426         einfo "The new default location for lircd.conf is inside of"
427         einfo "/etc/lirc/ directory"
428 }