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