Parent

Platform

Abstraction for platform-specific system commands and variables This class only contains static methods.

Attributes

host_os[R]
target_os[R]

Public Class Methods

archiver(archive,members) click to toggle source
# File lib/makeconf/platform.rb, line 63
def Platform.archiver(archive,members)
  if is_windows? && ! ENV['MSYSTEM']
    'lib.exe ' + members.join(' ') + ' /OUT:' + archive
  else
    # TODO: add '/usr/bin/strip --strip-unneeded' + archive
    'ar rs ' + archive + ' ' + members.join(' ')
  end
end
cp(src,dst) click to toggle source
# File lib/makeconf/platform.rb, line 102
def Platform.cp(src,dst)
  if src.kind_of?(Array)
    src = src.join(' ')
  end

  if is_windows? && ! ENV['MSYSTEM']
    return "copy #{src} #{dst}"
  else
    return "cp -RL #{src} #{dst}"
  end
end
dev_null() click to toggle source

Send all output to /dev/null or it's equivalent

# File lib/makeconf/platform.rb, line 115
def Platform.dev_null
  if is_windows? && ! ENV['MSYSTEM'] 
    ' >NUL 2>NUL' 
  else
    ' >/dev/null 2>&1'
  end
end
dev_null_stderr() click to toggle source

Send standard error to /dev/null or it's equivalent

# File lib/makeconf/platform.rb, line 124
def Platform.dev_null_stderr
  if is_windows? && ! ENV['MSYSTEM'] 
    ' 2>NUL' 
  else
    ' 2>/dev/null'
  end
end
executable_extension() click to toggle source

The extension used for executable files

# File lib/makeconf/platform.rb, line 133
def Platform.executable_extension
  is_windows? ? '.exe' : ''
end
execute(cmd) click to toggle source

Run an external command. On Windows, the system() function uses cmd.exe which pops up an ugly DOS window.

# File lib/makeconf/platform.rb, line 180
  def Platform.execute(cmd)
    if is_windows?
      # NEED INFO
        #shell = WIN32OLE.new('Shell.Application')
#shell.ShellExecute('cmd.exe', '', ,,

# DOESNOT WORK
#p = IO.popen(cmd)
#        p.readlines
#        return $?.exitstatus == 0 ? true : false


        
        # NOTE: requires Ruby 1.9
#    pid = Process.spawn(cmd)
#        pid, status = Process.waitpid2(pid)
#        return status.exitstatus == 0 ? true : false

        return system(cmd)
    else
        system(cmd)
    end
  end
is_graphical?() click to toggle source

Returns true if the current environment supports graphical display

# File lib/makeconf/platform.rb, line 153
def Platform.is_graphical?
  return true if Platform.is_windows?
  return true if ENV.has_key?('DISPLAY') and not ENV['DISPLAY'].empty?
  return false
end
is_linux?() click to toggle source

Returns true or false depending on if the target is Linux

# File lib/makeconf/platform.rb, line 31
def Platform.is_linux?
  @@target_os =~ /^linux/
end
is_solaris?() click to toggle source

Returns true or false depending on if the target is Solaris

# File lib/makeconf/platform.rb, line 26
def Platform.is_solaris?
  @@target_os =~ /^solaris/
end
is_superuser?() click to toggle source

Returns true if the user is running as the superuser on Unix or has Administrator privileges on Windows.

# File lib/makeconf/platform.rb, line 206
def Platform.is_superuser?
  if is_windows?
    Process.euid == 0
  else
    system "reg query HKU\\S-1-5-19" + Platform.dev_null
  end
end
is_windows?() click to toggle source

Returns true or false depending on if the target is MS Windows

# File lib/makeconf/platform.rb, line 21
def Platform.is_windows?
  @@target_os =~ /mswin|mingw/
end
is_x86?() click to toggle source

Returns true or false depending on if the target is x86-compatible

# File lib/makeconf/platform.rb, line 36
def Platform.is_x86?
  RbConfig::CONFIG['host_cpu'] =~ /^(x86_64|i386)$/ ? true : false
end
mkdir(path) click to toggle source

Create a directory and all of it's components

# File lib/makeconf/platform.rb, line 73
def Platform.mkdir(path)
  if path.kind_of?(Array)
      path = path.flatten.join(' ')
  end
  throw 'invalid path' if path.nil? or path == ''
  if is_windows?
     "mkdir '#{path}'"
  else
     "umask 22 ; mkdir -p '#{path}'"
  end
end
object_extension() click to toggle source

The extension used for intermediate object files

# File lib/makeconf/platform.rb, line 138
def Platform.object_extension
  is_windows? ? '.obj' : '.o'
end
pathspec(path) click to toggle source

Converts a slash-delimited path into a backslash-delimited path on Windows.

# File lib/makeconf/platform.rb, line 170
def Platform.pathspec(path)
  if is_windows?
    path.gsub(%{/}) { "\\" }
  else
    path
  end
end
rm(path) click to toggle source

Remove a regular file

# File lib/makeconf/platform.rb, line 86
def Platform.rm(path)
  if path.kind_of?(Array)
      path = path.join(' ')
  end
  if is_windows? && ! ENV['MSYSTEM']
    return 'del /F ' + path
  else
    return 'rm -f ' + path
  end
end
rmdir(path) click to toggle source

Remove a directory along with all of it's contents

# File lib/makeconf/platform.rb, line 98
def Platform.rmdir(path)
  is_windows? ? "rmdir /S /Q #{path}" : "rm -rf #{path}"
end
shared_library_extension() click to toggle source

The extension used for shared libraries

# File lib/makeconf/platform.rb, line 148
def Platform.shared_library_extension
  is_windows? ? '.dll' : '.so'
end
static_library_extension() click to toggle source

The extension used for static libraries

# File lib/makeconf/platform.rb, line 143
def Platform.static_library_extension
  is_windows? ? '.lib' : '.a'
end
target_os=(val) click to toggle source
# File lib/makeconf/platform.rb, line 16
def Platform.target_os=(val)
  @@target_os = val
end
vendor() click to toggle source

Returns the name of the operating system vendor

# File lib/makeconf/platform.rb, line 41
def Platform.vendor
  return 'Fedora' if File.exists?('/etc/fedora-release')
  return 'Red Hat' if File.exists?('/etc/redhat-release')
  return 'Debian' if File.exists?('/etc/debian_version')
  return 'Unknown' 
end
which(command) click to toggle source

Emulate the which(1) command

# File lib/makeconf/platform.rb, line 160
def Platform.which(command)
  return nil if is_windows?      # FIXME: STUB
  ENV['PATH'].split(':').each do |prefix|
    path = prefix + '/' + command
    return command if File.executable?(path)
  end
  nil
end
word_size() click to toggle source

Returns the native word size

# File lib/makeconf/platform.rb, line 49
def Platform.word_size
  if @@host_os =~ /^solaris/
    `/usr/bin/isainfo -b`.to_i
  elsif @@host_os =~ /^linux/
    if `/usr/bin/file /bin/bash` =~ /32-bit/
      return 32
    else
      return 64
    end
  else
    throw 'Unknown word size'
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.