| 1 |
# Cross Compiling configuration for the Sega Dreamcast |
| 2 |
# https://dreamcast.wiki/Using_Ruby_for_Sega_Dreamcast_development |
| 3 |
# |
| 4 |
# Requires KallistiOS (KOS) |
| 5 |
# http://gamedev.allusion.net/softprj/kos/ |
| 6 |
# |
| 7 |
# Tested on GNU/Linux, macOS and Windows (through MinGW-w64/MSYS2, Cygwin and DreamSDK). |
| 8 |
# DreamSDK is based on MinGW/MSYS: https://dreamsdk.org/ |
| 9 |
# |
| 10 |
# Input this command on the directory where mruby is installed: |
| 11 |
# make MRUBY_CONFIG=dreamcast_shelf |
| 12 |
# |
| 13 |
MRuby::CrossBuild.new("dreamcast") do |conf| |
| 14 |
toolchain :gcc |
| 15 |
|
| 16 |
# Support for DreamSDK (based on MinGW/MSYS) |
| 17 |
# To compile mruby with DreamSDK, RubyInstaller for Windows should be installed |
| 18 |
DREAMSDK_HOME = ENV["DREAMSDK_HOME"] |
| 19 |
MSYS_ROOT = !(DREAMSDK_HOME.nil? || DREAMSDK_HOME.empty?) ? "#{DREAMSDK_HOME}/msys/1.0" : "" |
| 20 |
|
| 21 |
# Setting paths |
| 22 |
DREAMCAST_PATH = "#{MSYS_ROOT}/opt/toolchains/dc" |
| 23 |
KOS_PATH = "#{DREAMCAST_PATH}/kos" |
| 24 |
BIN_PATH = "#{DREAMCAST_PATH}/sh-elf/bin" |
| 25 |
|
| 26 |
# C compiler |
| 27 |
# Flags were extracted from KallistiOS environment files |
| 28 |
conf.cc do |cc| |
| 29 |
cc.command = "#{BIN_PATH}/sh-elf-gcc" |
| 30 |
cc.include_paths << ["#{KOS_PATH}/include", "#{KOS_PATH}/kernel/arch/dreamcast/include", "#{KOS_PATH}/addons/include", "#{KOS_PATH}/../kos-ports/include"] |
| 31 |
cc.flags << ["-O2", "-fomit-frame-pointer", "-ml", "-m4-single-only", "-ffunction-sections", "-fdata-sections", "-Wall", "-g", "-fno-builtin", "-ml", "-m4-single-only", "-Wl,-Ttext=0x8c010000", "-Wl,--gc-sections", "-T#{KOS_PATH}/utils/ldscripts/shlelf.xc", "-nodefaultlibs"] |
| 32 |
cc.compile_options = %Q[%{flags} -o "%{outfile}" -c "%{infile}"] |
| 33 |
cc.defines << %w(_arch_dreamcast) |
| 34 |
cc.defines << %w(_arch_sub_pristine) |
| 35 |
end |
| 36 |
|
| 37 |
# C++ compiler |
| 38 |
conf.cxx do |cxx| |
| 39 |
cxx.command = conf.cc.command.dup |
| 40 |
cxx.include_paths = conf.cc.include_paths.dup |
| 41 |
cxx.flags = conf.cc.flags.dup |
| 42 |
cxx.flags << %w(-fno-rtti -fno-exceptions) |
| 43 |
cxx.defines = conf.cc.defines.dup |
| 44 |
cxx.compile_options = conf.cc.compile_options.dup |
| 45 |
end |
| 46 |
|
| 47 |
# Linker |
| 48 |
# There is an issue when making the mruby library with KallistiOS: |
| 49 |
# 'newlib_kill.o' and 'newlib_getpid.o' aren't found so they are explicitly |
| 50 |
# specified here at least for now. |
| 51 |
conf.linker do |linker| |
| 52 |
linker.command="#{BIN_PATH}/sh-elf-gcc" |
| 53 |
linker.flags << ["#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_kill.o", "#{MSYS_ROOT}/opt/toolchains/dc/kos/kernel/build/newlib_getpid.o", "-Wl,--start-group -lkallisti -lc -lgcc -Wl,--end-group"] |
| 54 |
linker.library_paths << ["#{KOS_PATH}/lib/dreamcast", "#{KOS_PATH}/addons/lib/dreamcast", "#{KOS_PATH}/../kos-ports/lib"] |
| 55 |
end |
| 56 |
|
| 57 |
# Archiver |
| 58 |
conf.archiver do |archiver| |
| 59 |
archiver.command = "#{BIN_PATH}/sh-elf-ar" |
| 60 |
archiver.archive_options = 'rcs "%{outfile}" %{objs}' |
| 61 |
end |
| 62 |
|
| 63 |
# No executables |
| 64 |
conf.bins = [] |
| 65 |
|
| 66 |
# Do not build executable test |
| 67 |
conf.build_mrbtest_lib_only |
| 68 |
|
| 69 |
# Disable C++ exception |
| 70 |
conf.disable_cxx_exception |
| 71 |
|
| 72 |
# Gems from core |
| 73 |
# Some Gems are incompatible and were disabled. |
| 74 |
|
| 75 |
conf.gem :core => "mruby-array-ext" |
| 76 |
conf.gem :core => "mruby-catch" |
| 77 |
conf.gem :core => "mruby-class-ext" |
| 78 |
conf.gem :core => "mruby-cmath" |
| 79 |
conf.gem :core => "mruby-compar-ext" |
| 80 |
conf.gem :core => "mruby-compiler" |
| 81 |
conf.gem :core => "mruby-complex" |
| 82 |
conf.gem :core => "mruby-enum-chain" |
| 83 |
conf.gem :core => "mruby-enum-ext" |
| 84 |
conf.gem :core => "mruby-enum-lazy" |
| 85 |
conf.gem :core => "mruby-enumerator" |
| 86 |
conf.gem :core => "mruby-error" |
| 87 |
conf.gem :core => "mruby-eval" |
| 88 |
conf.gem :core => "mruby-exit" |
| 89 |
conf.gem :core => "mruby-fiber" |
| 90 |
conf.gem :core => "mruby-hash-ext" |
| 91 |
# conf.gem :core => "mruby-io" |
| 92 |
conf.gem :core => "mruby-kernel-ext" |
| 93 |
conf.gem :core => "mruby-math" |
| 94 |
conf.gem :core => "mruby-metaprog" |
| 95 |
conf.gem :core => "mruby-method" |
| 96 |
conf.gem :core => "mruby-numeric-ext" |
| 97 |
conf.gem :core => "mruby-object-ext" |
| 98 |
conf.gem :core => "mruby-objectspace" |
| 99 |
conf.gem :core => "mruby-os-memsize" |
| 100 |
conf.gem :core => "mruby-pack" |
| 101 |
conf.gem :core => "mruby-print" |
| 102 |
conf.gem :core => "mruby-proc-binding" |
| 103 |
conf.gem :core => "mruby-proc-ext" |
| 104 |
conf.gem :core => "mruby-random" |
| 105 |
conf.gem :core => "mruby-range-ext" |
| 106 |
conf.gem :core => "mruby-rational" |
| 107 |
conf.gem :core => "mruby-sleep" |
| 108 |
# conf.gem :core => "mruby-socket" |
| 109 |
conf.gem :core => "mruby-sprintf" |
| 110 |
conf.gem :core => "mruby-string-ext" |
| 111 |
conf.gem :core => "mruby-struct" |
| 112 |
conf.gem :core => "mruby-symbol-ext" |
| 113 |
# conf.gem :core => "mruby-test" |
| 114 |
# conf.gem :core => "mruby-time" |
| 115 |
conf.gem :core => "mruby-toplevel-ext" |
| 116 |
end |