MRuby::Toolchain.new(:riscv) do |conf, _params|
  toolchain :gcc

  [conf.cc, conf.objc, conf.asm].each do |cc|
    cc.command = ENV['CC'] || 'riscv64-unknown-elf-gcc'
    cc.flags = "-DMRB_WITHOUT_FLOAT -std=gnu99 -O3 -Os -g -Wall -Wextra -Werror -Wno-unused-parameter -Wno-missing-field-initializers -Wno-type-limits -Wno-clobbered -Wno-return-type -Wno-old-style-declaration -Wno-stringop-truncation -Wno-implicit-fallthrough "
  end
  conf.archiver.command = ENV['AR'] || 'riscv64-unknown-elf-ar'
  conf.cxx.command = ENV['CXX'] || 'riscv64-unknown-elf-g++'
  conf.linker.command = ENV['LD'] || 'riscv64-unknown-elf-gcc'
end

MRuby::Build.new do |conf|
  toolchain :gcc

  conf.gembox 'default'
end

MRuby::Build.new("riscv-with-io") do |conf|
  toolchain :riscv

  # Use standard Array#pack, String#unpack methods
  conf.gem :core => "mruby-pack"

  # Use standard Kernel#sprintf method
  conf.gem :core => "mruby-sprintf"

  # Use standard print/puts/p
  conf.gem :core => "mruby-print"

  # Use standard Time class
  conf.gem :core => "mruby-time"

  # Use standard Struct class
  conf.gem :core => "mruby-struct"

  # Use Comparable module extension
  conf.gem :core => "mruby-compar-ext"

  # Use Enumerable module extension
  conf.gem :core => "mruby-enum-ext"

  # Use String class extension
  conf.gem :core => "mruby-string-ext"

  # Use Numeric class extension
  conf.gem :core => "mruby-numeric-ext"

  # Use Array class extension
  conf.gem :core => "mruby-array-ext"

  # Use Hash class extension
  conf.gem :core => "mruby-hash-ext"

  # Use Range class extension
  conf.gem :core => "mruby-range-ext"

  # Use Proc class extension
  conf.gem :core => "mruby-proc-ext"

  # Use Symbol class extension
  conf.gem :core => "mruby-symbol-ext"

  # Use Random class
  conf.gem :core => "mruby-random"

  # Use Object class extension
  conf.gem :core => "mruby-object-ext"

  # Use ObjectSpace class
  conf.gem :core => "mruby-objectspace"

  # Use Fiber class
  conf.gem :core => "mruby-fiber"

  # Use Enumerator class (require mruby-fiber)
  conf.gem :core => "mruby-enumerator"

  # Use Enumerator::Lazy class (require mruby-enumerator)
  conf.gem :core => "mruby-enum-lazy"

  # Use toplevel object (main) methods extension
  conf.gem :core => "mruby-toplevel-ext"

  # Generate mirb command
  conf.gem :core => "mruby-bin-mirb"

  # Use Kernel module extension
  conf.gem :core => "mruby-kernel-ext"

  # Use class/module extension
  conf.gem :core => "mruby-class-ext"

  # Use mruby-compiler to build other mrbgems
  conf.gem :core => "mruby-compiler"

  conf.gem "deps/mruby-ckb"
  conf.gem "deps/mruby-blake2b"
  conf.gem "deps/mruby-tiny-bignum"

  conf.gem :core => "mruby-metaprog"
  conf.gem :github => "xxuejie/mruby-json"
end

MRuby::Build.new('riscv-without-io') do |conf|
  toolchain :riscv

  conf.cc.flags << "-DMRB_DISABLE_STDIO "

  # Use standard Array#pack, String#unpack methods
  conf.gem :core => "mruby-pack"

  # Use standard Time class
  conf.gem :core => "mruby-time"

  # Use standard Struct class
  conf.gem :core => "mruby-struct"

  # Use Comparable module extension
  conf.gem :core => "mruby-compar-ext"

  # Use Enumerable module extension
  conf.gem :core => "mruby-enum-ext"

  # Use String class extension
  conf.gem :core => "mruby-string-ext"

  # Use Numeric class extension
  conf.gem :core => "mruby-numeric-ext"

  # Use Array class extension
  conf.gem :core => "mruby-array-ext"

  # Use Hash class extension
  conf.gem :core => "mruby-hash-ext"

  # Use Range class extension
  conf.gem :core => "mruby-range-ext"

  # Use Proc class extension
  conf.gem :core => "mruby-proc-ext"

  # Use Symbol class extension
  conf.gem :core => "mruby-symbol-ext"

  # Use Random class
  conf.gem :core => "mruby-random"

  # Use Object class extension
  conf.gem :core => "mruby-object-ext"

  # Use ObjectSpace class
  conf.gem :core => "mruby-objectspace"

  # Use Fiber class
  conf.gem :core => "mruby-fiber"

  # Use Enumerator class (require mruby-fiber)
  conf.gem :core => "mruby-enumerator"

  # Use Enumerator::Lazy class (require mruby-enumerator)
  conf.gem :core => "mruby-enum-lazy"

  # Use toplevel object (main) methods extension
  conf.gem :core => "mruby-toplevel-ext"

  # Use Kernel module extension
  conf.gem :core => "mruby-kernel-ext"

  # Use class/module extension
  conf.gem :core => "mruby-class-ext"

  # Use mruby-compiler to build other mrbgems
  conf.gem :core => "mruby-compiler"

  conf.gem "deps/mruby-ckb"
  conf.gem "deps/mruby-blake2b"
  conf.gem "deps/mruby-tiny-bignum"

  conf.gem :core => "mruby-metaprog"
  conf.gem :github => "xxuejie/mruby-json"
end
