subdir('opcodes')
subdir('types')
subdir('cpus')
subdir('platforms')

arch_plugins_list = [
  '6502',
  '8051',
  'amd29k',
  'arm_as',
  'arm_cs',
  'avr',
  'bf',
  'c166',
  'chip8',
  'cil',
  'cr16',
  'dalvik',
  'dcpu16',
  'ebc',
  'gb',
  'h8300',
  'h8500',
  'hexagon',
  'i4004',
  'i8080',
  'java',
  'lh5801',
  'lm32',
  'luac',
  'm680x_cs',
  'm68k_cs',
  'malbolge',
  'mcore',
  'mcs96',
  'milstd1750',
  'mips_cs',
  'msp430',
  'null',
  'or1k',
  'pic',
  'ppc_as',
  'ppc_cs',
  'propeller',
  'pyc',
  'rl78',
  'rsp',
  'rx',
  'sh',
  'snes',
  'sparc_cs',
  'spc700',
  'sysz',
  'tms320',
  'v810',
  'v850',
  'vax',
  'wasm',
  'x86_as',
  'x86_nasm',
  'x86_nz',
  'xap',
  'xcore_cs',
  'x86_zydis',
]

arch_plugin_sources = [
  'p/arch_6502.c',
  'p/arch_8051.c',
  'p/arch_amd29k.c',
  'p/arch_arm_as.c',
  'p/arch_arm_cs.c',
  'p/arch_avr.c',
  'p/arch_bf.c',
  'p/arch_c166.c',
  'p/arch_chip8.c',
  'p/arch_cil.c',
  'p/arch_cr16.c',
  'p/arch_dalvik.c',
  'p/arch_dcpu16.c',
  'p/arch_ebc.c',
  'p/arch_gb.c',
  'p/arch_h8300.c',
  'p/arch_h8500.c',
  'p/arch_hexagon.c',
  'p/arch_i4004.c',
  'p/arch_i8080.c',
  'p/arch_java.c',
  'p/arch_lh5801.c',
  'p/arch_lm32.c',
  'p/arch_luac.c',
  'p/arch_m680x_cs.c',
  'p/arch_m68k_cs.c',
  'p/arch_malbolge.c',
  'p/arch_mcore.c',
  'p/arch_mcs96.c',
  'p/arch_milstd1750.c',
  'p/arch_mips_cs.c',
  'p/arch_msp430.c',
  'p/arch_null.c',
  'p/arch_or1k.c',
  'p/arch_pic.c',
  'p/arch_ppc_as.c',
  'p/arch_ppc_cs.c',
  'p/arch_propeller.c',
  'p/arch_pyc.c',
  'p/arch_rl78.c',
  'p/arch_rsp.c',
  'p/arch_rx.c',
  'p/arch_sh.c',
  'p/arch_snes.c',
  'p/arch_sparc_cs.c',
  'p/arch_spc700.c',
  'p/arch_sysz.c',
  'p/arch_tms320.c',
  'p/arch_v810.c',
  'p/arch_v850.c',
  'p/arch_vax.c',
  'p/arch_wasm.c',
  'p/arch_x86_as.c',
  'p/arch_x86_nasm.c',
  'p/arch_x86_nz.c',
  'p/arch_xap.c',
  'p/arch_xcore_cs.c',
  'p/arch_x86_zydis.c',
]

arch_esil_sources = [
  'esil/esil.c',
  'esil/esil_interrupt.c',
  'esil/esil_sources.c',
  'esil/esil_stats.c',
  'esil/esil_trace.c',
]

arch_il_sources = [
  'il/analysis_il.c',
  'il/analysis_il_trace.c',
]

