Class: Detroit::ExtConf

Inherits:
Tool
  • Object
show all
Includes:
Standard
Defined in:
lib/detroit-extconf.rb

Overview

TODO:

Can we implement a win32 cross-compile?

Note:

By neccessity this tool shells out to the command line.

The ExtConf tool utilizes extconf.rb script and Autotools standard Makefile to compile native extensions.

Targets the following standard toolchain stations:

  • compile

  • clean

  • purge

Constant Summary collapse

MANPAGE =

Location of manpage for tool.

File.dirname(__FILE__) + '/../man/detroit-dnote.5'
MAKE_COMMAND =

Platform specific make command.

ENV['make'] || (RUBY_PLATFORM =~ /(win|w)32$/ ? 'nmake' : 'make')

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#staticObject

Compile statically? Applies only to compile method. (false)



41
42
43
# File 'lib/detroit-extconf.rb', line 41

def static
  @static
end

Instance Method Details

#assemble?(station, options = {}) ⇒ Boolean

This tool ties into the ‘compile`, `clean` and `purge` stations of the standard assembly.

Returns:

  • (Boolean)


107
108
109
110
111
112
# File 'lib/detroit-extconf.rb', line 107

def assemble?(station, options={})
  return true if station == :compile
  return true if station == :clean
  return true if station == :purge
  return false
end

#cleanObject

Remove enough compile products for a clean compile.



67
68
69
# File 'lib/detroit-extconf.rb', line 67

def clean
  make 'clean'
end

#compileObject

Compile extensions.



57
58
59
60
61
62
63
64
# File 'lib/detroit-extconf.rb', line 57

def compile
  configure
  if static
    make 'static'
  else
    make
  end
end

#compiles?Boolean Also known as: compile?, clean?, purge?

Check to see if this project has extensions that need to be compiled.

Returns:

  • (Boolean)


83
84
85
# File 'lib/detroit-extconf.rb', line 83

def compiles?
  !extensions.empty?
end

#configurevoid

This method returns an undefined value.

Create Makefile(s).



46
47
48
49
50
51
52
53
54
# File 'lib/detroit-extconf.rb', line 46

def configure
  extensions.each do |directory|
    next if File.exist?(File.join(directory, 'Makefile'))
    report "configuring #{directory}"
    cd(directory) do
      sh "ruby extconf.rb"
    end
  end
end

#distcleanObject Also known as: purge

Remove all compile products.



72
73
74
75
76
77
78
# File 'lib/detroit-extconf.rb', line 72

def distclean
  make 'distclean'
  extensions.each do |directory|
    makefile = File.join(directory, 'Makefile')
    rm(makefile) if File.exist?(makefile)
  end
end

#extensionsObject

Extension directories. Often this will simply be ‘ext’. but sometimes more then one extension is needed and are kept in separate directories. This works by looking for ext/*/.c files, where ever they are is considered an extension directory.



95
96
97
# File 'lib/detroit-extconf.rb', line 95

def extensions
  @extensions ||= Dir['ext/**/*.c'].collect{ |file| File.dirname(file) }.uniq
end

#prerequisitevoid

This method returns an undefined value.

Set attribute defaults.



36
37
38
# File 'lib/detroit-extconf.rb', line 36

def prerequisite
  @static = false
end