1# SPDX-License-Identifier: LGPL-2.1-or-later
2
3udevadm_sources = files(
4        'udevadm.c',
5        'udevadm.h',
6        'udevadm-control.c',
7        'udevadm-hwdb.c',
8        'udevadm-info.c',
9        'udevadm-lock.c',
10        'udevadm-monitor.c',
11        'udevadm-settle.c',
12        'udevadm-test.c',
13        'udevadm-test-builtin.c',
14        'udevadm-trigger.c',
15        'udevadm-util.c',
16        'udevadm-util.h',
17        'udevadm-wait.c',
18        'udevd.c',
19)
20
21libudevd_core_sources = files(
22        'udev-ctrl.c',
23        'udev-ctrl.h',
24        'udev-event.c',
25        'udev-event.h',
26        'udev-node.c',
27        'udev-node.h',
28        'udev-rules.c',
29        'udev-rules.h',
30        'udev-watch.c',
31        'udev-watch.h',
32        'udev-builtin.c',
33        'udev-builtin.h',
34        'udev-builtin-btrfs.c',
35        'udev-builtin-hwdb.c',
36        'udev-builtin-input_id.c',
37        'udev-builtin-keyboard.c',
38        'udev-builtin-net_id.c',
39        'udev-builtin-net_setup_link.c',
40        'udev-builtin-path_id.c',
41        'udev-builtin-usb_id.c',
42        'udev-netlink.c',
43        'udev-netlink.h',
44        'net/link-config.c',
45        'net/link-config.h',
46)
47
48if conf.get('HAVE_KMOD') == 1
49        libudevd_core_sources += files('udev-builtin-kmod.c')
50endif
51
52if conf.get('HAVE_BLKID') == 1
53        libudevd_core_sources += files('udev-builtin-blkid.c')
54endif
55
56if conf.get('HAVE_ACL') == 1
57        libudevd_core_sources += files('udev-builtin-uaccess.c')
58endif
59
60############################################################
61
62generate_keyboard_keys_list = find_program('generate-keyboard-keys-list.sh')
63keyboard_keys_list_txt = custom_target(
64        'keyboard-keys-list.txt',
65        output : 'keyboard-keys-list.txt',
66        command : [generate_keyboard_keys_list, cpp],
67        capture : true)
68
69generate_keyboard_keys_gperf = find_program('generate-keyboard-keys-gperf.sh')
70fname = 'keyboard-keys-from-name.gperf'
71gperf_file = custom_target(
72        fname,
73        input : keyboard_keys_list_txt,
74        output : fname,
75        command : [generate_keyboard_keys_gperf, '@INPUT@'],
76        capture : true)
77
78fname = 'keyboard-keys-from-name.h'
79keyboard_keys_from_name_h = custom_target(
80        fname,
81        input : gperf_file,
82        output : fname,
83        command : [gperf,
84                   '-L', 'ANSI-C', '-t',
85                   '-N', 'keyboard_lookup_key',
86                   '-H', 'hash_key_name',
87                   '-p', '-C',
88                   '@INPUT@'],
89        capture : true)
90
91############################################################
92
93link_config_gperf_c = custom_target(
94        'link-config-gperf.c',
95        input : 'net/link-config-gperf.gperf',
96        output : 'link-config-gperf.c',
97        command : [gperf, '@INPUT@', '--output-file', '@OUTPUT@'])
98
99############################################################
100
101if get_option('link-udev-shared')
102        udev_link_with = [libshared]
103        udev_rpath = rootlibexecdir
104else
105        udev_link_with = [libshared_static,
106                          libsystemd_static]
107        udev_rpath = ''
108endif
109
110############################################################
111
112udev_includes = [includes, include_directories('net', '.')]
113libudevd_core = static_library(
114        'udev-core',
115        libudevd_core_sources,
116        link_config_gperf_c,
117        keyboard_keys_from_name_h,
118        include_directories : udev_includes,
119        link_with : udev_link_with,
120        dependencies : [libblkid,
121                        libkmod],
122        build_by_default : false)
123
124udev_progs = [['ata_id/ata_id.c'],
125              ['cdrom_id/cdrom_id.c'],
126              ['fido_id/fido_id.c',
127               'fido_id/fido_id_desc.c',
128               'fido_id/fido_id_desc.h'],
129              ['scsi_id/scsi_id.c',
130               'scsi_id/scsi_id.h',
131               'scsi_id/scsi_serial.c',
132               'scsi_id/scsi.h'],
133              ['v4l_id/v4l_id.c'],
134              ['mtd_probe/mtd_probe.c',
135               'mtd_probe/mtd_probe.h',
136               'mtd_probe/probe_smartmedia.c']]
137
138dmi_arches = ['x86', 'x86_64', 'aarch64', 'arm', 'ia64', 'loongarch64', 'mips']
139if dmi_arches.contains(host_machine.cpu_family())
140        udev_progs += [['dmi_memory_id/dmi_memory_id.c']]
141endif
142
143udev_prog_paths = {}
144foreach prog : udev_progs
145        name = prog[0].split('/')[0]
146
147        exe = executable(
148                name,
149                prog,
150                include_directories : includes,
151                dependencies : versiondep,
152                link_with : udev_link_with,
153                install_rpath : udev_rpath,
154                install : true,
155                install_dir : udevlibexecdir)
156
157        udev_prog_paths += {name : exe}
158endforeach
159
160if install_sysconfdir_samples
161        install_data('udev.conf',
162                     install_dir : sysconfdir / 'udev')
163endif
164
165custom_target(
166        'udev.pc',
167        input : 'udev.pc.in',
168        output : 'udev.pc',
169        command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
170        install : pkgconfigdatadir != 'no',
171        install_dir : pkgconfigdatadir)
172
173if install_sysconfdir
174        meson.add_install_script('sh', '-c',
175                                 mkdir_p.format(sysconfdir / 'udev/rules.d'))
176endif
177
178fuzzers += [
179        [files('net/fuzz-link-parser.c'),
180         [libudevd_core,
181          libshared],
182         [threads,
183          libacl],
184         udev_includes],
185
186        [files('fuzz-udev-rules.c'),
187         [libudevd_core,
188          libshared],
189         [threads,
190          libacl]],
191
192        [files('fuzz-udev-rule-parse-value.c')],
193
194        [files('fido_id/fuzz-fido-id-desc.c',
195               'fido_id/fido_id_desc.c')],
196]
197
198tests += [
199        [files('test-udev-event.c'),
200         [libudevd_core,
201          libshared],
202         [threads,
203          libacl]],
204
205        [files('test-udev-node.c'),
206         [libudevd_core,
207          libshared],
208         [threads,
209          libacl]],
210
211        [files('test-udev-builtin.c'),
212         [libudevd_core,
213          libshared],
214         [threads,
215          libacl]],
216
217        [files('test-udev-netlink.c',
218               'udev-netlink.c',
219               'udev-netlink.h')],
220
221        [files('fido_id/test-fido-id-desc.c',
222               'fido_id/fido_id_desc.c')],
223]
224