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/utility_scripts/generate_makefile.rb, line 59
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/utility_scripts/generate_makefile.rb, line 158
def add_comment
  @_ << '# =========================================================================== #'+N
end
add_header() click to toggle source
#

add_header

#
# File lib/rbt/utility_scripts/generate_makefile.rb, line 89
def add_header
  add_comment
  @_ << '# Autogenerated Makefile from '+NAME_OF_THE_FILE_HERE+N
  add_comment
  add_newline
end
add_newline() click to toggle source
#

add_newline

#
# File lib/rbt/utility_scripts/generate_makefile.rb, line 99
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/utility_scripts/generate_makefile.rb, line 108
def add_tabs
  @_.gsub!(/^    /, TABULATOR)
end
check_against_input( i = nil )
Alias for: menu
create_makefile_variable(this_variable) click to toggle source
#

create_makefile_variable

Creates a makefile variable for you to use.

#
# File lib/rbt/utility_scripts/generate_makefile.rb, line 143
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/utility_scripts/generate_makefile.rb, line 127
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/utility_scripts/generate_makefile.rb, line 149
def data?
  @_
end
fill_up_string() click to toggle source
#

fill_up_string

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

# =========================================================================== #
# COMPILE TO USE
# =========================================================================== #
CC=gcc
    
CCOPTS=-Wall
    
# =========================================================================== #
# TARGET
# =========================================================================== #
foobar.dvi: $(SRCS)
        $(DITROFF) $(MACROS) $(SRCS) >paper.dvi
       
id3: id3.c
        $(CC) $(CCOPTS) -o id3 id3.c
        
prefix          = '+prefix?+'
exec_prefix     = ${prefix}
'
  end
input(i) click to toggle source
#

input

#
# File lib/rbt/utility_scripts/generate_makefile.rb, line 71
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/utility_scripts/generate_makefile.rb, line 201
def prefix?
  @prefix
end
report_what_we_will_do() click to toggle source
#

report_what_we_will_do

#
# File lib/rbt/utility_scripts/generate_makefile.rb, line 226
def report_what_we_will_do
  _ = @base_dir+NAME_OF_MAKEFILE
  opn; e 'Generating Makefile in `'+sfile(_)+'`.'
end
reset() click to toggle source
#

reset

#
Calls superclass method RBT::Base#reset
# File lib/rbt/utility_scripts/generate_makefile.rb, line 79
def reset
  super()
  @_ = ''.dup # string that will be generated
  @base_dir = return_pwd.dup # Trailing / is easier.
  @prefix = '/usr/' # prefix to use
end
run() click to toggle source
#

run (run tag)

Bundle together the various actions.

#
# File lib/rbt/utility_scripts/generate_makefile.rb, line 263
def run
  check_against_input
  report_what_we_will_do
  add_header
  fill_up_string
  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'
  sanitize
  add_tabs # should be called right before save_to is invoked
  save_to('Makefile')
end
sanitize() click to toggle source
#

sanitize

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

#
# File lib/rbt/utility_scripts/generate_makefile.rb, line 117
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/utility_scripts/generate_makefile.rb, line 210
def save_to(
    where_to    = 'Makefile',
    mode_to_use = 'w+'
  )
  if File.exist? where_to
    name = 'old_Makefile'
    e 'A Makefile already exists. We will rename this Makefile'
    e 'to '+sfile(name)+' before generating a new Makefile.'
    mv('Makefile', name)
  end
  save_what_into(data?, where_to)
end
show_help() click to toggle source
#

show_help

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