28
28
module PhusionPassenger
30
30
module PlatformInfo
31
# Compiler flags that should be used for compiling every C/C++ program,
31
# Linker flags that should be used for linking every C/C++ program,
32
32
# for portability reasons. These flags should be specified as last
33
# when invoking the compiler.
34
def self.portability_cflags
35
flags = ["-D_REENTRANT -I/usr/local/include"]
37
# There are too many implementations of of the hash map!
38
# Figure out the right one.
39
ok = try_compile("Checking for tr1/unordered_map", :cxx, %Q{
40
#include <tr1/unordered_map>
33
# when invoking the linker.
34
def self.portability_ldflags
35
if os_name =~ /solaris/
36
result = '-lxnet -lsocket -lnsl -lpthread'
40
result << ' -lrt' if has_rt_library?
41
result << ' -lmath' if has_math_library?
44
memoize :portability_ldflags
46
# Extra compiler flags that should always be passed to the C compiler,
47
# last in the command string.
48
def self.default_extra_cflags
49
return default_extra_c_or_cxxflags(:cc)
51
memoize :default_extra_cflags, true
53
# Extra compiler flags that should always be passed to the C++ compiler,
54
# last in the command string.
55
def self.default_extra_cxxflags
56
return default_extra_c_or_cxxflags(:cxx)
58
memoize :default_extra_cxxflags, true
61
def self.check_unordered_map(flags, class_name, header_name, macro_name)
62
ok = try_compile("Checking for unordered_map", :cxx, %Q{
63
#include <#{header_name}>
43
std::tr1::unordered_map<int, int> m;
66
#{class_name}<int, int> m;
48
flags << "-DHAS_TR1_UNORDERED_MAP"
52
['__gnu_cxx', '', 'std', 'stdext'].each do |namespace|
53
['hash_map', 'ext/hash_map'].each do |hash_map_header|
54
ok = try_compile("Checking for #{hash_map_header}", :cxx, %Q{
55
#include <#{hash_map_header}>
58
#{namespace}::hash_map<int, int> m;
63
hash_namespace = namespace
64
flags << "-DHASH_NAMESPACE=\"#{namespace}\""
65
flags << "-DHASH_MAP_HEADER=\"<#{hash_map_header}>\""
66
flags << "-DHASH_MAP_CLASS=\"hash_map\""
72
['ext/hash_fun.h', 'functional', 'tr1/functional',
73
'ext/stl_hash_fun.h', 'hash_fun.h', 'stl_hash_fun.h',
74
'stl/_hash_fun.h'].each do |hash_function_header|
75
ok = try_compile("Checking for #{hash_function_header}", :cxx, %Q{
76
#include <#{hash_function_header}>
70
flags << "-D#{macro_name}" if ok
73
private_class_method :check_unordered_map
75
def self.check_hash_map(flags)
78
['__gnu_cxx', '', 'std', 'stdext'].each do |namespace|
79
['hash_map', 'ext/hash_map'].each do |hash_map_header|
80
ok = try_compile("Checking for #{hash_map_header}", :cxx, %Q{
81
#include <#{hash_map_header}>
79
#{hash_namespace}::hash<int>()(5);
84
#{namespace}::hash_map<int, int> m;
84
flags << "-DHASH_FUN_H=\"<#{hash_function_header}>\""
89
hash_namespace = namespace
90
flags << "-DHASH_NAMESPACE=\"#{namespace}\""
91
flags << "-DHASH_MAP_HEADER=\"<#{hash_map_header}>\""
92
flags << "-DHASH_MAP_CLASS=\"hash_map\""
90
ok = try_compile("Checking for accept4()", :c, %Q{
92
#include <sys/socket.h>
93
static void *foo = accept4;
95
flags << '-DHAVE_ACCEPT4' if ok
97
if RUBY_PLATFORM =~ /solaris/
99
if RUBY_PLATFORM =~ /solaris2.11/
98
['ext/hash_fun.h', 'functional', 'tr1/functional',
99
'ext/stl_hash_fun.h', 'hash_fun.h', 'stl_hash_fun.h',
100
'stl/_hash_fun.h'].each do |hash_function_header|
101
ok = try_compile("Checking for #{hash_function_header}", :cxx, %Q{
102
#include <#{hash_function_header}>
105
#{hash_namespace}::hash<int>()(5);
110
flags << "-DHASH_FUN_H=\"<#{hash_function_header}>\""
115
private_class_method :check_hash_map
117
def self.default_extra_c_or_cxxflags(cc_or_cxx)
118
flags = ["-D_REENTRANT", "-I/usr/local/include"]
120
if !send("#{cc_or_cxx}_is_sun_studio?")
121
flags << "-Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long"
122
if send("#{cc_or_cxx}_supports_wno_missing_field_initializers_flag?")
123
flags << "-Wno-missing-field-initializers"
125
if requires_no_tls_direct_seg_refs? && send("#{cc_or_cxx}_supports_no_tls_direct_seg_refs_option?")
126
flags << "-mno-tls-direct-seg-refs"
128
# Work around Clang warnings in ev++.h.
129
if send("#{cc_or_cxx}_is_clang?")
130
flags << "-Wno-ambiguous-member-template"
134
if !send("#{cc_or_cxx}_is_sun_studio?")
136
if send("#{cc_or_cxx}_supports_feliminate_unused_debug?")
137
flags << "-feliminate-unused-debug-symbols -feliminate-unused-debug-types"
139
if send("#{cc_or_cxx}_supports_visibility_flag?")
140
flags << "-fvisibility=hidden -DVISIBILITY_ATTRIBUTE_SUPPORTED"
141
if send("#{cc_or_cxx}_visibility_flag_generates_warnings?") &&
142
send("#{cc_or_cxx}_supports_wno_attributes_flag?")
143
flags << "-Wno-attributes"
148
flags << debugging_cflags
149
flags << '-DHAS_ALLOCA_H' if has_alloca_h?
150
flags << '-DHAVE_ACCEPT4' if has_accept4?
151
flags << '-DHAS_SFENCE' if supports_sfence_instruction?
152
flags << '-DHAS_LFENCE' if supports_lfence_instruction?
153
flags << "-DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS"
156
# There are too many implementations of of the hash map!
157
# Figure out the right one.
158
check_unordered_map(flags, "std::unordered_map", "unordered_map", "HAS_UNORDERED_MAP") ||
159
check_unordered_map(flags, "std::tr1::unordered_map", "unordered_map", "HAS_TR1_UNORDERED_MAP") ||
160
check_hash_map(flags)
163
if os_name =~ /solaris/
164
if send("#{cc_or_cxx}_is_sun_studio?")
169
if os_name =~ /solaris2\.11/
100
170
# skip the _XOPEN_SOURCE and _XPG4_2 definitions in later versions of Solaris / OpenIndiana
101
171
flags << '-D__EXTENSIONS__ -D__SOLARIS__ -D_FILE_OFFSET_BITS=64'
103
173
flags << '-D_XOPEN_SOURCE=500 -D_XPG4_2 -D__EXTENSIONS__ -D__SOLARIS__ -D_FILE_OFFSET_BITS=64'
104
flags << '-D__SOLARIS9__ -DBOOST__STDC_CONSTANT_MACROS_DEFINED' if RUBY_PLATFORM =~ /solaris2.9/
106
flags << '-DBOOST_HAS_STDINT_H' unless RUBY_PLATFORM =~ /solaris2.9/
107
flags << '-mcpu=ultrasparc' if RUBY_PLATFORM =~ /sparc/
108
elsif RUBY_PLATFORM =~ /openbsd/
174
flags << '-D__SOLARIS9__ -DBOOST__STDC_CONSTANT_MACROS_DEFINED' if os_name =~ /solaris2\.9/
176
flags << '-DBOOST_HAS_STDINT_H' unless os_name =~ /solaris2\.9/
177
if send("#{cc_or_cxx}_is_sun_studio?")
178
flags << '-xtarget=ultra' if RUBY_PLATFORM =~ /sparc/
180
flags << '-mcpu=ultrasparc' if RUBY_PLATFORM =~ /sparc/
182
elsif os_name =~ /openbsd/
109
183
flags << '-DBOOST_HAS_STDINT_H -D_GLIBCPP__PTHREADS'
110
elsif RUBY_PLATFORM =~ /aix/
184
elsif os_name =~ /aix/
111
185
flags << '-pthread'
112
186
flags << '-DOXT_DISABLE_BACKTRACES'
113
187
elsif RUBY_PLATFORM =~ /(sparc-linux|arm-linux|^arm.*-linux|sh4-linux)/