blob: 940f113eeb47c9a49328aeef15f9c38f03fec82d [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',
Thomas Heijligen51208f32022-04-28 11:07:29 +020064 'opaque.c',
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100065 'parallel.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020066 'print.c',
67 'programmer.c',
68 'programmer_table.c',
69 'sfdp.c',
70 'spi25.c',
71 'spi25_statusreg.c',
72 'spi95.c',
73 'spi.c',
74 'sst28sf040.c',
75 'sst49lfxxxc.c',
76 'sst_fwhub.c',
77 'stm50.c',
78 'udelay.c',
79 'w29ee011.c',
80 'w39.c',
81 'writeprotect.c',
82 'writeprotect_ranges.c',
83)
Richard Hughescb973682018-12-19 11:44:22 +000084
Richard Hughescb973682018-12-19 11:44:22 +000085# check for required symbols
86if cc.has_function('clock_gettime')
87 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
88endif
89if cc.has_function('strnlen')
90 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
91endif
92if cc.check_header('sys/utsname.h')
93 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
94endif
Thomas Heijligenc02b1a92022-04-25 14:54:10 +020095if host_machine.system() in ['cygwin', 'windows']
96 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
97else
98 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
99endif
Richard Hughescb973682018-12-19 11:44:22 +0000100
Peter Stuge272b0732022-12-11 03:55:02 +0100101if host_machine.system() == 'linux'
102 custom_baud_c = 'custom_baud_linux.c'
Peter Stugeb8ee2d62022-12-11 16:20:16 +0100103elif host_machine.system() == 'darwin'
104 custom_baud_c = 'custom_baud_darwin.c'
Peter Stuge272b0732022-12-11 03:55:02 +0100105else
106 custom_baud_c = 'custom_baud.c'
107endif
108
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200109systems_hwaccess = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd' ]
110systems_serial = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd', 'darwin' ]
Richard Hughescb973682018-12-19 11:44:22 +0000111
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200112cpus_port_io = [ 'x86', 'x86_64' ]
Peter Marheine306c8b72022-01-21 02:07:30 +0000113
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200114group_ftdi = get_option('programmer').contains('group_ftdi')
115group_pci = get_option('programmer').contains('group_pci')
116group_usb = get_option('programmer').contains('group_usb')
117group_i2c = get_option('programmer').contains('group_i2c')
118group_serial = get_option('programmer').contains('group_serial')
119group_jlink = get_option('programmer').contains('group_jlink')
Steve Markgraf61899472023-01-09 23:06:52 +0100120group_gpiod = get_option('programmer').contains('group_gpiod')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200121group_internal = get_option('programmer').contains('group_internal')
122group_external = get_option('programmer').contains('group_external')
Peter Marheine306c8b72022-01-21 02:07:30 +0000123
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200124libpci = 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
125libusb1 = dependency('libusb-1.0', required : group_usb)
126libftdi1 = dependency('libftdi1', required : group_ftdi)
127libjaylink = dependency('libjaylink', required : group_jlink)
Steve Markgraf61899472023-01-09 23:06:52 +0100128libgpiod = dependency('libgpiod', required : group_gpiod)
Richard Hughescb973682018-12-19 11:44:22 +0000129
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200130subdir('platform')
Richard Hughescb973682018-12-19 11:44:22 +0000131
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200132if systems_hwaccess.contains(host_machine.system())
Thomas Heijligen4bd966c2022-05-16 10:56:55 +0200133 srcs += files('hwaccess_physmap.c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200134 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
135 srcs += files('hwaccess_x86_msr.c', 'hwaccess_x86_io.c')
Thomas Heijligen140c1262021-09-27 15:12:26 +0200136 endif
Richard Hughescb973682018-12-19 11:44:22 +0000137endif
138
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200139# Pseudo dependencies
140linux_headers = \
141 cc.has_header('linux/i2c.h') and \
142 cc.has_header('linux/i2c-dev.h') and \
143 cc.has_header('mtd/mtd-user.h') and \
144 cc.has_header('linux/spi/spidev.h') ? declare_dependency() : dependency('', required : false)
Thomas Heijligenb975da12022-08-13 12:10:05 +0200145
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200146# '<programmer_name>' : {
147# 'system' : list[string], # default: ['all']
148# 'cpu_families : list[string], # default: ['all']
149# 'deps' : list[dep], # default: []
150# 'groups : list[boolean], # default: []
151# 'srcs' : list[file], # default: []
152# 'flags' : list[string], # default: []
153# 'default' : boolean, # default: true
154# 'active' : boolean, # added on runtime
155# }
156programmer = {
157 'atahpt' : {
158 'systems' : systems_hwaccess,
159 'cpu_families' : cpus_port_io,
160 'deps' : [ libpci ],
161 'groups' : [ group_pci, group_internal ],
162 'srcs' : files('atahpt.c', 'pcidev.c'),
163 'flags' : [ '-DCONFIG_ATAHPT=1' ],
164 'default' : false, # not yet working
165 },
166 'atapromise' : {
167 'systems' : systems_hwaccess,
168 'cpu_families' : cpus_port_io,
169 'deps' : [ libpci ],
170 'groups' : [ group_pci, group_internal ],
171 'srcs' : files('atapromise.c', 'pcidev.c'),
172 'flags' : [ '-DCONFIG_ATAPROMISE=1' ],
173 'default' : false,
174 },
175 'atavia' : {
176 'systems' : systems_hwaccess,
177 'deps' : [ libpci ],
178 'groups' : [ group_pci, group_internal ],
179 'srcs' : files('atavia.c', 'pcidev.c'),
180 'flags' : [ '-DCONFIG_ATAVIA=1' ],
181 },
182 'buspirate_spi' : {
183 'systems' : systems_serial,
184 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100185 'srcs' : files('buspirate_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200186 'flags' : [ '-DCONFIG_BUSPIRATE_SPI=1' ],
187 },
188 'ch341a_spi' : {
189 'deps' : [ libusb1 ],
190 'groups' : [ group_usb, group_external ],
191 'srcs' : files('ch341a_spi.c'),
192 'flags' : [ '-DCONFIG_CH341A_SPI=1' ],
193 },
Nicholas Chin197b7c72022-10-23 13:10:31 -0600194 'ch347_spi' : {
195 'deps' : [ libusb1 ],
196 'groups' : [ group_usb, group_external ],
197 'srcs' : files('ch347_spi.c'),
198 'flags' : [ '-DCONFIG_CH347_SPI=1' ],
199 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200200 'dediprog' : {
201 'deps' : [ libusb1 ],
202 'groups' : [ group_usb, group_external ],
203 'srcs' : files('dediprog.c', 'usbdev.c'),
204 'flags' : [ '-DCONFIG_DEDIPROG=1' ],
205 },
206 'developerbox_spi' : {
207 'deps' : [ libusb1 ],
208 'groups' : [ group_usb, group_external ],
209 'srcs' : files('developerbox_spi.c', 'usbdev.c'),
210 'flags' : [ '-DCONFIG_DEVELOPERBOX_SPI=1' ],
211 },
212 'digilent_spi' : {
213 'deps' : [ libusb1 ],
214 'groups' : [ group_usb, group_external ],
215 'srcs' : files('digilent_spi.c'),
216 'flags' : [ '-DCONFIG_DIGILENT_SPI=1' ],
217 },
218 'dirtyjtag_spi' : {
219 'deps' : [ libusb1 ],
220 'groups' : [ group_usb, group_external ],
221 'srcs' : files('dirtyjtag_spi.c'),
222 'flags' : [ '-DCONFIG_DIRTYJTAG_SPI=1' ],
223 },
224 'drkaiser' : {
225 'systems' : systems_hwaccess,
226 'deps' : [ libpci ],
227 'groups' : [ group_pci, group_internal ],
228 'srcs' : files('drkaiser.c', 'pcidev.c'),
229 'flags' : [ '-DCONFIG_DRKAISER=1' ],
230 },
231 'dummy' : {
232 'srcs' : files('dummyflasher.c'),
233 'flags' : [ '-DCONFIG_DUMMY=1' ],
234 },
235 'ft2232_spi' : {
236 'deps' : [ libftdi1 ],
237 'groups' : [ group_ftdi, group_external ],
238 'srcs' : files('ft2232_spi.c' ),
239 'flags' : [ '-DCONFIG_FT2232_SPI=1' ],
240 },
241 'gfxnvidia' : {
242 'systems' : systems_hwaccess,
243 'deps' : [ libpci ],
244 'groups' : [ group_pci, group_internal ],
245 'srcs' : files('gfxnvidia.c', 'pcidev.c'),
246 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ],
247 },
248 'internal' : {
249 'systems' : systems_hwaccess + ['linux'],
250 'cpu_families' : (host_machine.system() == 'linux' ? [host_machine.cpu_family()] : ['x86', 'x86_64']),
251 'deps' : [ libpci ],
252 'groups' : [ group_internal ],
253 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files(
254 'processor_enable.c',
255 'chipset_enable.c',
256 'board_enable.c',
257 'cbtable.c',
258 'internal.c',
259 'it87spi.c',
260 'sb600spi.c',
261 'amd_imc.c',
Nico Huber735b1862023-01-29 18:28:45 +0000262 'amd_spi100.c',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200263 'wbsio_spi.c',
264 'mcp6x_spi.c',
265 'ichspi.c',
266 'dmi.c',
267 'pcidev.c',
268 'known_boards.c',
269 ) : files(
270 'board_enable.c',
271 'cbtable.c',
272 'chipset_enable.c',
273 'internal.c',
274 'processor_enable.c',
275 'pcidev.c',
276 'known_boards.c',
277 )),
278 'flags' : [
279 '-DCONFIG_INTERNAL=1',
280 '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'),
Nico Huber2f753792023-03-28 00:46:50 +0200281 '-DLINUX_MTD_AS_INTERNAL=' + (host_machine.cpu_family() in ['x86', 'x86_64'] ? '0' : '1'),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200282 ]
283 },
284 'it8212' : {
285 'systems' : systems_hwaccess,
286 'deps' : [ libpci ],
287 'groups' : [ group_pci, group_internal ],
288 'srcs' : files('it8212.c', 'pcidev.c'),
289 'flags' : [ '-DCONFIG_IT8212=1' ],
290 },
291 'jlink_spi' : {
292 'deps' : [ libjaylink ],
293 'groups' : [ group_jlink, group_external ],
294 'srcs' : files('jlink_spi.c'),
295 'flags' : [ '-DCONFIG_JLINK_SPI=1' ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200296 },
Steve Markgraf61899472023-01-09 23:06:52 +0100297 'linux_gpio_spi' : {
298 'systems' : [ 'linux' ],
299 'deps' : [ libgpiod ],
300 'groups' : [ group_gpiod, group_external ],
Nico Huber8d2c0df2024-01-14 23:39:40 +0100301 'srcs' : libgpiod.version() < '2.0.0'
302 ? files('linux_gpio_spi.c')
303 : files('linux_gpio2_spi.c'),
Nico Huberaa5268d2023-03-09 17:15:23 +0100304 'flags' : [ '-DCONFIG_LINUX_GPIO_SPI=1' ],
Steve Markgraf61899472023-01-09 23:06:52 +0100305 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200306 'linux_mtd' : {
307 'systems' : [ 'linux' ],
308 'deps' : [ linux_headers ],
309 'groups' : [ group_internal ],
310 'srcs' : files('linux_mtd.c'),
311 'flags' : [ '-DCONFIG_LINUX_MTD=1' ],
312 },
313 'linux_spi' : {
314 'systems' : [ 'linux' ],
315 'deps' : [ linux_headers ],
316 # internal / external?
317 'srcs' : files('linux_spi.c'),
318 'flags' : [ '-DCONFIG_LINUX_SPI=1' ],
319 },
320 'mstarddc_spi' : {
321 'systems' : [ 'linux' ],
322 'deps' : [ linux_headers ],
323 'groups' : [ group_i2c ],
324 'srcs' : files('mstarddc_spi.c'),
325 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ],
326 'default' : false
327 },
328 'nic3com' : {
329 'systems' : systems_hwaccess,
330 'cpu_families' : cpus_port_io,
331 'deps' : [ libpci ],
332 'groups' : [ group_pci, group_internal ],
333 'srcs' : files('nic3com.c', 'pcidev.c'),
334 'flags' : [ '-DCONFIG_NIC3COM=1' ],
335 },
336 'nicintel' : {
337 'systems' : systems_hwaccess,
338 'deps' : [ libpci ],
339 'groups' : [ group_pci, group_internal ],
340 'srcs' : files('nicintel.c', 'pcidev.c'),
341 'flags' : [ '-DCONFIG_NICINTEL=1' ],
342 },
343 'nicintel_eeprom' : {
344 'systems' : systems_hwaccess,
345 'deps' : [ libpci ],
346 'groups' : [ group_pci, group_internal ],
347 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'),
348 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ],
349 },
350 'nicintel_spi' : {
351 'systems' : systems_hwaccess,
352 'deps' : [ libpci ],
353 'groups' : [ group_pci, group_internal ],
354 'srcs' : files('nicintel_spi.c', 'pcidev.c'),
355 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ],
356 },
357 'nicnatsemi' : {
358 'systems' : systems_hwaccess,
359 'cpu_families' : cpus_port_io,
360 'deps' : [ libpci ],
361 'groups' : [ group_pci, group_internal ],
362 'srcs' : files('nicnatsemi.c', 'pcidev.c'),
363 'flags' : [ '-DCONFIG_NICNATSEMI=1' ],
364 'default' : false, # not complete nor tested
365 },
366 'nicrealtek' : {
367 'systems' : systems_hwaccess,
368 'cpu_families' : cpus_port_io,
369 'deps' : [ libpci ],
370 'groups' : [ group_pci, group_internal ],
371 'srcs' : files('nicrealtek.c', 'pcidev.c'),
372 'flags' : [ '-DCONFIG_NICREALTEK=1' ],
373 },
374 'ogp_spi' : {
375 'systems' : systems_hwaccess,
376 'deps' : [ libpci ],
377 'groups' : [ group_pci, group_internal ],
378 'srcs' : files('ogp_spi.c', 'pcidev.c'),
379 'flags' : [ '-DCONFIG_OGP_SPI=1' ],
380 },
381 'pickit2_spi' : {
382 'deps' : [ libusb1 ],
383 'groups' : [ group_usb, group_external ],
384 'srcs' : files('pickit2_spi.c'),
385 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ],
386 },
387 'pony_spi' : {
388 'systems' : systems_serial,
389 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100390 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200391 'flags' : [ '-DCONFIG_PONY_SPI=1' ],
392 },
393 'rayer_spi' : {
394 'systems' : systems_hwaccess,
395 'cpu_families' : cpus_port_io,
396 'groups' : [ group_internal ],
397 'srcs' : files('rayer_spi.c'),
398 'flags' : [ '-DCONFIG_RAYER_SPI=1' ],
399 },
400 'satamv' : {
401 'systems' : systems_hwaccess,
402 'cpu_families' : cpus_port_io,
403 'deps' : [ libpci ],
404 'groups' : [ group_pci, group_internal ],
405 'srcs' : files('satamv.c', 'pcidev.c'),
406 'flags' : ['-DCONFIG_SATAMV=1'],
407 },
408 'satasii' : {
409 'systems' : systems_hwaccess,
410 'deps' : [ libpci ],
411 'groups' : [ group_pci, group_internal ],
412 'srcs' : files('satasii.c', 'pcidev.c'),
413 'flags' : [ '-DCONFIG_SATASII=1' ],
414 },
415 'serprog' : {
416 'systems' : systems_serial,
417 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100418 'srcs' : files('serprog.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200419 'flags' : [ '-DCONFIG_SERPROG=1' ],
420 },
421 'stlinkv3_spi' : {
422 'deps' : [ libusb1 ],
423 'groups' : [ group_usb, group_external ],
424 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'),
425 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ],
426 },
427 'usbblaster_spi' : {
428 'deps' : [ libftdi1 ],
429 'groups' : [ group_ftdi, group_external ],
430 'srcs' : files('usbblaster_spi.c'),
431 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ],
432 },
433}
434
435active_programmer_count = 0
436foreach p_name, p_data : programmer
437 p_data += {
438 'systems' : p_data.get('systems', ['all']),
439 'cpu_families' : p_data.get('cpu_families', ['all']),
440 'deps' : p_data.get('deps', []),
441 'groups' : p_data.get('groups', []),
442 'srcs' : p_data.get('srcs', []),
443 'flags' : p_data.get('flags', []),
444 'default' : p_data.get('default', true),
445 }
446
447 active = false
448 deps_found = true
449 not_found_dep = ''
450 not_active_message = ''
451 selected_hard = p_name in get_option('programmer')
452 selected_soft = p_data.get('groups').contains(true) or \
453 'all' in get_option('programmer') or \
454 'auto' in get_option('programmer') and p_data.get('default')
455 available = (p_data.get('systems').contains('all') or p_data.get('systems').contains(host_machine.system())) \
456 and (p_data.get('cpu_families').contains('all') or p_data.get('cpu_families').contains(host_machine.cpu_family()))
457
458 foreach dep : p_data.get('deps')
459 if not dep.found()
460 deps_found = false
461 not_found_dep = dep.name()
462 break
463 endif
464 endforeach
465
466 if selected_hard
467 if not available
468 error(p_name + ' selected but not supported on this platform')
469 elif not deps_found
470 error(p_name + ' selected but dependency ' + not_found_dep +'not found')
471 else
472 active = true
473 endif
474 elif selected_soft
475 if not available
476 not_active_message = 'Not available on platform'
477 elif not deps_found
478 not_active_message = 'dependency ' + not_found_dep + ' not found'
479 else
480 active = true
481 endif
482 else
483 not_active_message = 'not selected'
484 endif
485
486 p_data += {
487 'active' : active,
488 'summary' : not_active_message,
489 }
490 programmer += {p_name : p_data}
491 if active
492 active_programmer_count += 1
493 endif
494endforeach
495
496if active_programmer_count == 0
497 error('At least one programmer must be selected')
498endif
499
500# add srcs, cargs & deps from active programmer to global srcs, cargs & deps
501foreach p_name, p_data : programmer
502 if p_data.get('active')
503 srcs += p_data.get('srcs')
504 cargs += p_data.get('flags')
505 deps += p_data.get('deps')
506 endif
507endforeach
Thomas Heijligenb975da12022-08-13 12:10:05 +0200508
509if config_print_wiki.enabled()
510 if get_option('classic_cli').disabled()
511 error('`classic_cli_print_wiki` can not be enabled without `classic_cli`')
512 else
513 srcs += files('print_wiki.c')
514 cargs += '-DCONFIG_PRINT_WIKI=1'
515 endif
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200516endif
517
518if config_default_programmer_name != ''
519 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
520else
521 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
522endif
523
524cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
525
Richard Hughescb973682018-12-19 11:44:22 +0000526install_headers([
Nico Huberc3b02dc2023-08-12 01:13:45 +0200527 'include/libflashprog.h',
Richard Hughescb973682018-12-19 11:44:22 +0000528 ],
529)
530
Thomas Heijligen58015c22022-04-14 13:50:55 +0200531include_dir = include_directories('include')
532
Nico Huberc3b02dc2023-08-12 01:13:45 +0200533mapfile = 'libflashprog.map'
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200534if host_machine.system() == 'darwin'
535 vflag = ''
536else
537 vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
538endif
Nico Huberc3b02dc2023-08-12 01:13:45 +0200539libflashprog = both_libraries(
540 'flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000541 sources : [
542 srcs,
543 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200544 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000545 soversion : lt_current,
546 version : lt_version,
547 dependencies : [
548 deps,
549 ],
550 c_args : [
551 cargs,
552 ],
553 install : true,
554 link_args : vflag,
555 link_depends : mapfile,
556)
557
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500558version = meson.project_version()
559#strip leading characters
560if version.startswith('v')
561 version = version.split('v')[1]
562endif
563if version.startswith('p')
564 version = version.split('p')[1]
565endif
566
Richard Hughescb973682018-12-19 11:44:22 +0000567pkgg = import('pkgconfig')
568pkgg.generate(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200569 libraries : libflashprog,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500570 version : version,
Nico Huberc3b02dc2023-08-12 01:13:45 +0200571 name : 'flashprog',
572 filebase : 'flashprog',
573 description : 'library to interact with flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000574)
575
Felix Singer9818b3f2022-11-29 17:08:03 +0100576config_manfile = configuration_data()
577config_manfile.set('VERSION', version)
578config_manfile.set('MAN_DATE', run_command('util/getversion.sh', '--man-date', check : true).stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000579configure_file(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200580 input : 'flashprog.8.tmpl',
581 output : 'flashprog.8',
Felix Singer9818b3f2022-11-29 17:08:03 +0100582 configuration : config_manfile,
Richard Hughesdad3a162020-02-17 09:57:01 +0000583 install: true,
Thomas Heijligen454a28c2022-05-03 11:50:16 +0200584 install_dir: join_paths(get_option('mandir'), 'man8'),
Richard Hughesdad3a162020-02-17 09:57:01 +0000585)
586
Thomas Heijligena12e0102022-08-13 12:42:05 +0200587if get_option('classic_cli').auto() or get_option('classic_cli').enabled()
588 executable(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200589 'flashprog',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200590 files(
591 'cli_classic.c',
592 'cli_common.c',
593 'cli_output.c',
594 ),
595 c_args : cargs,
596 include_directories : include_dir,
597 install : true,
598 install_dir : get_option('sbindir'),
Nico Huberc3b02dc2023-08-12 01:13:45 +0200599 link_with : libflashprog.get_static_lib(), # flashprog needs internal symbols of libflashprog
Thomas Heijligena12e0102022-08-13 12:42:05 +0200600 )
601endif
Richard Hughescb973682018-12-19 11:44:22 +0000602
Thomas Heijligenb7341b12022-08-13 12:21:44 +0200603if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled()
604 subdir('util/ich_descriptors_tool')
605endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200606
607programmer_names_active = []
608programmer_names_not_active = []
609foreach p_name, p_data : programmer
610 if p_data.get('active')
611 programmer_names_active += p_name
612 else
613 programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')'
614 endif
615endforeach
616
617summary({
618 'active' : [programmer_names_active],
619 'non active' : [programmer_names_not_active],
620}, section : 'Programmer')