arch_isa_sources = [
  'isa/6502/6502dis.c',
  'isa/8051/8051_ass.c',
  'isa/8051/8051_disas.c',
  'isa/8051/8051_il.c',
  'isa/8051/8051_parse.c',
  'isa/amd29k/amd29k.c',
  'isa/arm/arm_esil32.c',
  'isa/arm/arm_esil64.c',
  'isa/arm/arm_il32.c',
  'isa/arm/arm_il64.c',
  'isa/arm/arm_it.c',
  'isa/arm/armass.c',
  'isa/arm/armass64.c',
  'isa/avr/assembler.c',
  'isa/avr/avr_esil.c',
  'isa/avr/avr_il.c',
  'isa/avr/disassembler.c',
  'isa/cil/cil_dis.c',
  'isa/cr16/cr16_disas.c',
  'isa/dcpu16/asm.c',
  'isa/dcpu16/dis.c',
  'isa/ebc/ebc_disas.c',
  'isa/gb/gbasm.c',
  # 'isa/gb/gbdis.c',
  # 'isa/gb/meta_gb_cmt.c',
  'isa/h8300/h8300_disas.c',
  'isa/h8300/h8300_esil.c',
  'isa/h8300/h8300_il.c',
  'isa/h8500/h8500.c',
  'isa/hexagon/hexagon.c',
  'isa/hexagon/hexagon_arch.c',
  'isa/hexagon/hexagon_disas.c',
  'isa/hexagon/hexagon_il.c',
  'isa/hexagon/hexagon_il_getter_table.h',
  'isa/hexagon/il_ops/hexagon_il_A2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_A4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_A5_ops.c',
  'isa/hexagon/il_ops/hexagon_il_A6_ops.c',
  'isa/hexagon/il_ops/hexagon_il_A7_ops.c',
  'isa/hexagon/il_ops/hexagon_il_C2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_C4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_F2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_G4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_IMPORTED_ops.c',
  'isa/hexagon/il_ops/hexagon_il_J2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_J4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_L2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_L4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_L6_ops.c',
  'isa/hexagon/il_ops/hexagon_il_M2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_M4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_M5_ops.c',
  'isa/hexagon/il_ops/hexagon_il_M6_ops.c',
  'isa/hexagon/il_ops/hexagon_il_M7_ops.c',
  'isa/hexagon/il_ops/hexagon_il_PS_ops.c',
  'isa/hexagon/il_ops/hexagon_il_R6_ops.c',
  'isa/hexagon/il_ops/hexagon_il_S2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_S4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_S5_ops.c',
  'isa/hexagon/il_ops/hexagon_il_S6_ops.c',
  'isa/hexagon/il_ops/hexagon_il_SA1_ops.c',
  'isa/hexagon/il_ops/hexagon_il_SL1_ops.c',
  'isa/hexagon/il_ops/hexagon_il_SL2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_SS1_ops.c',
  'isa/hexagon/il_ops/hexagon_il_SS2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_UNDOCUMENTED_ops.c',
  'isa/hexagon/il_ops/hexagon_il_V6_ops.c',
  'isa/hexagon/il_ops/hexagon_il_Y2_ops.c',
  'isa/hexagon/il_ops/hexagon_il_Y4_ops.c',
  'isa/hexagon/il_ops/hexagon_il_Y5_ops.c',
  'isa/hexagon/il_ops/hexagon_il_Y6_ops.c',
  'isa/hexagon/il_ops/hexagon_il_dep_ops.c',
  'isa/hexagon/il_ops/hexagon_il_invalid_ops.c',
  'isa/hexagon/il_ops/hexagon_il_non_insn_ops.c',
  'isa/i4004/i4004dis.c',
  'isa/i8080/i8080dis.c',
  'isa/java/assembler.c',
  'isa/java/jvm.c',
  'isa/lh5801/lh5801.c',
  'isa/luac/lua_arch.c',
  'isa/luac/v50/analysis_50.c',
  'isa/luac/v50/assembly_50.c',
  'isa/luac/v50/disassembly_50.c',
  'isa/luac/v50/opcode_50.c',
  'isa/luac/v51/analysis_51.c',
  'isa/luac/v51/assembly_51.c',
  'isa/luac/v51/disassembly_51.c',
  'isa/luac/v51/opcode_51.c',
  'isa/luac/v52/analysis_52.c',
  'isa/luac/v52/assembly_52.c',
  'isa/luac/v52/disassembly_52.c',
  'isa/luac/v52/opcode_52.c',
  'isa/luac/v53/analysis_53.c',
  'isa/luac/v53/assembly_53.c',
  'isa/luac/v53/disassembly_53.c',
  'isa/luac/v53/opcode_53.c',
  'isa/luac/v54/analysis_54.c',
  'isa/luac/v54/assembly_54.c',
  'isa/luac/v54/disassembly_54.c',
  'isa/luac/v54/opcode_54.c',
  'isa/luac/v55/analysis_55.c',
  'isa/luac/v55/assembly_55.c',
  'isa/luac/v55/disassembly_55.c',
  'isa/luac/v55/opcode_55.c',
  'isa/luac/luajit/analysis_2.1.c',
  'isa/luac/luajit/arch_2.1.c',
  'isa/luac/luajit/asm_2.1.c',
  'isa/luac/luajit/opcode_2.1.c',
  'isa/mcore/mcore.c',
  'isa/milstd1750/milstd1750_disas.c',
  'isa/mips/mips_assembler.c',
  'isa/mips/mips_esil.c',
  'isa/mips/mips_il.c',
  'isa/msp430/msp430_disas.c',
  'isa/msp430/msp430_il.c',
  'isa/or1k/or1k_disas.c',
  'isa/pic/pic_baseline.c',
  'isa/pic/pic_midrange.c',
  'isa/pic/pic_highend.c',
  'isa/pic/pic_midrange_analysis.c',
  'isa/pic/pic_highend_analysis.c',
  'isa/ppc/libps/libps.c',
  'isa/ppc/libvle/vle.c',
  'isa/ppc/ppc_il.c',
  'isa/ppc/ppc_il_flag_ops.c',
  'isa/ppc/ppc_il_ops.c',
  'isa/propeller/propeller_disas.c',
  'isa/pyc/opcode.c',
  'isa/pyc/opcode_10.c',
  'isa/pyc/opcode_11.c',
  'isa/pyc/opcode_12.c',
  'isa/pyc/opcode_13.c',
  'isa/pyc/opcode_14.c',
  'isa/pyc/opcode_15.c',
  'isa/pyc/opcode_16.c',
  'isa/pyc/opcode_20.c',
  'isa/pyc/opcode_21.c',
  'isa/pyc/opcode_22.c',
  'isa/pyc/opcode_23.c',
  'isa/pyc/opcode_24.c',
  'isa/pyc/opcode_25.c',
  'isa/pyc/opcode_26.c',
  'isa/pyc/opcode_27.c',
  'isa/pyc/opcode_2x.c',
  'isa/pyc/opcode_30.c',
  'isa/pyc/opcode_31.c',
  'isa/pyc/opcode_310.c',
  'isa/pyc/opcode_311.c',
  'isa/pyc/opcode_312.c',
  'isa/pyc/opcode_313.c',
  'isa/pyc/opcode_314.c',
  'isa/pyc/opcode_32.c',
  'isa/pyc/opcode_33.c',
  'isa/pyc/opcode_34.c',
  'isa/pyc/opcode_35.c',
  'isa/pyc/opcode_36.c',
  'isa/pyc/opcode_37.c',
  'isa/pyc/opcode_38.c',
  'isa/pyc/opcode_39.c',
  'isa/pyc/opcode_3x.c',
  'isa/pyc/opcode_analysis.c',
  'isa/pyc/opcode_arg_fmt.c',
  'isa/pyc/pyc_dis.c',
  'isa/rl78/rl78.c',
  'isa/rl78/rl78_instr.c',
  'isa/rl78/rl78_maps.c',
  'isa/rl78/rl78_operand.c',
  'isa/rsp/rsp_idec.c',
  'isa/rx/rx.c',
  'isa/rx/rx_inst.c',
  'isa/rx/rx_opcode_detail.c',
  'isa/sh/assembler.c',
  'isa/sh/disassembler.c',
  'isa/sh/lookup.c',
  'isa/sh/sh_il.c',
  'isa/snes/snesdis.c',
  'isa/sparc/sparc_il.c',
  'isa/sparc/sparc_il_ops.c',
  'isa/spc700/spc700dis.c',
  'isa/tms320/c55_ir.c',
  'isa/tms320/c54x/c54x.c',
  'isa/tms320/c54x/c54x_il.c',
  'isa/tms320/c2x/c2x.c',
  'isa/tms320/c2x/c2x_il.c',
  'isa/tms320/c5x/c5x.c',
  'isa/tms320/c5x/c5x_decode.c',
  'isa/tms320/c5x/c5x_il.c',
  'isa/tms320/c55x_plus/c55plus_arch.c',
  'isa/tms320/c55x/c55x_analysis.c',
  'isa/tms320/c55x_plus/c55plus_analysis.c',
  'isa/tms320/c55x_plus/c55plus_il_config.c',
  'isa/tms320/c55x_plus/ins.c',
  'isa/tms320/c64x/c64x.c',
  'isa/tms320/tms320c55x_insn.c',
  'isa/v810/v810_disas.c',
  'isa/v810/v810_il.c',
  'isa/v850/v850_disas.c',
  'isa/v850/v850_il.c',
  'isa/vax/vax_dis.c',
  'isa/wasm/wasm.c',
  'isa/x86/common.c',
  'isa/x86/x86_il.c',
  # 'isa/xap/dis.c',
]

