blob: 408b87aab14e9b660bcee55c3663d068f2536590 [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 },
245 'gfxnvidia' : {
246 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200247 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200248 'deps' : [ libpci ],
249 'groups' : [ group_pci, group_internal ],
250 'srcs' : files('gfxnvidia.c', 'pcidev.c'),
251 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ],
252 },
253 'internal' : {
254 'systems' : systems_hwaccess + ['linux'],
Nico Huber72c9e402024-04-21 13:07:17 +0200255 'cpu_families' : (host_machine.system() == 'linux' ? [ cpus_raw_mem ] : [ ['x86', 'x86_64'] ]),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200256 'deps' : [ libpci ],
257 'groups' : [ group_internal ],
258 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files(
259 'processor_enable.c',
260 'chipset_enable.c',
261 'board_enable.c',
262 'cbtable.c',
263 'internal.c',
264 'it87spi.c',
265 'sb600spi.c',
266 'amd_imc.c',
Nico Huber735b1862023-01-29 18:28:45 +0000267 'amd_spi100.c',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200268 'wbsio_spi.c',
269 'mcp6x_spi.c',
270 'ichspi.c',
271 'dmi.c',
272 'pcidev.c',
273 'known_boards.c',
274 ) : files(
275 'board_enable.c',
276 'cbtable.c',
277 'chipset_enable.c',
278 'internal.c',
279 'processor_enable.c',
280 'pcidev.c',
281 'known_boards.c',
282 )),
283 'flags' : [
284 '-DCONFIG_INTERNAL=1',
285 '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'),
Nico Huber2f753792023-03-28 00:46:50 +0200286 '-DLINUX_MTD_AS_INTERNAL=' + (host_machine.cpu_family() in ['x86', 'x86_64'] ? '0' : '1'),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200287 ]
288 },
289 'it8212' : {
290 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200291 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200292 'deps' : [ libpci ],
293 'groups' : [ group_pci, group_internal ],
294 'srcs' : files('it8212.c', 'pcidev.c'),
295 'flags' : [ '-DCONFIG_IT8212=1' ],
296 },
297 'jlink_spi' : {
298 'deps' : [ libjaylink ],
299 'groups' : [ group_jlink, group_external ],
300 'srcs' : files('jlink_spi.c'),
301 'flags' : [ '-DCONFIG_JLINK_SPI=1' ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200302 },
Steve Markgraf61899472023-01-09 23:06:52 +0100303 'linux_gpio_spi' : {
304 'systems' : [ 'linux' ],
305 'deps' : [ libgpiod ],
306 'groups' : [ group_gpiod, group_external ],
Nico Huber8d2c0df2024-01-14 23:39:40 +0100307 'srcs' : libgpiod.version() < '2.0.0'
308 ? files('linux_gpio_spi.c')
309 : files('linux_gpio2_spi.c'),
Nico Huberaa5268d2023-03-09 17:15:23 +0100310 'flags' : [ '-DCONFIG_LINUX_GPIO_SPI=1' ],
Steve Markgraf61899472023-01-09 23:06:52 +0100311 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200312 'linux_mtd' : {
313 'systems' : [ 'linux' ],
314 'deps' : [ linux_headers ],
315 'groups' : [ group_internal ],
316 'srcs' : files('linux_mtd.c'),
317 'flags' : [ '-DCONFIG_LINUX_MTD=1' ],
318 },
319 'linux_spi' : {
320 'systems' : [ 'linux' ],
321 'deps' : [ linux_headers ],
322 # internal / external?
323 'srcs' : files('linux_spi.c'),
324 'flags' : [ '-DCONFIG_LINUX_SPI=1' ],
325 },
326 'mstarddc_spi' : {
327 'systems' : [ 'linux' ],
328 'deps' : [ linux_headers ],
329 'groups' : [ group_i2c ],
330 'srcs' : files('mstarddc_spi.c'),
331 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ],
332 'default' : false
333 },
334 'nic3com' : {
335 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200336 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200337 'deps' : [ libpci ],
338 'groups' : [ group_pci, group_internal ],
339 'srcs' : files('nic3com.c', 'pcidev.c'),
340 'flags' : [ '-DCONFIG_NIC3COM=1' ],
341 },
342 'nicintel' : {
343 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200344 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200345 'deps' : [ libpci ],
346 'groups' : [ group_pci, group_internal ],
347 'srcs' : files('nicintel.c', 'pcidev.c'),
348 'flags' : [ '-DCONFIG_NICINTEL=1' ],
349 },
350 'nicintel_eeprom' : {
351 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200352 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200353 'deps' : [ libpci ],
354 'groups' : [ group_pci, group_internal ],
355 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'),
356 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ],
357 },
358 'nicintel_spi' : {
359 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200360 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200361 'deps' : [ libpci ],
362 'groups' : [ group_pci, group_internal ],
363 'srcs' : files('nicintel_spi.c', 'pcidev.c'),
364 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ],
365 },
366 'nicnatsemi' : {
367 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200368 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200369 'deps' : [ libpci ],
370 'groups' : [ group_pci, group_internal ],
371 'srcs' : files('nicnatsemi.c', 'pcidev.c'),
372 'flags' : [ '-DCONFIG_NICNATSEMI=1' ],
373 'default' : false, # not complete nor tested
374 },
375 'nicrealtek' : {
376 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200377 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200378 'deps' : [ libpci ],
379 'groups' : [ group_pci, group_internal ],
380 'srcs' : files('nicrealtek.c', 'pcidev.c'),
381 'flags' : [ '-DCONFIG_NICREALTEK=1' ],
382 },
383 'ogp_spi' : {
384 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200385 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200386 'deps' : [ libpci ],
387 'groups' : [ group_pci, group_internal ],
388 'srcs' : files('ogp_spi.c', 'pcidev.c'),
389 'flags' : [ '-DCONFIG_OGP_SPI=1' ],
390 },
391 'pickit2_spi' : {
392 'deps' : [ libusb1 ],
393 'groups' : [ group_usb, group_external ],
394 'srcs' : files('pickit2_spi.c'),
395 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ],
396 },
397 'pony_spi' : {
398 'systems' : systems_serial,
399 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100400 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200401 'flags' : [ '-DCONFIG_PONY_SPI=1' ],
402 },
403 'rayer_spi' : {
404 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200405 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200406 'groups' : [ group_internal ],
407 'srcs' : files('rayer_spi.c'),
408 'flags' : [ '-DCONFIG_RAYER_SPI=1' ],
409 },
410 'satamv' : {
411 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200412 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200413 'deps' : [ libpci ],
414 'groups' : [ group_pci, group_internal ],
415 'srcs' : files('satamv.c', 'pcidev.c'),
416 'flags' : ['-DCONFIG_SATAMV=1'],
417 },
418 'satasii' : {
419 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200420 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200421 'deps' : [ libpci ],
422 'groups' : [ group_pci, group_internal ],
423 'srcs' : files('satasii.c', 'pcidev.c'),
424 'flags' : [ '-DCONFIG_SATASII=1' ],
425 },
426 'serprog' : {
427 'systems' : systems_serial,
428 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100429 'srcs' : files('serprog.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200430 'flags' : [ '-DCONFIG_SERPROG=1' ],
431 },
432 'stlinkv3_spi' : {
433 'deps' : [ libusb1 ],
434 'groups' : [ group_usb, group_external ],
435 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'),
436 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ],
437 },
438 'usbblaster_spi' : {
439 'deps' : [ libftdi1 ],
440 'groups' : [ group_ftdi, group_external ],
441 'srcs' : files('usbblaster_spi.c'),
442 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ],
443 },
444}
445
446active_programmer_count = 0
447foreach p_name, p_data : programmer
448 p_data += {
449 'systems' : p_data.get('systems', ['all']),
450 'cpu_families' : p_data.get('cpu_families', ['all']),
451 'deps' : p_data.get('deps', []),
452 'groups' : p_data.get('groups', []),
453 'srcs' : p_data.get('srcs', []),
454 'flags' : p_data.get('flags', []),
455 'default' : p_data.get('default', true),
456 }
457
458 active = false
459 deps_found = true
460 not_found_dep = ''
461 not_active_message = ''
462 selected_hard = p_name in get_option('programmer')
463 selected_soft = p_data.get('groups').contains(true) or \
464 'all' in get_option('programmer') or \
465 'auto' in get_option('programmer') and p_data.get('default')
Nico Huber72c9e402024-04-21 13:07:17 +0200466
467 available = (p_data.get('systems') == ['all'] or p_data.get('systems').contains(host_machine.system()))
468 if p_data.get('cpu_families') != ['all']
469 foreach families_list : p_data.get('cpu_families')
470 available = available and families_list.contains(host_machine.cpu_family())
471 endforeach
472 endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200473
474 foreach dep : p_data.get('deps')
475 if not dep.found()
476 deps_found = false
477 not_found_dep = dep.name()
478 break
479 endif
480 endforeach
481
482 if selected_hard
483 if not available
484 error(p_name + ' selected but not supported on this platform')
485 elif not deps_found
486 error(p_name + ' selected but dependency ' + not_found_dep +'not found')
487 else
488 active = true
489 endif
490 elif selected_soft
491 if not available
492 not_active_message = 'Not available on platform'
493 elif not deps_found
494 not_active_message = 'dependency ' + not_found_dep + ' not found'
495 else
496 active = true
497 endif
498 else
499 not_active_message = 'not selected'
500 endif
501
502 p_data += {
503 'active' : active,
504 'summary' : not_active_message,
505 }
506 programmer += {p_name : p_data}
507 if active
508 active_programmer_count += 1
509 endif
510endforeach
511
512if active_programmer_count == 0
513 error('At least one programmer must be selected')
514endif
515
516# add srcs, cargs & deps from active programmer to global srcs, cargs & deps
517foreach p_name, p_data : programmer
518 if p_data.get('active')
519 srcs += p_data.get('srcs')
520 cargs += p_data.get('flags')
521 deps += p_data.get('deps')
522 endif
523endforeach
Thomas Heijligenb975da12022-08-13 12:10:05 +0200524
525if config_print_wiki.enabled()
526 if get_option('classic_cli').disabled()
527 error('`classic_cli_print_wiki` can not be enabled without `classic_cli`')
528 else
529 srcs += files('print_wiki.c')
530 cargs += '-DCONFIG_PRINT_WIKI=1'
531 endif
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200532endif
533
534if config_default_programmer_name != ''
535 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
536else
537 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
538endif
539
540cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
541
Richard Hughescb973682018-12-19 11:44:22 +0000542install_headers([
Nico Huberc3b02dc2023-08-12 01:13:45 +0200543 'include/libflashprog.h',
Richard Hughescb973682018-12-19 11:44:22 +0000544 ],
545)
546
Thomas Heijligen58015c22022-04-14 13:50:55 +0200547include_dir = include_directories('include')
548
Nico Huberc3b02dc2023-08-12 01:13:45 +0200549mapfile = 'libflashprog.map'
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200550if host_machine.system() == 'darwin'
551 vflag = ''
552else
553 vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
554endif
Nico Huberc3b02dc2023-08-12 01:13:45 +0200555libflashprog = both_libraries(
556 'flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000557 sources : [
558 srcs,
559 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200560 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000561 soversion : lt_current,
562 version : lt_version,
563 dependencies : [
564 deps,
565 ],
566 c_args : [
567 cargs,
568 ],
569 install : true,
570 link_args : vflag,
571 link_depends : mapfile,
572)
573
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500574version = meson.project_version()
575#strip leading characters
576if version.startswith('v')
577 version = version.split('v')[1]
578endif
579if version.startswith('p')
580 version = version.split('p')[1]
581endif
582
Richard Hughescb973682018-12-19 11:44:22 +0000583pkgg = import('pkgconfig')
584pkgg.generate(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200585 libraries : libflashprog,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500586 version : version,
Nico Huberc3b02dc2023-08-12 01:13:45 +0200587 name : 'flashprog',
588 filebase : 'flashprog',
589 description : 'library to interact with flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000590)
591
Felix Singer9818b3f2022-11-29 17:08:03 +0100592config_manfile = configuration_data()
593config_manfile.set('VERSION', version)
594config_manfile.set('MAN_DATE', run_command('util/getversion.sh', '--man-date', check : true).stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000595configure_file(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200596 input : 'flashprog.8.tmpl',
597 output : 'flashprog.8',
Felix Singer9818b3f2022-11-29 17:08:03 +0100598 configuration : config_manfile,
Richard Hughesdad3a162020-02-17 09:57:01 +0000599 install: true,
Thomas Heijligen454a28c2022-05-03 11:50:16 +0200600 install_dir: join_paths(get_option('mandir'), 'man8'),
Richard Hughesdad3a162020-02-17 09:57:01 +0000601)
602
Thomas Heijligena12e0102022-08-13 12:42:05 +0200603if get_option('classic_cli').auto() or get_option('classic_cli').enabled()
604 executable(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200605 'flashprog',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200606 files(
607 'cli_classic.c',
608 'cli_common.c',
609 'cli_output.c',
610 ),
611 c_args : cargs,
612 include_directories : include_dir,
613 install : true,
614 install_dir : get_option('sbindir'),
Nico Huberc3b02dc2023-08-12 01:13:45 +0200615 link_with : libflashprog.get_static_lib(), # flashprog needs internal symbols of libflashprog
Thomas Heijligena12e0102022-08-13 12:42:05 +0200616 )
617endif
Richard Hughescb973682018-12-19 11:44:22 +0000618
Thomas Heijligenb7341b12022-08-13 12:21:44 +0200619if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled()
620 subdir('util/ich_descriptors_tool')
621endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200622
623programmer_names_active = []
624programmer_names_not_active = []
625foreach p_name, p_data : programmer
626 if p_data.get('active')
627 programmer_names_active += p_name
628 else
629 programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')'
630 endif
631endforeach
632
633summary({
634 'active' : [programmer_names_active],
635 'non active' : [programmer_names_not_active],
636}, section : 'Programmer')