/
build
258 lines (230 loc) · 6.07 KB
/
build
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/usr/bin/env bash
# show the user selected compiler or return 1
__rvm_selected_compiler()
{
if
[[ " ${rvm_configure_flags[*]}" =~ " --with-gcc=" ]]
then
typeset __compiler
for __compiler in "${rvm_configure_flags[@]}"
do
if
[[ "$__compiler" == ^--with-gcc= ]]
then
echo "${__compiler#--with-gcc=}"
return 0
fi
done
elif
[[ -n "${CC:-}" ]]
then
echo "${CC}"
return 0
else
return 1
fi
}
__rvm_found_compiler()
{
__rvm_selected_compiler || which gcc 2>/dev/null
}
__rvm_compiler_is_llvm()
{
typeset compiler
if compiler=$(__rvm_found_compiler)
then
$compiler --version | GREP_OPTIONS="" \grep -i llvm >/dev/null
else
return 1
fi
}
__rvm_compiler_is_gcc47()
{
typeset compiler
if compiler=$(__rvm_found_compiler)
then
[[ "$($compiler -dumpversion)" =~ "4.7" ]]
else
return 1
fi
}
__rvm_setup_compile_environment()
{
export -a rvm_configure_env
__rvm_setup_compile_environment_osx_gcc
__rvm_setup_compile_environment_osx_architectures
__rvm_setup_compile_environment_gcc47
__rvm_setup_compile_environment_smartos
}
__rvm_update_configure_env()
{
typeset -a local_configure_env
typeset _variable _value _iterator _found
while (( $# ))
do
_variable="${1%%=*}"
_value="${1#*=}"
shift
if
[[ " ${rvm_configure_env[*]}" =~ " ${_variable}=" ]]
then
local_configure_env=()
for _iterator in "${rvm_configure_env[@]}"
do
if [[ "${_iterator}" =~ ^${_variable}= ]]
then local_configure_env+=( "${_iterator} ${_value}" )
else local_configure_env+=( "${_iterator}" )
fi
done
rvm_configure_env=( "${local_configure_env[@]]}" )
else
rvm_configure_env=( "${rvm_configure_env[@]]}" "${_variable}=${_value}" )
fi
done
}
__rvm_setup_compile_environment_osx_gcc()
{
if [[ "Darwin" == "$(uname)" ]] && ! __rvm_selected_compiler > /dev/null
then
export CC
# override CC if gcc-4.2 available (OSX)
if
[[ -x /usr/bin/gcc-4.2 ]]
then
CC=/usr/bin/gcc-4.2
elif
which gcc-4.2 > /dev/null
then
CC=gcc-4.2
elif
which gcc-apple-4.2 > /dev/null
then
CC=gcc-apple-4.2
fi
fi
if [[ "${rvm_patch_names[*]}" =~ *debug* ]]
then rvm_force_autoconf_flag=1
fi
}
__rvm_setup_compile_environment_osx_architectures()
{
[[ -n "${rvm_architectures:-}" ]] || return 0
# Ruby 1.9.x supports the easy way
if
[[ "${rvm_ruby_version}" =~ 1.9.* ]]
then
rvm_configure_flags+=( --with-arch="${rvm_architectures}" )
else
typeset architectures architecture
typeset -a _local_osx_env
for architecture in ${rvm_architectures//,/ }
do architectures="${architectures} -arch ${architecture}"
done
_local_osx_env=(
MACOSX_DEPLOYMENT_TARGET="$( sw_vers -productVersion | awk -F'.' '{print $1"."$2}' )"
CFLAGS="${architectures} -g -Os -pipe -no-cpp-precomp"
CCFLAGS="${architectures} -g -Os -pipe"
CXXFLAGS="${architectures} -g -Os -pipe"
LDFLAGS="${architectures} -bind_at_load"
LDSHARED="cc ${architectures} -dynamiclib -undefined suppress -flat_namespace"
)
__rvm_update_configure_env "${_local_osx_env[@]}"
[[ "${rvm_patch_names[*]}" =~ *osx-arch-fix* ]] || rvm_patch_names+=( osx-arch-fix )
fi
}
__rvm_setup_compile_environment_gcc47()
{
__rvm_compiler_is_gcc47 || return 0
[[ "${rvm_ruby_version}" =~ 1.8.* ]] || return 0
__rvm_update_configure_env CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls"
}
__rvm_setup_compile_environment_smartos()
{
[[ "$(uname -v)" =~ ^joyent ]] || return 0
__rvm_update_configure_env CCFLAGS="-I/opt/local/include"
}
__rvm_check_for_compiler()
{
if __rvm_selected_compiler > /dev/null &&
! builtin command -v $(__rvm_selected_compiler) >/dev/null
then
rvm_error "You requested building with '$(__rvm_selected_compiler)' but it is not in your path."
return 1
fi
}
# Checks for bison, returns zero iff it is found
__rvm_check_for_bison()
{
true ${rvm_head_flag:=0}
if (( rvm_head_flag > 0 ))
then
if ! builtin command -v bison > /dev/null
then
rvm_error "\nbison is not available in your path. \nPlease ensure bison is installed before compiling from head.\n"
return 1
fi
fi
}
__rvm_mono_env()
{
DYLD_LIBRARY_PATH="${rvm_usr_path}/lib:$DYLD_LIBRARY_PATH"
C_INCLUDE_PATH="${rvm_usr_path}/include:$C_INCLUDE_PATH"
ACLOCAL_PATH="${rvm_usr_path}/share/aclocal"
ACLOCAL_FLAGS="-I $ACLOCAL_PATH"
PKG_CONFIG_PATH="${rvm_usr_path}/lib/pkgconfig:$PKG_CONFIG_PATH"
export DYLD_LIBRARY_PATH C_INCLUDE_PATH ACLOCAL_PATH ACLOCAL_FLAGS PKG_CONFIG_PATH
__rvm_add_to_path prepend "${rvm_usr_path}/bin"
builtin hash -r
return 0
}
# Returns all mri compatible (partly) ruby for use
# with things like rbx etc which require a ruby be installed.
__rvm_mri_rubies()
{
typeset versions _ruby
versions="${1:-"1.8.|ree|1.9."}"
for _ruby in $( find $rvm_rubies_path/ -maxdepth 1 -mindepth 1 -type d -not -type l )
do
printf "%b" "${_ruby##*/}\n"
done | GREP_OPTIONS="" \grep -E "$versions"
}
# Returns the first mri compatible (partly) ruby for use
# with things like rbx etc which require a ruby be installed.
__rvm_mri_ruby()
{
typeset versions
versions="${1:-"1.8.|ree|1.9."}"
_mri_rubies=( $( __rvm_mri_rubies "$versions" ) )
_current_ruby=$(__rvm_env_string)
if [[ " ${_mri_rubies[*]} " =~ " ${_current_ruby} " ]]
then
printf "%b" "${_current_ruby}\n"
else
for _ruby in ${_mri_rubies[@]}
do
printf "%b" "${_ruby}\n"
done | sort | head -n 1
fi
return 0
}
__rvm_ensure_has_mri_ruby()
{
typeset versions
versions="${1:-"1.8.|ree|1.9."}"
if [[ -z "$(__rvm_mri_ruby $versions)" ]]
then
typeset compat_result
compat_result=0
if ! ( "$rvm_bin_path"/rvm install 1.8.7 )
then
rvm_error "
To proceed rvm requires a 1.8-compatible ruby is installed.
We attempted to install 1.8.7 automatically but it failed.
Please install it manually (or a compatible alternative) to proceed.
"
compat_result=1
fi
return $compat_result
fi
return 0
}