*/*: Discontinue Gentoo SuperH port
[gentoo.git] / sys-fs / udev / udev-243-r2.ebuild
1 # Copyright 2003-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit bash-completion-r1 linux-info meson ninja-utils multilib-minimal toolchain-funcs udev usr-ldscript
7
8 if [[ ${PV} = 9999* ]]; then
9         EGIT_REPO_URI="https://github.com/systemd/systemd.git"
10         inherit git-r3
11 else
12         MY_PV=${PV/_/-}
13         MY_P=systemd-${MY_PV}
14         S=${WORKDIR}/${MY_P}
15         SRC_URI="https://github.com/systemd/systemd/archive/v${MY_PV}/${MY_P}.tar.gz"
16         KEYWORDS="~alpha amd64 arm arm64 hppa ia64 ~m68k ~mips ppc ppc64 s390 sparc x86"
17 fi
18
19 DESCRIPTION="Linux dynamic and persistent device naming support (aka userspace devfs)"
20 HOMEPAGE="https://www.freedesktop.org/wiki/Software/systemd"
21
22 LICENSE="LGPL-2.1 MIT GPL-2"
23 SLOT="0"
24 IUSE="acl +kmod selinux static-libs"
25
26 RESTRICT="test"
27
28 COMMON_DEPEND=">=sys-apps/util-linux-2.30[${MULTILIB_USEDEP}]
29         sys-libs/libcap[${MULTILIB_USEDEP}]
30         acl? ( sys-apps/acl )
31         kmod? ( >=sys-apps/kmod-16 )
32         selinux? ( >=sys-libs/libselinux-2.1.9 )
33         !<sys-libs/glibc-2.11
34         !sys-apps/gentoo-systemd-integration
35         !sys-apps/systemd"
36 DEPEND="${COMMON_DEPEND}
37         dev-util/gperf
38         >=dev-util/intltool-0.50
39         >=dev-util/meson-0.40.0
40         dev-util/ninja
41         >=sys-apps/coreutils-8.16
42         virtual/os-headers
43         virtual/pkgconfig
44         >=sys-kernel/linux-headers-3.9
45         app-text/docbook-xml-dtd:4.2
46         app-text/docbook-xml-dtd:4.5
47         app-text/docbook-xsl-stylesheets
48         dev-libs/libxslt"
49 RDEPEND="${COMMON_DEPEND}
50         acct-group/kmem
51         acct-group/tty
52         acct-group/audio
53         acct-group/cdrom
54         acct-group/dialout
55         acct-group/disk
56         acct-group/input
57         acct-group/kvm
58         acct-group/lp
59         acct-group/render
60         acct-group/tape
61         acct-group/video
62         !<sys-fs/lvm2-2.02.103
63         !<sec-policy/selinux-base-2.20120725-r10"
64 PDEPEND=">=sys-apps/hwids-20140304[udev]
65         >=sys-fs/udev-init-scripts-26"
66
67 pkg_setup() {
68         if [[ ${MERGE_TYPE} != buildonly ]]; then
69                 CONFIG_CHECK="~BLK_DEV_BSG ~DEVTMPFS ~!IDE ~INOTIFY_USER ~!SYSFS_DEPRECATED ~!SYSFS_DEPRECATED_V2 ~SIGNALFD ~EPOLL ~FHANDLE ~NET ~!FW_LOADER_USER_HELPER ~UNIX"
70                 linux-info_pkg_setup
71
72                 # CONFIG_FHANDLE was introduced by 2.6.39
73                 local MINKV=2.6.39
74
75                 if kernel_is -lt ${MINKV//./ }; then
76                         eerror "Your running kernel is too old to run this version of ${P}"
77                         eerror "You need to upgrade kernel at least to ${MINKV}"
78                 fi
79
80                 if kernel_is -lt 3 7; then
81                         ewarn "Your running kernel is too old to have firmware loader and"
82                         ewarn "this version of ${P} doesn't have userspace firmware loader"
83                         ewarn "If you need firmware support, you need to upgrade kernel at least to 3.7"
84                 fi
85         fi
86 }
87
88 src_prepare() {
89         cat <<-EOF > "${T}"/40-gentoo.rules
90         # Gentoo specific floppy and usb groups
91         ACTION=="add", SUBSYSTEM=="block", KERNEL=="fd[0-9]", GROUP="floppy"
92         ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GROUP="usb"
93         EOF
94
95         if [[ -d "${WORKDIR}/patches" ]]; then
96                 eapply "${WORKDIR}/patches"
97         fi
98
99         default
100 }
101
102 meson_multilib_native_use() {
103         if multilib_is_native_abi && use "$1"; then
104                 echo true
105         else
106                 echo false
107         fi
108 }
109
110 multilib_src_configure() {
111         local emesonargs=(
112                 -Dacl=$(meson_multilib_native_use acl)
113                 -Defi=false
114                 -Dkmod=$(meson_multilib_native_use kmod)
115                 -Dselinux=$(meson_multilib_native_use selinux)
116                 -Dlink-udev-shared=false
117                 -Dsplit-usr=true
118                 -Drootlibdir="${EPREFIX}/usr/$(get_libdir)"
119                 -Dstatic-libudev=$(usex static-libs true false)
120
121                 # Prevent automagic deps
122                 -Dgcrypt=false
123                 -Dlibcryptsetup=false
124                 -Dlibidn=false
125                 -Dlibidn2=false
126                 -Dlibiptc=false
127                 -Dseccomp=false
128                 -Dlz4=false
129                 -Dxz=false
130         )
131         meson_src_configure
132 }
133
134 src_configure() {
135         # Prevent conflicts with i686 cross toolchain, bug 559726
136         tc-export AR CC NM OBJCOPY RANLIB
137         multilib-minimal_src_configure
138 }
139
140 multilib_src_compile() {
141         # meson creates this link
142         local libudev=$(readlink src/udev/libudev.so.1)
143
144         local targets=(
145                 src/udev/${libudev}
146         )
147         if use static-libs; then
148                 targets+=( src/udev/libudev.a )
149         fi
150         if multilib_is_native_abi; then
151                 targets+=(
152                         systemd-udevd
153                         udevadm
154                         src/udev/ata_id
155                         src/udev/cdrom_id
156                         src/udev/mtd_probe
157                         src/udev/scsi_id
158                         src/udev/v4l_id
159                         man/udev.conf.5
160                         man/systemd.link.5
161                         man/hwdb.7
162                         man/udev.7
163                         man/systemd-udevd.service.8
164                         man/udevadm.8
165                 )
166         fi
167         eninja "${targets[@]}"
168 }
169
170 multilib_src_install() {
171         local libudev=$(readlink src/udev/libudev.so.1)
172
173         dolib.so src/udev/{${libudev},libudev.so.1,libudev.so}
174         gen_usr_ldscript -a udev
175         use static-libs && dolib.a src/udev/libudev.a
176
177         insinto "/usr/$(get_libdir)/pkgconfig"
178         doins src/libudev/libudev.pc
179
180         if multilib_is_native_abi; then
181                 into /
182                 dobin udevadm
183
184                 exeinto /lib/systemd
185                 doexe systemd-udevd
186
187                 exeinto /lib/udev
188                 doexe src/udev/{ata_id,cdrom_id,mtd_probe,scsi_id,v4l_id}
189
190                 rm rules/99-systemd.rules || die
191                 insinto /lib/udev/rules.d
192                 doins rules/*.rules
193
194                 insinto /usr/share/pkgconfig
195                 doins src/udev/udev.pc
196
197                 mv man/systemd-udevd.service.8 man/systemd-udevd.8 || die
198                 rm man/systemd-udevd-{control,kernel}.socket.8 || die
199                 doman man/*.[0-9]
200         fi
201 }
202
203 multilib_src_install_all() {
204         doheader src/libudev/libudev.h
205
206         insinto /etc/udev
207         doins src/udev/udev.conf
208         keepdir /etc/udev/{hwdb.d,rules.d}
209
210         insinto /lib/systemd/network
211         doins network/99-default.link
212
213         # see src_prepare() for content of 40-gentoo.rules
214         insinto /lib/udev/rules.d
215         doins "${T}"/40-gentoo.rules
216         doins "${S}"/rules/*.rules
217
218         dobashcomp shell-completion/bash/udevadm
219
220         insinto /usr/share/zsh/site-functions
221         doins shell-completion/zsh/_udevadm
222
223         einstalldocs
224 }
225
226 pkg_postinst() {
227         mkdir -p "${ROOT%/}"/run
228
229         # "losetup -f" is confused if there is an empty /dev/loop/, Bug #338766
230         # So try to remove it here (will only work if empty).
231         rmdir "${ROOT%/}"/dev/loop 2>/dev/null
232         if [[ -d ${ROOT%/}/dev/loop ]]; then
233                 ewarn "Please make sure your remove /dev/loop,"
234                 ewarn "else losetup may be confused when looking for unused devices."
235         fi
236
237         local fstab="${ROOT%/}"/etc/fstab dev path fstype rest
238         while read -r dev path fstype rest; do
239                 if [[ ${path} == /dev && ${fstype} != devtmpfs ]]; then
240                         ewarn "You need to edit your /dev line in ${fstab} to have devtmpfs"
241                         ewarn "filesystem. Otherwise udev won't be able to boot."
242                         ewarn "See, https://bugs.gentoo.org/453186"
243                 fi
244         done < "${fstab}"
245
246         if [[ -d ${ROOT%/}/usr/lib/udev ]]; then
247                 ewarn
248                 ewarn "Please re-emerge all packages on your system which install"
249                 ewarn "rules and helpers in /usr/lib/udev. They should now be in"
250                 ewarn "/lib/udev."
251                 ewarn
252                 ewarn "One way to do this is to run the following command:"
253                 ewarn "emerge -av1 \$(qfile -q -S -C /usr/lib/udev)"
254                 ewarn "Note that qfile can be found in app-portage/portage-utils"
255         fi
256
257         local old_cd_rules="${ROOT%/}"/etc/udev/rules.d/70-persistent-cd.rules
258         local old_net_rules="${ROOT%/}"/etc/udev/rules.d/70-persistent-net.rules
259         for old_rules in "${old_cd_rules}" "${old_net_rules}"; do
260                 if [[ -f ${old_rules} ]]; then
261                         ewarn
262                         ewarn "File ${old_rules} is from old udev installation but if you still use it,"
263                         ewarn "rename it to something else starting with 70- to silence this deprecation"
264                         ewarn "warning."
265                 fi
266         done
267
268         elog
269         elog "Starting from version >= 197 the new predictable network interface names are"
270         elog "used by default, see:"
271         elog "https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames"
272         elog "https://cgit.freedesktop.org/systemd/systemd/tree/src/udev/udev-builtin-net_id.c"
273         elog
274         elog "Example command to get the information for the new interface name before booting"
275         elog "(replace <ifname> with, for example, eth0):"
276         elog "# udevadm test-builtin net_id /sys/class/net/<ifname> 2> /dev/null"
277         elog
278         elog "You can use either kernel parameter \"net.ifnames=0\", create empty"
279         elog "file /etc/systemd/network/99-default.link, or symlink it to /dev/null"
280         elog "to disable the feature."
281
282         if has_version 'sys-apps/biosdevname'; then
283                 ewarn
284                 ewarn "You can replace the functionality of sys-apps/biosdevname which has been"
285                 ewarn "detected to be installed with the new predictable network interface names."
286         fi
287
288         ewarn
289         ewarn "You need to restart udev as soon as possible to make the upgrade go"
290         ewarn "into effect."
291         ewarn "The method you use to do this depends on your init system."
292         if has_version 'sys-apps/openrc'; then
293                 ewarn "For sys-apps/openrc users it is:"
294                 ewarn "# /etc/init.d/udev --nodeps restart"
295         fi
296
297         elog
298         elog "For more information on udev on Gentoo, upgrading, writing udev rules, and"
299         elog "fixing known issues visit:"
300         elog "https://wiki.gentoo.org/wiki/Udev"
301         elog "https://wiki.gentoo.org/wiki/Udev/upgrade"
302
303         # If user has disabled 80-net-name-slot.rules using a empty file or a symlink to /dev/null,
304         # do the same for 80-net-setup-link.rules to keep the old behavior
305         local net_move=no
306         local net_name_slot_sym=no
307         local net_rules_path="${ROOT%/}"/etc/udev/rules.d
308         local net_name_slot="${net_rules_path}"/80-net-name-slot.rules
309         local net_setup_link="${net_rules_path}"/80-net-setup-link.rules
310         if [[ ! -e ${net_setup_link} ]]; then
311                 [[ -f ${net_name_slot} && $(sed -e "/^#/d" -e "/^\W*$/d" ${net_name_slot} | wc -l) == 0 ]] && net_move=yes
312                 if [[ -L ${net_name_slot} && $(readlink ${net_name_slot}) == /dev/null ]]; then
313                         net_move=yes
314                         net_name_slot_sym=yes
315                 fi
316         fi
317         if [[ ${net_move} == yes ]]; then
318                 ebegin "Copying ${net_name_slot} to ${net_setup_link}"
319
320                 if [[ ${net_name_slot_sym} == yes ]]; then
321                         ln -nfs /dev/null "${net_setup_link}"
322                 else
323                         cp "${net_name_slot}" "${net_setup_link}"
324                 fi
325                 eend $?
326         fi
327
328         # Update hwdb database in case the format is changed by udev version.
329         if has_version 'sys-apps/hwids[udev]'; then
330                 udevadm hwdb --update --root="${ROOT%/}"
331                 # Only reload when we are not upgrading to avoid potential race w/ incompatible hwdb.bin and the running udevd
332                 # https://cgit.freedesktop.org/systemd/systemd/commit/?id=1fab57c209035f7e66198343074e9cee06718bda
333                 [[ -z ${REPLACING_VERSIONS} ]] && udev_reload
334         fi
335 }