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

The C compiler flags that are necessary to compile an Apache module. Possibly includes APR and APU compiler flags.

     # File lib/phusion_passenger/platform_info.rb, line 383
383:         def self.apache2_module_cflags(with_apr_flags = true)
384:                 flags = ["-fPIC"]
385:                 if with_apr_flags
386:                         flags << apr_flags
387:                         flags << apu_flags
388:                 end
389:                 if !apxs2.nil?
390:                         apxs2_flags = `#{apxs2} -q CFLAGS`.strip << " -I" << `#{apxs2} -q INCLUDEDIR`.strip
391:                         apxs2_flags.gsub!(/-O\d? /, '')
392: 
393:                         # Remove flags not supported by GCC
394:                         if RUBY_PLATFORM =~ /solaris/ # TODO: Add support for people using SunStudio
395:                                 # The big problem is Coolstack apxs includes a bunch of solaris -x directives.
396:                                 options = apxs2_flags.split
397:                                 options.reject! { |f| f =~ /^\-x/ }
398:                                 options.reject! { |f| f =~ /^\-Xa/ }
399:                                 apxs2_flags = options.join(' ')
400:                         end
401:                         
402:                         apxs2_flags.strip!
403:                         flags << apxs2_flags
404:                 end
405:                 if !httpd.nil? && RUBY_PLATFORM =~ /darwin/
406:                         # The default Apache install on OS X is a universal binary.
407:                         # Figure out which architectures it's compiled for and do the same
408:                         # thing for mod_passenger. We use the 'file' utility to do this.
409:                         #
410:                         # Running 'file' on the Apache executable usually outputs something
411:                         # like this:
412:                         #
413:                         #   /usr/sbin/httpd: Mach-O universal binary with 4 architectures
414:                         #   /usr/sbin/httpd (for architecture ppc7400):     Mach-O executable ppc
415:                         #   /usr/sbin/httpd (for architecture ppc64):       Mach-O 64-bit executable ppc64
416:                         #   /usr/sbin/httpd (for architecture i386):        Mach-O executable i386
417:                         #   /usr/sbin/httpd (for architecture x86_64):      Mach-O 64-bit executable x86_64
418:                         #
419:                         # But on some machines, it may output just:
420:                         #
421:                         #   /usr/sbin/httpd: Mach-O fat file with 4 architectures
422:                         #
423:                         # (http://code.google.com/p/phusion-passenger/issues/detail?id=236)
424:                         output = `file "#{httpd}"`.strip
425:                         if output =~ /Mach-O fat file/ && output !~ /for architecture/
426:                                 architectures = ["-arch i386 -arch ppc -arch x86_64 -arch ppc64"]
427:                         else
428:                                 architectures = []
429:                                 output.split("\n").grep(/for architecture/).each do |line|
430:                                         line =~ /for architecture (.*?)\)/
431:                                         architectures << "-arch #{$1}"
432:                                 end
433:                         end
434:                         flags << architectures.compact.join(' ')
435:                 end
436:                 return flags.compact.join(' ').strip
437:         end
apache2_module_ldflags()

Linker flags that are necessary for linking an Apache module. Possibly includes APR and APU linker flags.

     # File lib/phusion_passenger/platform_info.rb, line 442
442:         def self.apache2_module_ldflags
443:                 flags = "-fPIC #{apr_libs} #{apu_libs}"
444:                 flags.strip!
445:                 return flags
446:         end
apache2_sbindir()

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

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

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

     # File lib/phusion_passenger/platform_info.rb, line 234
234:         def self.apache2ctl
235:                 return find_apache2_executable('apache2ctl', 'apachectl2', 'apachectl')
236:         end
apr_config()

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

     # 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
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 478
478:         def self.apr_config_needed_for_building_apache_modules?
479:                 filename = File.join("/tmp/passenger-platform-check-#{Process.pid}.c")
480:                 File.open(filename, "w") do |f|
481:                         f.puts("#include <apr.h>")
482:                 end
483:                 begin
484:                         return !system("(gcc #{apache2_module_cflags(false)} -c '#{filename}' -o '#{filename}.o') >/dev/null 2>/dev/null")
485:                 ensure
486:                         File.unlink(filename) rescue nil
487:                         File.unlink("#{filename}.o") rescue nil
488:                 end
489:         end
apr_flags()

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

     # File lib/phusion_passenger/platform_info.rb, line 450
