class RBT::CreatePkgconfigFile

Public Class Methods

[](i = '') click to toggle source
#

RBT::CreatePkgconfigFile[]

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 343
def self.[](i = '')
  new(i)
end
new( i = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 34
def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input_hash(i)
  run if run_already
end

Public Instance Methods

add(i = '') click to toggle source
#

add

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 169
def add(i = '')
  @store_this_string << i+N
end
build_up_the_main_string() click to toggle source
#

build_up_the_main_string (main string, main tag)

This method depends on information made available prior to calling it, e. g. the method description? or prefix? and so forth.

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 297
def build_up_the_main_string
  add 'prefix='+prefix?.to_s # Need .to_s here since we can also pass class Prefix.
  add 'exec_prefix=${prefix}'
  add 'libdir=${exec_prefix}/lib'
  add 'includedir=${prefix}/include'
  add
  add 'Name: '+program_name?.dup
  add "Description: #{word_wrapped_description?}"
  add 'Requires:'
  add 'Version: '+program_version?
  add (
        'Libs: -L${libdir} -l'+program_name?+' '+extra_libs?.to_s
      ).rstrip
  add 'Cflags: -I${includedir}'
end
description?() click to toggle source
#

description?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 85
def description?
  @description
end
ensure_that_the_pkgconfig_directory_exists_for(i) click to toggle source
#

ensure_that_the_pkgconfig_directory_exists_for

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 286
def ensure_that_the_pkgconfig_directory_exists_for(i)
  i = File.dirname(i)
  mkdir(i, :be_quiet) unless File.directory? i
end
extra_libs?() click to toggle source
#

extra_libs?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 316
def extra_libs?
  @extra_libs
end
handle_special_programs() click to toggle source
#

handle_special_programs

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 323
def handle_special_programs
  case raw_name_of_the_program?
  when 'lua'
    @extra_libs << '-lm -ldl'
  end
end
input_hash?() click to toggle source
#

input_hash?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 145
def input_hash?
  @input_hash
end
main_string?()
Alias for: store_this_string?
parse_input_hash() click to toggle source
#

parse_input_hash

This method can be used to decompose the given input at hand. It is the first method that is called from within run() itself.

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 191
def parse_input_hash
  _ = input_hash?
  # ======================================================================= #
  # === :pkgconfig_filename
  # ======================================================================= #
  if _.has_key? :pkgconfig_filename
    set_pkgconfig_filename(_.delete(:pkgconfig_filename))
  end
  # ======================================================================= #
  # === :prefix
  # ======================================================================= #
  if _.has_key? :prefix
    @prefix = _.delete(:prefix)
  end
  # ======================================================================= #
  # === :program_version
  # ======================================================================= #
  if _.has_key? :program_version
    set_program_version _.delete(:program_version)
  # ======================================================================= #
  # === :version
  # ======================================================================= #
  elsif _.has_key? :version
    set_program_version _.delete(:version)
  end
  # ======================================================================= #
  # === :description
  # ======================================================================= #
  if _.has_key? :description
    @description = _.delete(:description)
  end
end
pkgconfig_filename?() click to toggle source
#

pkgconfig_filename?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 152
def pkgconfig_filename?
  @pkgconfig_filename
end
prefix?() click to toggle source
#

prefix?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 92
def prefix?
  @prefix
end
program_name?() click to toggle source
#

program_name?

This method is guaranteed to return the name without the .pc name.

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 161
def program_name?
  File.basename(pkgconfig_filename?).
  delete_suffix('.pc').dup
end
program_version?() click to toggle source
#

program_version?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 245
def program_version?
  @program_version
end
raw_name_of_the_program?() click to toggle source
#

raw_name_of_the_program?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 279
def raw_name_of_the_program?
  return File.basename(pkgconfig_filename?.dup).delete_suffix('.pc')
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method RBT::Base#reset
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 46
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @store_this_string
  # ======================================================================= #
  @store_this_string  = ''.dup
  # ======================================================================= #
  # === @prefix
  # ======================================================================= #
  @prefix             = '/usr' # This is the default prefix.
  # ======================================================================= #
  # === @program_version
  # ======================================================================= #
  @program_version    = '1.0.0'
  # ======================================================================= #
  # === @pkgconfig_filename
  # ======================================================================= #
  @pkgconfig_filename = 'mad'
  # ======================================================================= #
  # === @description
  # ======================================================================= #
  @description        = ''
  # ======================================================================= #
  # === @extra_libs
  # ======================================================================= #
  @extra_libs         = ''.dup
end
run() click to toggle source
#

run (run tag)

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 333
def run
  parse_input_hash # Must parse the Hash prior to String build-up.
  handle_special_programs
  build_up_the_main_string
  store_pc_file
end
sanitize_the_input_hash( i = @input_hash ) click to toggle source
#

sanitize_the_input_hash

The main idea for this method is to turn symbol input such as :htop, or pseudo-symbols such as ‘:htop’, into the real dataset.

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 129
def sanitize_the_input_hash(
    i = @input_hash
  )
  if i.is_a?(Symbol) or (i.is_a?(String) and i.start_with?(':'))
    require 'rbt/requires/require_the_installer_class.rb'
    @input_hash = RBT::Installer.new(i, :do_not_run_yet)
    # ======================================================================= #
    # We will also generate another filename when RBT::Installer is used.
    # ======================================================================= #
    set_pkgconfig_filename(i)
  end
end
set_input_hash( i = {} ) click to toggle source
#

set_input_hash

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 99
def set_input_hash(
    i = {}
  )
  i = i.first if i.is_a? Array
  if i.is_a?(String) and i.start_with?(':')
    unless RBT.const_defined?(:Cookbook)
      require 'rbt/cookbooks/sanitize_cookbook/sanitize_cookbook.rb'
    end
    cookbook_dataset = RBT::Cookbook.new(i.delete(':'))
    # ===================================================================== #
    # Build up the most important Hash next:
    # ===================================================================== #
    i = {
      prefix:      cookbook_dataset.prefix_to_use?,
      pkgconfig_filename: cookbook_dataset.prefix_to_use?+
                          '/lib/pkgconfig/'+cookbook_dataset.real_short_name?.to_s+'.pc',
      version:     cookbook_dataset.program_version?,
      description: cookbook_dataset.short_description?
    }
  end
  @input_hash = i
  sanitize_the_input_hash
end
set_pkgconfig_filename(i) click to toggle source
#

set_pkgconfig_filename

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 176
def set_pkgconfig_filename(i)
  i = i.to_s.dup
  i = rds(i).dup
  if i.start_with? ':'
    i[0,1] = ''
  end
  @pkgconfig_filename = i
end
set_program_version(i) click to toggle source
#

set_program_version

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 238
def set_program_version(i)
  @program_version = i
end
short_description?() click to toggle source
#

short_description?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 227
def short_description?
  if @input_hash.is_a? Hash
    @description
  elsif @input_hash.is_a? ::RBT::Installer
    @input_hash.short_description?
  end
end
store_pc_file() click to toggle source
#

store_pc_file

We must ensure that the pkgconfig/ directory also exists.

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 265
def store_pc_file
  what = main_string?
  into = File.basename(pkgconfig_filename?.dup)
  into << '.pc' unless into.end_with? '.pc'
  ensure_that_the_pkgconfig_directory_exists_for(into)
  opne "Now storing into the file `#{sfile(into)}`."
  opne 'This .pc file could be moved onto'
  opne sdir(pkgconfig_filename?)
  store_what_into(what, into)
end
store_this_string?() click to toggle source
#

store_this_string?

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 78
def store_this_string?
  @store_this_string
end
Also aliased as: main_string?
word_wrapped_description?() click to toggle source
#

word_wrapped_description? (wrap tag)

Wrap the description a bit.

#
# File lib/rbt/generate_files/create_pkgconfig_file.rb, line 254
def word_wrapped_description?
  _ = short_description?.tr(N, ' ').squeeze(' ')
  _ = word_wrap(_, 68) if _.size > 66
  return _
end