Class: Teapot::Build::Targets::Library

Inherits:
Teapot::Build::Target show all
Includes:
Compiler, Installation
Defined in:
lib/teapot/build/targets/library.rb

Direct Known Subclasses

Executable

Instance Attribute Summary collapse

Attributes inherited from Teapot::Build::Target

#parent

Instance Method Summary collapse

Methods included from Installation

#install_prefix!

Methods included from Compiler

#build_prefix!, #compile, #link_prefix!

Methods inherited from Teapot::Build::Target

#configure, #execute, #root, target

Constructor Details

#initialize(parent, name, options = {}) ⇒ Library

Returns a new instance of Library.



35
36
37
38
39
40
# File 'lib/teapot/build/targets/library.rb', line 35

def initialize(parent, name, options = {})
	super parent
			
	@name = name
	@options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



42
43
44
# File 'lib/teapot/build/targets/library.rb', line 42

def options
  @options
end

Instance Method Details

#build(environment) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/teapot/build/targets/library.rb', line 56

def build(environment)
	file_list = self.source_files(environment)

	pool = Commands::Pool.new

	objects = file_list.collect do |source_file|
		relative_path = source_file.relative_path_from(file_list.root)
	
		compile(environment, file_list.root, relative_path, pool)
	end

	pool.wait

	return Array link(environment, objects)
end

#install(environment) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/teapot/build/targets/library.rb', line 82

def install(environment)
	prefix = install_prefix!(environment)
	
	build(environment).each do |path|
		destination_path = prefix + subdirectory + path.basename
	
		destination_path.dirname.mkpath
	
		FileUtils.cp path, destination_path
	end
	
	if self.respond_to? :headers
		install_file_list(self.headers(environment), prefix + "include")
	end
end

#install_file_list(file_list, prefix) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/teapot/build/targets/library.rb', line 72

def install_file_list(file_list, prefix)
	file_list.each do |path|
		relative_path = path.relative_path_from(file_list.root)
		destination_path = prefix + file_list.prefix + relative_path
	
		destination_path.dirname.mkpath
		FileUtils.cp path, destination_path
	end
end


48
49
50
51
52
53
54
# File 'lib/teapot/build/targets/library.rb', line 48

def link(environment, objects)
	library_file = link_prefix!(environment) + "lib#{@name}.a"

	Linker.link_static(environment, library_file, objects)

	return library_file
end

#subdirectoryObject



44
45
46
# File 'lib/teapot/build/targets/library.rb', line 44

def subdirectory
	options[:subdirectory] || "lib"
end