arch_isa_includes = [
  'isa',
]

if capstone_dep.version() == 'next' or capstone_dep.version().split('.')[0].to_int() > 6
  # plugins
  arch_plugins_list += [
    'cbpf_cs',
    'riscv_cs',
  ]

  # plugins sources
  arch_plugin_sources += [
    'p/arch_cbpf_cs.c',
    'p/arch_riscv_cs.c',
  ]
endif

if capstone_dep.version() == 'next' or capstone_dep.version().split('.')[0].to_int() > 5
  # plugins
  arch_plugins_list += [
    'bpf_cs',
  ]

  # plugins sources
  arch_plugin_sources += [
    'p/arch_bpf_cs.c',
  ]
endif

if capstone_dep.version() == 'next' or capstone_dep.version().split('.')[0].to_int() > 4
  # plugins
  arch_plugins_list += [
    'tricore_cs',
  ]

  # plugins sources
  arch_plugin_sources += [
    'p/arch_tricore_cs.c',
  ]

  # isa sources
  arch_isa_sources += [
    'isa/tricore/tricore_il.c',
  ]
endif

if capstone_dep.version() == 'next'
  # plugins
  arch_plugins_list += [
    'alpha_cs',
    'hppa_cs',
    'loongarch_cs',
    'xtensa_cs',
  ]

  # plugins sources
  arch_plugin_sources += [
    'p/arch_alpha.c',
    'p/arch_loongarch_cs.c',
    'p/arch_hppa_cs.c',
    'p/arch_xtensa_cs.c',
  ]

  # isa sources
  arch_isa_sources += [
    'isa/xtensa/xtensa.c',
    'isa/xtensa/xtensa_esil.c',
    'isa/xtensa/xtensa_il.c',
  ]
