Class: Xot::ExtConf

Inherits:
Object
  • Object
show all
Includes:
Rake, Util
Defined in:
lib/xot/extconf.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rake

#append_env, #ar, #arflags, #build_application, #build_native_library, #build_ruby_extension, #build_ruby_gem, #cd_sh, #compile_erb, #compile_erb_str, #cppflags, #cxx, #cxxflags, #debug?, #default_tasks, #define_placeholder_tasks, #doc_dir, #env, #env_array, #erbs_map, #excluded?, #excludes, #ext_dir, #ext_lib_dir, #filter_file, #get_env, #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, #target, #target_name, #test_alones, #test_dir, #test_excludes, #test_ruby_extension, #use_boost_library, #use_bundler, #use_external_library, #vendor_dir, #vendor_srcs_map, #verbose?, #verbose_puts

Constructor Details

#initialize(*extensions, &block) ⇒ ExtConf

Returns a new instance of ExtConf.



16
17
18
19
20
21
# File 'lib/xot/extconf.rb', line 16

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

#defsObject (readonly)

Returns the value of attribute defs.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def defs
  @defs
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def extensions
  @extensions
end

#frameworksObject (readonly)

Returns the value of attribute frameworks.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def frameworks
  @frameworks
end

#headersObject (readonly)

Returns the value of attribute headers.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def headers
  @headers
end

#inc_dirsObject (readonly)

Returns the value of attribute inc_dirs.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def inc_dirs
  @inc_dirs
end

#lib_dirsObject (readonly)

Returns the value of attribute lib_dirs.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def lib_dirs
  @lib_dirs
end

#libsObject (readonly)

Returns the value of attribute libs.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def libs
  @libs
end

#local_libsObject (readonly)

Returns the value of attribute local_libs.



14
15
16
# File 'lib/xot/extconf.rb', line 14

def local_libs
  @local_libs
end

Instance Method Details

#create_makefile(*args) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/xot/extconf.rb', line 51

def create_makefile(*args)
  extensions.each do |ext|
    dir_config ext.name.downcase, 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'}

  super
end

#debugObject



23
24
25
# File 'lib/xot/extconf.rb', line 23

def debug()
  env :DEBUG, false
end

#setupObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/xot/extconf.rb', line 27

def setup()
  yield if block_given?

  extensions.each do |ext|
    name = ext.name.downcase
    headers    << "#{name}.h"
    local_libs << name
  end

  ldflags = $LDFLAGS.dup
  if osx?
    opt = '-Wl,-undefined,dynamic_lookup'
    ldflags << " #{opt}" unless ($DLDFLAGS || '').include?(opt)
  end

  local_libs << (clang? ? 'c++' : 'stdc++')

  $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