Class: Easycompile::Base

Inherits:
Object
  • Object
show all
Includes:
Colours, Constants
Defined in:
lib/easycompile/base/colours.rb,
lib/easycompile/base/gem.rb,
lib/easycompile/base/opn.rb,
lib/easycompile/base/run.rb,
lib/easycompile/base/help.rb,
lib/easycompile/base/menu.rb,
lib/easycompile/base/misc.rb,
lib/easycompile/base/cmake.rb,
lib/easycompile/base/reset.rb,
lib/easycompile/base/remove.rb,
lib/easycompile/base/esystem.rb,
lib/easycompile/base/constants.rb,
lib/easycompile/base/initialize.rb,
lib/easycompile/base/meson_and_ninja.rb,
lib/easycompile/base/change_directory.rb,
lib/easycompile/base/process_the_input.rb,
lib/easycompile/base/commandline_arguments.rb

Overview

Easycompile::Base

Direct Known Subclasses

CompileAsAppdir, Easycompile

Constant Summary collapse

THIS_FILE =
#

THIS_FILE

This constant refers to the main .rb file for class Easycompile::Base, that is the file that contains most of the ruby code for the Base class.

#
"#{PROJECT_BASE_DIR}base/misc.rb"

Constants included from Constants

Constants::ARRAY_POSSIBLE_ARCHIVES, Constants::CMAKE_FILE, Constants::ERROR_LINE, Constants::FILE_NAME_OF_THE_BUILD_DIRECTORY, Constants::INDIVIDUAL_COOKBOOKS, Constants::LAST_DOWNLOADED_FILE, Constants::LOCATION_OF_SETUP_RB, Constants::MESON_BUILD_FILE, Constants::NAMESPACE, Constants::PROGRAMS_DIRECTORY, Constants::RUBY_SRC, Constants::SHALL_WE_CREATE_A_BUILD_DIRECTORY, Constants::SRC_DIR, Constants::TEMP_DIR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Constants

#ruby_src?, #source_dir?, temp_dir?

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ Base

#

initialize

#


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/easycompile/base/initialize.rb', line 14

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  case run_already
  # ======================================================================= #
  # === :dont_run_yet
  # ======================================================================= #
  when :dont_run_yet,
       :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Class Method Details

.version?Boolean

#

Easycompile::Base.version?

#

Returns:

  • (Boolean)


137
138
139
# File 'lib/easycompile/base/misc.rb', line 137

def self.version?
  Easycompile.version?
end

Instance Method Details

#add_this_archive(i) ⇒ Object Also known as: add_to_commandline_arguments, set_files, add_these_files, add

#

add_this_archive (add tag)

#


584
585
586
587
588
589
590
# File 'lib/easycompile/base/misc.rb', line 584

def add_this_archive(i)
  if i
    @compile_these_programs << i
    @compile_these_programs.flatten!
    @compile_these_programs.compact!
  end
end

#are_we_on_gobolinux?Boolean

#

are_we_on_gobolinux?

#

Returns:

  • (Boolean)


289
290
291
# File 'lib/easycompile/base/misc.rb', line 289

def are_we_on_gobolinux?
  ENV['IS_ON_GOBOLINUX'].to_s == '1'
end

#attempt_to_find_a_valid_file(i) ⇒ Object

#

attempt_to_find_a_valid_file

This method will attempt to sanitize incomplete entries such as “nettle-2.7” towards “nettle-2.7.tar.xz”.

When we pass something such as “htop.yml” and this file does not exist in the current directory, then we will attempt to find it in another directory.

#


475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
# File 'lib/easycompile/base/misc.rb', line 475

def attempt_to_find_a_valid_file(i)
  if i.is_a? Array
    i.map! {|entry|
      unless File.exist? entry
        entry = File.basename(entry)
        if entry.include?('.yml') or entry.end_with?('.')
          entry = INDIVIDUAL_COOKBOOKS+entry
          yaml_dataset = get_dataset_from(entry)
          entry = yaml_dataset['program_path']
          set_program_version(yaml_dataset['program_version'])
        else
          # Then we try a glob.
          _ = Dir["#{entry}*"]
          entry = _.first unless _.empty?
        end
      end
      entry
    }
  end
  return i
end

#base_dir?Boolean

#

base_dir`

#

Returns:

  • (Boolean)


454
455
456
# File 'lib/easycompile/base/misc.rb', line 454

def base_dir?
  @base_dir
end

#can_not_continueObject

#

can_not_continue

Set @continue_past_configure_stage to false, so tha we won’t continue.

#


321
322
323
# File 'lib/easycompile/base/misc.rb', line 321

def can_not_continue
  @continue_past_configure_stage = false
end

#change_directory(i) ⇒ Object Also known as: cd

#

change_directory (cd tag)

Use this method when changing directories.

#


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/easycompile/base/change_directory.rb', line 16

def change_directory(i)
  if i
    File.expand_path(i) if i.start_with? '.'
    if File.exist?(i)
      Dir.chdir(i)
    else
      show_namespace
      e "Can not change into #{sdir(i)} as it does not exist."
    end
  end
end

#check_for_dependenciesObject

#

check_for_dependencies

#


598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/easycompile/base/misc.rb', line 598

def check_for_dependencies
  # ======================================================================= #
  # Next, add dependencies. To try this, do:
  #
  #   ecompile metacity.yml wdeps
  #
  # ======================================================================= #
  if @compile_with_dependencies
    dependencies = get_dataset_from(@original_input)['required_deps_on']
    dependencies.map! {|entry|
      entry = entry.dup if entry.frozen?
      entry << '.yml'
    }
    add(dependencies)
  end
end

#cmake_file?Boolean

#

cmake_file?

This method wille ssentially refer to “CMakeLists.txt”.

#

Returns:

  • (Boolean)


16
17
18
# File 'lib/easycompile/base/cmake.rb', line 16

def cmake_file?
  CMAKE_FILE
end

#commandline_arguments?Boolean

#

commandline_arguments?

#

Returns:

  • (Boolean)


14
15
16
# File 'lib/easycompile/base/commandline_arguments.rb', line 14

def commandline_arguments?
  @commandline_arguments
end

#compile_as_meson_based_projectObject

#

compile_as_meson_based_project

#


14
15
16
17
18
19
# File 'lib/easycompile/base/meson_and_ninja.rb', line 14

def compile_as_meson_based_project
  use_this_build_directory = name_of_the_build_directory?
  esystem 'meson --prefix='+prefix?+' '+use_this_build_directory
  cd(use_this_build_directory)
  ninjait
end

#compile_these_programs?Boolean Also known as: files?, file?

#

compile_these_programs?

This method will return on which input-files we will be working on, that is our target-programs.

#

Returns:

  • (Boolean)


576
577
578
# File 'lib/easycompile/base/misc.rb', line 576

def compile_these_programs?
  @compile_these_programs
end

#consider_creating_a_build_directory(where = return_pwd) ⇒ Object

#

consider_creating_a_build_directory

Here we will consider whether we will create a build directory or whether we will not do so.

If such a directory already exists then we do not need to create a new directory.

#


536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/easycompile/base/misc.rb', line 536

def consider_creating_a_build_directory(
    where = return_pwd
  )
  if shall_we_create_a_build_directory?
    _ = name_of_build_directory?
    if File.exist? _
      show_namespace
      e "We will use the already existing build directory "\
        "called `#{sdir(_)}`."
      set_build_directory(_)
    else
      @base_dir = rds(where)
      set_this_build_dir(File.absolute_path(_))
      show_namespace
      e 'We will create a build directory next called `'+sdir(_)+'` '\
        '(Full target will be: '+@build_directory_is_stored_here+').'
      # =================================================================== #
      # Keep track of where the build directory is.
      # =================================================================== #
      mkdir @build_directory_is_stored_here # Creating the build directory finally.
    end
    # ===================================================================== #
    # Next, we will enter that BUILD directory.
    # ===================================================================== #
    cd @build_directory_is_stored_here
    show_namespace
    # ===================================================================== #
    # Notify the user that we have cd-ed already.
    # ===================================================================== #
    e 'Now entering the directory '+
       sdir(@build_directory_is_stored_here)+'.'
  end
