blob: efe10cd34354241c06328aa6dfd9f34ff6e79d60 [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' ]
Nico Huber72c9e402024-04-21 13:07:17 +0200114cpus_raw_mem = [ 'x86', 'x86_64', 'mips', 'mips64', 'ppc', 'ppc64', 'arm', 'aarch64', 'sparc', 'sparc64', 'arc', 'e2k' ]
Peter Marheine306c8b72022-01-21 02:07:30 +0000115
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200116group_ftdi = get_option('programmer').contains('group_ftdi')
117group_pci = get_option('programmer').contains('group_pci')
118group_usb = get_option('programmer').contains('group_usb')
119group_i2c = get_option('programmer').contains('group_i2c')
120group_serial = get_option('programmer').contains('group_serial')
121group_jlink = get_option('programmer').contains('group_jlink')
Steve Markgraf61899472023-01-09 23:06:52 +0100122group_gpiod = get_option('programmer').contains('group_gpiod')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200123group_internal = get_option('programmer').contains('group_internal')
124group_external = get_option('programmer').contains('group_external')
Peter Marheine306c8b72022-01-21 02:07:30 +0000125
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200126libpci = 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
127libusb1 = dependency('libusb-1.0', required : group_usb)
128libftdi1 = dependency('libftdi1', required : group_ftdi)
129libjaylink = dependency('libjaylink', required : group_jlink)
Steve Markgraf61899472023-01-09 23:06:52 +0100130libgpiod = dependency('libgpiod', required : group_gpiod)
Richard Hughescb973682018-12-19 11:44:22 +0000131
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200132subdir('platform')
Richard Hughescb973682018-12-19 11:44:22 +0000133
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200134if systems_hwaccess.contains(host_machine.system())
Thomas Heijligen4bd966c2022-05-16 10:56:55 +0200135 srcs += files('hwaccess_physmap.c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200136 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
137 srcs += files('hwaccess_x86_msr.c', 'hwaccess_x86_io.c')
Thomas Heijligen140c1262021-09-27 15:12:26 +0200138 endif
Richard Hughescb973682018-12-19 11:44:22 +0000139endif
140
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200141# Pseudo dependencies
142linux_headers = \
143 cc.has_header('linux/i2c.h') and \
144 cc.has_header('linux/i2c-dev.h') and \
145 cc.has_header('mtd/mtd-user.h') and \
146 cc.has_header('linux/spi/spidev.h') ? declare_dependency() : dependency('', required : false)
Thomas Heijligenb975da12022-08-13 12:10:05 +0200147
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200148# '<programmer_name>' : {
149# 'system' : list[string], # default: ['all']
150# 'cpu_families : list[string], # default: ['all']
151# 'deps' : list[dep], # default: []
152# 'groups : list[boolean], # default: []
153# 'srcs' : list[file], # default: []
154# 'flags' : list[string], # default: []
155# 'default' : boolean, # default: true
156# 'active' : boolean, # added on runtime
157# }
158programmer = {
159 'atahpt' : {
160 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200161 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200162 'deps' : [ libpci ],
163 'groups' : [ group_pci, group_internal ],
164 'srcs' : files('atahpt.c', 'pcidev.c'),
165 'flags' : [ '-DCONFIG_ATAHPT=1' ],
166 'default' : false, # not yet working
167 },
168 'atapromise' : {
169 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200170 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200171 'deps' : [ libpci ],
172 'groups' : [ group_pci, group_internal ],
173 'srcs' : files('atapromise.c', 'pcidev.c'),
174 'flags' : [ '-DCONFIG_ATAPROMISE=1' ],
175 'default' : false,
176 },
177 'atavia' : {
178 'systems' : systems_hwaccess,
179 'deps' : [ libpci ],
180 'groups' : [ group_pci, group_internal ],
181 'srcs' : files('atavia.c', 'pcidev.c'),
182 'flags' : [ '-DCONFIG_ATAVIA=1' ],
183 },
184 'buspirate_spi' : {
185 'systems' : systems_serial,
186 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100187 'srcs' : files('buspirate_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200188 'flags' : [ '-DCONFIG_BUSPIRATE_SPI=1' ],
189 },
190 'ch341a_spi' : {
191 'deps' : [ libusb1 ],
192 'groups' : [ group_usb, group_external ],
193 'srcs' : files('ch341a_spi.c'),
194 'flags' : [ '-DCONFIG_CH341A_SPI=1' ],
195 },
Nicholas Chin197b7c72022-10-23 13:10:31 -0600196 'ch347_spi' : {
197 'deps' : [ libusb1 ],
198 'groups' : [ group_usb, group_external ],
199 'srcs' : files('ch347_spi.c'),
200 'flags' : [ '-DCONFIG_CH347_SPI=1' ],
201 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200202 'dediprog' : {
203 'deps' : [ libusb1 ],
204 'groups' : [ group_usb, group_external ],
205 'srcs' : files('dediprog.c', 'usbdev.c'),
206 'flags' : [ '-DCONFIG_DEDIPROG=1' ],
207 },
208 'developerbox_spi' : {
209 'deps' : [ libusb1 ],
210 'groups' : [ group_usb, group_external ],
211 'srcs' : files('developerbox_spi.c', 'usbdev.c'),
212 'flags' : [ '-DCONFIG_DEVELOPERBOX_SPI=1' ],
213 },
214 'digilent_spi' : {
215 'deps' : [ libusb1 ],
216 'groups' : [ group_usb, group_external ],
217 'srcs' : files('digilent_spi.c'),
218 'flags' : [ '-DCONFIG_DIGILENT_SPI=1' ],
219 },
220 'dirtyjtag_spi' : {
221 'deps' : [ libusb1 ],
222 'groups' : [ group_usb, group_external ],
223 'srcs' : files('dirtyjtag_spi.c'),
224 'flags' : [ '-DCONFIG_DIRTYJTAG_SPI=1' ],
225 },
226 'drkaiser' : {
227 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200228 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200229 'deps' : [ libpci ],
230 'groups' : [ group_pci, group_internal ],
231 'srcs' : files('drkaiser.c', 'pcidev.c'),
232 'flags' : [ '-DCONFIG_DRKAISER=1' ],
233 },
234 'dummy' : {
235 'srcs' : files('dummyflasher.c'),
236 'flags' : [ '-DCONFIG_DUMMY=1' ],
237 },
238 'ft2232_spi' : {
239 'deps' : [ libftdi1 ],
240 'groups' : [ group_ftdi, group_external ],
241 'srcs' : files('ft2232_spi.c' ),
242 'flags' : [ '-DCONFIG_FT2232_SPI=1' ],
243 },
244 'gfxnvidia' : {
245 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200246 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200247 'deps' : [ libpci ],
248 'groups' : [ group_pci, group_internal ],
249 'srcs' : files('gfxnvidia.c', 'pcidev.c'),
250 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ],
251 },
252 'internal' : {
253 'systems' : systems_hwaccess + ['linux'],
Nico Huber72c9e402024-04-21 13:07:17 +0200254 'cpu_families' : (host_machine.system() == 'linux' ? [ cpus_raw_mem ] : [ ['x86', 'x86_64'] ]),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200255 'deps' : [ libpci ],
256 'groups' : [ group_internal ],
257 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files(
258 'processor_enable.c',
259 'chipset_enable.c',
260 'board_enable.c',
261 'cbtable.c',
262 'internal.c',
263 'it87spi.c',
264 'sb600spi.c',
265 'amd_imc.c',
Nico Huber735b1862023-01-29 18:28:45 +0000266 'amd_spi100.c',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200267 'wbsio_spi.c',
268 'mcp6x_spi.c',
269 'ichspi.c',
270 'dmi.c',
271 'pcidev.c',
272 'known_boards.c',
273 ) : files(
274 'board_enable.c',
275 'cbtable.c',
276 'chipset_enable.c',
277 'internal.c',
278 'processor_enable.c',
279 'pcidev.c',
280 'known_boards.c',
281 )),
282 'flags' : [
283 '-DCONFIG_INTERNAL=1',
284 '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'),
Nico Huber2f753792023-03-28 00:46:50 +0200285 '-DLINUX_MTD_AS_INTERNAL=' + (host_machine.cpu_family() in ['x86', 'x86_64'] ? '0' : '1'),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200286 ]
287 },
288 'it8212' : {
289 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200290 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200291 'deps' : [ libpci ],
292 'groups' : [ group_pci, group_internal ],
293 'srcs' : files('it8212.c', 'pcidev.c'),
294 'flags' : [ '-DCONFIG_IT8212=1' ],
295 },
296 'jlink_spi' : {
297 'deps' : [ libjaylink ],
298 'groups' : [ group_jlink, group_external ],
299 'srcs' : files('jlink_spi.c'),
300 'flags' : [ '-DCONFIG_JLINK_SPI=1' ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200301 },
Steve Markgraf61899472023-01-09 23:06:52 +0100302 'linux_gpio_spi' : {
303 'systems' : [ 'linux' ],
304 'deps' : [ libgpiod ],
305 'groups' : [ group_gpiod, group_external ],
Nico Huber8d2c0df2024-01-14 23:39:40 +0100306 'srcs' : libgpiod.version() < '2.0.0'
307 ? files('linux_gpio_spi.c')
308 : files('linux_gpio2_spi.c'),
Nico Huberaa5268d2023-03-09 17:15:23 +0100309 'flags' : [ '-DCONFIG_LINUX_GPIO_SPI=1' ],
Steve Markgraf61899472023-01-09 23:06:52 +0100310 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200311 'linux_mtd' : {
312 'systems' : [ 'linux' ],
313 'deps' : [ linux_headers ],
314 'groups' : [ group_internal ],
315 'srcs' : files('linux_mtd.c'),
316 'flags' : [ '-DCONFIG_LINUX_MTD=1' ],
317 },
318 'linux_spi' : {
319 'systems' : [ 'linux' ],
320 'deps' : [ linux_headers ],
321 # internal / external?
322 'srcs' : files('linux_spi.c'),
323 'flags' : [ '-DCONFIG_LINUX_SPI=1' ],
324 },
325 'mstarddc_spi' : {
326 'systems' : [ 'linux' ],
327 'deps' : [ linux_headers ],
328 'groups' : [ group_i2c ],
329 'srcs' : files('mstarddc_spi.c'),
330 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ],
331 'default' : false
332 },
333 'nic3com' : {
334 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200335 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200336 'deps' : [ libpci ],
337 'groups' : [ group_pci, group_internal ],
338 'srcs' : files('nic3com.c', 'pcidev.c'),
339 'flags' : [ '-DCONFIG_NIC3COM=1' ],
340 },
341 'nicintel' : {
342 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200343 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200344 'deps' : [ libpci ],
345 'groups' : [ group_pci, group_internal ],
346 'srcs' : files('nicintel.c', 'pcidev.c'),
347 'flags' : [ '-DCONFIG_NICINTEL=1' ],
348 },
349 'nicintel_eeprom' : {
350 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200351 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200352 'deps' : [ libpci ],
353 'groups' : [ group_pci, group_internal ],
354 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'),
355 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ],
356 },
357 'nicintel_spi' : {
358 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200359 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200360 'deps' : [ libpci ],
361 'groups' : [ group_pci, group_internal ],
362 'srcs' : files('nicintel_spi.c', 'pcidev.c'),
363 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ],
364 },
365 'nicnatsemi' : {
366 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200367 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200368 'deps' : [ libpci ],
369 'groups' : [ group_pci, group_internal ],
370 'srcs' : files('nicnatsemi.c', 'pcidev.c'),
371 'flags' : [ '-DCONFIG_NICNATSEMI=1' ],
372 'default' : false, # not complete nor tested
373 },
374 'nicrealtek' : {
375 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200376 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200377 'deps' : [ libpci ],
378 'groups' : [ group_pci, group_internal ],
379 'srcs' : files('nicrealtek.c', 'pcidev.c'),
380 'flags' : [ '-DCONFIG_NICREALTEK=1' ],
381 },
382 'ogp_spi' : {
383 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200384 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200385 'deps' : [ libpci ],
386 'groups' : [ group_pci, group_internal ],
387 'srcs' : files('ogp_spi.c', 'pcidev.c'),
388 'flags' : [ '-DCONFIG_OGP_SPI=1' ],
389 },
390 'pickit2_spi' : {
391 'deps' : [ libusb1 ],
392 'groups' : [ group_usb, group_external ],
393 'srcs' : files('pickit2_spi.c'),
394 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ],
395 },
396 'pony_spi' : {
397 'systems' : systems_serial,
398 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100399 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200400 'flags' : [ '-DCONFIG_PONY_SPI=1' ],
401 },
402 'rayer_spi' : {
403 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200404 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200405 'groups' : [ group_internal ],
406 'srcs' : files('rayer_spi.c'),
407 'flags' : [ '-DCONFIG_RAYER_SPI=1' ],
408 },
409 'satamv' : {
410 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200411 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200412 'deps' : [ libpci ],
413 'groups' : [ group_pci, group_internal ],
414 'srcs' : files('satamv.c', 'pcidev.c'),
415 'flags' : ['-DCONFIG_SATAMV=1'],
416 },
417 'satasii' : {
418 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200419 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200420 'deps' : [ libpci ],
421 'groups' : [ group_pci, group_internal ],
422 'srcs' : files('satasii.c', 'pcidev.c'),
423 'flags' : [ '-DCONFIG_SATASII=1' ],
424 },
425 'serprog' : {
426 'systems' : systems_serial,
427 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100428 'srcs' : files('serprog.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200429 'flags' : [ '-DCONFIG_SERPROG=1' ],
430 },
431 'stlinkv3_spi' : {
432 'deps' : [ libusb1 ],
433 'groups' : [ group_usb, group_external ],
434 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'),
435 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ],
436 },
437 'usbblaster_spi' : {
438 'deps' : [ libftdi1 ],
439 'groups' : [ group_ftdi, group_external ],
440 'srcs' : files('usbblaster_spi.c'),
441 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ],
442 },
443}
444
445active_programmer_count = 0
446foreach p_name, p_data : programmer
447 p_data += {
448 'systems' : p_data.get('systems', ['all']),
449 'cpu_families' : p_data.get('cpu_families', ['all']),
450 'deps' : p_data.get('deps', []),
451 'groups' : p_data.get('groups', []),
452 'srcs' : p_data.get('srcs', []),
453 'flags' : p_data.get('flags', []),
454 'default' : p_data.get('default', true),
455 }
456
457 active = false
458 deps_found = true
459 not_found_dep = ''
460 not_active_message = ''
461 selected_hard = p_name in get_option('programmer')
462 selected_soft = p_data.get('groups').contains(true) or \
463 'all' in get_option('programmer') or \
464 'auto' in get_option('programmer') and p_data.get('default')
Nico Huber72c9e402024-04-21 13:07:17 +0200465
466 available = (p_data.get('systems') == ['all'] or p_data.get('systems').contains(host_machine.system()))
467 if p_data.get('cpu_families') != ['all']
468 foreach families_list : p_data.get('cpu_families')
469 available = available and families_list.contains(host_machine.cpu_family())
470 endforeach
471 endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200472
473 foreach dep : p_data.get('deps')
474 if not dep.found()
475 deps_found = false
476 not_found_dep = dep.name()
477 break
478 endif
479 endforeach
480
481 if selected_hard
482 if not available
483 error(p_name + ' selected but not supported on this platform')
484 elif not deps_found
485 error(p_name + ' selected but dependency ' + not_found_dep +'not found')
486 else
487 active = true
488 endif
489 elif selected_soft
490 if not available
491 not_active_message = 'Not available on platform'
492 elif not deps_found
493 not_active_message = 'dependency ' + not_found_dep + ' not found'
494 else
495 active = true
496 endif
497 else
498 not_active_message = 'not selected'
499 endif
500
501 p_data += {
502 'active' : active,
503 'summary' : not_active_message,
504 }
505 programmer += {p_name : p_data}
506 if active
507 active_programmer_count += 1
508 endif
509endforeach
510
511if active_programmer_count == 0
512 error('At least one programmer must be selected')
513endif
514
515# add srcs, cargs & deps from active programmer to global srcs, cargs & deps
516foreach p_name, p_data : programmer
517 if p_data.get('active')
518 srcs += p_data.get('srcs')
519 cargs += p_data.get('flags')
520 deps += p_data.get('deps')
521 endif
522endforeach
Thomas Heijligenb975da12022-08-13 12:10:05 +0200523
524if config_print_wiki.enabled()
525 if get_option('classic_cli').disabled()
526 error('`classic_cli_print_wiki` can not be enabled without `classic_cli`')
527 else
528 srcs += files('print_wiki.c')
529 cargs += '-DCONFIG_PRINT_WIKI=1'
530 endif
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200531endif
532
533if config_default_programmer_name != ''
534 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
535else
536 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
537endif
538
539cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
540
Richard Hughescb973682018-12-19 11:44:22 +0000541install_headers([
Nico Huberc3b02dc2023-08-12 01:13:45 +0200542 'include/libflashprog.h',
Richard Hughescb973682018-12-19 11:44:22 +0000543 ],
544)
545
Thomas Heijligen58015c22022-04-14 13:50:55 +0200546include_dir = include_directories('include')
547
Nico Huberc3b02dc2023-08-12 01:13:45 +0200548mapfile = 'libflashprog.map'
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200549if host_machine.system() == 'darwin'
550 vflag = ''
551else
552 vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
553endif
Nico Huberc3b02dc2023-08-12 01:13:45 +0200554libflashprog = both_libraries(
555 'flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000556 sources : [
557 srcs,
558 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200559 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000560 soversion : lt_current,
561 version : lt_version,
562 dependencies : [
563 deps,
564 ],
565 c_args : [
566 cargs,
567 ],
568 install : true,
569 link_args : vflag,
570 link_depends : mapfile,
571)
572
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500573version = meson.project_version()
574#strip leading characters
575if version.startswith('v')
576 version = version.split('v')[1]
577endif
578if version.startswith('p')
579 version = version.split('p')[1]
580endif
581
Richard Hughescb973682018-12-19 11:44:22 +0000582pkgg = import('pkgconfig')
583pkgg.generate(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200584 libraries : libflashprog,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500585 version : version,
Nico Huberc3b02dc2023-08-12 01:13:45 +0200586 name : 'flashprog',
587 filebase : 'flashprog',
588 description : 'library to interact with flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000589)
590
Felix Singer9818b3f2022-11-29 17:08:03 +0100591config_manfile = configuration_data()
592config_manfile.set('VERSION', version)
593config_manfile.set('MAN_DATE', run_command('util/getversion.sh', '--man-date', check : true).stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000594configure_file(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200595 input : 'flashprog.8.tmpl',
596 output : 'flashprog.8',
Felix Singer9818b3f2022-11-29 17:08:03 +0100597 configuration : config_manfile,
Richard Hughesdad3a162020-02-17 09:57:01 +0000598 install: true,
Thomas Heijligen454a28c2022-05-03 11:50:16 +0200599 install_dir: join_paths(get_option('mandir'), 'man8'),
Richard Hughesdad3a162020-02-17 09:57:01 +0000600)
601
Thomas Heijligena12e0102022-08-13 12:42:05 +0200602if get_option('classic_cli').auto() or get_option('classic_cli').enabled()
603 executable(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200604 'flashprog',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200605 files(
606 'cli_classic.c',
607 'cli_common.c',
608 'cli_output.c',
609 ),
610 c_args : cargs,
611 include_directories : include_dir,
612 install : true,
613 install_dir : get_option('sbindir'),
Nico Huberc3b02dc2023-08-12 01:13:45 +0200614 link_with : libflashprog.get_static_lib(), # flashprog needs internal symbols of libflashprog
Thomas Heijligena12e0102022-08-13 12:42:05 +0200615 )
616endif
Richard Hughescb973682018-12-19 11:44:22 +0000617
Thomas Heijligenb7341b12022-08-13 12:21:44 +0200618if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled()
619 subdir('util/ich_descriptors_tool')
620endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200621
622programmer_names_active = []
623programmer_names_not_active = []
624foreach p_name, p_data : programmer
625 if p_data.get('active')
626 programmer_names_active += p_name
627 else
628 programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')'
629 endif
630endforeach
631
632summary({
633 'active' : [programmer_names_active],
634 'non active' : [programmer_names_not_active],
635}, section : 'Programmer')