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
- 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 305 305: def self.apache2_bindir 306: if apxs2.nil? 307: return nil 308: else 309: return `#{apxs2} -q BINDIR 2>/dev/null`.strip 310: end 311: end
The C compiler flags that are necessary to compile an Apache module. Includes portability_cflags.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 372 372: def self.apache2_module_cflags(with_apr_flags = true) 373: flags = ["-fPIC"] 374: if with_apr_flags 375: flags << apr_flags 376: flags << apu_flags 377: end 378: if !apxs2.nil? 379: apxs2_flags = `#{apxs2} -q CFLAGS`.strip << " -I" << `#{apxs2} -q INCLUDEDIR`.strip 380: apxs2_flags.gsub!(/-O\d? /, '') 381: 382: # Remove flags not supported by GCC 383: if RUBY_PLATFORM =~ /solaris/ # TODO: Add support for people using SunStudio 384: # The big problem is Coolstack apxs includes a bunch of solaris -x directives. 385: options = apxs2_flags.split 386: options.reject! { |f| f =~ /^\-x/ } 387: options.reject! { |f| f =~ /^\-Xa/ } 388: apxs2_flags = options.join(' ') 389: end 390: 391: apxs2_flags.strip! 392: flags << apxs2_flags 393: end 394: if !httpd.nil? && RUBY_PLATFORM =~ /darwin/ 395: # Add possible universal binary flags. 396: architectures = [] 397: `file "#{httpd}"`.split("\n").grep(/for architecture/).each do |line| 398: line =~ /for architecture (.*?)\)/ 399: architectures << "-arch #{$1}" 400: end 401: flags << architectures.join(' ') 402: end 403: flags << portability_cflags 404: return flags.compact.join(' ').strip 405: end
Linker flags that are necessary for linking an Apache module. Includes portability_ldflags
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 410 410: def self.apache2_module_ldflags 411: flags = "-fPIC #{apr_libs} #{apu_libs} #{portability_ldflags}" 412: flags.strip! 413: return flags 414: end
The absolute path to the Apache 2 ‘sbin’ directory.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 315 315: def self.apache2_sbindir 316: if apxs2.nil? 317: return nil 318: else 319: return `#{apxs2} -q SBINDIR`.strip 320: end 321: end
The absolute path to the ‘apachectl’ or ‘apache2ctl’ binary.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 227 227: def self.apache2ctl 228: return find_apache2_executable('apache2ctl', 'apachectl2', 'apachectl') 229: end
The absolute path to the ‘apr-config’ or ‘apr-1-config’ executable.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 251 251: def self.apr_config 252: if env_defined?('APR_CONFIG') 253: return ENV['APR_CONFIG'] 254: elsif apxs2.nil? 255: return nil 256: else 257: filename = `#{apxs2} -q APR_CONFIG 2>/dev/null`.strip 258: if filename.empty? 259: apr_bindir = `#{apxs2} -q APR_BINDIR 2>/dev/null`.strip 260: if apr_bindir.empty? 261: return nil 262: else 263: return select_executable(apr_bindir, 264: "apr-1-config", "apr-config") 265: end 266: elsif File.exist?(filename) 267: return filename 268: else 269: return nil 270: end 271: end 272: 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 446 446: def self.apr_config_needed_for_building_apache_modules? 447: filename = File.join("/tmp/passenger-platform-check-#{Process.pid}.c") 448: File.open(filename, "w") do |f| 449: f.puts("#include <apr.h>") 450: end 451: begin 452: return !system("(gcc #{apache2_module_cflags(false)} -c '#{filename}' -o '#{filename}.o') >/dev/null 2>/dev/null") 453: ensure 454: File.unlink(filename) rescue nil 455: File.unlink("#{filename}.o") rescue nil 456: end 457: end
The C compiler flags that are necessary for programs that use APR.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 418 418: def self.apr_flags 419: return determine_apr_info[0] 420: end
The linker flags that are necessary for linking programs that use APR.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 423 423: def self.apr_libs 424: return determine_apr_info[1] 425: end
The absolute path to the ‘apu-config’ or ‘apu-1-config’ executable.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 276 276: def self.apu_config 277: if env_defined?('APU_CONFIG') 278: return ENV['APU_CONFIG'] 279: elsif apxs2.nil? 280: return nil 281: else 282: filename = `#{apxs2} -q APU_CONFIG 2>/dev/null`.strip 283: if filename.empty? 284: apu_bindir = `#{apxs2} -q APU_BINDIR 2>/dev/null`.strip 285: if apu_bindir.empty? 286: return nil 287: else 288: return select_executable(apu_bindir, 289: "apu-1-config", "apu-config") 290: end 291: elsif File.exist?(filename) 292: return filename 293: else 294: return nil 295: end 296: end 297: end
The C compiler flags that are necessary for programs that use APR-Util.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 428 428: def self.apu_flags 429: return determine_apu_info[0] 430: end
The linker flags that are necessary for linking programs that use APR-Util.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 433 433: def self.apu_libs 434: return determine_apu_info[1] 435: 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 212 212: def self.apxs2 213: if env_defined?("APXS2") 214: return ENV["APXS2"] 215: end 216: ['apxs2', 'apxs'].each do |name| 217: command = find_command(name) 218: if !command.nil? 219: return command 220: end 221: end 222: return nil 223: end
C compiler flags that should be passed in order to enable debugging information.
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 359 359: def self.debugging_cflags 360: if RUBY_PLATFORM =~ /openbsd/ 361: # According to OpenBSD's pthreads man page, pthreads do not work 362: # correctly when an app is compiled with -g. It recommends using 363: # -ggdb instead. 364: return '-ggdb' 365: else 366: return '-g' 367: end 368: 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 181 181: def self.find_command(name) 182: ENV['PATH'].split(File::PATH_SEPARATOR).detect do |directory| 183: path = File.join(directory, name.to_s) 184: if File.executable?(path) 185: return path 186: end 187: end 188: return nil 189: 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 233 233: def self.httpd 234: if env_defined?('HTTPD') 235: return ENV['HTTPD'] 236: elsif apxs2.nil? 237: ["apache2", "httpd2", "apache", "httpd"].each do |name| 238: command = find_command(name) 239: if !command.nil? 240: return command 241: end 242: end 243: return nil 244: else 245: return find_apache2_executable(`#{apxs2} -q TARGET`.strip) 246: end 247: end
The current platform‘s shared library extension (‘so’ on most Unices).
[ show source ]
# File lib/phusion_passenger/platform_info.rb, line 461 461: def self.library_extension 462: if RUBY_PLATFORM =~ /darwin/ 463: return "bundle" 464: else 465: return "so" 466: end 467: 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 470 470: def self.linux_distro 471: if RUBY_PLATFORM !~ /linux/ 472: return nil 473: end 474: lsb_release = read_file("/etc/lsb-release") 475: if lsb_release =~ /Ubuntu/ 476: return :ubuntu 477: elsif File.exist?("/etc/debian_version") 478: return :debian 479: elsif File.exist?("/etc/redhat-release") 480: redhat_release = read_file("/etc/redhat-release") 481: if redhat_release =~ /CentOS/ 482: return :centos 483: elsif redhat_release =~ /Fedora/ # is this correct? 484: return :fedora 485: else 486: # On official RHEL distros, the content is in the form of 487: # "Red Hat Enterprise Linux Server release 5.1 (Tikanga)" 488: return :rhel 489: end 490: elsif File.exist?("/etc/suse-release") 491: return :suse 492: elsif File.exist?("/etc/gentoo-release") 493: return :gentoo 494: else 495: return :unknown 496: end 497: # TODO: Slackware, Mandrake/Mandriva 498: 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 331 331: def self.portability_cflags 332: # _GLIBCPP__PTHREADS is for fixing Boost compilation on OpenBSD. 333: flags = ["-D_REENTRANT -D_GLIBCPP__PTHREADS -I/usr/local/include"] 334: if RUBY_PLATFORM =~ /solaris/ 335: flags << '-D_XOPEN_SOURCE=500 -D_XPG4_2 -D__EXTENSIONS__ -D__SOLARIS__' 336: flags << '-DBOOST_HAS_STDINT_H' unless RUBY_PLATFORM =~ /solaris2.9/ 337: flags << '-D__SOLARIS9__ -DBOOST__STDC_CONSTANT_MACROS_DEFINED' if RUBY_PLATFORM =~ /solaris2.9/ 338: flags << '-mcpu=ultrasparc' if RUBY_PLATFORM =~ /sparc/ 339: elsif RUBY_PLATFORM =~ /openbsd/ 340: flags << '-DBOOST_HAS_STDINT_H' 341: end 342: return flags.compact.join(" ").strip 343: 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 349 349: def self.portability_ldflags 350: if RUBY_PLATFORM =~ /solaris/ 351: return '-lxnet -lrt -lsocket -lnsl -lpthread' 352: else 353: return '-lpthread' 354: end 355: 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 198 198: def self.rake 199: return locate_ruby_executable('rake') 200: 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 206 206: def self.rspec 207: return locate_ruby_executable('spec') 208: end