lib/neutron/pkgconf.rb in neutron-0.1.0 vs lib/neutron/pkgconf.rb in neutron-0.2.0

- old
+ new

@@ -45,6 +45,41 @@ def to_valac raise InvalidPkgConfError if tainted? @packages.map{|p|"--pkg #{p}"}.join(' ') end + + def self.gen_pc(filename, **opts) + prefix = if ENV['PREFIX'] then ENV['PREFIX'] else '/usr' end + filename = File.expand_path(filename) + + content = '' + + content << "prefix=#{prefix}\n" + content << "exec_prefix=${prefix}\n" + content << "includedir=${prefix}/include\n" + content << "libdir=${exec_prefix}/lib\n" + content << "\n" + + reqs = if opts[:requires] then opts[:requires].packages.join(' ') else '' end + preqs = if opts[:prequires] then opts[:prequires].packages.join(' ') else '' end + + lname = opts[:name] + if m = /lib(.+)/.match(lname.downcase) + lname = m[1] + end + + content << "Name: #{opts[:name] or 'Unnamed'}\n" + content << "Description: #{opts[:description] or 'No description'}\n" + content << "Version: #{opts[:version] or '0.1.0'}\n" + content << "Requires: #{reqs}\n" + content << "Requires.private: #{preqs}\n" + content << "Cflags: #{opts[:cflags] or "-I${includedir}/#{opts[:name].downcase or 'undefined'}"}\n" + content << "Libs: -L${libdir} -l#{lname or 'undefined'}\n" + content << "Libs.private: #{opts[:plibs] or ''}\n" + + File.delete(filename) if File.exist?(filename) + File.write(filename, content) + + puts "] Done generating pkg-config #{filename}" + end end \ No newline at end of file