blob: 1923fdfb7ae0598733362c0420e98701182509bc [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
70need_libusb0 = false
71need_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
94endif
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'
245 need_libusb0 = true
246endif
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
296# raw deprecated and old USB library
297if need_libusb0
298 deps += dependency('libusb')
299endif
300
301prefix = get_option('prefix')
302sbindir = join_paths(prefix, get_option('sbindir'))
303libdir = join_paths(prefix, get_option('libdir'))
304
305install_headers([
306 'libflashrom.h',
307 ],
308)
309
310# core modules needed by both the library and the CLI
311srcs += '82802ab.c'
312srcs += 'at45db.c'
313srcs += 'edi.c'
314srcs += 'en29lv640b.c'
315srcs += 'flashchips.c'
316srcs += 'flashrom.c'
317srcs += 'fmap.c'
318srcs += 'helpers.c'
319srcs += 'ich_descriptors.c'
320srcs += 'jedec.c'
321srcs += 'layout.c'
322srcs += 'libflashrom.c'
323srcs += 'opaque.c'
324srcs += 'print.c'
325srcs += 'programmer.c'
326srcs += 'sfdp.c'
327srcs += 'spi25.c'
328srcs += 'spi25_statusreg.c'
329srcs += 'spi.c'
330srcs += 'sst28sf040.c'
331srcs += 'sst49lfxxxc.c'
332srcs += 'sst_fwhub.c'
333srcs += 'stm50.c'
334srcs += 'udelay.c'
335srcs += 'w29ee011.c'
336srcs += 'w39.c'
337
338mapfile = 'libflashrom.map'
339vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
340flashrom = shared_library(
341 'flashrom',
342 sources : [
343 srcs,
344 ],
345 soversion : lt_current,
346 version : lt_version,
347 dependencies : [
348 deps,
349 ],
350 c_args : [
351 cargs,
352 ],
353 install : true,
354 link_args : vflag,
355 link_depends : mapfile,
356)
357
358pkgg = import('pkgconfig')
359pkgg.generate(
360 libraries : flashrom,
361 version : meson.project_version(),
362 name : 'libflashrom',
363 filebase : 'libflashrom',
364 description : 'libflashrom',
365)
366
367flashrom_dep = declare_dependency(
368 link_with : flashrom,
369 include_directories : include_directories('.'),
370 dependencies : deps
371)
372
373# we can't just link_with libflashrom as we require all the internal symbols...
374executable(
375 'flashrom',
376 sources : [
377 srcs,
378 'cli_classic.c',
379 'cli_common.c',
380 'cli_output.c',
381 'flashrom.c',
382 ],
383 dependencies : [
384 deps,
385 ],
386 c_args : [
387 cargs,
388 '-DSTANDALONE',
389 '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID',
390 '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
391 ],
392 install : true,
393 install_dir : sbindir,
394)
395
396subdir('util')