blob: f1905f881cd6951ae664eb2724d16c9128d7b6af [file] [log] [blame]
Nico Huberc3b02dc2023-08-12 01:13:45 +02001project('flashprogutils', 'c',
Nikolai Artemiev47cb6fc2022-07-22 09:58:14 +10002 version : run_command('util/getversion.sh', '--version', check : true).stdout().strip(),
Nico Huberb417c0c2019-09-24 22:12:40 +02003 license : 'GPL-2.0',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +02004 meson_version : '>=0.53.0',
Anastasia Klimchuk3c508432022-04-13 15:15:24 +10005 default_options : [
6 'warning_level=2',
7 'c_std=c99',
Anastasia Klimchukc676be92022-04-26 14:53:18 +10008 'werror=true',
Anastasia Klimchuk3c508432022-04-13 15:15:24 +10009 'optimization=s',
Nikolai Artemiev47cb6fc2022-07-22 09:58:14 +100010 'debug=false',
11 ],
Richard Hughescb973682018-12-19 11:44:22 +000012)
13
14# libtool versioning
15lt_current = '1'
16lt_revision = '0'
17lt_age = '0'
18lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)
19
Jacob Garber4a84ec22019-07-25 19:12:31 -060020# hide/enable some warnings
Richard Hughescb973682018-12-19 11:44:22 +000021warning_flags = [
Anastasia Klimchukcde70112021-10-25 13:20:26 +110022 '-Wshadow',
23 '-Wmissing-prototypes',
Jacob Garber4a84ec22019-07-25 19:12:31 -060024 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000025 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000026 '-Wno-address-of-packed-member',
27 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000028 '-Wno-missing-braces',
29]
30
Richard Hughescb973682018-12-19 11:44:22 +000031cc = meson.get_compiler('c')
32add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
33add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
Rosen Penev566193f2020-07-18 12:50:16 -070034add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000035add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +020036add_project_arguments('-D__BSD_VISIBLE', language : 'c') # required for u_char, u_int, u_long on FreeBSD
37add_project_arguments('-D__XSI_VISIBLE', language : 'c') # required for gettimeofday() on FreeBSD
38add_project_arguments('-D_NETBSD_SOURCE', language : 'c') # required for indirect include of strings.h on NetBSD
39add_project_arguments('-D_DARWIN_C_SOURCE', language : 'c') # required for indirect include of strings.h on MacOS
Nico Huberc3b02dc2023-08-12 01:13:45 +020040add_project_arguments('-DFLASHPROG_VERSION="' + meson.project_version() + '"', language : 'c')
Richard Hughescb973682018-12-19 11:44:22 +000041
42# get defaults from configure
Thomas Heijligenb975da12022-08-13 12:10:05 +020043config_print_wiki = get_option('classic_cli_print_wiki')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020044config_default_programmer_name = get_option('default_programmer_name')
45config_default_programmer_args = get_option('default_programmer_args')
Richard Hughescb973682018-12-19 11:44:22 +000046
47cargs = []
48deps = []
Thomas Heijligen51208f32022-04-28 11:07:29 +020049srcs = files(
50 '82802ab.c',
51 'at45db.c',
52 'bitbang_spi.c',
53 'edi.c',
54 'en29lv640b.c',
55 'flashchips.c',
Nico Huberc3b02dc2023-08-12 01:13:45 +020056 'flashprog.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020057 'fmap.c',
58 'helpers.c',
Edward O'Callaghan4c76c732022-08-12 11:03:00 +100059 'helpers_fileio.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020060 'ich_descriptors.c',
61 'jedec.c',
62 'layout.c',
Nico Huberc3b02dc2023-08-12 01:13:45 +020063 'libflashprog.c',
Nico Huber0e76d992023-01-12 20:22:55 +010064 'memory_bus.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020065 'opaque.c',
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100066 'parallel.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020067 'print.c',
68 'programmer.c',
69 'programmer_table.c',
70 'sfdp.c',
71 'spi25.c',
72 'spi25_statusreg.c',
73 'spi95.c',
74 'spi.c',
75 'sst28sf040.c',
76 'sst49lfxxxc.c',
77 'sst_fwhub.c',
78 'stm50.c',
79 'udelay.c',
80 'w29ee011.c',
81 'w39.c',
82 'writeprotect.c',
83 'writeprotect_ranges.c',
84)
Richard Hughescb973682018-12-19 11:44:22 +000085
Richard Hughescb973682018-12-19 11:44:22 +000086# check for required symbols
87if cc.has_function('clock_gettime')
88 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
89endif
90if cc.has_function('strnlen')
91 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
92endif
93if cc.check_header('sys/utsname.h')
94 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
95endif
Thomas Heijligenc02b1a92022-04-25 14:54:10 +020096if host_machine.system() in ['cygwin', 'windows']
97 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
98else
99 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
100endif
Richard Hughescb973682018-12-19 11:44:22 +0000101
Peter Stuge272b0732022-12-11 03:55:02 +0100102if host_machine.system() == 'linux'
103 custom_baud_c = 'custom_baud_linux.c'
Peter Stugeb8ee2d62022-12-11 16:20:16 +0100104elif host_machine.system() == 'darwin'
105 custom_baud_c = 'custom_baud_darwin.c'
Peter Stuge272b0732022-12-11 03:55:02 +0100106else
107 custom_baud_c = 'custom_baud.c'
108endif
109
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200110systems_hwaccess = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd' ]
111systems_serial = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd', 'darwin' ]
Richard Hughescb973682018-12-19 11:44:22 +0000112
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200113cpus_port_io = [ 'x86', 'x86_64' ]
Peter Marheine306c8b72022-01-21 02:07:30 +0000114
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200115group_ftdi = get_option('programmer').contains('group_ftdi')
116group_pci = get_option('programmer').contains('group_pci')
117group_usb = get_option('programmer').contains('group_usb')
118group_i2c = get_option('programmer').contains('group_i2c')
119group_serial = get_option('programmer').contains('group_serial')
120group_jlink = get_option('programmer').contains('group_jlink')
Steve Markgraf61899472023-01-09 23:06:52 +0100121group_gpiod = get_option('programmer').contains('group_gpiod')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200122group_internal = get_option('programmer').contains('group_internal')
123group_external = get_option('programmer').contains('group_external')
Peter Marheine306c8b72022-01-21 02:07:30 +0000124
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200125libpci = dependency('libpci', required : group_pci, static : (host_machine.system() == 'openbsd' ? true : false)) # On openbsd a static version of libpci is needed to get also -libz
126libusb1 = dependency('libusb-1.0', required : group_usb)
127libftdi1 = dependency('libftdi1', required : group_ftdi)
128libjaylink = dependency('libjaylink', required : group_jlink)
Steve Markgraf61899472023-01-09 23:06:52 +0100129libgpiod = dependency('libgpiod', required : group_gpiod)
Richard Hughescb973682018-12-19 11:44:22 +0000130
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200131subdir('platform')
Richard Hughescb973682018-12-19 11:44:22 +0000132
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200133if systems_hwaccess.contains(host_machine.system())
Thomas Heijligen4bd966c2022-05-16 10:56:55 +0200134 srcs += files('hwaccess_physmap.c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200135 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
136 srcs += files('hwaccess_x86_msr.c', 'hwaccess_x86_io.c')
Thomas Heijligen140c1262021-09-27 15:12:26 +0200137 endif
Richard Hughescb973682018-12-19 11:44:22 +0000138endif
139
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200140# Pseudo dependencies
141linux_headers = \
142 cc.has_header('linux/i2c.h') and \
143 cc.has_header('linux/i2c-dev.h') and \
144 cc.has_header('mtd/mtd-user.h') and \
145 cc.has_header('linux/spi/spidev.h') ? declare_dependency() : dependency('', required : false)
Thomas Heijligenb975da12022-08-13 12:10:05 +0200146
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200147# '<programmer_name>' : {
148# 'system' : list[string], # default: ['all']
149# 'cpu_families : list[string], # default: ['all']
150# 'deps' : list[dep], # default: []
151# 'groups : list[boolean], # default: []
152# 'srcs' : list[file], # default: []
153# 'flags' : list[string], # default: []
154# 'default' : boolean, # default: true
155# 'active' : boolean, # added on runtime
156# }
157programmer = {
158 'atahpt' : {
159 'systems' : systems_hwaccess,
160 'cpu_families' : cpus_port_io,
161 'deps' : [ libpci ],
162 'groups' : [ group_pci, group_internal ],
163 'srcs' : files('atahpt.c', 'pcidev.c'),
164 'flags' : [ '-DCONFIG_ATAHPT=1' ],
165 'default' : false, # not yet working
166 },
167 'atapromise' : {
168 'systems' : systems_hwaccess,
169 'cpu_families' : cpus_port_io,
170 'deps' : [ libpci ],
171 'groups' : [ group_pci, group_internal ],
172 'srcs' : files('atapromise.c', 'pcidev.c'),
173 'flags' : [ '-DCONFIG_ATAPROMISE=1' ],
174 'default' : false,
175 },
176 'atavia' : {
177 'systems' : systems_hwaccess,
178 'deps' : [ libpci ],
179 'groups' : [ group_pci, group_internal ],
180 'srcs' : files('atavia.c', 'pcidev.c'),
181 'flags' : [ '-DCONFIG_ATAVIA=1' ],
182 },
183 'buspirate_spi' : {
184 'systems' : systems_serial,
185 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100186 'srcs' : files('buspirate_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200187 'flags' : [ '-DCONFIG_BUSPIRATE_SPI=1' ],
188 },
189 'ch341a_spi' : {
190 'deps' : [ libusb1 ],
191 'groups' : [ group_usb, group_external ],
192 'srcs' : files('ch341a_spi.c'),
193 'flags' : [ '-DCONFIG_CH341A_SPI=1' ],
194 },
Nicholas Chin197b7c72022-10-23 13:10:31 -0600195 'ch347_spi' : {
196 'deps' : [ libusb1 ],
197 'groups' : [ group_usb, group_external ],
198 'srcs' : files('ch347_spi.c'),
199 'flags' : [ '-DCONFIG_CH347_SPI=1' ],
200 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200201 'dediprog' : {
202 'deps' : [ libusb1 ],
203 'groups' : [ group_usb, group_external ],
204 'srcs' : files('dediprog.c', 'usbdev.c'),
205 'flags' : [ '-DCONFIG_DEDIPROG=1' ],
206 },
207 'developerbox_spi' : {
208 'deps' : [ libusb1 ],
209 'groups' : [ group_usb, group_external ],
210 'srcs' : files('developerbox_spi.c', 'usbdev.c'),
211 'flags' : [ '-DCONFIG_DEVELOPERBOX_SPI=1' ],
212 },
213 'digilent_spi' : {
214 'deps' : [ libusb1 ],
215 'groups' : [ group_usb, group_external ],
216 'srcs' : files('digilent_spi.c'),
217 'flags' : [ '-DCONFIG_DIGILENT_SPI=1' ],
218 },
219 'dirtyjtag_spi' : {
220 'deps' : [ libusb1 ],
221 'groups' : [ group_usb, group_external ],
222 'srcs' : files('dirtyjtag_spi.c'),
223 'flags' : [ '-DCONFIG_DIRTYJTAG_SPI=1' ],
224 },
225 'drkaiser' : {
226 'systems' : systems_hwaccess,
227 'deps' : [ libpci ],
228 'groups' : [ group_pci, group_internal ],
229 'srcs' : files('drkaiser.c', 'pcidev.c'),
230 'flags' : [ '-DCONFIG_DRKAISER=1' ],
231 },
232 'dummy' : {
233 'srcs' : files('dummyflasher.c'),
234 'flags' : [ '-DCONFIG_DUMMY=1' ],
235 },
236 'ft2232_spi' : {
237 'deps' : [ libftdi1 ],
238 'groups' : [ group_ftdi, group_external ],
239 'srcs' : files('ft2232_spi.c' ),
240 'flags' : [ '-DCONFIG_FT2232_SPI=1' ],
241 },
242 'gfxnvidia' : {
243 'systems' : systems_hwaccess,
244 'deps' : [ libpci ],
245 'groups' : [ group_pci, group_internal ],
246 'srcs' : files('gfxnvidia.c', 'pcidev.c'),
247 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ],
248 },
249 'internal' : {
250 'systems' : systems_hwaccess + ['linux'],
251 'cpu_families' : (host_machine.system() == 'linux' ? [host_machine.cpu_family()] : ['x86', 'x86_64']),
252 'deps' : [ libpci ],
253 'groups' : [ group_internal ],
254 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files(
255 'processor_enable.c',
256 'chipset_enable.c',
257 'board_enable.c',
258 'cbtable.c',
259 'internal.c',
260 'it87spi.c',
261 'sb600spi.c',
262 'amd_imc.c',
Nico Huber735b1862023-01-29 18:28:45 +0000263 'amd_spi100.c',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200264 'wbsio_spi.c',
265 'mcp6x_spi.c',
266 'ichspi.c',
267 'dmi.c',
268 'pcidev.c',
269 'known_boards.c',
270 ) : files(
271 'board_enable.c',
272 'cbtable.c',
273 'chipset_enable.c',
274 'internal.c',
275 'processor_enable.c',
276 'pcidev.c',
277 'known_boards.c',
278 )),
279 'flags' : [
280 '-DCONFIG_INTERNAL=1',
281 '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'),
Nico Huber2f753792023-03-28 00:46:50 +0200282 '-DLINUX_MTD_AS_INTERNAL=' + (host_machine.cpu_family() in ['x86', 'x86_64'] ? '0' : '1'),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200283 ]
284 },
285 'it8212' : {
286 'systems' : systems_hwaccess,
287 'deps' : [ libpci ],
288 'groups' : [ group_pci, group_internal ],
289 'srcs' : files('it8212.c', 'pcidev.c'),
290 'flags' : [ '-DCONFIG_IT8212=1' ],
291 },
292 'jlink_spi' : {
293 'deps' : [ libjaylink ],
294 'groups' : [ group_jlink, group_external ],
295 'srcs' : files('jlink_spi.c'),
296 'flags' : [ '-DCONFIG_JLINK_SPI=1' ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200297 },
Steve Markgraf61899472023-01-09 23:06:52 +0100298 'linux_gpio_spi' : {
299 'systems' : [ 'linux' ],
300 'deps' : [ libgpiod ],
301 'groups' : [ group_gpiod, group_external ],
Nico Huber8d2c0df2024-01-14 23:39:40 +0100302 'srcs' : libgpiod.version() < '2.0.0'
303 ? files('linux_gpio_spi.c')
304 : files('linux_gpio2_spi.c'),
Nico Huberaa5268d2023-03-09 17:15:23 +0100305 'flags' : [ '-DCONFIG_LINUX_GPIO_SPI=1' ],
Steve Markgraf61899472023-01-09 23:06:52 +0100306 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200307 'linux_mtd' : {
308 'systems' : [ 'linux' ],
309 'deps' : [ linux_headers ],
310 'groups' : [ group_internal ],
311 'srcs' : files('linux_mtd.c'),
312 'flags' : [ '-DCONFIG_LINUX_MTD=1' ],
313 },
314 'linux_spi' : {
315 'systems' : [ 'linux' ],
316 'deps' : [ linux_headers ],
317 # internal / external?
318 'srcs' : files('linux_spi.c'),
319 'flags' : [ '-DCONFIG_LINUX_SPI=1' ],
320 },
321 'mstarddc_spi' : {
322 'systems' : [ 'linux' ],
323 'deps' : [ linux_headers ],
324 'groups' : [ group_i2c ],
325 'srcs' : files('mstarddc_spi.c'),
326 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ],
327 'default' : false
328 },
329 'nic3com' : {
330 'systems' : systems_hwaccess,
331 'cpu_families' : cpus_port_io,
332 'deps' : [ libpci ],
333 'groups' : [ group_pci, group_internal ],
334 'srcs' : files('nic3com.c', 'pcidev.c'),
335 'flags' : [ '-DCONFIG_NIC3COM=1' ],
336 },
337 'nicintel' : {
338 'systems' : systems_hwaccess,
339 'deps' : [ libpci ],
340 'groups' : [ group_pci, group_internal ],
341 'srcs' : files('nicintel.c', 'pcidev.c'),
342 'flags' : [ '-DCONFIG_NICINTEL=1' ],
343 },
344 'nicintel_eeprom' : {
345 'systems' : systems_hwaccess,
346 'deps' : [ libpci ],
347 'groups' : [ group_pci, group_internal ],
348 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'),
349 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ],
350 },
351 'nicintel_spi' : {
352 'systems' : systems_hwaccess,
353 'deps' : [ libpci ],
354 'groups' : [ group_pci, group_internal ],
355 'srcs' : files('nicintel_spi.c', 'pcidev.c'),
356 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ],
357 },
358 'nicnatsemi' : {
359 'systems' : systems_hwaccess,
360 'cpu_families' : cpus_port_io,
361 'deps' : [ libpci ],
362 'groups' : [ group_pci, group_internal ],
363 'srcs' : files('nicnatsemi.c', 'pcidev.c'),
364 'flags' : [ '-DCONFIG_NICNATSEMI=1' ],
365 'default' : false, # not complete nor tested
366 },
367 'nicrealtek' : {
368 'systems' : systems_hwaccess,
369 'cpu_families' : cpus_port_io,
370 'deps' : [ libpci ],
371 'groups' : [ group_pci, group_internal ],
372 'srcs' : files('nicrealtek.c', 'pcidev.c'),
373 'flags' : [ '-DCONFIG_NICREALTEK=1' ],
374 },
375 'ogp_spi' : {
376 'systems' : systems_hwaccess,
377 'deps' : [ libpci ],
378 'groups' : [ group_pci, group_internal ],
379 'srcs' : files('ogp_spi.c', 'pcidev.c'),
380 'flags' : [ '-DCONFIG_OGP_SPI=1' ],
381 },
382 'pickit2_spi' : {
383 'deps' : [ libusb1 ],
384 'groups' : [ group_usb, group_external ],
385 'srcs' : files('pickit2_spi.c'),
386 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ],
387 },
388 'pony_spi' : {
389 'systems' : systems_serial,
390 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100391 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200392 'flags' : [ '-DCONFIG_PONY_SPI=1' ],
393 },
394 'rayer_spi' : {
395 'systems' : systems_hwaccess,
396 'cpu_families' : cpus_port_io,
397 'groups' : [ group_internal ],
398 'srcs' : files('rayer_spi.c'),
399 'flags' : [ '-DCONFIG_RAYER_SPI=1' ],
400 },
401 'satamv' : {
402 'systems' : systems_hwaccess,
403 'cpu_families' : cpus_port_io,
404 'deps' : [ libpci ],
405 'groups' : [ group_pci, group_internal ],
406 'srcs' : files('satamv.c', 'pcidev.c'),
407 'flags' : ['-DCONFIG_SATAMV=1'],
408 },
409 'satasii' : {
410 'systems' : systems_hwaccess,
411 'deps' : [ libpci ],
412 'groups' : [ group_pci, group_internal ],
413 'srcs' : files('satasii.c', 'pcidev.c'),
414 'flags' : [ '-DCONFIG_SATASII=1' ],
415 },
416 'serprog' : {
417 'systems' : systems_serial,
418 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100419 'srcs' : files('serprog.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200420 'flags' : [ '-DCONFIG_SERPROG=1' ],
421 },
422 'stlinkv3_spi' : {
423 'deps' : [ libusb1 ],
424 'groups' : [ group_usb, group_external ],
425 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'),
426 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ],
427 },
428 'usbblaster_spi' : {
429 'deps' : [ libftdi1 ],
430 'groups' : [ group_ftdi, group_external ],
431 'srcs' : files('usbblaster_spi.c'),
432 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ],
433 },
434}
435
436active_programmer_count = 0
437foreach p_name, p_data : programmer
438 p_data += {
439 'systems' : p_data.get('systems', ['all']),
440 'cpu_families' : p_data.get('cpu_families', ['all']),
441 'deps' : p_data.get('deps', []),
442 'groups' : p_data.get('groups', []),
443 'srcs' : p_data.get('srcs', []),
444 'flags' : p_data.get('flags', []),
445 'default' : p_data.get('default', true),
446 }
447
448 active = false
449 deps_found = true
450 not_found_dep = ''
451 not_active_message = ''
452 selected_hard = p_name in get_option('programmer')
453 selected_soft = p_data.get('groups').contains(true) or \
454 'all' in get_option('programmer') or \
455 'auto' in get_option('programmer') and p_data.get('default')
456 available = (p_data.get('systems').contains('all') or p_data.get('systems').contains(host_machine.system())) \
457 and (p_data.get('cpu_families').contains('all') or p_data.get('cpu_families').contains(host_machine.cpu_family()))
458
459 foreach dep : p_data.get('deps')
460 if not dep.found()
461 deps_found = false
462 not_found_dep = dep.name()
463 break
464 endif
465 endforeach
466
467 if selected_hard
468 if not available
469 error(p_name + ' selected but not supported on this platform')
470 elif not deps_found
471 error(p_name + ' selected but dependency ' + not_found_dep +'not found')
472 else
473 active = true
474 endif
475 elif selected_soft
476 if not available
477 not_active_message = 'Not available on platform'
478 elif not deps_found
479 not_active_message = 'dependency ' + not_found_dep + ' not found'
480 else
481 active = true
482 endif
483 else
484 not_active_message = 'not selected'
485 endif
486
487 p_data += {
488 'active' : active,
489 'summary' : not_active_message,
490 }
491 programmer += {p_name : p_data}
492 if active
493 active_programmer_count += 1
494 endif
495endforeach
496
497if active_programmer_count == 0
498 error('At least one programmer must be selected')
499endif
500
501# add srcs, cargs & deps from active programmer to global srcs, cargs & deps
502foreach p_name, p_data : programmer
503 if p_data.get('active')
504 srcs += p_data.get('srcs')
505 cargs += p_data.get('flags')
506 deps += p_data.get('deps')
507 endif
508endforeach
Thomas Heijligenb975da12022-08-13 12:10:05 +0200509
510if config_print_wiki.enabled()
511 if get_option('classic_cli').disabled()
512 error('`classic_cli_print_wiki` can not be enabled without `classic_cli`')
513 else
514 srcs += files('print_wiki.c')
515 cargs += '-DCONFIG_PRINT_WIKI=1'
516 endif
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200517endif
518
519if config_default_programmer_name != ''
520 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
521else
522 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
523endif
524
525cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
526
Richard Hughescb973682018-12-19 11:44:22 +0000527install_headers([
Nico Huberc3b02dc2023-08-12 01:13:45 +0200528 'include/libflashprog.h',
Richard Hughescb973682018-12-19 11:44:22 +0000529 ],
530)
531
Thomas Heijligen58015c22022-04-14 13:50:55 +0200532include_dir = include_directories('include')
533
Nico Huberc3b02dc2023-08-12 01:13:45 +0200534mapfile = 'libflashprog.map'
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200535if host_machine.system() == 'darwin'
536 vflag = ''
537else
538 vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
539endif
Nico Huberc3b02dc2023-08-12 01:13:45 +0200540libflashprog = both_libraries(
541 'flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000542 sources : [
543 srcs,
544 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200545 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000546 soversion : lt_current,
547 version : lt_version,
548 dependencies : [
549 deps,
550 ],
551 c_args : [
552 cargs,
553 ],
554 install : true,
555 link_args : vflag,
556 link_depends : mapfile,
557)
558
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500559version = meson.project_version()
560#strip leading characters
561if version.startswith('v')
562 version = version.split('v')[1]
563endif
564if version.startswith('p')
565 version = version.split('p')[1]
566endif
567
Richard Hughescb973682018-12-19 11:44:22 +0000568pkgg = import('pkgconfig')
569pkgg.generate(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200570 libraries : libflashprog,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500571 version : version,
Nico Huberc3b02dc2023-08-12 01:13:45 +0200572 name : 'flashprog',
573 filebase : 'flashprog',
574 description : 'library to interact with flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000575)
576
Felix Singer9818b3f2022-11-29 17:08:03 +0100577config_manfile = configuration_data()
578config_manfile.set('VERSION', version)
579config_manfile.set('MAN_DATE', run_command('util/getversion.sh', '--man-date', check : true).stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000580configure_file(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200581 input : 'flashprog.8.tmpl',
582 output : 'flashprog.8',
Felix Singer9818b3f2022-11-29 17:08:03 +0100583 configuration : config_manfile,
Richard Hughesdad3a162020-02-17 09:57:01 +0000584 install: true,
Thomas Heijligen454a28c2022-05-03 11:50:16 +0200585 install_dir: join_paths(get_option('mandir'), 'man8'),
Richard Hughesdad3a162020-02-17 09:57:01 +0000586)
587
Thomas Heijligena12e0102022-08-13 12:42:05 +0200588if get_option('classic_cli').auto() or get_option('classic_cli').enabled()
589 executable(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200590 'flashprog',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200591 files(
592 'cli_classic.c',
593 'cli_common.c',
594 'cli_output.c',
595 ),
596 c_args : cargs,
597 include_directories : include_dir,
598 install : true,
599 install_dir : get_option('sbindir'),
Nico Huberc3b02dc2023-08-12 01:13:45 +0200600 link_with : libflashprog.get_static_lib(), # flashprog needs internal symbols of libflashprog
Thomas Heijligena12e0102022-08-13 12:42:05 +0200601 )
602endif
Richard Hughescb973682018-12-19 11:44:22 +0000603
Thomas Heijligenb7341b12022-08-13 12:21:44 +0200604if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled()
605 subdir('util/ich_descriptors_tool')
606endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200607
608programmer_names_active = []
609programmer_names_not_active = []
610foreach p_name, p_data : programmer
611 if p_data.get('active')
612 programmer_names_active += p_name
613 else
614 programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')'
615 endif
616endforeach
617
618summary({
619 'active' : [programmer_names_active],
620 'non active' : [programmer_names_not_active],
621}, section : 'Programmer')