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.

Methods
Constants
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.
Public Class methods
apache2_bindir()

The absolute path to the Apache 2 ‘bin’ directory.

     # 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
apache2_module_cflags(with_apr_flags = true)

The C compiler flags that are necessary to compile an Apache module. Includes portability_cflags.

     # 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
apache2_module_ldflags()

Linker flags that are necessary for linking an Apache module. Includes portability_ldflags

     # 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
apache2_sbindir()

The absolute path to the Apache 2 ‘sbin’ directory.

     # 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
apache2ctl()

The absolute path to the ‘apachectl’ or ‘apache2ctl’ binary.

     # File lib/phusion_passenger/platform_info.rb, line 227
227:         def self.apache2ctl
228:                 return find_apache2_executable('apache2ctl', 'apachectl2', 'apachectl')
229:         end
apr_config()

The absolute path to the ‘apr-config’ or ‘apr-1-config’ executable.

     # 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
apr_config_needed_for_building_apache_modules?()

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.

     # 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
apr_flags()

The C compiler flags that are necessary for programs that use APR.

     # File lib/phusion_passenger/platform_info.rb, line 418
418:         def self.apr_flags
419:                 return determine_apr_info[0]
420:         end
apr_libs()

The linker flags that are necessary for linking programs that use APR.

     # File lib/phusion_passenger/platform_info.rb, line 423
423:         def self.apr_libs
424:                 return determine_apr_info[1]
425:         end
apu_config()

The absolute path to the ‘apu-config’ or ‘apu-1-config’ executable.

     # 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
apu_flags()

The C compiler flags that are necessary for programs that use APR-Util.

     # File lib/phusion_passenger/platform_info.rb, line 428
428:         def self.apu_flags
429:                 return determine_apu_info[0]
430:         end
apu_libs()

The linker flags that are necessary for linking programs that use APR-Util.

     # File lib/phusion_passenger/platform_info.rb, line 433
433:         def self.apu_libs
434:                 return determine_apu_info[1]
435:         end
apxs2()

The absolute path to the ‘apxs’ or ‘apxs2’ executable, or nil if not found.

     # 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
debugging_cflags()

C compiler flags that should be passed in order to enable debugging information.

     # 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
find_command(name)

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.

     # 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
httpd()

The absolute path to the Apache binary (that is, ‘httpd’, ‘httpd2’, ‘apache’ or ‘apache2’).

     # 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
library_extension()

The current platform‘s shared library extension (‘so’ on most Unices).

     # 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
linux_distro()

An identifier for the current Linux distribution. nil if the operating system is not Linux.

     # 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
portability_cflags()

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.

     # 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
portability_ldflags()

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.

     # 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
rake()

Returns the absolute path to the Rake executable that belongs to the current Ruby interpreter. Returns nil if it doesn‘t exist.

     # File lib/phusion_passenger/platform_info.rb, line 198
198:         def self.rake
199:                 return locate_ruby_executable('rake')
200:         end
rspec()

Returns the absolute path to the RSpec runner program that belongs to the current Ruby interpreter. Returns nil if it doesn‘t exist.

     # File lib/phusion_passenger/platform_info.rb, line 206
206:         def self.rspec
207:                 return locate_ruby_executable('spec')
208:         end