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, #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.



38
39
40
41
42
43
# File 'lib/teapot/build/targets/library.rb', line 38

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#build(environment) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/teapot/build/targets/library.rb', line 93

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


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/teapot/build/targets/library.rb', line 67

def compile_and_link(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

#dependent_libraries(environment) ⇒ Object



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

def dependent_libraries(environment)
	Extractors::LinkerExtractor.libraries(environment[:ldflags])
end

#install_file_list(file_list, prefix) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/teapot/build/targets/library.rb', line 83

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, :preserve => true)
	end
end


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/teapot/build/targets/library.rb', line 55

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

	graph = Build::dependency_graph(environment)
	
	if graph.regenerate?(library_file, objects + dependent_libraries(environment))
		Linker.link_static(environment, library_file, objects)
	end
	
	return library_file
end

#subdirectoryObject



47
48
49
# File 'lib/teapot/build/targets/library.rb', line 47

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