end

#consider_removing_the_archive(i = @build_directory_is_stored_here) ⇒ Object Also known as: consider_removing_this_archive, consider_purging_empty_build_directory

#

consider_removing_the_archive

#


707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
# File 'lib/easycompile/base/misc.rb', line 707

def consider_removing_the_archive(
    i = @build_directory_is_stored_here
  )
  if remove_all_after_compile?
    if i.responds_to? :each
      i.each {|entry|
        remove_directory(entry)
      }
    else
      i = i.to_s
      if shall_we_create_a_build_directory?
        if File.exist?(i) and empty_dir?(i)
          # =============================================================== #
          # Ok, we found an empty build-directory. Since it is empty,
          # we can safely remove it.
          # =============================================================== #
          remove_directory(i)
        end
      end
    end
  end
end

#consider_symlinking_appdirObject

#

consider_symlinking_appdir

Use this method to consider symlinking into the AppDir hierarchy.

We use class SymlinkProgram for this, from the RBT project. However had, when we are on GoboLinux, we will instead use the GoboLinux program called SymlinkProgram.

#


398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/easycompile/base/misc.rb', line 398

def consider_symlinking_appdir
  _ = rds(prefix?+'/')
  opn :namespace => NAMESPACE
  e 'Next attempting to symlink at '+sdir(_)
  if are_we_on_gobolinux?
    cmd = 'SymlinkProgram '+_
    esystem cmd
  else
    begin
      require 'rbt/requires/require_symlink_this_program.rb'
    rescue LoadError; end
    if Object.const_defined?('RBT') and
       RBT.const_defined?(SymlinkFromToCurrent)
      RBT::SymlinkFromToCurrent.new(_)
    end
  end 
end

#continue_after_extracting?Boolean

#

continue_after_extracting?

#

Returns:

  • (Boolean)


328
329
330
# File 'lib/easycompile/base/misc.rb', line 328

def continue_after_extracting?
  @continue_after_extracting
end

#continue_past_configure_stage?Boolean

#

continue_past_configure_stage?

#

Returns:

  • (Boolean)


275
276
277
# File 'lib/easycompile/base/misc.rb', line 275

def continue_past_configure_stage?
  @continue_past_configure_stage
end

#copy_setup_rbObject

#

copy_setup_rb

#


106
107
108
# File 'lib/easycompile/base/misc.rb', line 106

def copy_setup_rb
  FileUtils.cp(LOCATION_OF_SETUP_RB, return_pwd)
end

#cparser_is_available?Boolean

#

cparser_is_available?

Determine whether we can use the ColourizeParser from the RBT project.

#

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/easycompile/base/esystem.rb', line 34

def cparser_is_available?
  Object.const_defined?(:RBT) and
  RBT.const_defined?(:ColourizeParser)
end

#determine_which_programs_to_compileObject

#

determine_which_programs_to_compile

#


933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
# File 'lib/easycompile/base/misc.rb', line 933

def determine_which_programs_to_compile
  if @commandline_arguments.empty?
    # ===================================================================== #
    # If we did not input anything then use all archives from the
    # current working directory.
    # ===================================================================== #
    _ = Dir['*'].select {|entry| is_an_archive?(entry) }
  else
    if @commandline_arguments.any? {|entry| entry.end_with? '.yml' }
      # =================================================================== #
      # Handle .yml files here.
      # =================================================================== #
      @commandline_arguments = replace_all_yaml_files(@commandline_arguments)
    end
    _ = @commandline_arguments.select {|entry| File.exist?(entry) }
  end
  set_compile_these_programs(_)
end

#do_compile_with_dependenciesObject

#

do_compile_with_dependencies

#


335
336
337
338
# File 'lib/easycompile/base/misc.rb', line 335

def do_compile_with_dependencies
  opn_namespace; e 'We will compile the dependencies first.'
  @compile_with_dependencies = true
end

#do_make_use_of_a_build_directoryObject

#

do_make_use_of_a_build_directory

#


282
283
284
# File 'lib/easycompile/base/misc.rb', line 282

def do_make_use_of_a_build_directory
  @shall_we_create_a_build_directory = true
end

#do_not_compileObject

#

do_not_compile

#


375
376
377
378
# File 'lib/easycompile/base/misc.rb', line 375

def do_not_compile
  show_namespace; e 'We will not compile after extracting the source archive.'
  do_not_continue
end

#do_not_continueObject

#

do_not_continue

This method does not output anything to the user, on purpose.

#


368
369
370
# File 'lib/easycompile/base/misc.rb', line 368

def do_not_continue
  @continue_after_extracting = false
end

#do_not_create_a_build_directoryObject

#

do_not_create_a_build_directory

Use this method if you do not wish to create a build directory.

#


160
161
162
# File 'lib/easycompile/base/misc.rb', line 160

def do_not_create_a_build_directory
  @shall_we_create_a_build_directory = false
end

#do_remove_all_after_compileObject

#

do_remove_all_after_compile

#


65
66
67
68
# File 'lib/easycompile/base/remove.rb', line 65

def do_remove_all_after_compile
  opn_namespace; e 'We will remove all after compile.'
  @remove_all_after_compile = true
end

#does_a_meson_build_file_exist?Boolean

#

does_a_meson_build_file_exist?

#

Returns:

  • (Boolean)


24
25
26
# File 'lib/easycompile/base/meson_and_ninja.rb', line 24

def does_a_meson_build_file_exist?
  File.exist?(MESON_BUILD_FILE)
end

#e_colourize(i) ⇒ Object

#

e_colourize

#


69
70
71
72
73
74
75
# File 'lib/easycompile/base/colours.rb', line 69

def e_colourize(i)
  if use_colours?
    e sfancy(i)
  else
    e i
  end
end

#ecomment(i) ⇒ Object

#

ecomment

#


80
81
82
83
84
85
86
# File 'lib/easycompile/base/colours.rb', line 80

def ecomment(i)
  if use_colours?
    ::Colours.ecomment(i)
  else
    i
  end
end

#empty_dir?(i) ⇒ Boolean

#

empty_dir?

#

Returns:

  • (Boolean)


189
190
191
# File 'lib/easycompile/base/misc.rb', line 189

def empty_dir?(i)
  Dir["#{i}/*"].empty?
end

#enable_skip_make_installObject

#

enable_skip_make_install

#


343
344
345
346
# File 'lib/easycompile/base/misc.rb', line 343

def enable_skip_make_install
  show_namespace; e 'We will skip running the "make install" step.'
  @skip_make_install = true
end

#enter_extracted_directory(i = @original_input) ⇒ Object

#

enter_extracted_directory

We use this method to enter the extracted directory.

#


421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'lib/easycompile/base/misc.rb', line 421