endif

if get_option('use_gpl')
  # GPL plugins
  arch_plugins_list += [
    'arc_gnu',
    'cris_gnu',
    'lanai_gnu',
    'z80_gnu',
  ]

  # GPL plugins sources
  arch_plugin_sources += [
    'p_gnu/arch_arc.c',
    'p_gnu/arch_cris.c',
    'p_gnu/arch_lanai.c',
    'p_gnu/arch_z80.c',
  ]

  # GPL isa sources
  arch_isa_sources += [
    'isa_gnu/arc/arc-dis.c',
    'isa_gnu/arc/arc-ext.c',
    'isa_gnu/arc/arc-opc.c',
    'isa_gnu/arc/arcompact-dis.c',
    'isa_gnu/cris/cris-dis.c',
    'isa_gnu/cris/cris-opc.c',
    'isa_gnu/lanai/lanai-dis.c',
    'isa_gnu/lanai/lanai-opc.c',
    # 'isa_gnu/z80/expressions.c',
    # 'isa_gnu/z80/z80.c',
    # 'isa_gnu/z80/z80asm.c',
  ]

  # GPL isa includes
  arch_isa_includes += [
    'isa_gnu',
  ]
endif

arch_common_sources = [
  'acode.c',
  'analysis.c',
  'aop.c',
  'arch.c',
  'asm.c',
  'binutils_as.c',
  'block.c',
  'cc.c',
  'class.c',
  'cond.c',
  'cycles.c',
  'data.c',
  'dwarf_process.c',
  'luac_process.c',
  'fcn.c',
  'filter.c',
  'function.c',
  'hint.c',
  'il_trace.c',
  'jmptbl.c',
  'labels.c',
  'meta.c',
  'no_rtti.c',
  'objc_rtti.c',
  'omf_process.c',
  'op.c',
  'parse.c',
  'parse_helper.c',
  'pdb_process.c',
  'platform_profile.c',
  'platform_target_index.c',
  'reflines.c',
  'rtti.c',
  'rtti_itanium.c',
  'rtti_msvc.c',
  'serialize_analysis.c',
  'similarity.c',
  'swift_rtti.c',
  'switch.c',
  'types.c',
  'value.c',
  'var.c',
  'var_global.c',
  'vtable.c',
  'xrefs.c',
]

