diff options
Diffstat (limited to 'meson.build')
-rw-r--r-- | meson.build | 1072 |
1 files changed, 692 insertions, 380 deletions
diff --git a/meson.build b/meson.build index 73df7221c..c85fdf4d0 100644 --- a/meson.build +++ b/meson.build @@ -1,18 +1,47 @@ project('flashromutils', 'c', - version : run_command('util/getversion.sh', '-v').stdout().strip(), + version : run_command('cat', 'VERSION', check: true).stdout().strip(), license : 'GPL-2.0', - meson_version : '>=0.50.0', - default_options : ['warning_level=2', 'c_std=c99'], + meson_version : '>=0.56.0', + default_options : [ + 'warning_level=2', + 'c_std=c99', + 'werror=true', + 'optimization=s', + 'debug=false', + 'default_library=both' + ], ) +fs = import('fs') + +if get_option('classic_cli').enabled() and get_option('default_library') == 'shared' + error(''' + Cannot build cli_classic with shared libflashrom. Use \'-Dclassic_cli=disabled\' to disable the cli, + or use \'--default-library=both\' to also build the classic_cli + ''') +endif + # libtool versioning lt_current = '1' lt_revision = '0' lt_age = '0' lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision) +flashrom_version = meson.project_version() +git = find_program('git', native : true, required : false) +if git.found() + version_git = run_command('git', 'describe', check : false) + if version_git.returncode() == 0 + flashrom_version += ' (git:@0@)'.format(version_git.stdout().strip()) + endif +endif + +subdir('doc') + # hide/enable some warnings warning_flags = [ + '-Wshadow', + '-Wmissing-prototypes', '-Wwrite-strings', '-Wno-unused-parameter', '-Wno-address-of-packed-member', @@ -20,61 +49,63 @@ warning_flags = [ '-Wno-missing-braces', ] -conf = configuration_data() - cc = meson.get_compiler('c') add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c') add_project_arguments('-D_DEFAULT_SOURCE', language : 'c') add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19 -add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c') +add_project_arguments('-D__BSD_VISIBLE', language : 'c') # required for u_char, u_int, u_long on FreeBSD +add_project_arguments('-D__XSI_VISIBLE', language : 'c') # required for gettimeofday() on FreeBSD +add_project_arguments('-D_NETBSD_SOURCE', language : 'c') # required for indirect include of strings.h on NetBSD +add_project_arguments('-D_DARWIN_C_SOURCE', language : 'c') # required for indirect include of strings.h on MacOS +add_project_arguments('-DFLASHROM_VERSION="' + flashrom_version + '"', language : 'c') # get defaults from configure -config_atahpt = get_option('config_atahpt') -config_atapromise = get_option('config_atapromise') -config_atavia = get_option('config_atavia') -config_buspirate_spi = get_option('config_buspirate_spi') -config_ch341a_spi = get_option('config_ch341a_spi') -config_dediprog = get_option('config_dediprog') -config_developerbox_spi = get_option('config_developerbox_spi') -config_digilent_spi = get_option('config_digilent_spi') -config_jlink_spi = get_option('config_jlink_spi') -config_drkaiser = get_option('config_drkaiser') -config_dummy = get_option('config_dummy') -config_ene_lpc = get_option('config_ene_lpc') -config_ft2232_spi = get_option('config_ft2232_spi') -config_gfxnvidia = get_option('config_gfxnvidia') -config_raiden_debug_spi = get_option('config_raiden_debug_spi') -config_internal = get_option('config_internal') -config_it8212 = get_option('config_it8212') -config_linux_mtd = get_option('config_linux_mtd') -config_linux_spi = get_option('config_linux_spi') -config_mec1308 = get_option('config_mec1308') -config_mstarddc_spi = get_option('config_mstarddc_spi') -config_nic3com = get_option('config_nic3com') -config_nicintel_eeprom = get_option('config_nicintel_eeprom') -config_nicintel = get_option('config_nicintel') -config_nicintel_spi = get_option('config_nicintel_spi') -config_nicnatsemi = get_option('config_nicnatsemi') -config_nicrealtek = get_option('config_nicrealtek') -config_ogp_spi = get_option('config_ogp_spi') -config_pickit2_spi = get_option('config_pickit2_spi') -config_pony_spi = get_option('config_pony_spi') -config_rayer_spi = get_option('config_rayer_spi') -config_satamv = get_option('config_satamv') -config_satasii = get_option('config_satasii') -config_serprog = get_option('config_serprog') -config_usbblaster_spi = get_option('config_usbblaster_spi') -config_stlinkv3_spi = get_option('config_stlinkv3_spi') -config_lspcon_i2c_spi = get_option('config_lspcon_i2c_spi') -config_realtek_mst_i2c_spi = get_option('config_realtek_mst_i2c_spi') +config_print_wiki= get_option('classic_cli_print_wiki') +config_default_programmer_name = get_option('default_programmer_name') +config_default_programmer_args = get_option('default_programmer_args') cargs = [] +link_args = [] deps = [] -srcs = [] - -need_raw_access = false -need_serial = false +srcs = files( + '82802ab.c', + 'at45db.c', + 'bitbang_spi.c', + 'edi.c', + 'en29lv640b.c', + 'erasure_layout.c', + 'flashchips.c', + 'flashrom.c', + 'fmap.c', + 'helpers.c', + 'helpers_fileio.c', + 'ich_descriptors.c', + 'jedec.c', + 'printlock.c', + 'layout.c', + 'libflashrom.c', + 'opaque.c', + 'parallel.c', + 'print.c', + 'programmer.c', + 'programmer_table.c', + 's25f.c', + 'sfdp.c', + 'spi25.c', + 'spi25_statusreg.c', + 'spi95.c', + 'spi.c', + 'sst28sf040.c', + 'sst49lfxxxc.c', + 'sst_fwhub.c', + 'stm50.c', + 'udelay.c', + 'w29ee011.c', + 'w39.c', + 'writeprotect.c', + 'writeprotect_ranges.c', +) # check for required symbols if cc.has_function('clock_gettime') @@ -86,302 +117,538 @@ endif if cc.check_header('sys/utsname.h') add_project_arguments('-DHAVE_UTSNAME=1', language : 'c') endif - -# some programmers require libusb -if get_option('usb') - srcs += 'usbdev.c' - srcs += 'usb_device.c' - deps += dependency('libusb-1.0') +if host_machine.system() in ['cygwin', 'windows'] + add_project_arguments('-DIS_WINDOWS=1', language : 'c') else - config_ch341a_spi = false - config_dediprog = false - config_digilent_spi = false - config_developerbox_spi = false - config_pickit2_spi = false + add_project_arguments('-DIS_WINDOWS=0', language : 'c') endif -# some programmers require libpci -if get_option('pciutils') - srcs += 'pcidev.c' - deps += dependency('libpci') - cargs += '-DNEED_PCI=1' +if host_machine.system() == 'linux' + custom_baud_c = 'custom_baud_linux.c' +elif host_machine.system() == 'darwin' + custom_baud_c = 'custom_baud_darwin.c' else - config_atahpt = false - config_atapromise = false - config_atavia = false - config_drkaiser = false - config_gfxnvidia = false - config_raiden_debug_spi = false - config_internal = false - config_it8212 = false - config_nic3com = false - config_nicintel_eeprom = false - config_nicintel = false - config_nicintel_spi = false - config_nicnatsemi = false - config_nicrealtek = false - config_ogp_spi = false - config_rayer_spi = false - config_satamv = false - config_satasii = false + custom_baud_c = 'custom_baud.c' endif -# set defines for configured programmers -if config_atahpt - srcs += 'atahpt.c' - cargs += '-DCONFIG_ATAHPT=1' -endif -if config_atapromise - srcs += 'atapromise.c' - cargs += '-DCONFIG_ATAPROMISE=1' -endif -if config_atavia - srcs += 'atavia.c' - cargs += '-DCONFIG_ATAVIA=1' -endif -if config_buspirate_spi - srcs += 'buspirate_spi.c' - cargs += '-DCONFIG_BUSPIRATE_SPI=1' - need_serial = true -endif -if config_ch341a_spi - srcs += 'ch341a_spi.c' - cargs += '-DCONFIG_CH341A_SPI=1' -endif -if config_dediprog - srcs += 'dediprog.c' - cargs += '-DCONFIG_DEDIPROG=1' -endif -if config_developerbox_spi - srcs += 'developerbox_spi.c' - cargs += '-DCONFIG_DEVELOPERBOX_SPI=1' -endif -if config_digilent_spi - srcs += 'digilent_spi.c' - cargs += '-DCONFIG_DIGILENT_SPI=1' -endif -if config_jlink_spi - srcs += 'jlink_spi.c' - cargs += '-DCONFIG_JLINK_SPI=1' - deps += dependency('libjaylink') -endif -if config_drkaiser - srcs += 'drkaiser.c' - cargs += '-DCONFIG_DRKAISER=1' -endif -if config_dummy - srcs += 'dummyflasher.c' - cargs += '-DCONFIG_DUMMY=1' -endif -if config_ft2232_spi - srcs += 'ft2232_spi.c' - cargs += '-DCONFIG_FT2232_SPI=1' - deps += dependency('libftdi1') - cargs += '-DHAVE_FT232H=1' -endif -if config_gfxnvidia - srcs += 'gfxnvidia.c' - cargs += '-DCONFIG_GFXNVIDIA=1' +systems_hwaccess = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd', 'dos' ] +systems_serial = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd', 'darwin', 'windows' ] + +cpus_port_io = [ 'x86', 'x86_64' ] + +group_ftdi = get_option('programmer').contains('group_ftdi') +group_pci = get_option('programmer').contains('group_pci') +group_usb = get_option('programmer').contains('group_usb') +group_i2c = get_option('programmer').contains('group_i2c') +group_serial = get_option('programmer').contains('group_serial') +group_jlink = get_option('programmer').contains('group_jlink') +group_internal = get_option('programmer').contains('group_internal') +group_external = get_option('programmer').contains('group_external') + +libpci = dependency('libpci', required : group_pci, version : '>=2.2.0', + static : (host_machine.system() == 'openbsd' ? true : false)) # On openbsd a static version of libpci is needed to get also -libz +libusb1 = dependency('libusb-1.0', required : group_usb) +libftdi1 = dependency('libftdi1', required : group_ftdi) +libjaylink = dependency('libjaylink', required : group_jlink, version : '>=0.3.0') + +if host_machine.system() == 'windows' + # Specifying an include_path that doesn't exist is an error, + # but we only use this if the library is found in the same directory. + ni845x_search_path = get_option('ni845x_search_path') + if fs.is_dir(ni845x_search_path) + ni845x_include_path = [ni845x_search_path] + else + ni845x_include_path = [] + endif + + libni845x = declare_dependency( + dependencies : [ + cc.find_library( + 'ni845x', + dirs : get_option('ni845x_search_path'), + required : get_option('programmer').contains('ni845x_spi') + ), + ], + include_directories : ni845x_include_path, + ) +else + libni845x = dependency('', required : false) endif -if config_raiden_debug_spi - srcs += 'raiden_debug_spi.c' - cargs += '-DCONFIG_RAIDEN_DEBUG_SPI=1' + +subdir('platform') + +if systems_hwaccess.contains(host_machine.system()) + srcs += files('hwaccess_physmap.c') + if ['x86', 'x86_64'].contains(host_machine.cpu_family()) + srcs += files('hwaccess_x86_msr.c', 'hwaccess_x86_io.c') + endif endif -if config_internal - srcs += 'board_enable.c' - srcs += 'cbtable.c' - srcs += 'chipset_enable.c' - srcs += 'internal.c' - srcs += 'processor_enable.c' - if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64' - srcs += 'amd_imc.c' - srcs += 'dmi.c' - srcs += 'ichspi.c' - srcs += 'it85spi.c' - srcs += 'it87spi.c' - srcs += 'mcp6x_spi.c' - srcs += 'sb600spi.c' - srcs += 'wbsio_spi.c' + +# Pseudo dependencies +linux_headers = \ + cc.has_header('linux/i2c.h') and \ + cc.has_header('linux/i2c-dev.h') and \ + cc.has_header('mtd/mtd-user.h') and \ + cc.has_header('linux/spi/spidev.h') ? declare_dependency() : dependency('', required : false) + +# '<programmer_name>' : { +# 'system' : list[string], # default: ['all'] +# 'cpu_families : list[string], # default: ['all'] +# 'deps' : list[dep], # default: [] +# 'groups : list[boolean], # default: [] +# 'srcs' : list[file], # default: [] +# 'flags' : list[string], # default: [] +# 'default' : boolean, # default: true +# 'active' : boolean, # added on runtime +# } +programmer = { + 'asm106x' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('asm106x.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_ASM106X=1' ], + }, + 'atahpt' : { + 'systems' : systems_hwaccess, + 'cpu_families' : cpus_port_io, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('atahpt.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_ATAHPT=1' ], + 'default' : false, # not yet working + }, + 'atapromise' : { + 'systems' : systems_hwaccess, + 'cpu_families' : cpus_port_io, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('atapromise.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_ATAPROMISE=1' ], + 'default' : false, + }, + 'atavia' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('atavia.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_ATAVIA=1' ], + }, + 'buspirate_spi' : { + 'systems' : systems_serial, + 'groups' : [ group_serial, group_external ], + 'srcs' : files('buspirate_spi.c', 'serial.c', custom_baud_c), + 'flags' : [ '-DCONFIG_BUSPIRATE_SPI=1' ], + }, + 'ch341a_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('ch341a_spi.c'), + 'test_srcs' : files('tests/ch341a_spi.c'), + 'flags' : [ '-DCONFIG_CH341A_SPI=1' ], + }, + 'ch347_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('ch347_spi.c'), + 'flags' : [ '-DCONFIG_CH347_SPI=1' ], + }, + 'dediprog' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('dediprog.c', 'usbdev.c'), + 'test_srcs' : files('tests/dediprog.c'), + 'flags' : [ '-DCONFIG_DEDIPROG=1' ], + }, + 'developerbox_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('developerbox_spi.c', 'usbdev.c'), + 'flags' : [ '-DCONFIG_DEVELOPERBOX_SPI=1' ], + }, + 'digilent_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('digilent_spi.c'), + 'flags' : [ '-DCONFIG_DIGILENT_SPI=1' ], + }, + 'dirtyjtag_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('dirtyjtag_spi.c'), + 'flags' : [ '-DCONFIG_DIRTYJTAG_SPI=1' ], + }, + 'drkaiser' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('drkaiser.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_DRKAISER=1' ], + }, + 'dummy' : { + 'srcs' : files('dummyflasher.c'), + 'test_srcs' : files('tests/dummyflasher.c'), + 'flags' : [ '-DCONFIG_DUMMY=1' ], + }, + 'ft2232_spi' : { + 'deps' : [ libftdi1 ], + 'groups' : [ group_ftdi, group_external ], + 'srcs' : files('ft2232_spi.c' ), + 'flags' : [ '-DCONFIG_FT2232_SPI=1' ], + }, + 'gfxnvidia' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('gfxnvidia.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ], + }, + 'internal' : { + 'systems' : systems_hwaccess + ['linux'], + 'cpu_families' : (host_machine.system() == 'linux' ? [host_machine.cpu_family()] : ['x86', 'x86_64']), + 'deps' : [ libpci ], + 'groups' : [ group_internal ], + 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files( + 'processor_enable.c', + 'chipset_enable.c', + 'board_enable.c', + 'cbtable.c', + 'internal.c', + 'internal_par.c', + 'it87spi.c', + 'sb600spi.c', + 'superio.c', + 'amd_imc.c', + 'wbsio_spi.c', + 'mcp6x_spi.c', + 'ichspi.c', + 'dmi.c', + 'pcidev.c', + 'known_boards.c', + ) : files( + 'board_enable.c', + 'cbtable.c', + 'chipset_enable.c', + 'internal.c', + 'internal_par.c', + 'processor_enable.c', + 'pcidev.c', + 'known_boards.c', + )), + 'flags' : [ + '-DCONFIG_INTERNAL=1', + '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'), + ] + }, + 'it8212' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('it8212.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_IT8212=1' ], + }, + 'jlink_spi' : { + 'deps' : [ libjaylink ], + 'groups' : [ group_jlink, group_external ], + 'srcs' : files('jlink_spi.c'), + 'flags' : [ '-DCONFIG_JLINK_SPI=1' ], + }, + 'linux_mtd' : { + 'systems' : [ 'linux' ], + 'deps' : [ linux_headers ], + 'groups' : [ group_internal ], + 'srcs' : files('linux_mtd.c'), + 'test_srcs' : files('tests/linux_mtd.c'), + 'flags' : [ '-DCONFIG_LINUX_MTD=1' ], + }, + 'linux_spi' : { + 'systems' : [ 'linux' ], + 'deps' : [ linux_headers ], + # internal / external? + 'srcs' : files('linux_spi.c'), + 'test_srcs' : files('tests/linux_spi.c'), + 'flags' : [ '-DCONFIG_LINUX_SPI=1' ], + }, + 'parade_lspcon' : { + 'systems' : [ 'linux' ], + 'deps' : [ linux_headers ], + 'groups' : [ group_i2c ], + 'srcs' : files('parade_lspcon.c', 'i2c_helper_linux.c'), + 'test_srcs' : files('tests/parade_lspcon.c'), + 'flags' : [ '-DCONFIG_PARADE_LSPCON=1' ], + 'default' : false + }, + 'mediatek_i2c_spi' : { + 'systems' : [ 'linux' ], + 'deps' : [ linux_headers ], + 'groups' : [ group_i2c ], + 'srcs' : files('mediatek_i2c_spi.c', 'i2c_helper_linux.c'), + 'test_srcs' : files('tests/mediatek_i2c_spi.c'), + 'flags' : [ '-DCONFIG_MEDIATEK_I2C_SPI=1' ], + 'default' : false, + }, + 'mstarddc_spi' : { + 'systems' : [ 'linux' ], + 'deps' : [ linux_headers ], + 'groups' : [ group_i2c ], + 'srcs' : files('mstarddc_spi.c', 'i2c_helper_linux.c'), + 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ], + 'default' : false + }, + 'ni845x_spi' : { + 'systems' : [ 'windows' ], + 'cpu_families' : [ 'x86' ], # The required ni845x library is 32-bit only + 'deps' : [ libni845x ], + 'srcs' : files('ni845x_spi.c'), + 'flags' : [ '-DCONFIG_NI845X_SPI=1' ], + 'default' : false, + }, + 'nic3com' : { + 'systems' : systems_hwaccess, + 'cpu_families' : cpus_port_io, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('nic3com.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_NIC3COM=1' ], + }, + 'nicintel' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('nicintel.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_NICINTEL=1' ], + }, + 'nicintel_eeprom' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ], + }, + 'nicintel_spi' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('nicintel_spi.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ], + }, + 'nicnatsemi' : { + 'systems' : systems_hwaccess, + 'cpu_families' : cpus_port_io, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('nicnatsemi.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_NICNATSEMI=1' ], + 'default' : false, # not complete nor tested + }, + 'nicrealtek' : { + 'systems' : systems_hwaccess, + 'cpu_families' : cpus_port_io, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('nicrealtek.c', 'pcidev.c'), + 'test_srcs' : files('tests/nicrealtek.c'), + 'flags' : [ '-DCONFIG_NICREALTEK=1' ], + }, + 'ogp_spi' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('ogp_spi.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_OGP_SPI=1' ], + }, + 'pickit2_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('pickit2_spi.c'), + 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ], + }, + 'pony_spi' : { + 'systems' : systems_serial, + 'groups' : [ group_serial, group_external ], + 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c), + 'flags' : [ '-DCONFIG_PONY_SPI=1' ], + }, + 'raiden_debug_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('raiden_debug_spi.c', 'usb_device.c'), + 'test_srcs' : files('tests/raiden_debug_spi.c'), + 'flags' : [ '-DCONFIG_RAIDEN_DEBUG_SPI=1' ], + }, + 'rayer_spi' : { + 'systems' : systems_hwaccess, + 'cpu_families' : cpus_port_io, + 'groups' : [ group_internal ], + 'srcs' : files('rayer_spi.c'), + 'flags' : [ '-DCONFIG_RAYER_SPI=1' ], + }, + 'realtek_mst_i2c_spi' : { + 'systems' : [ 'linux' ], + 'deps' : [ linux_headers ], + 'groups' : [ group_i2c ], + 'srcs' : files('realtek_mst_i2c_spi.c', 'i2c_helper_linux.c'), + 'test_srcs' : files('tests/realtek_mst_i2c_spi.c'), + 'flags' : [ '-DCONFIG_REALTEK_MST_I2C_SPI=1' ], + 'default' : false, + }, + 'satamv' : { + 'systems' : systems_hwaccess, + 'cpu_families' : cpus_port_io, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('satamv.c', 'pcidev.c'), + 'flags' : ['-DCONFIG_SATAMV=1'], + }, + 'satasii' : { + 'systems' : systems_hwaccess, + 'deps' : [ libpci ], + 'groups' : [ group_pci, group_internal ], + 'srcs' : files('satasii.c', 'pcidev.c'), + 'flags' : [ '-DCONFIG_SATASII=1' ], + }, + 'serprog' : { + 'systems' : systems_serial, + 'groups' : [ group_serial, group_external ], + 'srcs' : files('serprog.c', 'serial.c', custom_baud_c), + 'flags' : [ '-DCONFIG_SERPROG=1' ], + }, + 'stlinkv3_spi' : { + 'deps' : [ libusb1 ], + 'groups' : [ group_usb, group_external ], + 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'), + 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ], + }, + 'usbblaster_spi' : { + 'deps' : [ libftdi1 ], + 'groups' : [ group_ftdi, group_external ], + 'srcs' : files('usbblaster_spi.c'), + 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ], + }, +} + +active_programmer_count = 0 +foreach p_name, p_data : programmer + p_data += { + 'systems' : p_data.get('systems', ['all']), + 'cpu_families' : p_data.get('cpu_families', ['all']), + 'deps' : p_data.get('deps', []), + 'groups' : p_data.get('groups', []), + 'srcs' : p_data.get('srcs', []), + 'test_srcs': p_data.get('test_srcs', []), + 'flags' : p_data.get('flags', []), + 'default' : p_data.get('default', true), + } + + active = false + deps_found = true + not_found_dep = '' + not_active_message = '' + selected_hard = p_name in get_option('programmer') + selected_soft = p_data.get('groups').contains(true) or \ + 'all' in get_option('programmer') or \ + 'auto' in get_option('programmer') and p_data.get('default') + available = (p_data.get('systems').contains('all') or p_data.get('systems').contains(host_machine.system())) \ + and (p_data.get('cpu_families').contains('all') or p_data.get('cpu_families').contains(host_machine.cpu_family())) + + foreach dep : p_data.get('deps') + if not dep.found() + deps_found = false + not_found_dep = dep.name() + break + endif + endforeach + + if selected_hard + if not available + error('programmer @0@ was selected but is not supported on this platform (needs @1@/@2@, but system is @3@/@4@)'.format( + p_name, + p_data.get('systems'), + p_data.get('cpu_families'), + host_machine.system(), + host_machine.cpu_family() + )) + elif not deps_found + error(p_name + ' selected but dependency ' + not_found_dep +'not found') + else + active = true + endif + elif selected_soft + if not available + not_active_message = 'Not available on platform' + elif not deps_found + not_active_message = 'dependency ' + not_found_dep + ' not found' + else + active = true + endif + else + not_active_message = 'not selected' endif - config_bitbang_spi = true - cargs += '-DCONFIG_INTERNAL=1' - if get_option('config_internal_dmi') - # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode. - cargs += '-DCONFIG_INTERNAL_DMI=1' + + p_data += { + 'active' : active, + 'summary' : not_active_message, + } + programmer += {p_name : p_data} + if active + active_programmer_count += 1 endif -endif -if config_ene_lpc - srcs += 'ene_lpc.c' - cargs += '-DCONFIG_ENE_LPC=1' -endif -if config_it8212 - srcs += 'it8212.c' - cargs += '-DCONFIG_IT8212=1' -endif -if config_linux_mtd - srcs += 'linux_mtd.c' - cargs += '-DCONFIG_LINUX_MTD=1' -endif -if config_linux_spi - srcs += 'linux_spi.c' - cargs += '-DCONFIG_LINUX_SPI=1' -endif -if config_mec1308 - srcs += 'mec1308.c' - cargs += '-DCONFIG_MEC1308=1' -endif -if config_mstarddc_spi - srcs += 'mstarddc_spi.c' - cargs += '-DCONFIG_MSTARDDC_SPI=1' -endif -if config_nic3com - srcs += 'nic3com.c' - cargs += '-DCONFIG_NIC3COM=1' -endif -if config_nicintel - srcs += 'nicintel.c' - cargs += '-DCONFIG_NICINTEL=1' -endif -if config_nicintel_eeprom - srcs += 'nicintel_eeprom.c' - cargs += '-DCONFIG_NICINTEL_EEPROM=1' -endif -if config_nicintel_spi - srcs += 'nicintel_spi.c' - config_bitbang_spi = true - cargs += '-DCONFIG_NICINTEL_SPI=1' -endif -if config_nicnatsemi - srcs += 'nicnatsemi.c' - cargs += '-DCONFIG_NICNATSEMI=1' -endif -if config_nicrealtek - srcs += 'nicrealtek.c' - cargs += '-DCONFIG_NICREALTEK=1' -endif -if config_ogp_spi - config_bitbang_spi = true - srcs += 'ogp_spi.c' - cargs += '-DCONFIG_OGP_SPI=1' -endif -if config_pickit2_spi - srcs += 'pickit2_spi.c' - cargs += '-DCONFIG_PICKIT2_SPI=1' -endif -if config_pony_spi - srcs += 'pony_spi.c' - need_serial = true - config_bitbang_spi = true - cargs += '-DCONFIG_PONY_SPI=1' -endif -if config_rayer_spi - srcs += 'rayer_spi.c' - config_bitbang_spi = true - need_raw_access = true - cargs += '-DCONFIG_RAYER_SPI=1' -endif -if config_satamv - srcs += 'satamv.c' - cargs += '-DCONFIG_SATAMV=1' -endif -if config_satasii - srcs += 'satasii.c' - cargs += '-DCONFIG_SATASII=1' -endif -if config_serprog - srcs += 'serprog.c' - cargs += '-DCONFIG_SERPROG=1' - need_serial = true -endif -if config_usbblaster_spi - srcs += 'usbblaster_spi.c' - cargs += '-DCONFIG_USBBLASTER_SPI=1' -endif -if config_stlinkv3_spi - srcs += 'stlinkv3_spi.c' - cargs += '-DCONFIG_STLINKV3_SPI=1' -endif -if config_lspcon_i2c_spi - srcs += 'lspcon_i2c_spi.c' - cargs += '-DCONFIG_LSPCON_I2C_SPI=1' -endif -if config_realtek_mst_i2c_spi - srcs += 'realtek_mst_i2c_spi.c' - cargs += '-DCONFIG_REALTEK_MST_I2C_SPI=1' -endif +endforeach -# bitbanging SPI infrastructure -if config_bitbang_spi - srcs += 'bitbang_spi.c' - cargs += '-DCONFIG_BITBANG_SPI=1' +if active_programmer_count == 0 + error('At least one programmer must be selected') endif -if host_machine.system() == 'linux' - srcs += 'i2c_helper_linux.c' - cargs += '-DCONFIG_I2C_SUPPORT=1' -endif +# add srcs, cargs & deps from active programmer to global srcs, cargs & deps +foreach p_name, p_data : programmer + if p_data.get('active') + srcs += p_data.get('srcs') + cargs += p_data.get('flags') + deps += p_data.get('deps') + endif +endforeach -# raw memory, MSR or PCI port I/O access -if need_raw_access - srcs += 'hwaccess.c' - srcs += 'physmap.c' - cargs += '-DNEED_RAW_ACCESS=1' +if config_print_wiki.enabled() + if get_option('classic_cli').disabled() + error('`classic_cli_print_wiki` can not be enabled without `classic_cli`') + else + srcs += files('print_wiki.c') + cargs += '-DCONFIG_PRINT_WIKI=1' + endif endif -# raw serial IO -if need_serial - srcs += 'custom_baud.c' - srcs += 'serial.c' +if config_default_programmer_name != '' + cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name +else + cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL' endif -prefix = get_option('prefix') -sbindir = join_paths(prefix, get_option('sbindir')) -libdir = join_paths(prefix, get_option('libdir')) -mandir = join_paths(prefix, get_option('mandir')) +cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"' + +if get_option('llvm_cov').enabled() + cargs += ['-fprofile-instr-generate', '-fcoverage-mapping'] + link_args += ['-fprofile-instr-generate', '-fcoverage-mapping'] +endif install_headers([ - 'libflashrom.h', + 'include/libflashrom.h', ], ) -# core modules needed by both the library and the CLI -srcs += '82802ab.c' -srcs += 'at45db.c' -srcs += 'edi.c' -srcs += 'en29lv640b.c' -srcs += 'flashchips.c' -srcs += 'flashrom.c' -srcs += 'fmap.c' -srcs += 'helpers.c' -srcs += 'ich_descriptors.c' -srcs += 'jedec.c' -srcs += 'layout.c' -srcs += 'libflashrom.c' -srcs += 'opaque.c' -srcs += 'print.c' -srcs += 'programmer.c' -srcs += 's25f.c' -srcs += 'sfdp.c' -srcs += 'spi25.c' -srcs += 'spi25_statusreg.c' -srcs += 'spi95.c' -srcs += 'spi.c' -srcs += 'sst28sf040.c' -srcs += 'sst49lfxxxc.c' -srcs += 'sst_fwhub.c' -srcs += 'stm50.c' -srcs += 'udelay.c' -srcs += 'w29ee011.c' -srcs += 'w39.c' -srcs += 'writeprotect.c' +include_dir = include_directories('include') mapfile = 'libflashrom.map' -vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) -flashrom = shared_library( +if host_machine.system() == 'darwin' + vflag = '' +else + vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) +endif +libflashrom = library( 'flashrom', sources : [ srcs, ], + include_directories : include_dir, soversion : lt_current, version : lt_version, dependencies : [ @@ -391,84 +658,129 @@ flashrom = shared_library( cargs, ], install : true, - link_args : vflag, + link_args : link_args + [vflag], link_depends : mapfile, ) -version = meson.project_version() -#strip leading characters -if version.startswith('v') - version = version.split('v')[1] -endif -if version.startswith('p') - version = version.split('p')[1] -endif - pkgg = import('pkgconfig') pkgg.generate( - libraries : flashrom, - version : version, + libraries : libflashrom, + version : flashrom_version.split()[0], # cut off the git version name : 'flashrom', filebase : 'flashrom', description : 'library to interact with flashrom', ) -conf.set('VERSION', version) -conf.set('MAN_DATE', run_command('util/getrevision.sh', '--date', 'flashrom.8.tmpl').stdout().strip()) -configure_file( - input : 'flashrom.8.tmpl', - output : 'flashrom.8', - configuration : conf, - install: true, - install_dir: join_paths(mandir, 'man8'), -) - -flashrom_dep = declare_dependency( - link_with : flashrom, - include_directories : include_directories('.'), - dependencies : deps -) +if get_option('classic_cli').enabled() or get_option('classic_cli').auto() and not get_option('default_library') == 'shared' -# we can't just link_with libflashrom as we require all the internal symbols... -executable( - 'flashrom', - sources : [ - srcs, + cli_srcs = files( 'cli_classic.c', 'cli_common.c', - 'cli_output.c', - 'flashrom.c', - ], - dependencies : [ - deps, - ], - c_args : [ - cargs, - '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID', - '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""', - ], - install : true, - install_dir : sbindir, -) + 'cli_output.c' + ) -subdir('util') + if not cc.has_function('getopt_long') + cli_srcs += files('cli_getopt.c') + endif -# unit-test framework -cmocka_dep = dependency( - 'cmocka', - fallback: ['cmocka', 'cmocka_dep'] -) -flashrom_test_dep = declare_dependency( - include_directories : include_directories('.'), - sources : [ - srcs, - 'cli_common.c', - 'cli_output.c', - 'flashrom.c', - ], - dependencies : [ - deps, - ], -) + classic_cli = executable( + 'flashrom', + cli_srcs, + c_args : cargs, + include_directories : include_dir, + install : true, + install_dir : get_option('sbindir'), + link_args : link_args, + # flashrom needs internal symbols of libflashrom + link_with : get_option('default_library') == 'static' ? libflashrom : libflashrom.get_static_lib(), + ) + if get_option('llvm_cov').enabled() + run_target('llvm-cov-cli', command : ['scripts/llvm-cov', classic_cli]) + endif +endif + +if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled() + subdir('util/ich_descriptors_tool') +endif + +if get_option('bash_completion').auto() or get_option('bash_completion').enabled() + if get_option('classic_cli').disabled() + if get_option('bash_completion').enabled() + error('`bash_completion` can not be enabled without `classic_cli`') + endif + else + bash_comp = dependency('bash-completion', required : false) + if bash_comp.found() + bash_comp_install_dir = bash_comp.get_variable( + pkgconfig : 'completionsdir', + pkgconfig_define : ['datadir', get_option('datadir')] + ) + else + bash_comp_install_dir = join_paths(get_option('datadir'), 'bash-completion', 'completions') + endif + + programmer_names_active_str = '' + foreach p_name, p_data : programmer + if p_data.get('active') + programmer_names_active_str += p_name + ' ' + endif + endforeach + + configure_file( + input : 'util/flashrom.bash-completion.tmpl', + output : 'flashrom.bash', + configuration : { + 'PROGRAMMERS' : programmer_names_active_str, + }, + install: true, + install_dir: bash_comp_install_dir, + ) + endif +endif + +# Use `.auto() or .enabled()` instead of `.allowed()` to keep the minimum meson version as low as possible. +# `.allowed()` gets introduced in 0.59.0 +if get_option('tests').auto() or get_option('tests').enabled() + # unit-test framework + cmocka_dep = dependency( + 'cmocka', + fallback: ['cmocka', 'cmocka_dep'], + required : get_option('tests') + ) + + flashrom_test_dep = declare_dependency( + include_directories : include_dir, + sources : [ + srcs, + 'cli_common.c', + 'cli_output.c', + 'flashrom.c', + ], + compile_args : [ + '-includestdlib.h', + '-includeunittest_env.h', + ], + dependencies : [ + deps, + ], + ) + + if cmocka_dep.found() + subdir('tests') + endif +endif + +programmer_names_active = [] +programmer_names_not_active = [] +foreach p_name, p_data : programmer + if p_data.get('active') + programmer_names_active += p_name + else + programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')' + endif +endforeach -subdir('tests') +summary({ + 'active' : [programmer_names_active], + 'non active' : [programmer_names_not_active], +}, section : 'Programmer') |