def enter_extracted_directory(i = @original_input)
  i = remove_extension_from(i)
  if File.directory? i
    _ = i
  else
    _ = "#{@temp_directory}#{get_program_name(i)}"
  end
  i = i.dup
  _ << '/' unless _.end_with? '/'
  if Dir.exist? _ # Only inform the user that we cd if that directory exists.
    show_namespace; e "Now entering the directory `#{sdir(_)}`."
    cd _
  end
end

#esystem(i) ⇒ Object Also known as: _

#

esystem

Run a colourized system() command here.

This can either be through oldschool system(), or as of August 2017, preferentially via IO.popen().

#


20
21
22
23
24
25
26
# File 'lib/easycompile/base/esystem.rb', line 20

def esystem(i)
  e_colourize(i) # Output it here already.
  i = i.dup if i.frozen?
  i << ERROR_LINE
  @result = i # Not in use right now.
  internal_system(i) # Defined in this file here.
end

#extract_to_this_directory?Boolean Also known as: extract_to?

#

extract_to_this_directory?

#

Returns:

  • (Boolean)


230
231
232
# File 'lib/easycompile/base/misc.rb', line 230

def extract_to_this_directory?
  @extract_to_this_directory
end

#filenameObject Also known as: filename?

#

filename

#


120
121
122
# File 'lib/easycompile/base/misc.rb', line 120

def filename
  return File.basename(__FILE__)+':'
end

#find_partial_match_for(i) ⇒ Object

#

find_partial_match_for

#


127
128
129
130
131
132
# File 'lib/easycompile/base/misc.rb', line 127

def find_partial_match_for(i)
  possible_matches = Dir["#{i}*"]
  return_value = false
  return_value = true unless possible_matches.empty?
  return [return_value, possible_matches] # Returns an Array.
end

#find_this_program?Boolean Also known as: find_which_program?

#

find_this_program?

#

Returns:

  • (Boolean)


53
54
55
# File 'lib/easycompile/base/misc.rb', line 53

def find_this_program?
  @find_this_program
end

#get_dataset_from(i) ⇒ Object

#

get_dataset_from

#


890
891
892
893
894
895
896
897
898
899
900
901
# File 'lib/easycompile/base/misc.rb', line 890

def get_dataset_from(i)
  if !Object.const_defined?(:RBT) and !RBT.const_defined?(:Cookbooks)
    begin
      require 'rbt/requires/require_the_cookbook_class.rb'
    rescue LoadError; end
  end
  i.chop! if i.end_with? '.'
  if is_the_cookbook_class_available?
    i = RBT::Cookbooks::SanitizeCookbook.new(i).dataset?
  end
  return i
end

#get_program_name(i = @original_input) ⇒ Object

#

get_program_name

Obtain the program name here.

#


983
984
985
986
987
988
989
# File 'lib/easycompile/base/misc.rb', line 983

def get_program_name(i = @original_input)
  if i.include? ' '
    i = i.split(' ').first
  end
  program_name = remove_file_suffix(File.basename(i))
  return program_name
end

#install_this_gem(i) ⇒ Object

#

install_this_gem

Consistently use this method when trying to install a gem.

We will ignore the dependencies, though, to speed up the installation process.

#


23
24
25
26
# File 'lib/easycompile/base/gem.rb', line 23

def install_this_gem(i)
  _ = "gem install --ignore-dependencies #{i}"
  esystem(_)
end

#internal_system(i) ⇒ Object

#

internal_system

The key idea for this method is to handle system()-related calls via IO.popen(). This gives us more control over as to what to do with the given input and output.

#


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/easycompile/base/esystem.rb', line 46

def internal_system(i)
  cparser_is_available = cparser_is_available?
  cparser = @colourize_parser if cparser_is_available
  io_object = IO.popen(i, :err => [:child, :out]).each { |line|
    if cparser_is_available
      cparser.grab_this_line(line) # The cparser object will deal with colours.
      line = cparser.line?
    end
    e line # Output here.
  }
  io_object.close # Close it here.
end

#is_a_gem?(i) ⇒ Boolean

#

is_a_gem?

#

Returns:

  • (Boolean)


31
32
33
# File 'lib/easycompile/base/gem.rb', line 31

def is_a_gem?(i)
  i.end_with? '.gem'
end

#is_an_appdir?Boolean

#

is_an_appdir?

Return true if this is an appdir-based program.

#

Returns:

  • (Boolean)


926
927
928
# File 'lib/easycompile/base/misc.rb', line 926

def is_an_appdir?
  @hash.has_key?(:prefix) and @hash[:prefix] == :appdir
end

#is_archive?(i) ⇒ Boolean Also known as: is_an_archive?

#

is_archive?

Return true if the given input is an archive.

#

Returns:

  • (Boolean)


385
386
387
# File 'lib/easycompile/base/misc.rb', line 385

def is_archive?(i)
  ::Easycompile.is_archive?(i)
end

#is_the_cookbook_class_available?Boolean

#

is_the_cookbook_class_available?

#

Returns:

  • (Boolean)


881
882
883
884
885
# File 'lib/easycompile/base/misc.rb', line 881

def is_the_cookbook_class_available?
  Object.const_defined?(:RBT) and
  RBT.const_defined?(:Cookbooks) and
  RBT::Cookbooks.const_defined?(:Cookbook)
end

#make_distcleanObject

#

make_distclean

#


1031
1032
1033
# File 'lib/easycompile/base/misc.rb', line 1031

def make_distclean
  esystem 'make distclean'
end
#

menu

#


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/easycompile/base/menu.rb', line 14

