blob: bda6b08135996321cbfee8cbbabf5bafc91fcfe8 [file] [log] [blame]
Richard Hughescb973682018-12-19 11:44:22 +00001project('flashromutils', 'c',
2 version : '1.0',
Nico Huberb417c0c2019-09-24 22:12:40 +02003 license : 'GPL-2.0',
Richard Hughescb973682018-12-19 11:44:22 +00004 meson_version : '>=0.47.0',
5 default_options : ['warning_level=2', 'c_std=c99'],
6)
7
8# libtool versioning
9lt_current = '1'
10lt_revision = '0'
11lt_age = '0'
12lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)
13
Jacob Garber4a84ec22019-07-25 19:12:31 -060014# hide/enable some warnings
Richard Hughescb973682018-12-19 11:44:22 +000015warning_flags = [
Jacob Garber4a84ec22019-07-25 19:12:31 -060016 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000017 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000018 '-Wno-address-of-packed-member',
19 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000020 '-Wno-missing-braces',
21]
22
23conf = configuration_data()
24
25cc = meson.get_compiler('c')
26add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
27add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
28add_project_arguments('-D_POSIX_C_SOURCE', language : 'c') # required for fileno
29add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
30add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
31
32# get defaults from configure
33config_atahpt = get_option('config_atahpt')
34config_atapromise = get_option('config_atapromise')
35config_atavia = get_option('config_atavia')
36config_buspirate_spi = get_option('config_buspirate_spi')
37config_ch341a_spi = get_option('config_ch341a_spi')
38config_dediprog = get_option('config_dediprog')
39config_developerbox_spi = get_option('config_developerbox_spi')
40config_digilent_spi = get_option('config_digilent_spi')
41config_drkaiser = get_option('config_drkaiser')
42config_dummy = get_option('config_dummy')
43config_ft2232_spi = get_option('config_ft2232_spi')
44config_gfxnvidia = get_option('config_gfxnvidia')
45config_internal = get_option('config_internal')
46config_it8212 = get_option('config_it8212')
47config_linux_mtd = get_option('config_linux_mtd')
48config_linux_spi = get_option('config_linux_spi')
49config_mstarddc_spi = get_option('config_mstarddc_spi')
50config_nic3com = get_option('config_nic3com')
51config_nicintel_eeprom = get_option('config_nicintel_eeprom')
52config_nicintel = get_option('config_nicintel')
53config_nicintel_spi = get_option('config_nicintel_spi')
54config_nicnatsemi = get_option('config_nicnatsemi')
55config_nicrealtek = get_option('config_nicrealtek')
56config_ogp_spi = get_option('config_ogp_spi')
57config_pickit2_spi = get_option('config_pickit2_spi')
58config_pony_spi = get_option('config_pony_spi')
59config_rayer_spi = get_option('config_rayer_spi')
60config_satamv = get_option('config_satamv')
61config_satasii = get_option('config_satasii')
62config_serprog = get_option('config_serprog')
63config_usbblaster_spi = get_option('config_usbblaster_spi')
64
65cargs = []
66deps = []
67srcs = []
68
Richard Hughescb973682018-12-19 11:44:22 +000069need_raw_access = false
70need_serial = false
71
72# check for required symbols
73if cc.has_function('clock_gettime')
74 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
75endif
76if cc.has_function('strnlen')
77 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
78endif
79if cc.check_header('sys/utsname.h')
80 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
81endif
82
83# some programmers require libusb
84if get_option('usb')
85 srcs += 'usbdev.c'
86 deps += dependency('libusb-1.0')
87else
88 config_ch341a_spi = false
89 config_dediprog = false
90 config_digilent_spi = false
91 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +020092 config_pickit2_spi = false
Richard Hughescb973682018-12-19 11:44:22 +000093endif
94
95# some programmers require libpci
96if get_option('pciutils')
97 srcs += 'pcidev.c'
98 deps += dependency('libpci')
99 cargs += '-DNEED_PCI=1'
100else
101 config_atahpt = false
102 config_atapromise = false
103 config_atavia = false
104 config_drkaiser = false
105 config_gfxnvidia = false
106 config_internal = false
107 config_it8212 = false
108 config_nic3com = false
109 config_nicintel_eeprom = false
110 config_nicintel = false
111 config_nicintel_spi = false
112 config_nicnatsemi = false
113 config_nicrealtek = false
114 config_ogp_spi = false
115 config_rayer_spi = false
116 config_satamv = false
117 config_satasii = false
118endif
119
120# set defines for configured programmers
121if config_atahpt
122 srcs += 'atahpt.c'
123 cargs += '-DCONFIG_ATAHPT=1'
124endif
125if config_atapromise
126 srcs += 'atapromise.c'
127 cargs += '-DCONFIG_ATAPROMISE=1'
128endif
129if config_atavia
130 srcs += 'atavia.c'
131 cargs += '-DCONFIG_ATAVIA=1'
132endif
133if config_buspirate_spi
134 srcs += 'buspirate_spi.c'
135 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
136 need_serial = true
137endif
138if config_ch341a_spi
139 srcs += 'ch341a_spi.c'
140 cargs += '-DCONFIG_CH341A_SPI=1'
141endif
142if config_dediprog
143 srcs += 'dediprog.c'
144 cargs += '-DCONFIG_DEDIPROG=1'
145endif
146if config_developerbox_spi
147 srcs += 'developerbox_spi.c'
148 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
149endif
150if config_digilent_spi
151 srcs += 'digilent_spi.c'
152 cargs += '-DCONFIG_DIGILENT_SPI=1'
153endif
154if config_drkaiser
155 srcs += 'drkaiser.c'
156 cargs += '-DCONFIG_DRKAISER=1'
157endif
158if config_dummy
159 srcs += 'dummyflasher.c'
160 cargs += '-DCONFIG_DUMMY=1'
161endif
162if config_ft2232_spi
163 srcs += 'ft2232_spi.c'
164 cargs += '-DCONFIG_FT2232_SPI=1'
165 deps += dependency('libftdi1')
166 cargs += '-DHAVE_FT232H=1'
167endif
168if config_gfxnvidia
169 srcs += 'gfxnvidia.c'
170 cargs += '-DCONFIG_GFXNVIDIA=1'
171endif
172if config_internal
173 srcs += 'board_enable.c'
174 srcs += 'cbtable.c'
175 srcs += 'chipset_enable.c'
176 srcs += 'internal.c'
177 srcs += 'processor_enable.c'
178 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
179 srcs += 'amd_imc.c'
180 srcs += 'dmi.c'
181 srcs += 'ichspi.c'
182 srcs += 'it85spi.c'
183 srcs += 'it87spi.c'
184 srcs += 'mcp6x_spi.c'
185 srcs += 'sb600spi.c'
186 srcs += 'wbsio_spi.c'
187 endif
188 config_bitbang_spi = true
189 cargs += '-DCONFIG_INTERNAL=1'
190 if get_option('config_internal_dmi')
191 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
192 cargs += '-DCONFIG_INTERNAL_DMI=1'
193 endif
194endif
195if config_it8212
196 srcs += 'it8212.c'
197 cargs += '-DCONFIG_IT8212=1'
198endif
199if config_linux_mtd
200 srcs += 'linux_mtd.c'
201 cargs += '-DCONFIG_LINUX_MTD=1'
202endif
203if config_linux_spi
204 srcs += 'linux_spi.c'
205 cargs += '-DCONFIG_LINUX_SPI=1'
206endif
207if config_mstarddc_spi
208 srcs += 'mstarddc_spi.c'
209 cargs += '-DCONFIG_MSTARDDC_SPI=1'
210endif
211if config_nic3com
212 srcs += 'nic3com.c'
213 cargs += '-DCONFIG_NIC3COM=1'
214endif
215if config_nicintel
216 srcs += 'nicintel.c'
217 cargs += '-DCONFIG_NICINTEL=1'
218endif
219if config_nicintel_eeprom
220 srcs += 'nicintel_eeprom.c'
221 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
222endif
223if config_nicintel_spi
224 srcs += 'nicintel_spi.c'
225 config_bitbang_spi = true
226 cargs += '-DCONFIG_NICINTEL_SPI=1'
227endif
228if config_nicnatsemi
229 srcs += 'nicnatsemi.c'
230 cargs += '-DCONFIG_NICNATSEMI=1'
231endif
232if config_nicrealtek
233 srcs += 'nicrealtek.c'
234 cargs += '-DCONFIG_NICREALTEK=1'
235endif
236if config_ogp_spi
237 config_bitbang_spi = true
238 srcs += 'ogp_spi.c'
239 cargs += '-DCONFIG_OGP_SPI=1'
240endif
241if config_pickit2_spi
242 srcs += 'pickit2_spi.c'
243 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000244endif
245if config_pony_spi
246 srcs += 'pony_spi.c'
247 need_serial = true
248 config_bitbang_spi = true
249 cargs += '-DCONFIG_PONY_SPI=1'
250endif
251if config_rayer_spi
252 srcs += 'rayer_spi.c'
253 config_bitbang_spi = true
254 need_raw_access = true
255 cargs += '-DCONFIG_RAYER_SPI=1'
256endif
257if config_satamv
258 srcs += 'satamv.c'
259 cargs += '-DCONFIG_SATAMV=1'
260endif
261if config_satasii
262 srcs += 'satasii.c'
263 cargs += '-DCONFIG_SATASII=1'
264endif
265if config_serprog
266 srcs += 'serprog.c'
267 cargs += '-DCONFIG_SERPROG=1'
268 need_serial = true
269endif
270if config_usbblaster_spi
271 srcs += 'usbblaster_spi.c'
272 cargs += '-DCONFIG_USBBLASTER_SPI=1'
273endif
274
275# bitbanging SPI infrastructure
276if config_bitbang_spi
277 srcs += 'bitbang_spi.c'
278 cargs += '-DCONFIG_BITBANG_SPI=1'
279endif
280
281# raw memory, MSR or PCI port I/O access
282if need_raw_access
283 srcs += 'hwaccess.c'
284 srcs += 'physmap.c'
285 cargs += '-DNEED_RAW_ACCESS=1'
286endif
287
288# raw serial IO
289if need_serial
290 srcs += 'custom_baud.c'
291 srcs += 'serial.c'
292endif
293
Richard Hughescb973682018-12-19 11:44:22 +0000294prefix = get_option('prefix')
295sbindir = join_paths(prefix, get_option('sbindir'))
296libdir = join_paths(prefix, get_option('libdir'))
297
298install_headers([
299 'libflashrom.h',
300 ],
301)
302
303# core modules needed by both the library and the CLI
304srcs += '82802ab.c'
305srcs += 'at45db.c'
306srcs += 'edi.c'
307srcs += 'en29lv640b.c'
308srcs += 'flashchips.c'
309srcs += 'flashrom.c'
310srcs += 'fmap.c'
311srcs += 'helpers.c'
312srcs += 'ich_descriptors.c'
313srcs += 'jedec.c'
314srcs += 'layout.c'
315srcs += 'libflashrom.c'
316srcs += 'opaque.c'
317srcs += 'print.c'
318srcs += 'programmer.c'
319srcs += 'sfdp.c'
320srcs += 'spi25.c'
321srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700322srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000323srcs += 'spi.c'
324srcs += 'sst28sf040.c'
325srcs += 'sst49lfxxxc.c'
326srcs += 'sst_fwhub.c'
327srcs += 'stm50.c'
328srcs += 'udelay.c'
329srcs += 'w29ee011.c'
330srcs += 'w39.c'
331
332mapfile = 'libflashrom.map'
333vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
334flashrom = shared_library(
335 'flashrom',
336 sources : [
337 srcs,
338 ],
339 soversion : lt_current,
340 version : lt_version,
341 dependencies : [
342 deps,
343 ],
344 c_args : [
345 cargs,
346 ],
347 install : true,
348 link_args : vflag,
349 link_depends : mapfile,
350)
351
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500352version = meson.project_version()
353#strip leading characters
354if version.startswith('v')
355 version = version.split('v')[1]
356endif
357if version.startswith('p')
358 version = version.split('p')[1]
359endif
360
Richard Hughescb973682018-12-19 11:44:22 +0000361pkgg = import('pkgconfig')
362pkgg.generate(
363 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500364 version : version,
Richard Hughescb973682018-12-19 11:44:22 +0000365 name : 'libflashrom',
366 filebase : 'libflashrom',
367 description : 'libflashrom',
368)
369
370flashrom_dep = declare_dependency(
371 link_with : flashrom,
372 include_directories : include_directories('.'),
373 dependencies : deps
374)
375
376# we can't just link_with libflashrom as we require all the internal symbols...
377executable(
378 'flashrom',
379 sources : [
380 srcs,
381 'cli_classic.c',
382 'cli_common.c',
383 'cli_output.c',
384 'flashrom.c',
385 ],
386 dependencies : [
387 deps,
388 ],
389 c_args : [
390 cargs,
391 '-DSTANDALONE',
392 '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID',
393 '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
394 ],
395 install : true,
396 install_dir : sbindir,
397)
398
399subdir('util')