blob: 171cd0cad5d31024937cdc7910c1f79c6bb89bbf [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',
Nico Huber8d0f4652024-05-04 18:52:51 +020072 'spi25_prepare.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020073 'spi25_statusreg.c',
74 'spi95.c',
75 'spi.c',
76 'sst28sf040.c',
77 'sst49lfxxxc.c',
78 'sst_fwhub.c',
79 'stm50.c',
80 'udelay.c',
81 'w29ee011.c',
82 'w39.c',
83 'writeprotect.c',
84 'writeprotect_ranges.c',
85)
Richard Hughescb973682018-12-19 11:44:22 +000086
Richard Hughescb973682018-12-19 11:44:22 +000087# check for required symbols
88if cc.has_function('clock_gettime')
89 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
90endif
91if cc.has_function('strnlen')
92 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
93endif
94if cc.check_header('sys/utsname.h')
95 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
96endif
Thomas Heijligenc02b1a92022-04-25 14:54:10 +020097if host_machine.system() in ['cygwin', 'windows']
98 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
99else
100 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
101endif
Richard Hughescb973682018-12-19 11:44:22 +0000102
Peter Stuge272b0732022-12-11 03:55:02 +0100103if host_machine.system() == 'linux'
104 custom_baud_c = 'custom_baud_linux.c'
Peter Stugeb8ee2d62022-12-11 16:20:16 +0100105elif host_machine.system() == 'darwin'
106 custom_baud_c = 'custom_baud_darwin.c'
Peter Stuge272b0732022-12-11 03:55:02 +0100107else
108 custom_baud_c = 'custom_baud.c'
109endif
110
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200111systems_hwaccess = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd' ]
112systems_serial = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd', 'darwin' ]
Richard Hughescb973682018-12-19 11:44:22 +0000113
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200114cpus_port_io = [ 'x86', 'x86_64' ]
Nico Huber72c9e402024-04-21 13:07:17 +0200115cpus_raw_mem = [ 'x86', 'x86_64', 'mips', 'mips64', 'ppc', 'ppc64', 'arm', 'aarch64', 'sparc', 'sparc64', 'arc', 'e2k' ]
Peter Marheine306c8b72022-01-21 02:07:30 +0000116
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200117group_ftdi = get_option('programmer').contains('group_ftdi')
118group_pci = get_option('programmer').contains('group_pci')
119group_usb = get_option('programmer').contains('group_usb')
120group_i2c = get_option('programmer').contains('group_i2c')
121group_serial = get_option('programmer').contains('group_serial')
122group_jlink = get_option('programmer').contains('group_jlink')
Steve Markgraf61899472023-01-09 23:06:52 +0100123group_gpiod = get_option('programmer').contains('group_gpiod')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200124group_internal = get_option('programmer').contains('group_internal')
125group_external = get_option('programmer').contains('group_external')
Peter Marheine306c8b72022-01-21 02:07:30 +0000126
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200127libpci = 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
128libusb1 = dependency('libusb-1.0', required : group_usb)
129libftdi1 = dependency('libftdi1', required : group_ftdi)
130libjaylink = dependency('libjaylink', required : group_jlink)
Steve Markgraf61899472023-01-09 23:06:52 +0100131libgpiod = dependency('libgpiod', required : group_gpiod)
Richard Hughescb973682018-12-19 11:44:22 +0000132
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200133subdir('platform')
Richard Hughescb973682018-12-19 11:44:22 +0000134
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200135if systems_hwaccess.contains(host_machine.system())
Thomas Heijligen4bd966c2022-05-16 10:56:55 +0200136 srcs += files('hwaccess_physmap.c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200137 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
138 srcs += files('hwaccess_x86_msr.c', 'hwaccess_x86_io.c')
Thomas Heijligen140c1262021-09-27 15:12:26 +0200139 endif
Richard Hughescb973682018-12-19 11:44:22 +0000140endif
141
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200142# Pseudo dependencies
143linux_headers = \
144 cc.has_header('linux/i2c.h') and \
145 cc.has_header('linux/i2c-dev.h') and \
146 cc.has_header('mtd/mtd-user.h') and \
147 cc.has_header('linux/spi/spidev.h') ? declare_dependency() : dependency('', required : false)
Thomas Heijligenb975da12022-08-13 12:10:05 +0200148
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200149# '<programmer_name>' : {
150# 'system' : list[string], # default: ['all']
151# 'cpu_families : list[string], # default: ['all']
152# 'deps' : list[dep], # default: []
153# 'groups : list[boolean], # default: []
154# 'srcs' : list[file], # default: []
155# 'flags' : list[string], # default: []
156# 'default' : boolean, # default: true
157# 'active' : boolean, # added on runtime
158# }
159programmer = {
160 'atahpt' : {
161 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200162 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200163 'deps' : [ libpci ],
164 'groups' : [ group_pci, group_internal ],
165 'srcs' : files('atahpt.c', 'pcidev.c'),
166 'flags' : [ '-DCONFIG_ATAHPT=1' ],
167 'default' : false, # not yet working
168 },
169 'atapromise' : {
170 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200171 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200172 'deps' : [ libpci ],
173 'groups' : [ group_pci, group_internal ],
174 'srcs' : files('atapromise.c', 'pcidev.c'),
175 'flags' : [ '-DCONFIG_ATAPROMISE=1' ],
176 'default' : false,
177 },
178 'atavia' : {
179 'systems' : systems_hwaccess,
180 'deps' : [ libpci ],
181 'groups' : [ group_pci, group_internal ],
182 'srcs' : files('atavia.c', 'pcidev.c'),
183 'flags' : [ '-DCONFIG_ATAVIA=1' ],
184 },
185 'buspirate_spi' : {
186 'systems' : systems_serial,
187 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100188 'srcs' : files('buspirate_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200189 'flags' : [ '-DCONFIG_BUSPIRATE_SPI=1' ],
190 },
191 'ch341a_spi' : {
192 'deps' : [ libusb1 ],
193 'groups' : [ group_usb, group_external ],
194 'srcs' : files('ch341a_spi.c'),
195 'flags' : [ '-DCONFIG_CH341A_SPI=1' ],
196 },
Nicholas Chin197b7c72022-10-23 13:10:31 -0600197 'ch347_spi' : {
198 'deps' : [ libusb1 ],
199 'groups' : [ group_usb, group_external ],
200 'srcs' : files('ch347_spi.c'),
201 'flags' : [ '-DCONFIG_CH347_SPI=1' ],
202 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200203 'dediprog' : {
204 'deps' : [ libusb1 ],
205 'groups' : [ group_usb, group_external ],
206 'srcs' : files('dediprog.c', 'usbdev.c'),
207 'flags' : [ '-DCONFIG_DEDIPROG=1' ],
208 },
209 'developerbox_spi' : {
210 'deps' : [ libusb1 ],
211 'groups' : [ group_usb, group_external ],
212 'srcs' : files('developerbox_spi.c', 'usbdev.c'),
213 'flags' : [ '-DCONFIG_DEVELOPERBOX_SPI=1' ],
214 },
215 'digilent_spi' : {
216 'deps' : [ libusb1 ],
217 'groups' : [ group_usb, group_external ],
218 'srcs' : files('digilent_spi.c'),
219 'flags' : [ '-DCONFIG_DIGILENT_SPI=1' ],
220 },
221 'dirtyjtag_spi' : {
222 'deps' : [ libusb1 ],
223 'groups' : [ group_usb, group_external ],
224 'srcs' : files('dirtyjtag_spi.c'),
225 'flags' : [ '-DCONFIG_DIRTYJTAG_SPI=1' ],
226 },
227 'drkaiser' : {
228 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200229 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200230 'deps' : [ libpci ],
231 'groups' : [ group_pci, group_internal ],
232 'srcs' : files('drkaiser.c', 'pcidev.c'),
233 'flags' : [ '-DCONFIG_DRKAISER=1' ],
234 },
235 'dummy' : {
236 'srcs' : files('dummyflasher.c'),
237 'flags' : [ '-DCONFIG_DUMMY=1' ],
238 },
239 'ft2232_spi' : {
240 'deps' : [ libftdi1 ],
241 'groups' : [ group_ftdi, group_external ],
242 'srcs' : files('ft2232_spi.c' ),
243 'flags' : [ '-DCONFIG_FT2232_SPI=1' ],
244 },
Nico Huber522160f2024-08-11 11:03:05 +0200245 'ft4222_spi' : {
246 'deps' : [ libusb1 ],
247 'groups' : [ group_usb, group_ftdi, group_external ],
248 'srcs' : files('ft4222_spi.c' ),
249 'flags' : [ '-DCONFIG_FT4222_SPI=1' ],
250 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200251 'gfxnvidia' : {
252 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200253 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200254 'deps' : [ libpci ],
255 'groups' : [ group_pci, group_internal ],
256 'srcs' : files('gfxnvidia.c', 'pcidev.c'),
257 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ],
258 },
259 'internal' : {
260 'systems' : systems_hwaccess + ['linux'],
Nico Huber72c9e402024-04-21 13:07:17 +0200261 'cpu_families' : (host_machine.system() == 'linux' ? [ cpus_raw_mem ] : [ ['x86', 'x86_64'] ]),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200262 'deps' : [ libpci ],
263 'groups' : [ group_internal ],
264 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files(
265 'processor_enable.c',
266 'chipset_enable.c',
267 'board_enable.c',
268 'cbtable.c',
269 'internal.c',
270 'it87spi.c',
271 'sb600spi.c',
272 'amd_imc.c',
Nico Huber735b1862023-01-29 18:28:45 +0000273 'amd_spi100.c',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200274 'wbsio_spi.c',
275 'mcp6x_spi.c',
276 'ichspi.c',
277 'dmi.c',
278 'pcidev.c',
279 'known_boards.c',
280 ) : files(
281 'board_enable.c',
282 'cbtable.c',
283 'chipset_enable.c',
284 'internal.c',
285 'processor_enable.c',
286 'pcidev.c',
287 'known_boards.c',
288 )),
289 'flags' : [
290 '-DCONFIG_INTERNAL=1',
291 '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'),
Nico Huber2f753792023-03-28 00:46:50 +0200292 '-DLINUX_MTD_AS_INTERNAL=' + (host_machine.cpu_family() in ['x86', 'x86_64'] ? '0' : '1'),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200293 ]
294 },
295 'it8212' : {
296 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200297 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200298 'deps' : [ libpci ],
299 'groups' : [ group_pci, group_internal ],
300 'srcs' : files('it8212.c', 'pcidev.c'),
301 'flags' : [ '-DCONFIG_IT8212=1' ],
302 },
303 'jlink_spi' : {
304 'deps' : [ libjaylink ],
305 'groups' : [ group_jlink, group_external ],
306 'srcs' : files('jlink_spi.c'),
307 'flags' : [ '-DCONFIG_JLINK_SPI=1' ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200308 },
Steve Markgraf61899472023-01-09 23:06:52 +0100309 'linux_gpio_spi' : {
310 'systems' : [ 'linux' ],
311 'deps' : [ libgpiod ],
312 'groups' : [ group_gpiod, group_external ],
Nico Huber8d2c0df2024-01-14 23:39:40 +0100313 'srcs' : libgpiod.version() < '2.0.0'
314 ? files('linux_gpio_spi.c')
315 : files('linux_gpio2_spi.c'),
Nico Huberaa5268d2023-03-09 17:15:23 +0100316 'flags' : [ '-DCONFIG_LINUX_GPIO_SPI=1' ],
Steve Markgraf61899472023-01-09 23:06:52 +0100317 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200318 'linux_mtd' : {
319 'systems' : [ 'linux' ],
320 'deps' : [ linux_headers ],
321 'groups' : [ group_internal ],
322 'srcs' : files('linux_mtd.c'),
323 'flags' : [ '-DCONFIG_LINUX_MTD=1' ],
324 },
325 'linux_spi' : {
326 'systems' : [ 'linux' ],
327 'deps' : [ linux_headers ],
328 # internal / external?
329 'srcs' : files('linux_spi.c'),
330 'flags' : [ '-DCONFIG_LINUX_SPI=1' ],
331 },
332 'mstarddc_spi' : {
333 'systems' : [ 'linux' ],
334 'deps' : [ linux_headers ],
335 'groups' : [ group_i2c ],
336 'srcs' : files('mstarddc_spi.c'),
337 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ],
338 'default' : false
339 },
340 'nic3com' : {
341 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200342 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200343 'deps' : [ libpci ],
344 'groups' : [ group_pci, group_internal ],
345 'srcs' : files('nic3com.c', 'pcidev.c'),
346 'flags' : [ '-DCONFIG_NIC3COM=1' ],
347 },
348 'nicintel' : {
349 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200350 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200351 'deps' : [ libpci ],
352 'groups' : [ group_pci, group_internal ],
353 'srcs' : files('nicintel.c', 'pcidev.c'),
354 'flags' : [ '-DCONFIG_NICINTEL=1' ],
355 },
356 'nicintel_eeprom' : {
357 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200358 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200359 'deps' : [ libpci ],
360 'groups' : [ group_pci, group_internal ],
361 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'),
362 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ],
363 },
364 'nicintel_spi' : {
365 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200366 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200367 'deps' : [ libpci ],
368 'groups' : [ group_pci, group_internal ],
369 'srcs' : files('nicintel_spi.c', 'pcidev.c'),
370 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ],
371 },
372 'nicnatsemi' : {
373 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200374 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200375 'deps' : [ libpci ],
376 'groups' : [ group_pci, group_internal ],
377 'srcs' : files('nicnatsemi.c', 'pcidev.c'),
378 'flags' : [ '-DCONFIG_NICNATSEMI=1' ],
379 'default' : false, # not complete nor tested
380 },
381 'nicrealtek' : {
382 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200383 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200384 'deps' : [ libpci ],
385 'groups' : [ group_pci, group_internal ],
386 'srcs' : files('nicrealtek.c', 'pcidev.c'),
387 'flags' : [ '-DCONFIG_NICREALTEK=1' ],
388 },
389 'ogp_spi' : {
390 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200391 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200392 'deps' : [ libpci ],
393 'groups' : [ group_pci, group_internal ],
394 'srcs' : files('ogp_spi.c', 'pcidev.c'),
395 'flags' : [ '-DCONFIG_OGP_SPI=1' ],
396 },
397 'pickit2_spi' : {
398 'deps' : [ libusb1 ],
399 'groups' : [ group_usb, group_external ],
400 'srcs' : files('pickit2_spi.c'),
401 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ],
402 },
403 'pony_spi' : {
404 'systems' : systems_serial,
405 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100406 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200407 'flags' : [ '-DCONFIG_PONY_SPI=1' ],
408 },
409 'rayer_spi' : {
410 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200411 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200412 'groups' : [ group_internal ],
413 'srcs' : files('rayer_spi.c'),
414 'flags' : [ '-DCONFIG_RAYER_SPI=1' ],
415 },
416 'satamv' : {
417 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200418 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200419 'deps' : [ libpci ],
420 'groups' : [ group_pci, group_internal ],
421 'srcs' : files('satamv.c', 'pcidev.c'),
422 'flags' : ['-DCONFIG_SATAMV=1'],
423 },
424 'satasii' : {
425 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200426 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200427 'deps' : [ libpci ],
428 'groups' : [ group_pci, group_internal ],
429 'srcs' : files('satasii.c', 'pcidev.c'),
430 'flags' : [ '-DCONFIG_SATASII=1' ],
431 },
432 'serprog' : {
433 'systems' : systems_serial,
434 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100435 'srcs' : files('serprog.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200436 'flags' : [ '-DCONFIG_SERPROG=1' ],
437 },
438 'stlinkv3_spi' : {
439 'deps' : [ libusb1 ],
440 'groups' : [ group_usb, group_external ],
441 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'),
442 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ],
443 },
444 'usbblaster_spi' : {
445 'deps' : [ libftdi1 ],
446 'groups' : [ group_ftdi, group_external ],
447 'srcs' : files('usbblaster_spi.c'),
448 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ],
449 },
450}
451
452active_programmer_count = 0
453foreach p_name, p_data : programmer
454 p_data += {
455 'systems' : p_data.get('systems', ['all']),
456 'cpu_families' : p_data.get('cpu_families', ['all']),
457 'deps' : p_data.get('deps', []),
458 'groups' : p_data.get('groups', []),
459 'srcs' : p_data.get('srcs', []),
460 'flags' : p_data.get('flags', []),
461 'default' : p_data.get('default', true),
462 }
463
464 active = false
465 deps_found = true
466 not_found_dep = ''
467 not_active_message = ''
468 selected_hard = p_name in get_option('programmer')
469 selected_soft = p_data.get('groups').contains(true) or \
470 'all' in get_option('programmer') or \
471 'auto' in get_option('programmer') and p_data.get('default')
Nico Huber72c9e402024-04-21 13:07:17 +0200472
473 available = (p_data.get('systems') == ['all'] or p_data.get('systems').contains(host_machine.system()))
474 if p_data.get('cpu_families') != ['all']
475 foreach families_list : p_data.get('cpu_families')
476 available = available and families_list.contains(host_machine.cpu_family())
477 endforeach
478 endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200479
480 foreach dep : p_data.get('deps')
481 if not dep.found()
482 deps_found = false
483 not_found_dep = dep.name()
484 break
485 endif
486 endforeach
487
488 if selected_hard
489 if not available
490 error(p_name + ' selected but not supported on this platform')
491 elif not deps_found
492 error(p_name + ' selected but dependency ' + not_found_dep +'not found')
493 else
494 active = true
495 endif
496 elif selected_soft
497 if not available
498 not_active_message = 'Not available on platform'
499 elif not deps_found
500 not_active_message = 'dependency ' + not_found_dep + ' not found'
501 else
502 active = true
503 endif
504 else
505 not_active_message = 'not selected'
506 endif
507
508 p_data += {
509 'active' : active,
510 'summary' : not_active_message,
511 }
512 programmer += {p_name : p_data}
513 if active
514 active_programmer_count += 1
515 endif
516endforeach
517
518if active_programmer_count == 0
519 error('At least one programmer must be selected')
520endif
521
522# add srcs, cargs & deps from active programmer to global srcs, cargs & deps
523foreach p_name, p_data : programmer
524 if p_data.get('active')
525 srcs += p_data.get('srcs')
526 cargs += p_data.get('flags')
527 deps += p_data.get('deps')
528 endif
529endforeach
Thomas Heijligenb975da12022-08-13 12:10:05 +0200530
531if config_print_wiki.enabled()
532 if get_option('classic_cli').disabled()
533 error('`classic_cli_print_wiki` can not be enabled without `classic_cli`')
534 else
535 srcs += files('print_wiki.c')
536 cargs += '-DCONFIG_PRINT_WIKI=1'
537 endif
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200538endif
539
540if config_default_programmer_name != ''
541 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
542else
543 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
544endif
545
546cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
547
Richard Hughescb973682018-12-19 11:44:22 +0000548install_headers([
Nico Huberc3b02dc2023-08-12 01:13:45 +0200549 'include/libflashprog.h',
Richard Hughescb973682018-12-19 11:44:22 +0000550 ],
551)
552
Thomas Heijligen58015c22022-04-14 13:50:55 +0200553include_dir = include_directories('include')
554
Nico Huberc3b02dc2023-08-12 01:13:45 +0200555mapfile = 'libflashprog.map'
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200556if host_machine.system() == 'darwin'
557 vflag = ''
558else
559 vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
560endif
Nico Huberc3b02dc2023-08-12 01:13:45 +0200561libflashprog = both_libraries(
562 'flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000563 sources : [
564 srcs,
565 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200566 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000567 soversion : lt_current,
568 version : lt_version,
569 dependencies : [
570 deps,
571 ],
572 c_args : [
573 cargs,
574 ],
575 install : true,
576 link_args : vflag,
577 link_depends : mapfile,
578)
579
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500580version = meson.project_version()
581#strip leading characters
582if version.startswith('v')
583 version = version.split('v')[1]
584endif
585if version.startswith('p')
586 version = version.split('p')[1]
587endif
588
Richard Hughescb973682018-12-19 11:44:22 +0000589pkgg = import('pkgconfig')
590pkgg.generate(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200591 libraries : libflashprog,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500592 version : version,
Nico Huberc3b02dc2023-08-12 01:13:45 +0200593 name : 'flashprog',
594 filebase : 'flashprog',
595 description : 'library to interact with flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000596)
597
Felix Singer9818b3f2022-11-29 17:08:03 +0100598config_manfile = configuration_data()
599config_manfile.set('VERSION', version)
600config_manfile.set('MAN_DATE', run_command('util/getversion.sh', '--man-date', check : true).stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000601configure_file(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200602 input : 'flashprog.8.tmpl',
603 output : 'flashprog.8',
Felix Singer9818b3f2022-11-29 17:08:03 +0100604 configuration : config_manfile,
Richard Hughesdad3a162020-02-17 09:57:01 +0000605 install: true,
Thomas Heijligen454a28c2022-05-03 11:50:16 +0200606 install_dir: join_paths(get_option('mandir'), 'man8'),
Richard Hughesdad3a162020-02-17 09:57:01 +0000607)
608
Thomas Heijligena12e0102022-08-13 12:42:05 +0200609if get_option('classic_cli').auto() or get_option('classic_cli').enabled()
610 executable(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200611 'flashprog',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200612 files(
613 'cli_classic.c',
614 'cli_common.c',
615 'cli_output.c',
616 ),
617 c_args : cargs,
618 include_directories : include_dir,
619 install : true,
620 install_dir : get_option('sbindir'),
Nico Huberc3b02dc2023-08-12 01:13:45 +0200621 link_with : libflashprog.get_static_lib(), # flashprog needs internal symbols of libflashprog
Thomas Heijligena12e0102022-08-13 12:42:05 +0200622 )
623endif
Richard Hughescb973682018-12-19 11:44:22 +0000624
Thomas Heijligenb7341b12022-08-13 12:21:44 +0200625if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled()
626 subdir('util/ich_descriptors_tool')
627endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200628
629programmer_names_active = []
630programmer_names_not_active = []
631foreach p_name, p_data : programmer
632 if p_data.get('active')
633 programmer_names_active += p_name
634 else
635 programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')'
636 endif
637endforeach
638
639summary({
640 'active' : [programmer_names_active],
641 'non active' : [programmer_names_not_active],
642}, section : 'Programmer')