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