class RBT::GenerateMakefile

Constants

NAME_OF_MAKEFILE
#

NAME_OF_MAKEFILE

#
NAME_OF_THE_FILE_HERE
#

NAME_OF_THE_FILE_HERE

#
WHICH_SHELL_TO_USE
#

WHICH_SHELL_TO_USE

#

Attributes

base_dir[W]

Public Class Methods

new( optional_makefile = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/rbt/generate_files/generate_makefile.rb, line 62
def initialize(
    optional_makefile = nil,
    run_already       = true
  )
  reset
  set_input(optional_makefile)
  run if run_already
end

Public Instance Methods

add_comment() click to toggle source
#

add_comment

Add a comment to the Makefile.

#
# File lib/rbt/generate_files/generate_makefile.rb, line 187
def add_comment
  @_ << '# =========================================================================== #'+N
end
add_header() click to toggle source
#

add_header

#
# File lib/rbt/generate_files/generate_makefile.rb, line 117
def add_header
  add_comment
  @_ << "# Autogenerated Makefile from "\
        "$RBT/generate_files/#{NAME_OF_THE_FILE_HERE}#{N}"
  add_comment
  add_newline
end
add_newline() click to toggle source
#

add_newline

#
# File lib/rbt/generate_files/generate_makefile.rb, line 128
def add_newline
  @_ << N
end
add_tabs() click to toggle source
#

add_tabs

This will replace the first 4 spaces with a tab

#
# File lib/rbt/generate_files/generate_makefile.rb, line 137
def add_tabs
  @_.gsub!(/^    /, TABULATOR)
end
all_c_files?()
array_available_C_files?() click to toggle source
#

array_available_C_files?

#
# File lib/rbt/generate_files/generate_makefile.rb, line 110
def array_available_C_files?
  @array_available_C_files
end
Also aliased as: all_c_files?
check_against_input( i = nil )
Alias for: menu
consider_generating_a_new_makefile() click to toggle source
#

consider_generating_a_new_makefile

#
# File lib/rbt/generate_files/generate_makefile.rb, line 277
def consider_generating_a_new_makefile
  target = 'Makefile'
  if File.exist?(target) and !@may_we_overwrite_existing_makefiles
    opne 'A file '+sfile(target)+rev+' already exists. We may '\
         'not generate the same-named file.'
  end
  save_to(target)
end
could_we_find_a_C_file?() click to toggle source
#

could_we_find_a_C_file?

#
# File lib/rbt/generate_files/generate_makefile.rb, line 289
def could_we_find_a_C_file?
  !@array_available_C_files.empty?
end
create_makefile_variable(this_variable) click to toggle source
#

create_makefile_variable

Creates a makefile variable for you to use.

#
# File lib/rbt/generate_files/generate_makefile.rb, line 172
def create_makefile_variable(this_variable)
end
create_rule( name_of_rule, action, extended_instruction_set = '' ) click to toggle source
#

create_rule

Use this to create a specific rule.

#
# File lib/rbt/generate_files/generate_makefile.rb, line 156
def create_rule(
    name_of_rule,
    action,
    extended_instruction_set = ''
  )
  extended_instruction_set = ' '+extended_instruction_set unless extended_instruction_set.empty?
  @_ << N # right now, we always add a newline
  @_ << name_of_rule+':'+extended_instruction_set+N
  @_ << TABULATOR+action+N # rm *.o temp
end
data?() click to toggle source
#

data?

#
# File lib/rbt/generate_files/generate_makefile.rb, line 178
def data?
  @_
end
fill_up_string() click to toggle source
#

fill_up_string

#
# File lib/rbt/generate_files/generate_makefile.rb, line 194
  def fill_up_string
    @_ << 
'# =========================================================================== #
# MACRO LISTING
# =========================================================================== #
SHELL='+WHICH_SHELL_TO_USE+'
    
# =========================================================================== #
# === CFLAGS TO USE
# =========================================================================== #
CFLAGS = # -O -systype bsd43

# =========================================================================== #
# === COMPILER TO USE
#
# This variable can be used to keep track as to which compiler has to be
# used.
# =========================================================================== #
CC=gcc
    
CCOPTS=-Wall
    
# =========================================================================== #
# === TARGET
# =========================================================================== #
# foobar.dvi: $(SRCS)
#       $(DITROFF) $(MACROS) $(SRCS) >paper.dvi
       
dummy: '+all_c_files?.join(' ')+'
        $(CC) $(CCOPTS) -o dummy '+all_c_files?.join(' ')+'
        
prefix          = '+prefix?+'
exec_prefix     = ${prefix}


'
  end
input(i) click to toggle source
#

input

#
# File lib/rbt/generate_files/generate_makefile.rb, line 74
def input(i)
  i = i.join(' ').strip if i.is_a? Array
  @input = i
end
menu( i = nil ) click to toggle source
#

menu

#
Also aliased as: check_against_input
prefix?() click to toggle source
#

prefix?

#
# File lib/rbt/generate_files/generate_makefile.rb, line 235
def prefix?
  @prefix
end
report_what_we_will_do() click to toggle source
#

report_what_we_will_do

#
# File lib/rbt/generate_files/generate_makefile.rb, line 242
def report_what_we_will_do
  _ = @base_dir+NAME_OF_MAKEFILE
  opne "#{rev}Generating Makefile in `#{sfile(_)}`."
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::LeanPrototype#reset
# File lib/rbt/generate_files/generate_makefile.rb, line 82
def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @_
  # ======================================================================= #
  @_ = ''.dup # string that will be generated
  # ======================================================================= #
  # === @base_dir
  # ======================================================================= #
  @base_dir = return_pwd.dup # Trailing / is easier.
  # ======================================================================= #
  # === @prefix
  # ======================================================================= #
  @prefix = '/usr/' # prefix to use
  # ======================================================================= #
  # === @may_we_overwrite_existing_makefiles
  # ======================================================================= #
  @may_we_overwrite_existing_makefiles = false
  # ======================================================================= #
  # === @array_available_C_files
  # ======================================================================= #
  @array_available_C_files = Dir['*.c']
end
run() click to toggle source
#

run (run tag)

Bundle together the various actions.

#
# File lib/rbt/generate_files/generate_makefile.rb, line 317
def run
  check_against_input
  report_what_we_will_do
  add_header
  fill_up_string
  if could_we_find_a_C_file?
  else
    create_rule 'joe_goes_crazy', 'echo "ok joe is crazy..."'
    create_rule 'all','g++ main.cpp hello.cpp factorial.cpp -o hello'
    create_rule 'hello','g++ main.o factorial.o hello.o -o hello','main.o factorial.o hello.o'
  end
  sanitize
  add_tabs # should be called right before save_to is invoked
  consider_generating_a_new_makefile
end
sanitize() click to toggle source
#

sanitize

You can use this method to sanitize an existing makefile as well.

#
# File lib/rbt/generate_files/generate_makefile.rb, line 146
def sanitize
  @_.gsub!(/chown root/,'chown 0')
  @_.gsub!(/\/usr\/bin\//,'')
end
save_to( where_to = 'Makefile', mode_to_use = 'w+' ) click to toggle source
#

save_to

Where to save the Makefile.

#
# File lib/rbt/generate_files/generate_makefile.rb, line 298
def save_to(
    where_to    = 'Makefile',
    mode_to_use = 'w+'
  )
  if File.exist? where_to
    name = 'old_Makefile'
    opne 'A Makefile already exists in this directory. We will rename this'
    opne 'Makefile to '+sfile(name)+' before generating a new Makefile.'
    opnn; mv('Makefile', name)
  end
  save_what_into(data?, where_to)
  opne 'A new '+steelblue('Makefile')+rev+' was generated!'
end
show_help() click to toggle source
#

show_help (help tag)

#
# File lib/rbt/generate_files/generate_makefile.rb, line 250
def show_help
  e 'These are the available options:'
end