450:         def self.apr_flags
451:                 return determine_apr_info[0]
452:         end
apr_libs()

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

     # File lib/phusion_passenger/platform_info.rb, line 455
455:         def self.apr_libs
456:                 return determine_apr_info[1]
457:         end
apu_config()

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

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

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

     # File lib/phusion_passenger/platform_info.rb, line 460
460:         def self.apu_flags
461:                 return determine_apu_info[0]
462:         end
apu_libs()

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

     # File lib/phusion_passenger/platform_info.rb, line 465
465:         def self.apu_libs
466:                 return determine_apu_info[1]
467:         end
apxs2()

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

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

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

     # File lib/phusion_passenger/platform_info.rb, line 370
370:         def self.debugging_cflags
371:                 if RUBY_PLATFORM =~ /openbsd/
372:                         # According to OpenBSD's pthreads man page, pthreads do not work
373:                         # correctly when an app is compiled with -g. It recommends using
374:                         # -ggdb instead.
375:                         return '-ggdb'
376:                 else
377:                         return '-g'
378:                 end
379:         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 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
httpd()

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

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

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

     # File lib/phusion_passenger/platform_info.rb, line 493
493:         def self.library_extension
494:                 if RUBY_PLATFORM =~ /darwin/
495:                         return "bundle"
496:                 else
497:                         return "so"
498:                 end
499:         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 502
502:         def self.linux_distro
503:                 if RUBY_PLATFORM !~ /linux/
504:                         return nil
505:                 end
506:                 lsb_release = read_file("/etc/lsb-release")
507:                 if lsb_release =~ /Ubuntu/
508:                         return :ubuntu
509:                 elsif File.exist?("/etc/debian_version")
510:                         return :debian
511:                 elsif File.exist?("/etc/redhat-release")
512:                         redhat_release = read_file("/etc/redhat-release")
513:                         if redhat_release =~ /CentOS/
514:                                 return :centos
515:                         elsif redhat_release =~ /Fedora/  # is this correct?
516:                                 return :fedora
517:                         else
518:                                 # On official RHEL distros, the content is in the form of
519:                                 # "Red Hat Enterprise Linux Server release 5.1 (Tikanga)"
520:                                 return :rhel
521:                         end
522:                 elsif File.exist?("/etc/suse-release")
523:                         return :suse
524:                 elsif File.exist?("/etc/gentoo-release")
525:                         return :gentoo
526:                 else
527:                         return :unknown
528:                 end
529:                 # TODO: Slackware, Mandrake/Mandriva
530:         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 338
338:         def self.portability_cflags
339:                 # _GLIBCPP__PTHREADS is for fixing Boost compilation on OpenBSD.
340:                 flags = ["-D_REENTRANT -I/usr/local/include"]
341:                 if RUBY_PLATFORM =~ /solaris/
342:                         flags << '-D_XOPEN_SOURCE=500 -D_XPG4_2 -D__EXTENSIONS__ -D__SOLARIS__'
343:                         flags << '-DBOOST_HAS_STDINT_H' unless RUBY_PLATFORM =~ /solaris2.9/
344:                         flags << '-D__SOLARIS9__ -DBOOST__STDC_CONSTANT_MACROS_DEFINED' if RUBY_PLATFORM =~ /solaris2.9/
345:                         flags << '-mcpu=ultrasparc' if RUBY_PLATFORM =~ /sparc/
346:                 elsif RUBY_PLATFORM =~ /openbsd/
347:                         flags << '-DBOOST_HAS_STDINT_H -D_GLIBCPP__PTHREADS'
348:                 elsif RUBY_PLATFORM =~ /aix/
349:                         flags << '-DOXT_DISABLE_BACKTRACES'
350:                 elsif RUBY_PLATFORM =~ /sparc-linux/
351:                         flags << '-DBOOST_SP_USE_PTHREADS'
352:                 end
353:                 return flags.compact.join(" ").strip
354:         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 360
360:         def self.portability_ldflags
361:                 if RUBY_PLATFORM =~ /solaris/
362:                         return '-lxnet -lrt -lsocket -lnsl -lpthread'
363:                 else
364:                         return '-lpthread'
365:                 end
366:         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 205
205:         def self.rake
206:                 return locate_ruby_executable('rake')
207:         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 213
213:         def self.rspec
214:                 return locate_ruby_executable('spec')
215:         end