Class: Xezat::Generator::Pkgconfig
- Inherits:
-
Object
- Object
- Xezat::Generator::Pkgconfig
show all
- Includes:
- Xezat
- Defined in:
- lib/xezat/generator/pkgconfig.rb
Constant Summary
Constants included
from Xezat
CONFIG_FILE, DATA_DIR, REPOSITORY_DIR, ROOT_DIR, TEMPLATE_DIR, VERSION
Instance Method Summary
collapse
Methods included from Xezat
#bashvar, #config, #packages, #variables
Constructor Details
#initialize(options, cygport) ⇒ Pkgconfig
Returns a new instance of Pkgconfig.
17
18
19
20
|
# File 'lib/xezat/generator/pkgconfig.rb', line 17
def initialize(options, cygport)
@options = options
@cygport = cygport
end
|
Instance Method Details
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/xezat/generator/pkgconfig.rb', line 77
def append_commands_to_autotools(variables, options)
srcdir = variables[:CYGCONF_SOURCE] || variables[:S]
srcdir = File.expand_path(File.join(variables[:S], options['srcdir'])) if options['srcdir']
pn = variables[:PN]
configure_ac = File.expand_path(File.join(srcdir, 'configure.ac'))
configure_ac = File.expand_path(File.join(srcdir, 'configure.in')) unless File.exist?(configure_ac)
raise AutotoolsFileNotFoundError unless File.exist?(configure_ac)
original_ac = File.read(configure_ac).scrub
if /#{pn}.pc/.match?(original_ac)
Xezat.logger.debug(" Not rewrite #{configure_ac}")
return
end
rewritten_ac = original_ac.gsub(/^AC_OUTPUT$/, "AC_CONFIG_FILES([#{pn}.pc])#{$INPUT_RECORD_SEPARATOR}AC_OUTPUT")
File.atomic_open(configure_ac, 'w') do |fa|
fa.write(rewritten_ac)
makefile_am = File.expand_path(File.join(srcdir, 'Makefile.am'))
raise AutotoolsFileNotFoundError unless File.exist?(makefile_am)
if File.read(makefile_am).include?('pkgconfig_DATA')
Xezat.logger.debug(" Not rewrite #{makefile_am}")
break
end
commands_am = File.read(File.expand_path(File.join(TEMPLATE_DIR, 'pkgconfig', 'Makefile.am')))
File.atomic_open(makefile_am, 'a') do |fm|
fm.write(commands_am)
end
end
end
|
#append_commands_to_cmakelists(variables, options) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/xezat/generator/pkgconfig.rb', line 56
def append_commands_to_cmakelists(variables, options)
srcdir = variables[:CYGCMAKE_SOURCE] || variables[:S]
srcdir = File.expand_path(File.join(variables[:S], options['srcdir'])) if options['srcdir']
cmakelists = File.expand_path(File.join(srcdir, 'CMakeLists.txt'))
if %r!DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/pkgconfig!.match?(File.read(cmakelists))
Xezat.logger.debug(' Not rewrite CMakeLists.txt')
return
end
Xezat.logger.debug(' Rewrite CMakeLists.txt')
File.atomic_open(cmakelists, 'a') do |f|
f.write(get_cmakelists(variables))
end
end
|
#generate ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/xezat/generator/pkgconfig.rb', line 22
def generate
Xezat.logger.debug('Start package config generation')
vars = variables(@cygport)
generate_pkg_config(vars, @options)
if vars[:_cmake_CYGCLASS_]
append_commands_to_cmakelists(vars, @options)
else
append_commands_to_autotools(vars, @options)
end
Xezat.logger.debug('End package config generation')
end
|
#generate_pkg_config(variables, options) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/xezat/generator/pkgconfig.rb', line 35
def generate_pkg_config(variables, options)
srcdir = variables[:CYGCONF_SOURCE] || variables[:CYGCMAKE_SOURCE] || variables[:S]
srcdir = File.expand_path(File.join(variables[:S], options['srcdir'])) if options['srcdir']
Xezat.logger.debug(" srcdir = #{srcdir}")
pn = variables[:PN]
pc = File.expand_path(File.join(srcdir, "#{pn}.pc.in"))
raise UnregeneratableConfigurationError, "#{pn}.pc.in already exists" if File.exist?(pc) && !options['overwrite']
Xezat.logger.debug(' Generate pc')
File.atomic_write(pc) do |f|
f.write(get_pkg_config(variables))
end
end
|
#get_cmakelists(variables) ⇒ Object
72
73
74
75
|
# File 'lib/xezat/generator/pkgconfig.rb', line 72
def get_cmakelists(variables)
erb = File.expand_path(File.join(TEMPLATE_DIR, 'pkgconfig', 'cmake.erb'))
ERB.new(File.readlines(erb).join(nil), trim_mode: '%-').result(binding)
end
|
#get_pkg_config(variables) ⇒ Object
51
52
53
54
|
# File 'lib/xezat/generator/pkgconfig.rb', line 51
def get_pkg_config(variables)
erb = File.expand_path(File.join(TEMPLATE_DIR, 'pkgconfig', 'pkgconfig.erb'))
ERB.new(File.readlines(erb).join(nil), trim_mode: '%-').result(binding)
end
|