Class: Xot::ExtConf
Instance Attribute Summary collapse
-
#defs ⇒ Object
readonly
Returns the value of attribute defs.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#frameworks ⇒ Object
readonly
Returns the value of attribute frameworks.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#inc_dirs ⇒ Object
readonly
Returns the value of attribute inc_dirs.
-
#lib_dirs ⇒ Object
readonly
Returns the value of attribute lib_dirs.
-
#libs ⇒ Object
readonly
Returns the value of attribute libs.
-
#local_libs ⇒ Object
readonly
Returns the value of attribute local_libs.
Instance Method Summary collapse
- #build_lib_objs_for_wasm ⇒ Object
- #create_makefile(*args) ⇒ Object
- #debug ⇒ Object
- #export_all_symbols ⇒ Object
-
#initialize(*extensions, &block) ⇒ ExtConf
constructor
A new instance of ExtConf.
- #link_lib_objs_for_wasm ⇒ Object
- #my_ext ⇒ Object
- #setup ⇒ Object
Methods included from Rake
#arflags, #build_application, #build_native_library, #build_ruby_extension, #build_ruby_gem, #cd_sh, #compile_erb, #compile_erb_str, #cppflags, #cxxflags, #default_tasks, #define_placeholder_tasks, #doc_dir, #erbs_map, #excluded?, #excludes, #ext_dir, #filter_file, #glob, #inc_dir, #install_packages, #lib_dir, #make_cflags, #make_cppflags, #make_cppflags_defs, #make_cppflags_incdirs, #make_cppflags_sys_incdirs, #make_ldflags, #make_path_map, #noverbose_puts, #params, #rake_puts, #ruby_inc_dirs, #src_dir, #src_dirs, #src_ext_map, #src_exts, #srcs_map, #swiftc, #swiftflags, #target, #target_name, #test_dir, #test_ruby_extension, #tests_alone, #tests_exclude, #use_boost_library, #use_bundler, #use_external_library, #vendor_dir, #vendor_srcs_map, #verbose_puts
Constructor Details
#initialize(*extensions, &block) ⇒ ExtConf
Returns a new instance of ExtConf.
14 15 16 17 18 19 |
# File 'lib/xot/extconf.rb', line 14 def initialize(*extensions, &block) @extensions = extensions.map {|x| x.const_get :Extension} @defs, @inc_dirs, @lib_dirs, @headers, @libs, @local_libs, @frameworks = ([[]] * 7).map(&:dup) Xot::BlockUtil.instance_eval_or_block_call self, &block if block end |
Instance Attribute Details
#defs ⇒ Object (readonly)
Returns the value of attribute defs.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def defs @defs end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def extensions @extensions end |
#frameworks ⇒ Object (readonly)
Returns the value of attribute frameworks.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def frameworks @frameworks end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def headers @headers end |
#inc_dirs ⇒ Object (readonly)
Returns the value of attribute inc_dirs.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def inc_dirs @inc_dirs end |
#lib_dirs ⇒ Object (readonly)
Returns the value of attribute lib_dirs.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def lib_dirs @lib_dirs end |
#libs ⇒ Object (readonly)
Returns the value of attribute libs.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def libs @libs end |
#local_libs ⇒ Object (readonly)
Returns the value of attribute local_libs.
21 22 23 |
# File 'lib/xot/extconf.rb', line 21 def local_libs @local_libs end |
Instance Method Details
#build_lib_objs_for_wasm ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/xot/extconf.rb', line 87 def build_lib_objs_for_wasm() ruby_dirs = [ "#{ENV['extout']}/include/wasm32-emscripten", "#{ENV['top_srcdir']}/include" ] envs = { CC: '', CXX: '', AR: '', RANLIB: '', CPPFLAGS: ' -sUSE_SDL=2 -sUSE_SDL_TTF=2', CFLAGS: ' -sUSE_SDL=2 -sUSE_SDL_TTF=2', CXXFLAGS: '', LDFLAGS: ' -sUSE_SDL=2 -sUSE_SDL_TTF=2', INCDIRS: ruby_dirs.join(' ') }.map {|k, v| "#{k}='#{(RbConfig::CONFIG[k.to_s] || '') + v}'"} Dir.chdir target.root_dir do cmd = "#{envs.join ' '} rake ext:lib_objs" puts cmd system cmd end end |
#create_makefile(*args) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/xot/extconf.rb', line 60 def create_makefile(*args) extensions.each do |ext| dir_config ext.name(true), ext.inc_dir, ext.lib_dir end exit 1 unless headers.all? {|s| have_header s} exit 1 unless libs.all? {|s| have_library s, 't'} unless wasm? super export_all_symbols if mingw? || cygwin? link_lib_objs_for_wasm if wasm? end |
#debug ⇒ Object
27 28 29 |
# File 'lib/xot/extconf.rb', line 27 def debug() env :DEBUG, false end |
#export_all_symbols ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/xot/extconf.rb', line 74 def export_all_symbols() name = my_ext.name true opts = %W[ -Wl,--export-all-symbols,--whole-archive -l#{name} -Wl,--no-whole-archive ].join ' ' filter_file('Makefile') {|s| s.sub(/^DEFFILE\s*=.*$/, 'DEFFILE =') .sub(/^(LOCAL_LIBS\s*=.*) -l#{name}\b/) {"#{$1} #{opts}"} } end |
#link_lib_objs_for_wasm ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/xot/extconf.rb', line 111 def link_lib_objs_for_wasm() lib_objs = Dir.glob "#{target.ext_dir}/**/__libobj_*.o" filter_file 'Makefile' do |str| str.sub(/^(\s*)(.*\$\(AR\).*)$/) { "#{$1}#{$2}\n#{$1}$(Q) $(AR) r $@ #{lib_objs.join ' '}" } end end |
#my_ext ⇒ Object
23 24 25 |
# File 'lib/xot/extconf.rb', line 23 def my_ext() extensions.last end |
#setup ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/xot/extconf.rb', line 31 def setup() yield if block_given? extensions.each do |ext| name = ext.name true lib_name = ext == my_ext ? name : ext.lib_name headers << "#{name}.h" local_libs << lib_name if lib_name end ldflags = $LDFLAGS.dup case when osx? opt = '-Wl,-undefined,dynamic_lookup' ldflags << " #{opt}" unless ($DLDFLAGS || '').include?(opt) ldflags << ' -Wl,-bind_at_load' if osx? && debug? when wasm? build_lib_objs_for_wasm end local_libs << 'stdc++' if gcc? $CPPFLAGS = make_cppflags $CPPFLAGS, defs, inc_dirs $CFLAGS = make_cflags $CFLAGS + ' -x c++' $CXXFLAGS = make_cflags $CXXFLAGS + ' -x c++' if $CXXFLAGS $LDFLAGS = make_ldflags ldflags, lib_dirs, frameworks $LOCAL_LIBS << local_libs.reverse.map {|s| " -l#{s}"}.join end |