def menu(
    i = commandline_arguments?
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i
    # ===================================================================== #
    # === ecompile --home_dir
    # ===================================================================== #
    when /^-?-?home(_|-)?dir$/,
         /^-?-?home(_|-)?directory$/,
         /^-?-?home$/
      set_prefix(:home_directory)
    # ===================================================================== #
    # === ecompile --help
    #
    # This option allows us to show the available help options, on
    # the commandline.
    # ===================================================================== #
    when /^-?-?help$/i,
         /^-?h$/i
      show_help :then_exit
    # ===================================================================== #
    # === easycompile --homedir
    # ===================================================================== #
    when /^-?-?home(_|-)?dir$/i
      use_the_home_directory_as_prefix
    # ===================================================================== #
    # === easycompile --OPEN_ITSELF
    # ===================================================================== #
    when /^-?-?OPEN(_|-)?ITSELF$/i,
         /^-?-?OPEN$i/ # OPEN_SELF
      open_this_file
      exit
    # ===================================================================== #
    # === ALL
    # ===================================================================== #
    when /^-?-?all$/i,
         /^-?-?everything$/i
      set_compile_these_programs Dir['*']
    # ===================================================================== #
    # === --remove-all-after-compile
    # ===================================================================== #
    when /^-?-?remove(_|-| )?all(_|-| )?after(_|-| )?compile$/i
      do_remove_all_after_compile
    # ===================================================================== #
    # === set_extract_to
    #
    # This entry allows us to define a custom temp-directory.
    #
    # Invocation example:
    #
    #   ecompile php* --extract-to=/Depot/opt/
    #
    # ===================================================================== #
    when /^-?-?set(_|-| )?extract(_|-| )?to=(.+)$/i, # $3
         /^-?-?extract(_|-| )?to=(.+)$/i  # $2
      _ = $2
      _ = $3.to_s.dup if $3
      set_extract_to(_) { :be_verbose }
    # ===================================================================== #
    # === ecompile --sco
    #
    # Invocation example:
    #
    #   ecompile --sco php*xz
    #
    # ===================================================================== #
    when /^-?-?sco$/i,
         /^-?-?extended-configure-options$/i,
         /^-?-?use-configure-options$/i
      @try_to_use_extended_configure_options = true
    # ===================================================================== #
    # === --wdeps
    # ===================================================================== #
    when /^-?-?wdeps$/i,
         /^-?-?with(_|-| )?deps$/i
      do_compile_with_dependencies
    # ===================================================================== #
    # === --skipmakeinstall
    # ===================================================================== #
    when /^-?-?SKIP_?MAKE_?INSTALL/i,
         'NO_MAKE_INSTALL',
         'NOMAKEINSTALL',
         'NOINSTALL',
         'SKIPINSTALL'
      enable_skip_make_install # Skip the "make install" step.
    # ===================================================================== #
    # === --dontcompile
    # ===================================================================== #
    when /^-?-?DONT(_|-| )?COMPILE$/i
      enable_dont_compile
    # ===================================================================== #
    # === --skip_extracting
    # ===================================================================== #
    when 'SKIP_EXTRACT',
         /^-?-?SKIP(_|-| )?EXTRACTING$/i,
         'SKIPEXTRACTING'
      skip_extracting
    # ===================================================================== #
    # === --appdir
    # ===================================================================== #
    when /^-?-?appdir$/i
      set_prefix :appdir
      opn; e 'Will compile as AppDir. The prefix now is '+simp(prefix?.to_s)
    else # else tag
      if File.exist?(i) or i.end_with?('.yml')
        add_this_archive(i)
      else
        # ================================================================= #
        # Next, we will attempt to find a valid entry. 
        # ================================================================= #
        i = attempt_to_find_a_valid_file(i)
        if i.respond_to?(:select)
          add_these_files(
            i.select {|file|
              File.exist? file.to_s
            }
          )
        end
      end
    end
  end
end

#mkdir(i) ⇒ Object

#

mkdir (mkdir tag)

#


312
313
314
# File 'lib/easycompile/base/misc.rb', line 312

def mkdir(i)
  FileUtils.mkdir_p(i)
end

#name_of_build_directory?Boolean Also known as: name_for_build_dir?, name_of_the_build_directory?

#

name_of_build_directory?

This method will return the name of the BUILD/ directory. For now this is static but perhaps one day we may wish to change this, in order to make it more dynamic.

#

Returns:

  • (Boolean)


267
268
269
# File 'lib/easycompile/base/misc.rb', line 267

def name_of_build_directory?
  @name_of_build_directory
end

#ninjaitObject

#

ninjait

#


31
32
33
34
# File 'lib/easycompile/base/meson_and_ninja.rb', line 31

def ninjait
  esystem 'ninja'
  esystem 'ninja install'
end

#open_this_file(this_file = self.class::THIS_FILE) ⇒ Object

#

open_this_file

#


151
152
153
# File 'lib/easycompile/base/misc.rb', line 151

def open_this_file(this_file = self.class::THIS_FILE)
  esystem "bluefish #{this_file}"
end

#opn_namespaceObject

#

opn_namespace

We use a special namespace-name here.

#


16
17
18
# File 'lib/easycompile/base/opn.rb', line 16

def opn_namespace
  opn(namespace: NAMESPACE)
end

#original_input?Boolean

#

original_input?

#

Returns:

  • (Boolean)


305
306
307
# File 'lib/easycompile/base/misc.rb', line 305

def original_input?
  @original_input
end

#prefix?Boolean

#

prefix?

#

Returns:

  • (Boolean)


73
74
75
# File 'lib/easycompile/base/misc.rb', line 73

def prefix?
  @prefix
end

#process_the_input(i = compile_these_programs? ) ⇒ Object

#

process_the_input

#


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
# File 'lib/easycompile/base/process_the_input.rb', line 14

def process_the_input(
    i = compile_these_programs?
  )
  i.each {|this_entry|
    # ===================================================================== #
    # The this_entry part may look like so:
    #
    #   "php-7.4.2.tar.xz"
    #
    # ===================================================================== #
    # The entry may be nil at this point, though. In that case, we
    # fetch a random element.
    # ===================================================================== #
    this_entry = Dir['*'].first if this_entry.nil?
    this_entry = this_entry.to_s
    this_entry.sub!(/\^/,'') if this_entry.include? '^' # Remove ^ from the input here, if it is included.
    # ===================================================================== #
    # If input is a (positional) number, such as "3".
    # ===================================================================== #
    unless File.exist?(this_entry)
      if this_entry =~ /^\d+$/
        # ================================================================= #
        # Obtain all entries next.
        # ================================================================= #
        entries = Dir['*']
        unless entries.empty?
          this_entry = this_entry.to_i
          this_entry = entries.size if this_entry > entries.size # This is to fetch the proper last entry, if input is too long.
          this_entry = entries.sort[ (this_entry.to_i - 1) ] # Fetch an entry here.
        end
      end
    end
    # ===================================================================== #
    # === Handle .gem files too, early on - they won't need a build directory.
    # ===================================================================== #
    if this_entry =~ /\.gem$/ # If it is a gem file.
      do_not_create_a_build_directory # Gem files typically do not need a build dir.
    end
    # ===================================================================== #
    # === Handle yaml files first.
    #
    # If the input file is a yaml file, we will assume that the user wants
    # to change directory first into the SRC_DIR hierarchy.
    #
    # Invoke this by doing something like:
    # ===================================================================== #
    if this_entry.include? '.yml'
      yaml_dataset = get_dataset_from(this_entry)
      this_entry = yaml_dataset['program_path']
    end
    if File.directory? this_entry
      _ = Dir["#{this_entry}/*"].first # Fetch the first entry from this directory, in this case. But retain it only when it is an archive.
      if is_archive? _
        this_entry = _
      end # else we discard it.
    end
    # ===================================================================== #
    # Next, we need to check whether the input is an archive or whether
    # it is not. If it is a directory, then we will simply enter
    # this directory instead, without doing any further extraction.
    # ===================================================================== #
    unless this_entry.start_with?('--')
      if File.directory? this_entry # No need to do anything special in this case.
        # ================================================================= #
        # In this case we will enter the given directory at hand.
        # ================================================================= #
        cd this_entry
        consider_creating_a_build_directory
        run_configure_make_and_make_install
      else
        if File.exist?(this_entry)
          # ================================================================= #
          # Past this point we know that the entry must exist.
          # ================================================================= #
          set_original_input(this_entry)
          set_find_this_program(
            ProgramInformation.return_name(this_entry)
          )
          # =================================================================== #
          # The next method will also extract the archive, if the
          # archive exists and there is no other instruction given
          # by the user to NOT extract it.
          # =================================================================== #
          try_to_compile_or_install_this_program(this_entry)
          consider_symlinking_appdir if is_an_appdir?
          return_to_start_directory_again
          consider_removing_this_archive(this_entry)
        end
      end
    end
  }
end

#program_name?Boolean

#

program_name?

#

Returns:

  • (Boolean)


523
524
525
# File 'lib/easycompile/base/misc.rb', line 523

def program_name?
  @program_name
end

#program_version?Boolean Also known as: version?

#

program_version?

#

Returns:

  • (Boolean)


461
462
463
# File 'lib/easycompile/base/misc.rb', line 461

def program_version?
  @program_version
end

#rds(i) ⇒ Object

#

rds

#


46
47
48
# File 'lib/easycompile/base/misc.rb', line 46

def rds(i)
  i.squeeze('/')
end

#remove_all_after_compile?Boolean

#

remove_all_after_compile?

#

Returns:

  • (Boolean)


73
74
75
# File 'lib/easycompile/base/remove.rb', line 73

def remove_all_after_compile?
  @remove_all_after_compile
end

#remove_directory(i = nil) ⇒ Object Also known as: remove_this_directory

#

remove_directory

This method will remove a directory (if the input argument is a directory that is).

#


17
18
19
20
21
22
23
# File 'lib/easycompile/base/remove.rb', line 17

def remove_directory(i = nil)
  if i and File.directory?(i)
    i = i.dup if i.frozen?
    i.squeeze!('/')
    FileUtils.rm_rf(i) unless i == '/' # Don't delete "/" ever.
  end
end

#remove_extension_from(i) ⇒ Object Also known as: remove_file_suffix, remove_archive_at_the_end

#

remove_extension_from

#


41
42
43
44
45
46
47
48
49
50
# File 'lib/easycompile/base/remove.rb', line 41

def remove_extension_from(i)
  i = i.dup # Work on a copy.
  i.sub!(/\.xz$/,'')    if i.end_with? '.xz'
  i.sub!(/\.gz$/,'')    if i.end_with? '.gz'
  i.sub!(/\.bzip2$/,'') if i.end_with? '.bzip2'
  i.sub!(/\.bzip$/,'')  if i.end_with? '.bzip'
  i.sub!(/\.tar$/,'')   if i.end_with? '.tar'
  i.sub!(/\.zip$/,'')   if i.end_with? '.zip'
  i
end

#remove_this_archive(i) ⇒ Object

#

remove_this_archive

This method can only be used to remove an archive, that is some file like “foobar-1.2.0.tar.xz”. It may never remove a directory.

#


32
33
34
35
36
# File 'lib/easycompile/base/remove.rb', line 32

def remove_this_archive(i)
  if is_an_archive?(i)
    remove_file(i)
  end
end

#remove_this_file(i) ⇒ Object Also known as: remove

#

remove_this_file

#


56
57
58
59
60
# File 'lib/easycompile/base/remove.rb', line 56

def remove_this_file(i)
  i = @start_dir+File.basename(i)
  opn_namespace; e 'Now deleting `'+sfile(i)+'`.'
  File.delete(i) if File.exist? i
end

#replace_all_yaml_files(i = @commandline_arguments) ⇒ Object

#

replace_all_yaml_files

#


955
956
957
958
959
960
961
962
963
964
965
# File 'lib/easycompile/base/misc.rb', line 955

def replace_all_yaml_files(i = @commandline_arguments)
  i.map {|entry|
    if entry.end_with?('.yml')
      begin
        require 'rbt/requires/require_the_cookbook_class.rb'
        entry = return_yaml_file(entry)
      rescue LoadError; end
    end
    entry
  }
end

#resetObject

#

reset (reset tag)

The instance variable we will use here:

@prefix_to_base_directory # This is used to denote what is the base

directory.

#


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/easycompile/base/reset.rb', line 26

def reset
  set_base_dir
  set_start_dir
  # ======================================================================= #
  # === @commandline_arguments
  #
  # This Array will hold all commandline arguments, e. g. ARGV.
  # ======================================================================= #
  @commandline_arguments = []
  # ======================================================================= #
  # === @compile_these_programs
  #
  # These are the programs, as an Array, that we wish to compile.
  # ======================================================================= #
  @compile_these_programs = []
  # ======================================================================= #
  # === @program_name
  # ======================================================================= #
  @program_name = nil
  # ======================================================================= #
  # === @compile_with_dependencies
  # ======================================================================= #
  @compile_with_dependencies = false # If true then we will first compile all dependencies.
  # ======================================================================= #
  # === @program_version
  # ======================================================================= #
  @program_version = '1.0.0' # Default.
  # ======================================================================= #
  # Designate the default extract-to directory next.
  # ======================================================================= #
  set_extract_to(:default)
  # ======================================================================= #
  # === @hash
  # ======================================================================= #
  @hash = {}
  # ======================================================================= #
  # === @skip_extracting
  # ======================================================================= #
  @skip_extracting = false # Whether to skip extracting or not.
  # ======================================================================= #
  # === @continue_after_extracting
  # ======================================================================= #
  @continue_after_extracting = true # if true we continue after extracting.
  # ======================================================================= #
  # === @build_directory_is_stored_here
  # ======================================================================= #
  @build_directory_is_stored_here = nil
  # ======================================================================= #
  # === @continue_past_configure_stage
  # ======================================================================= #
  @continue_past_configure_stage = true
  # ======================================================================= #
  # === @skip_make_install
  # ======================================================================= #
  @skip_make_install = false
  set_prefix # Default.
  # ======================================================================= #
  # === @prefix_to_base_directory
  # ======================================================================= #
  @prefix_to_base_directory = ''
  # ======================================================================= #
  # === @shall_we_create_a_build_directory
  #
  # This variable keeps track as to whether we will create a 
  # build directory or not.
  # ======================================================================= #
  @shall_we_create_a_build_directory = SHALL_WE_CREATE_A_BUILD_DIRECTORY
  # ======================================================================= #
  # === @prefix
  #
  # Which prefix is to be used. Defaults to /usr/.
  # ======================================================================= #
  @prefix = '/usr/'
  # ======================================================================= #
  # === @original_input
  # ======================================================================= #
  @original_input = nil
  # ======================================================================= #
  # === @temp_directory
  # ======================================================================= #
  @temp_directory = ::Easycompile.temp_directory?
  # ======================================================================= #
  # === @remove_all_after_compile
  # ======================================================================= #
  @remove_all_after_compile = false
  # ======================================================================= #
  # === @try_to_use_extended_configure_options
  #
  # If this variable is set to true then we will try to
  # return the extended configure options, which are
  # part of the RBT project.
  # ======================================================================= #
  @try_to_use_extended_configure_options = false
  # ======================================================================= #
  # === @colourize_parser
  # ======================================================================= #
  if cparser_is_available?
    @colourize_parser = RBT::ColourizeParser.new
  else
    @colourize_parser = nil
  end
  # ======================================================================= #
  # === @name_of_build_directory
  #
  # Choose a default name for the build directory. This can be
  # overruled if we have a .yml file that tells us to do so.
  # ======================================================================= #
  set_name_of_build_directory 'BUILD_DIRECTORY/'
  if File.exist? FILE_NAME_OF_THE_BUILD_DIRECTORY
    require 'yaml'
    set_name_of_build_directory(:load_the_yaml_file)
  end
end

#return_all_arguments_with_hyphensObject

#

return_all_arguments_with_hyphens

This method will select all commandline arguments that begin with two – hyphens.

#


31
32
33
34
35
# File 'lib/easycompile/base/commandline_arguments.rb', line 31

def return_all_arguments_with_hyphens
  @commandline_arguments.select {|entry|
    entry.start_with? '--'
  }
end

#return_pwdObject

#

return_pwd

#


28
29
30
# File 'lib/easycompile/base/misc.rb', line 28

def return_pwd
  ("#{Dir.pwd}/").squeeze '/'
end

#return_to_start_directory_againObject

#

return_to_start_directory_again

#


874
875
876
# File 'lib/easycompile/base/misc.rb', line 874

def return_to_start_directory_again
  cd start_dir?
end

#return_yaml_file(i) ⇒ Object

#

return_yaml_file

#


970
971
972
973
974
975
976
# File 'lib/easycompile/base/misc.rb', line 970

def return_yaml_file(i)
  begin
    require 'rbt/requires/require_the_cookbook_class.rb'
    i = RBT::Cookbooks::SanitizeCookbook.new(i).program_path?
  rescue LoadError; end
  return i
end

#revObject

#

rev

#


58
59
60
61
62
63
64
# File 'lib/easycompile/base/colours.rb', line 58

def rev
  if use_colours?
    ::Colours.rev
  else
    ''
  end
end

#runObject

#

run (run tag)

#


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/easycompile/base/run.rb', line 14

def run
  @start_dir = return_pwd
  determine_which_programs_to_compile
  # ======================================================================= #
  # Next check against the menu (commandline-interface).
  # ======================================================================= #
  menu(
    return_all_arguments_with_hyphens
  )
  process_the_input
end

#run_build_shObject

#

run_build_sh

Run sh build.sh

#


1023
1024
1025
1026
# File 'lib/easycompile/base/misc.rb', line 1023

def run_build_sh
  _ = "#{@prefix_to_base_directory}sh build.sh"
  esystem _
end

#run_cmake_commandObject Also known as: run_cmake

#

run_cmake_command (cmake tag)

Compiling via cmake can yield errors. We will try to capture such an error.

Note that cmake-based projects typically require a dedicated build directory - this is why the method do_make_use_of_a_build_directory() is called within this method.

cmake -DCMAKE_INSTALL_PREFIX=/usr

#


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/easycompile/base/cmake.rb', line 32

def run_cmake_command
  do_make_use_of_a_build_directory
  _ = 'cmake'.dup
  # ======================================================================= #
  # Next, we will use the install prefix.
  # ======================================================================= #
  _ << " -DCMAKE_INSTALL_PREFIX=#{prefix?}"
  _ << ' .'
  _ << '.' if shall_we_create_a_build_directory? # Append this.
  if shall_we_create_a_build_directory?
    use_this_name = name_of_build_directory?
    unless File.directory?(use_this_name)
      opn; e "Next creating the build directory called `"\
             "#{sdir(use_this_name)}`."
      mkdir(use_this_name)
    end
    cd use_this_name
  end
  esystem _
end

#run_configureObject Also known as: run_configure_command, run_configure_command_or_another_command, run_configure_or_cmake

#

run_configure (configure tag)

This method runs the classical configure command with a specific prefix. It is equivalent to just run “./configure”.

#


737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# File 'lib/easycompile/base/misc.rb', line 737

def run_configure
  if shall_we_create_a_build_directory?
    @prefix_to_base_directory << '../'
  end
  # ======================================================================= #
  # === Check for Rakefile
  # ======================================================================= #
  if File.exist?(@prefix_to_base_directory+'Rakefile')
    run_rinstall2
  # ======================================================================= #
  # === Check for cmake-file
  #
  # Here we will run cmake.
  # ======================================================================= #
  elsif File.exist?("#{@prefix_to_base_directory}#{cmake_file?}")
    run_cmake_command
  # ======================================================================= #
  # === Check for setup.py file
  #
  # Note that a file called setup.py may exist, but the program itself
  # may still require a "configure" invocation. This is the case with
  # the official source archive for Python.
  # ======================================================================= #
  elsif File.exist?(@prefix_to_base_directory+'setup.py')
    run_python_installation
  # ======================================================================= #
  # === Check for Makefile.PL
  # ======================================================================= #
  elsif File.exist?(@prefix_to_base_directory+'Makefile.PL')
    run_perl_installation
  # ======================================================================= #
  # === Check for build.sh file
  #
  # This was disabled on 20.06.2020 as it was not working for the
  # program called "make". At a later time this may have to be
  # re-enabled again, but for now it has to stay disabled.
  # ======================================================================= #
  # elsif File.exist? @prefix_to_base_directory+'build.sh'
  #   run_build_sh
  # ======================================================================= #
  # === Run the configure command next
  # ======================================================================= #
  elsif File.exist? @prefix_to_base_directory+'configure'
    simply_run_the_configure_command
  # ======================================================================= #
  # === Check for ruby .gem files next
  # ======================================================================= #
  elsif (@original_input =~ /\.gem$/)
    install_this_gem(@original_input)
    exit
  # ======================================================================= #
  # === Check whether 'meson.build' exists
  # ======================================================================= #
  elsif does_a_meson_build_file_exist?
    compile_as_meson_based_project
    exit
  else # The default, that is - we will run ./configure here.
    show_namespace; e 'We could not find a configure script, no cmake'
    show_namespace; e 'file and we also could not find various other '
    show_namespace; e 'files. We will now assume that configure may'
    show_namespace; e 'still work, and thus run, but be aware that'
    show_namespace; e 'this may fail.'
    simply_run_the_configure_command
  end
end

#run_configure_make_and_make_installObject Also known as: run_configure_then_make_then_make_install

#

run_configure_make_and_make_install

#


1047
1048
1049
1050
1051
1052
1053
# File 'lib/easycompile/base/misc.rb', line 1047

def run_configure_make_and_make_install
  run_configure_command_or_another_command
  if continue_past_configure_stage?
    run_make_command_or_equivalent
    run_make_install_command
  end
end

#run_make_command_or_equivalentObject Also known as: run_make_command, run_make

#

run_make_command_or_equivalent (make tag)

This method will either run “make”, or another command.

For now we assume the alternative is via cmake. Please note that the command “make install” usually follows the “make” command.

#


911
912
913
914
915
916
917
918
# File 'lib/easycompile/base/misc.rb', line 911

def run_make_command_or_equivalent
  show_namespace; e 'Running "make" in '+sdir(return_pwd)+' next.'
  if File.exist? 'Makefile'
    esystem 'make' if continue_past_configure_stage?
  else # Else assume cmake.
    esystem 'make' if continue_past_configure_stage?
  end
end

#run_make_install_commandObject

#

run_make_install_command

This will run “make install”.

#


1040
1041
1042
# File 'lib/easycompile/base/misc.rb', line 1040

def run_make_install_command
  esystem 'make install' unless skip_make_install?
end

#run_make_then_make_installObject

#

run_make_then_make_install

#


1058
1059
1060
1061
# File 'lib/easycompile/base/misc.rb', line 1058

def run_make_then_make_install
  run_make_command_or_equivalent
  run_make_install_command
end

#run_perl_installationObject

#

run_perl_installation

#


99
100
101
# File 'lib/easycompile/base/misc.rb', line 99

def run_perl_installation
  _ 'perl Makefile.PL'
end

#run_python_installationObject

#

run_python_installation (python tag)

This method will additionally check for a file called ‘configure’.

#


1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/easycompile/base/misc.rb', line 1068

def run_python_installation
  if File.exist?("#{@prefix_to_base_directory}configure")
    simply_run_the_configure_command
    run_make_then_make_install
  else
    _ 'python setup.py configure'
    _ 'python setup.py build'
    _ 'python setup.py install'
  end
end

#run_rinstall2Object

#

run_rinstall2

#


60
61
62
63
64
65
66
67
68
# File 'lib/easycompile/base/misc.rb', line 60

def run_rinstall2
  copy_setup_rb
  internal_system 'ruby setup.rb config'
  internal_system 'ruby setup.rb setup'
  internal_system 'ruby setup.rb install'
  internal_system 'rm setup.rb'
  internal_system 'rm InstalledFiles'
  internal_system 'rm .config'
end

#set_base_dir(i = return_pwd) ⇒ Object

#

set_base_dir

#


446
447
448
449
# File 'lib/easycompile/base/misc.rb', line 446

def set_base_dir(i = return_pwd)
  i = i.squeeze('/')
  @base_dir = i
end

#set_commandline_arguments(i) ⇒ Object

#

set_commandline_arguments

#


21
22
23
# File 'lib/easycompile/base/commandline_arguments.rb', line 21

def set_commandline_arguments(i)
  @commandline_arguments = [i].flatten.compact
end

#set_compile_these_programs(i) ⇒ Object

#

set_compile_these_programs

This method specifies which programs this class will compile.

#


676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# File 'lib/easycompile/base/misc.rb', line 676

def set_compile_these_programs(i)
  i = [i].flatten.compact
  i.map! {|entry|
    # ======================================================================= #
    # The file in question may not exist, for instance if it is a remote URL
    # link. In that case we enter here.
    # ======================================================================= #
    unless File.exist? entry
      case entry # case tag
      when 'ALL','A' # simply get all.
        entry = Dir['*'].reject {|inner_entry| File.directory? inner_entry }
      when /LAST/,/LAT/ # Special instruction.
        entry = File.readlines(LAST_DOWNLOADED_FILE).first
      else # Try a (silent) glob here if the file does not exist.
        if entry.include?('http') # Assume this to be a remote file.
          esystem "wget #{entry}"
          entry = File.basename(entry)
        else
          glob = Dir["#{entry}*"]
          entry = glob.first unless glob.empty?
        end
      end
    end
    entry
  }
  @compile_these_programs = i
end

#set_extract_to_this_directory(i = :default) ⇒ Object Also known as: set_extract_to

#

set_extract_to_this_directory

#


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/easycompile/base/misc.rb', line 196

def set_extract_to_this_directory(i = :default)
  case i
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       nil
    i = temp_dir?
  end
  i = i.to_s.dup
  unless i.end_with? '/'
    i = i.dup if i.frozen?
    i << '/'
  end
  # ======================================================================= #
  # === Handle blocks given to this method next:
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :be_verbose
    # ===================================================================== #
    when :be_verbose
      e "#{rev}Using the directory #{sdir(i)} as temp-directory next."
      e '(The archive at hand will be extracted to this directory.)'
    end
  end
  @extract_to_this_directory = i
end

#set_find_this_program(i) ⇒ Object

#

set_find_this_program

This will store e. g. “php”, so that we can designate to work on a particular program, and pass this information to external programs if necessary.

#


39
40
41
# File 'lib/easycompile/base/misc.rb', line 39

def set_find_this_program(i)
  @find_this_program = i
end

#set_hash(i = {}) ⇒ Object

#

set_hash

#


500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/easycompile/base/misc.rb', line 500

def set_hash(i = {})
  if i.is_a? Hash
    if i.has_key? :extract_to
      set_extract_to(i[:extract_to])
    end
    if i.has_key? :program_version
      set_version(i[:program_version])
    end
    if i.has_key? :prefix
      set_prefix(i[:prefix])
    end
    if i.has_key? :appdir_layout
      set_prefix(i[:appdir_layout])
    elsif i.has_key? :usr_prefix
      set_prefix(i[:usr_prefix])
    end
  end
  @hash = i
end

#set_name_of_build_directory(i = :default) ⇒ Object

#

set_name_of_build_directory

#


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/easycompile/base/misc.rb', line 244

def set_name_of_build_directory(
    i = :default
  )
  case i
  # ======================================================================= #
  # === :load_the_yaml_file
  # ======================================================================= #
  when :load_the_yaml_file,
       :default
    i = YAML.load_file(FILE_NAME_OF_THE_BUILD_DIRECTORY)
  end
  i = i.dup if i.frozen?
  i << '/' unless i.end_with? '/'
  @name_of_build_directory = i
end

#set_original_input(i) ⇒ Object

#

set_original_input

This method will keep track of the “original” input.

#


298
299
300
# File 'lib/easycompile/base/misc.rb', line 298

def set_original_input(i)
  @original_input = i
end

#set_prefix(i = '/usr') ⇒ Object Also known as: set_prefix_for_this_program

#

set_prefix

Set the prefix here. By default the prefix will be /usr, but some programs, in particular app-dir like programs, will default to a prefix such as /Programs/Gimp/2.5.2.

#


1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
# File 'lib/easycompile/base/misc.rb', line 1086

def set_prefix(
    i = '/usr'
  )
  if i.is_a? Symbol # This may be triggered via :appdir, for instance.
    case i
    # ===================================================================== #
    # === :home_directory
    # ===================================================================== #
    when :home_directory,
         :home_dir,
         :home
      i = ENV['HOME'].to_s
    end
    i = i.to_s # Work on a String here.
    i = remove_file_suffix(i)
    # ===================================================================== #
    # Simply assemble the prefix now, based on the capitalized variant
    # of the program name, and then the version.
    # For this to work, program_name? and program_version? must have
    # been already defined.
    # ===================================================================== #
    # if program_name?.nil? and program_version?.nil?
    #   # In this case, we must first define these two entries.
    #   # This has not yet happened - stub.
    # end
    case i
    when /usr(_|-)?prefix/
      i = '/usr/'
    # ===================================================================== #
    # === appdir
    # ===================================================================== #
    when 'appdir',
         'app'
      # =================================================================== #
      # We will first check on the original input. If that original
      # input was an existing file, in form of an archive, then
      # we may make use of ProgramInformation to change the
      # version of the program at hand.
      # =================================================================== #
      if @original_input and
         File.exist?(@original_input) and
         File.file?(@original_input) and
         is_archive?(@original_input)
        # ================================================================= #
        # Ok, in this case, we will make use of ProgramInformation.
        # ================================================================= #
        _ = remove_archive_at_the_end(
          File.basename(
            @original_input
          )
        )
        set_program_name(_)
        set_program_version(
          ProgramInformation.return_version(@original_input)
        )
      end
      # =================================================================== #
      # Build up the full appdir-prefix next:
      # =================================================================== #
      i = "#{::Easycompile.programs_directory?}"\
          "#{program_name?.to_s.capitalize.delete('-')}"\
          "/#{program_version?}"
    end
  end
  if i.is_a? String # We can do this because the next step is rds().
    i = i.dup if i.frozen?
    i = rds("#{i}/")
  end
  @prefix = i
end

#set_program_name(i = nil) ⇒ Object

#

set_program_name

Note that this method can make use of ProgramInformation.

#


996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
# File 'lib/easycompile/base/misc.rb', line 996

def set_program_name(i = nil)
  i = i.first if i.is_a? Array
  if i
    i = get_program_name(i)
    # ===================================================================== #
    # Next, we need to obtain the real program name, without the
    # version. We used the following line for this in the past:
    #   _ = _.split('-').first if _.include? '-'
    # However had, as of 08.08.2015, we will instead use ProgramInformation.
    # ===================================================================== #
    i = ProgramInformation.return_name(i) # .first() will return the right name.
  end
  @program_name = i
end

#set_program_version(i) ⇒ Object

#

set_program_version

#


439
440
441
# File 'lib/easycompile/base/misc.rb', line 439

def set_program_version(i)
  @program_version = i
end

#set_start_dir(i = return_pwd) ⇒ Object

#

set_start_dir

#


174
175
176
177
# File 'lib/easycompile/base/misc.rb', line 174

def set_start_dir(i = return_pwd)
  i.squeeze! '/'
  @start_dir = i # This is not @base_dir.
end

#set_this_build_dir(i = :pwd) ⇒ Object Also known as: set_build_directory

#

set_this_build_dir

#


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/easycompile/base/misc.rb', line 80

def set_this_build_dir(i = :pwd)
  case i
  when :pwd
    i = return_pwd
  end
  i = i.to_s
  unless i.include? '/'
    i = File.absolute_path(i)
  end
  unless i.end_with? '/'
    i = i.dup if i.frozen?
    i << '/'
  end
  @build_directory_is_stored_here = i
end

#shall_we_create_a_build_directory?Boolean

#

shall_we_create_a_build_directory?

#

Returns:

  • (Boolean)


237
238
239
# File 'lib/easycompile/base/misc.rb', line 237

def shall_we_create_a_build_directory?
  @shall_we_create_a_build_directory
end

#show_help(optional_shall_we_exit = false) ⇒ Object

#

show_help (help tag)

#


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/easycompile/base/help.rb', line 14

def show_help(
    optional_shall_we_exit = false
  )
  case optional_shall_we_exit
  when :then_exit
    optional_shall_we_exit = true
  end
  e
  opn_namespace; e 'The following help options are documented:'
  e
  ecomment '  --appdir                   # Compile as Appdir, into '\
           'its own prefix.'
  ecomment '  --remove-all-after-compile # Remove '\
           'the archive after compilation is done.'
  ecomment '  --with-deps                '\
           '# Compile with dependencies.'
  ecomment '  --extract-to=/Depot/opt/   '\
           '# extract to that particular directory.'
  ecomment '  --homedir                  # '\
           'Compile into the home-directory as prefix'
  e
  exit if optional_shall_we_exit
end

#show_namespaceObject

#

show_namespace

#


23
24
25
# File 'lib/easycompile/base/opn.rb', line 23

def show_namespace
  opn(namespace: Constants::NAMESPACE)
end

#simply_run_the_configure_commandObject

#

simply_run_the_configure_command

#


808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/easycompile/base/misc.rb', line 808

def simply_run_the_configure_command
  _  = ''.dup # ← Buildup the command.
  _ << '.' if shall_we_create_a_build_directory?
  _ << "./configure --prefix=#{prefix?}"
  # ======================================================================= #
  # === Check for etended configure options next
  # ======================================================================= #
  if @try_to_use_extended_configure_options
    begin
      require 'rbt/requires/require_show_configuration_options.rb'
    rescue LoadError; end
    if RBT.respond_to? :return_configuration_options_for?
      _ << " #{RBT.return_configuration_options_for?(find_which_program?)}"
    end
  end
  begin
    # This part invokes the actual "./configure" run.
    esystem(_) # Also show the ./configure command we will use.
  rescue Errno::ENOENT
    show_namespace
    e 'An error happened - the configure-file could not be found. '\
      'The faulty line was:'
    show_namespace
    e "  #{simp(_)}"
    show_namespace
    e "It was issued from the directory: #{sdir(return_pwd)}"
    if return_pwd.include? name_for_build_dir?
      set_this_build_dir(:pwd)
    end
    can_not_continue # We can not continue past the configure-step.
    # ======================================================================= #
    # Do "make distclean" here.
    # ======================================================================= #
    if _.include?('configure: error: source directory already configured') or
       _.include?('source directory already configured; run "make distclean"')
      @base_dir = return_pwd
      cd '..'
      make_distclean
      cd @base_dir
      run_configure_command
    end if _
  end
end

#skip_extractingObject

#

skip_extracting

#


358
359
360
361
# File 'lib/easycompile/base/misc.rb', line 358

def skip_extracting
  show_namespace; e 'We will not extract.'
  @skip_extracting = true
end

#skip_extracting?Boolean

#

skip_extracting?

#

Returns:

  • (Boolean)


351
352
353
# File 'lib/easycompile/base/misc.rb', line 351

def skip_extracting?
  @skip_extracting
end

#skip_make_install?Boolean

#

skip_make_install?

#

Returns:

  • (Boolean)


167
168
169
# File 'lib/easycompile/base/misc.rb', line 167

def skip_make_install?
  @skip_make_install
end

#start_dir?Boolean

#

start_dir?

#

Returns:

  • (Boolean)


182
183
184
# File 'lib/easycompile/base/misc.rb', line 182

def start_dir?
  @start_dir
end

#temp_dir?Boolean

#

temp_dir?

#

Returns:

  • (Boolean)


113
114
115
# File 'lib/easycompile/base/misc.rb', line 113

def temp_dir?
  ::Easycompile.temp_dir?
end

#temp_directory?Boolean

#

temp_directory?

#

Returns:

  • (Boolean)


144
145
146
# File 'lib/easycompile/base/misc.rb', line 144

def temp_directory?
  @temp_directory
end

#try_to_compile_or_install_this_program(this_archive) ⇒ Object

#

try_to_compile_or_install_this_program

#


855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
# File 'lib/easycompile/base/misc.rb', line 855

def try_to_compile_or_install_this_program(this_archive)
  if is_a_gem?(this_archive)
    e "#{rev}Now installing the gem at #{sfile(this_archive)}."
    install_this_gem(this_archive)
  else
    extracted_to = try_to_extract(this_archive)
    if continue_after_extracting?
      if File.directory? extracted_to
        enter_extracted_directory(extracted_to)
        consider_creating_a_build_directory
        run_configure_make_and_make_install
      end
    end
  end
end

#try_to_extract(this_archive, extract_to = extract_to? ) ⇒ Object Also known as: extract_archive, extract, consider_extracting_this_archive

#

try_to_extract

Use this method here to extract a given archive.

#


621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/easycompile/base/misc.rb', line 621

def try_to_extract(
    this_archive, extract_to = extract_to?
  )
  if this_archive.is_a? Array # Obtain only the first element in this case.
    this_archive = this_archive.first
  end
  cd start_dir?
  if File.exist? this_archive.to_s
    # ===================================================================== #
    # In this case, we will assume that an valid archive was given to us.
    # ===================================================================== #
    unless skip_extracting?
      show_namespace; e "Now trying to extract `#{sfancy(this_archive)}`."
      @extracter = Extracter.what_to(this_archive, extract_to)
      return remove_archive_at_the_end(
        extract_to+
        File.basename(this_archive)
      )
    else
      nil
    end
  elsif File.exist? base_dir?+this_archive
    unless skip_extracting?
      @extracter = Extracter.what_to(base_dir?+this_archive, extract_to)
    end 
  else
    # ===================================================================== #
    # The file does not exist here at this point. Thus, we will
    # do some further checks.
    # ===================================================================== #
    if this_archive =~ /^\d+$/ # Ok, user inputted a number alone, check first.
      this_archive = Dir['*'].sort[ this_archive.to_i - 1 ]
      if File.exist? this_archive
        @extracter = Extracter.what_to(this_archive, extract_to)
      end
    elsif find_partial_match_for(this_archive).first # Ok, user could input a partial number and a string, like: "baobab-3.9"
      matched = find_partial_match_for(i)[1]
      consider_extracting_this_archive(matched)
    else # Ok, it indeed does not exist.
      show_namespace; e 'File `'+sfile(this_archive)+'` does '+
                        'not exist. We thus can not continue.'
      show_namespace; e 'We will not continue as a consequence.'
      do_not_continue
      return nil
    end
  end
end

#use_colours?Boolean

#

use_colours?

#

Returns:

  • (Boolean)


51
52
53
# File 'lib/easycompile/base/colours.rb', line 51

def use_colours?
  ::Easycompile.can_we_use_colours?
end

#use_the_home_directory_as_prefixObject

#

use_the_home_directory_as_prefix

#


1014
1015
1016
# File 'lib/easycompile/base/misc.rb', line 1014

def use_the_home_directory_as_prefix
  set_prefix(:home_directory)
end