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
#config, #packages, #print_yaml, #variables
Constructor Details
#initialize(options, cygport) ⇒ Pkgconfig
Returns a new instance of Pkgconfig.
19
20
21
22
|
# File 'lib/xezat/generator/pkgconfig.rb', line 19
def initialize(options, cygport)
@options = options
@cygport = cygport
end
|
Instance Method Details
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
111
112
|
# File 'lib/xezat/generator/pkgconfig.rb', line 79
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)
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, 'Makefile.am')))
File.atomic_open(makefile_am, 'a') do |fm|
fm.write(commands_am)
end
end
end
|
#append_commands_to_cmakelists(variables, options) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/xezat/generator/pkgconfig.rb', line 58
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
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/xezat/generator/pkgconfig.rb', line 24
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/xezat/generator/pkgconfig.rb', line 37
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
74
75
76
77
|
# File 'lib/xezat/generator/pkgconfig.rb', line 74
def get_cmakelists(variables)
erb = File.expand_path(File.join(TEMPLATE_DIR, 'cmake.erb'))
ERB.new(File.readlines(erb).join(nil), trim_mode: '%-').result(binding)
end
|
#get_pkg_config(variables) ⇒ Object
53
54
55
56
|
# File 'lib/xezat/generator/pkgconfig.rb', line 53
def get_pkg_config(variables)
erb = File.expand_path(File.join(TEMPLATE_DIR, 'pkgconfig.erb'))
ERB.new(File.readlines(erb).join(nil), trim_mode: '%-').result(binding)
end
|