module PlatformInfo require 'open3' a = Open3.popen3('uname -m'); a[1].each_line {|x| UNAME_ARCH=x.chomp! } a = Open3.popen3('uname -r'); a[1].each_line {|x| UNAME_VERS=x.chomp } a = Open3.popen3('uname -s'); a[1].each_line {|x| UNAME_SYST=x.chomp } $ret_arch = String.new(nil.to_s); $ret_dist = String.new(nil.to_s); $ret_syst = String.new(nil.to_s); def guess_arch unless $ret_arch.is_a?(NilClass) return $ret_arch end case UNAME_SYST when 'FreeBSD' ret = UNAME_ARCH; when 'NetBSD' ret = UNAME_ARCH; when 'OpenBSD' case UNAME_ARCH when 'sun3' ret = 'm68k'; when 'mvme68k' ret = 'm68k'; when 'mac68k' ret = 'm68k'; when 'amiga' ret = 'm68k'; else ret = UNAME_ARCH; end when 'Linux' case UNAME_ARCH when /ppc.*/ # This should handle ppc -> powerpc # and ppc64 -> powerpc64 ret = UNAME_ARCH.sub('ppc', 'powerpc'); when 'parisc64' ret = 'hppa64'; else ret = UNAME_ARCH; end when /.*DOS$/ # djgpp ret = 'i386'; else ret = ''; end $ret_arch = ret; return ret; end def guess_dist unless $ret_dist.empty? return $ret_dist end ret = 'unknown'; case UNAME_SYST when 'FreeBSD' unless ENV['SMART_ASS'].is_a?(NilClass) ret = 'ontopofmydesk'; end unless ENV['PORT_BUILD'].is_a?(NilClass) ret = 'portbld'; end when 'Linux' # GNU config.guess does dist=pc for ia32 boxen if $ret_arch =~ /^i.86$/ ret = 'pc'; end when /.*DOS$/ # djgpp core ret = 'pc'; end $ret_dist = ret; return ret; end def guess_os unless $ret_syst.empty? return $ret_syst end ret = UNAME_ARCH case UNAME_SYST when 'FreeBSD' ret = 'freebsd' + UNAME_VERS.sub(/-.*$/, ''); when 'OpenBSD' ret = 'openbsd' + UNAME_VERS when 'NetBSD' # NetBSD (nbsd) targets should (where applicable) match one or # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently # switched to ELF, *-*-netbsd* would select the old # object file format. This provides both forward # compatibility and a consistent mechanism for selecting the # object file format. ret = 'netbsd'; when 'Linux' ret = 'linux-gnu'; # Does anyone still use a.out or coff on ia32? Nah. when /.*DOS$/ # djgpp-core ret = 'msdosdjgpp'; end $ret_syst = ret; return ret; end def guess return guess_arch + '-' + guess_dist + '-' + guess_os end module_function :guess_arch, :guess_dist, :guess_os, :guess end