arch_common_includes = [
  '.',
]

arch_plugins = {
  'base_name': 'rz_arch',
  'base_struct': 'RzArchPlugin',
  'list': arch_plugins_list,
}

rz_arch_inc = [
  platform_inc,
  include_directories(arch_isa_includes + arch_common_includes)
]

rz_arch_sources = arch_isa_sources + arch_il_sources + arch_esil_sources + arch_plugin_sources + arch_common_sources

rz_arch = library('rz_arch', rz_arch_sources,
  include_directories: rz_arch_inc,
  dependencies: [
    rz_util_dep,
    rz_crypto_dep,
    rz_reg_dep,
    rz_syscall_dep,
    rz_search_dep,
    rz_config_dep,
    rz_cons_dep,
    rz_flag_dep,
    rz_hash_dep,
    rz_diff_dep,
    rz_bin_dep,
    rz_type_dep,
    rz_il_dep,
    capstone_dep,
    zydis_dep,
    mth,
    dependency('rzspp'),
  ],
  install: true,
  implicit_include_directories: false,
  install_rpath: rpath_lib,
  soversion: rizin_libversion,
  version: rizin_version,
  name_suffix: lib_name_suffix,
  name_prefix: lib_name_prefix,
)

rz_arch_dep = declare_dependency(link_with: rz_arch, include_directories: rz_arch_inc)
meson.override_dependency('rz_arch', rz_arch_dep)

modules += { 'rz_arch': {
    'target': rz_arch,
    'dependencies': [
      'rz_bin',
      'rz_config',
      'rz_cons',
      'rz_crypto',
      'rz_diff',
      'rz_flag',
      'rz_hash',
      'rz_il',
      'rz_reg',
      'rz_search',
      'rz_syscall',
      'rz_type',
      'rz_util',
    ],
    'plugins': [arch_plugins]
}}
