class MkmfTasks attr_writer :extconf_file_name, :project_dir, :file_extension, :extension_paths, :extconf_arguments def initialize(actor) @actor = actor end def default compile end def compile @extension_paths.each do |extension| dir = "ext/#{extension}" extconf dir make dir end end def spec compile install dir = @project_dir require File.expand_path("#{dir}/spec/spec_suite") end def lib directory "lib" end def install @extension_paths.each do |extension_path| build_path = build_path(extension_path) raise "File #{build_path} does not exist" unless File.exists?(build_path) cp build_path, library_path(extension_path) end end def cleanup @extension_paths.each do |extension_path| library_path = library_path(extension_path) rm library_path if library_path && File.exists?(library_path) build_file_path = build_path(extension_path) rm build_file_path if build_file_path && File.exists?(build_file_path) build_object_path = "#{build_path_without_file_extension(extension_path)}.o" rm build_object_path if build_object_path && File.exists?(build_object_path) build_dir = build_dir(extension_path) make_file_path = "#{build_dir}/Makefile" rm make_file_path if make_file_path && File.exists?(make_file_path) end end protected def extconf(dir) Dir.chdir(dir) do sh("ruby #{@extconf_arguments} #{@extconf_file_name}") end end def make(makedir) Dir.chdir(makedir) do sh("make") end end def build_dir(relative_extension_path) "#{@project_dir}/ext/#{relative_extension_path}" end def build_path(relative_extension_path) basename = build_path_without_file_extension(relative_extension_path) "#{basename}.#{@file_extension}" end def build_path_without_file_extension(relative_extension_path) "#{build_dir(relative_extension_path)}/#{File.basename(relative_extension_path)}" end def library_path(relative_extension_path) library_directory_path = File.expand_path("#{@project_dir}/lib/#{File.dirname(relative_extension_path)}") binary_name = "#{File.basename(relative_extension_path)}.#{@file_extension}" "#{library_directory_path}/#{binary_name}" end def rm(path) @actor.__send__ :rm, path end def sh(cmd) @actor.__send__ :sh, cmd end end