This module autodetects various platform-specific information, and provides that information through constants.
Users can change the detection behavior by setting the environment variable APXS2 to the correct ‘apxs’ (or ‘apxs2’) binary, as provided by Apache.
- apache2_bindir
- apache2_module_cflags
- apache2_module_ldflags
- apache2_sbindir
- apache2ctl
- apr_config
- apr_config_needed_for_building_apache_modules?
- apr_flags
- apr_libs
- apu_config
- apu_flags
- apu_libs
- apxs2
- debugging_cflags
- find_command
- httpd
- library_extension
- linux_distro
- linux_distro_tags
- portability_cflags
- portability_ldflags
- rake
- rspec
RUBY | = | Config::CONFIG['bindir'] + '/' + Config::CONFIG['RUBY_INSTALL_NAME'] + Config::CONFIG['EXEEXT'] |
The absolute path to the current Ruby interpreter. | ||
GEM | = | locate_ruby_executable('gem') |
The correct ‘gem’ command for this Ruby interpreter. |
The absolute path to the Apache 2 ‘bin’ directory.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 312 312: def self.apache2_bindir 313: if apxs2.nil? 314: return nil 315: else 316: return `#{apxs2} -q BINDIR 2>/dev/null`.strip 317: end 318: end
The C compiler flags that are necessary to compile an Apache module. Possibly includes APR and APU compiler flags.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 384 384: def self.apache2_module_cflags(with_apr_flags = true) 385: flags = ["-fPIC"] 386: if with_apr_flags 387: flags << apr_flags 388: flags << apu_flags 389: end 390: if !apxs2.nil? 391: apxs2_flags = `#{apxs2} -q CFLAGS`.strip << " -I" << `#{apxs2} -q INCLUDEDIR`.strip 392: apxs2_flags.gsub!(/-O\d? /, '') 393: 394: # Remove flags not supported by GCC 395: if RUBY_PLATFORM =~ /solaris/ # TODO: Add support for people using SunStudio 396: # The big problem is Coolstack apxs includes a bunch of solaris -x directives. 397: options = apxs2_flags.split 398: options.reject! { |f| f =~ /^\-x/ } 399: options.reject! { |f| f =~ /^\-Xa/ } 400: options.reject! { |f| f =~ /^\-fast/ } 401: options.reject! { |f| f =~ /^\-mt/ } 402: apxs2_flags = options.join(' ') 403: end 404: 405: apxs2_flags.strip! 406: flags << apxs2_flags 407: end 408: if !httpd.nil? && RUBY_PLATFORM =~ /darwin/ 409: # The default Apache install on OS X is a universal binary. 410: # Figure out which architectures it's compiled for and do the same 411: # thing for mod_passenger. We use the 'file' utility to do this. 412: # 413: # Running 'file' on the Apache executable usually outputs something 414: # like this: 415: # 416: # /usr/sbin/httpd: Mach-O universal binary with 4 architectures 417: # /usr/sbin/httpd (for architecture ppc7400): Mach-O executable ppc 418: # /usr/sbin/httpd (for architecture ppc64): Mach-O 64-bit executable ppc64 419: # /usr/sbin/httpd (for architecture i386): Mach-O executable i386 420: # /usr/sbin/httpd (for architecture x86_64): Mach-O 64-bit executable x86_64 421: # 422: # But on some machines, it may output just: 423: # 424: # /usr/sbin/httpd: Mach-O fat file with 4 architectures 425: # 426: # (http://code.google.com/p/phusion-passenger/issues/detail?id=236) 427: output = `file "#{httpd}"`.strip 428: if output =~ /Mach-O fat file/ && output !~ /for architecture/ 429: architectures = ["-arch i386 -arch ppc -arch x86_64 -arch ppc64"] 430: else 431: architectures = [] 432: output.split("\n").grep(/for architecture/).each do |line| 433: line =~ /for architecture (.*?)\)/ 434: architectures << "-arch #{$1}" 435: end 436: end 437: flags << architectures.compact.join(' ') 438: end 439: return flags.compact.join(' ').strip 440: end
Linker flags that are necessary for linking an Apache module. Possibly includes APR and APU linker flags.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 445 445: def self.apache2_module_ldflags 446: flags = "-fPIC #{apr_libs} #{apu_libs}" 447: flags.strip! 448: return flags 449: end
The absolute path to the Apache 2 ‘sbin’ directory.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 322 322: def self.apache2_sbindir 323: if apxs2.nil? 324: return nil 325: else 326: return `#{apxs2} -q SBINDIR`.strip 327: end 328: end
The absolute path to the ‘apachectl’ or ‘apache2ctl’ binary.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 234 234: def self.apache2ctl 235: return find_apache2_executable('apache2ctl', 'apachectl2', 'apachectl') 236: end
The absolute path to the ‘apr-config’ or ‘apr-1-config’ executable.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 258 258: def self.apr_config 259: if env_defined?('APR_CONFIG') 260: return ENV['APR_CONFIG'] 261: elsif apxs2.nil? 262: return nil 263: else 264: filename = `#{apxs2} -q APR_CONFIG 2>/dev/null`.strip 265: if filename.empty? 266: apr_bindir = `#{apxs2} -q APR_BINDIR 2>/dev/null`.strip 267: if apr_bindir.empty? 268: return nil 269: else 270: return select_executable(apr_bindir, 271: "apr-1-config", "apr-config") 272: end 273: elsif File.exist?(filename) 274: return filename 275: else 276: return nil 277: end 278: end 279: end
Returns whether it is necessary to use information outputted by ‘apr-config’ and ‘apu-config’ in order to compile an Apache module. When Apache is installed with —with-included-apr, the APR/APU headers are placed into the same directory as the Apache headers, and so ‘apr-config’ and ‘apu-config’ won‘t be necessary in that case.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 481 481: def self.apr_config_needed_for_building_apache_modules? 482: filename = File.join("/tmp/passenger-platform-check-#{Process.pid}.c") 483: File.open(filename, "w") do |f| 484: f.puts("#include <apr.h>") 485: end 486: begin 487: return !system("(gcc #{apache2_module_cflags(false)} -c '#{filename}' -o '#{filename}.o') >/dev/null 2>/dev/null") 488: ensure 489: File.unlink(filename) rescue nil 490: File.unlink("#{filename}.o") rescue nil 491: end 492: end
The C compiler flags that are necessary for programs that use APR.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 453 453: def self.apr_flags 454: return determine_apr_info[0] 455: end
The linker flags that are necessary for linking programs that use APR.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 458 458: def self.apr_libs 459: return determine_apr_info[1] 460: end
The absolute path to the ‘apu-config’ or ‘apu-1-config’ executable.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 283 283: def self.apu_config 284: if env_defined?('APU_CONFIG') 285: return ENV['APU_CONFIG'] 286: elsif apxs2.nil? 287: return nil 288: else 289: filename = `#{apxs2} -q APU_CONFIG 2>/dev/null`.strip 290: if filename.empty? 291: apu_bindir = `#{apxs2} -q APU_BINDIR 2>/dev/null`.strip 292: if apu_bindir.empty? 293: return nil 294: else 295: return select_executable(apu_bindir, 296: "apu-1-config", "apu-config") 297: end 298: elsif File.exist?(filename) 299: return filename 300: else 301: return nil 302: end 303: end 304: end
The C compiler flags that are necessary for programs that use APR-Util.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 463 463: def self.apu_flags 464: return determine_apu_info[0] 465: end
The linker flags that are necessary for linking programs that use APR-Util.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 468 468: def self.apu_libs 469: return determine_apu_info[1] 470: end
The absolute path to the ‘apxs’ or ‘apxs2’ executable, or nil if not found.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 219 219: def self.apxs2 220: if env_defined?("APXS2") 221: return ENV["APXS2"] 222: end 223: ['apxs2', 'apxs'].each do |name| 224: command = find_command(name) 225: if !command.nil? 226: return command 227: end 228: end 229: return nil 230: end
C compiler flags that should be passed in order to enable debugging information.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 371 371: def self.debugging_cflags 372: if RUBY_PLATFORM =~ /openbsd/ 373: # According to OpenBSD's pthreads man page, pthreads do not work 374: # correctly when an app is compiled with -g. It recommends using 375: # -ggdb instead. 376: return '-ggdb' 377: else 378: return '-g' 379: end 380: end
Check whether the specified command is in $PATH, and return its absolute filename. Returns nil if the command is not found.
This function exists because system(‘which’) doesn‘t always behave correctly, for some weird reason.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 188 188: def self.find_command(name) 189: ENV['PATH'].split(File::PATH_SEPARATOR).detect do |directory| 190: path = File.join(directory, name.to_s) 191: if File.executable?(path) 192: return path 193: end 194: end 195: return nil 196: end
The absolute path to the Apache binary (that is, ‘httpd’, ‘httpd2’, ‘apache’ or ‘apache2’).
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 240 240: def self.httpd 241: if env_defined?('HTTPD') 242: return ENV['HTTPD'] 243: elsif apxs2.nil? 244: ["apache2", "httpd2", "apache", "httpd"].each do |name| 245: command = find_command(name) 246: if !command.nil? 247: return command 248: end 249: end 250: return nil 251: else 252: return find_apache2_executable(`#{apxs2} -q TARGET`.strip) 253: end 254: end
The current platform‘s shared library extension (‘so’ on most Unices).
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 496 496: def self.library_extension 497: if RUBY_PLATFORM =~ /darwin/ 498: return "bundle" 499: else 500: return "so" 501: end 502: end
An identifier for the current Linux distribution. nil if the operating system is not Linux.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 505 505: def self.linux_distro 506: tags = linux_distro_tags 507: if tags 508: return tags.first 509: else 510: return nil 511: end 512: end
Autodetects the current Linux distribution and return a number of identifier tags. The first tag identifies the distribution while the other tags indicate which distributions it is likely compatible with. Returns nil if the operating system is not Linux.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 518 518: def self.linux_distro_tags 519: if RUBY_PLATFORM !~ /linux/ 520: return nil 521: end 522: lsb_release = read_file("/etc/lsb-release") 523: if lsb_release =~ /Ubuntu/ 524: return [:ubuntu, :debian] 525: elsif File.exist?("/etc/debian_version") 526: return [:debian] 527: elsif File.exist?("/etc/redhat-release") 528: redhat_release = read_file("/etc/redhat-release") 529: if redhat_release =~ /CentOS/ 530: return [:centos, :redhat] 531: elsif redhat_release =~ /Fedora/ 532: return [:fedora, :redhat] 533: elsif redhat_release =~ /Mandriva/ 534: return [:mandriva, :redhat] 535: else 536: # On official RHEL distros, the content is in the form of 537: # "Red Hat Enterprise Linux Server release 5.1 (Tikanga)" 538: return [:rhel, :redhat] 539: end 540: elsif File.exist?("/etc/suse-release") 541: return [:suse] 542: elsif File.exist?("/etc/gentoo-release") 543: return [:gentoo] 544: else 545: return [:unknown] 546: end 547: # TODO: Slackware 548: end
Compiler flags that should be used for compiling every C/C++ program, for portability reasons. These flags should be specified as last when invoking the compiler.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 338 338: def self.portability_cflags 339: flags = ["-D_REENTRANT -I/usr/local/include"] 340: if RUBY_PLATFORM =~ /solaris/ 341: flags << '-D_XOPEN_SOURCE=500 -D_XPG4_2 -D__EXTENSIONS__ -D__SOLARIS__ -D_FILE_OFFSET_BITS=64' 342: flags << '-DBOOST_HAS_STDINT_H' unless RUBY_PLATFORM =~ /solaris2.9/ 343: flags << '-D__SOLARIS9__ -DBOOST__STDC_CONSTANT_MACROS_DEFINED' if RUBY_PLATFORM =~ /solaris2.9/ 344: flags << '-mcpu=ultrasparc' if RUBY_PLATFORM =~ /sparc/ 345: elsif RUBY_PLATFORM =~ /openbsd/ 346: flags << '-DBOOST_HAS_STDINT_H -D_GLIBCPP__PTHREADS' 347: elsif RUBY_PLATFORM =~ /aix/ 348: flags << '-DOXT_DISABLE_BACKTRACES' 349: elsif RUBY_PLATFORM =~ /(sparc-linux|arm-linux|sh4-linux)/ 350: # http://code.google.com/p/phusion-passenger/issues/detail?id=200 351: # http://groups.google.com/group/phusion-passenger/t/6b904a962ee28e5c 352: flags << '-DBOOST_SP_USE_PTHREADS' 353: end 354: return flags.compact.join(" ").strip 355: end
Linker flags that should be used for linking every C/C++ program, for portability reasons. These flags should be specified as last when invoking the linker.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 361 361: def self.portability_ldflags 362: if RUBY_PLATFORM =~ /solaris/ 363: return '-lxnet -lrt -lsocket -lnsl -lpthread' 364: else 365: return '-lpthread' 366: end 367: end
Returns the absolute path to the Rake executable that belongs to the current Ruby interpreter. Returns nil if it doesn‘t exist.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 205 205: def self.rake 206: return locate_ruby_executable('rake') 207: end
Returns the absolute path to the RSpec runner program that belongs to the current Ruby interpreter. Returns nil if it doesn‘t exist.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 213 213: def self.rspec 214: return locate_ruby_executable('spec') 215: end