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