build 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/functions/autolibs"
  3. source "$rvm_scripts_path/functions/db"
  4. source "$rvm_scripts_path/functions/build_config"
  5. source "$rvm_scripts_path/functions/build_config_system"
  6. source "$rvm_scripts_path/functions/build_requirements"
  7. if
  8. [[ "Darwin" == "${_system_type}" ]]
  9. then
  10. source "$rvm_scripts_path/functions/osx-ssl-certs"
  11. source "$rvm_scripts_path/functions/osx-support"
  12. fi
  13. # show the user selected compiler or return 1
  14. __rvm_selected_compiler()
  15. {
  16. #TODO: add handling for rvm_configure_env
  17. if
  18. [[ " ${rvm_configure_flags[*]}" == *" --with-gcc="* ]]
  19. then
  20. \typeset __compiler
  21. for __compiler in "${rvm_configure_flags[@]}"
  22. do
  23. case "$__compiler" in
  24. (--with-gcc=*)
  25. echo "${__compiler#--with-gcc=}"
  26. return 0
  27. ;;
  28. esac
  29. done
  30. elif
  31. [[ -n "${CC:-}" ]]
  32. then
  33. echo "${CC}"
  34. return 0
  35. fi
  36. return 1
  37. }
  38. __rvm_found_compiler()
  39. {
  40. __rvm_selected_compiler ||
  41. __rvm_which gcc 2>/dev/null ||
  42. __rvm_which clang 2>/dev/null
  43. }
  44. __rvm_fix_rbconfig()
  45. {
  46. \typeset __config_file
  47. __config_file="$( __rvm_find $1/ -name rbconfig.rb 2>/dev/null )"
  48. [[ -n "${__config_file}" ]] &&
  49. __rvm_remove_static_flag "$@" &&
  50. __rvm_fix_gcc_path "$@" &&
  51. __rvm_fix_install_path "$@"
  52. }
  53. __rvm_remove_static_flag()
  54. {
  55. if
  56. __rvm_grep -- "-Z" "${__config_file}" >/dev/null
  57. then
  58. rvm_debug "Removing '-Z' from rbconfig."
  59. __rvm_sed_i "${__config_file}" -e "s#-Z##"
  60. fi
  61. }
  62. __rvm_fix_gcc_path()
  63. {
  64. \typeset __cc_value __cc_new
  65. __rvm_which $(
  66. "$1/bin/ruby" -rrbconfig -e 'puts RbConfig::CONFIG["CC"]||"true"' 2>/dev/null
  67. ) >/dev/null 2>/dev/null ||
  68. {
  69. __cc_value="$( "$1/bin/ruby" -rrbconfig -e 'puts RbConfig::CONFIG["CC"]' 2>/dev/null )" &&
  70. if
  71. __rvm_grep "CONFIG\[\"CC\"\]" "${__config_file}" >/dev/null
  72. then
  73. __cc_new="$( __rvm_found_compiler )"
  74. rvm_debug "Fixing ruby compiler from '${__cc_value}' to '${__cc_new}'."
  75. __rvm_sed_i "${__config_file}" \
  76. -e "s#CONFIG\[\"CC\"\].*\$#CONFIG[\"CC\"] = ENV[\"CC\"] || \"${__cc_new}\"#"
  77. else
  78. rvm_warn "Installed ruby contains path to non existing compiler '${__cc_value}', compiling native gems might be impossible."
  79. fi
  80. }
  81. }
  82. __rvm_fix_install_path()
  83. {
  84. \typeset __install_value __install_new
  85. __rvm_which $(
  86. "$1/bin/ruby" -rrbconfig -e 'puts RbConfig::CONFIG["INSTALL"]||"true"' 2>/dev/null
  87. ) >/dev/null 2>/dev/null ||
  88. {
  89. __install_value="$( "$1/bin/ruby" -rrbconfig -e 'puts RbConfig::CONFIG["INSTALL"]' 2>/dev/null )"
  90. if
  91. __rvm_grep "CONFIG\[\"INSTALL\"\]" "${__config_file}" >/dev/null
  92. then
  93. __install_new="$( \command \which install )"
  94. rvm_debug "Fixing ruby installer from '${__install_value}' to '${__install_new}'."
  95. __rvm_sed_i "${__config_file}" \
  96. -e "s#CONFIG\[\"INSTALL\"\].*\$#CONFIG[\"INSTALL\"] = \"${__install_new}\"#"
  97. else
  98. rvm_warn "Installed ruby contains path to non existing compiler '${__install_value}', compiling native gems might be impossible."
  99. fi
  100. }
  101. }
  102. __rvm_run_compiler()
  103. {
  104. if
  105. [[ -n "${1:-}" ]]
  106. then
  107. \typeset compiler="$1"
  108. shift
  109. if [[ -n "${ZSH_VERSION:-}" ]]
  110. then ${=compiler} "$@" 2>&1 || return $?
  111. else ${compiler} "$@" 2>&1 || return $?
  112. fi
  113. else
  114. return 1
  115. fi
  116. }
  117. __rvm_compiler_is()
  118. {
  119. __rvm_run_compiler "$1" "$2" | __rvm_grep -i "$3" >/dev/null
  120. }
  121. __rvm_compiler_version_is()
  122. {
  123. \typeset compiler __check
  124. __check="$1"
  125. compiler="${2:-$( __rvm_found_compiler )}" &&
  126. __rvm_compiler_is "$compiler" "--version" "${__check}" ||
  127. return $?
  128. }
  129. __rvm_compiler_is_llvm()
  130. {
  131. __rvm_compiler_version_is "llvm" "${1:-}" || return $?
  132. }
  133. __rvm_compiler_is_clang()
  134. {
  135. __rvm_compiler_version_is "clang" "${1:-}" || return $?
  136. }
  137. __rvm_compiler_version_or_higher()
  138. {
  139. \typeset __version compiler
  140. compiler="${2:-$( __rvm_found_compiler )}" &&
  141. __version="$( __rvm_run_compiler "$compiler" "-dumpversion" )" &&
  142. __rvm_version_compare "${__version:-0}" -ge "$1" ||
  143. return $?
  144. }
  145. __rvm_update_configure_env()
  146. {
  147. \typeset -a local_configure_env
  148. \typeset _variable _value _iterator _found
  149. rvm_debug "__rvm_update_configure_env($#):$*:"
  150. while (( $# ))
  151. do
  152. _variable="${1%%\=*}"
  153. _value="${1#*=}"
  154. shift
  155. __rvm_array_add_or_update rvm_configure_env "$_variable=" " " "$_value"
  156. done
  157. }
  158. __rvm_update_configure_env_arch()
  159. {
  160. __rvm_update_configure_env CFLAGS="$1" CCFLAGS="$1" CXXFLAGS="$1" LDFLAGS="$1"
  161. }
  162. __rvm_update_configure_opt_dir()
  163. {
  164. case "$1" in
  165. (rbx*|rubinius*)
  166. __rvm_update_configure_opt_dir_options "$2"
  167. ;;
  168. (ruby-head*|ruby-2*)
  169. __rvm_update_configure_opt_dir_option "$2"
  170. ;;
  171. (ruby-1.9.3-p*)
  172. \typeset __patchlevel
  173. __patchlevel="${1##ruby-1.9.3-p}"
  174. if
  175. (( __patchlevel < 297 ))
  176. then
  177. rvm_patch_names+=( cflags )
  178. __rvm_update_configure_opt_dir_option_or_flags "$2"
  179. else
  180. __rvm_update_configure_opt_dir_option "$2"
  181. fi
  182. ;;
  183. (ruby-1.9*)
  184. __rvm_update_configure_opt_dir_option_or_flags "$2"
  185. ;;
  186. (*)
  187. __rvm_update_configure_opt_dir_flags "$2"
  188. ;;
  189. esac
  190. }
  191. # add multiple --with-opt-dir=
  192. __rvm_update_configure_opt_dir_options()
  193. {
  194. rvm_debug "rvm_configure_flags+=( --with-opt-dir=$1 )"
  195. rvm_configure_flags+=( --with-opt-dir="$1" )
  196. }
  197. # update single --with-opt-dir=
  198. __rvm_update_configure_opt_dir_option()
  199. {
  200. rvm_debug "rvm_configure_flags+=( --with-opt-dir=$1 )"
  201. __rvm_array_add_or_update rvm_configure_flags --with-opt-dir= : "$1"
  202. }
  203. __rvm_update_configure_opt_dir_option_or_flags()
  204. {
  205. # Use option if first time - use flags if option available already
  206. case " ${rvm_configure_flags[*]} " in
  207. (*[[:space:]]--with-opt-dir=*)
  208. __rvm_update_configure_opt_dir_flags "$@"
  209. ;;
  210. (*)
  211. __rvm_update_configure_opt_dir_option "$@"
  212. ;;
  213. esac
  214. }
  215. __rvm_update_configure_opt_dir_flags()
  216. {
  217. \typeset __enable_rpath __lib_path
  218. if
  219. # __rvm_xargs \head -n 1 -- can not have \command - breaks xargs
  220. __rvm_which bash | __rvm_xargs \head -n 1 | \command \cat -e | __rvm_grep -b '^^?ELF' >/dev/null
  221. then
  222. __enable_rpath="true"
  223. fi
  224. __rvm_update_configure_env CFLAGS="-I$1/include"
  225. __rvm_update_configure_env LDFLAGS="-L$1/lib"
  226. [[ -z "${__enable_rpath:-}" ]] ||
  227. __rvm_update_configure_env LDFLAGS="-Wl,-rpath,$1/lib"
  228. if [[ -d "$1/lib64" ]]
  229. then
  230. __rvm_update_configure_env LDFLAGS="-L$1/lib64"
  231. [[ -z "${__enable_rpath:-}" ]] ||
  232. __rvm_update_configure_env LDFLAGS="-Wl,-rpath,$1/lib64"
  233. fi
  234. }
  235. __rvm_check_for_compiler()
  236. {
  237. if __rvm_selected_compiler > /dev/null &&
  238. ! builtin command -v $(__rvm_selected_compiler) >/dev/null
  239. then
  240. rvm_error "You requested building with '$(__rvm_selected_compiler)' but it is not in your path."
  241. return 1
  242. fi
  243. }
  244. # Checks for bison, returns zero iff it is found
  245. __rvm_check_for_bison()
  246. {
  247. true ${rvm_head_flag:=0}
  248. if (( rvm_head_flag > 0 ))
  249. then
  250. if ! builtin command -v bison > /dev/null
  251. then
  252. rvm_error "\nbison is not available in your path. \nPlease ensure bison is installed before compiling from head.\n"
  253. return 1
  254. fi
  255. fi
  256. }
  257. __rvm_mono_env()
  258. {
  259. DYLD_LIBRARY_PATH="${rvm_usr_path}/lib:$DYLD_LIBRARY_PATH"
  260. C_INCLUDE_PATH="${rvm_usr_path}/include:$C_INCLUDE_PATH"
  261. ACLOCAL_PATH="${rvm_usr_path}/share/aclocal"
  262. ACLOCAL_FLAGS="-I $ACLOCAL_PATH"
  263. PKG_CONFIG_PATH="${rvm_usr_path}/lib/pkgconfig:$PKG_CONFIG_PATH"
  264. export DYLD_LIBRARY_PATH C_INCLUDE_PATH ACLOCAL_PATH ACLOCAL_FLAGS PKG_CONFIG_PATH
  265. __rvm_add_to_path prepend "${rvm_usr_path}/bin"
  266. builtin hash -r
  267. return 0
  268. }
  269. # Returns all mri compatible (partly) ruby for use
  270. # with things like rbx etc which require a ruby be installed.
  271. __rvm_mri_rubies()
  272. (
  273. # find on bsd does not have -not, we need to use \!
  274. \typeset versions="${1:-"ruby-1.9|ruby-2"}"
  275. __rvm_cd "$rvm_rubies_path" &&
  276. __rvm_find . -maxdepth 1 -mindepth 1 -type d \! -type l |
  277. __rvm_awk -F/ "/$versions/"' {if (system("test -x \""$0"/bin/ruby\"")==0) print $2}' ||
  278. return $?
  279. )
  280. # Returns the first mri compatible (partly) ruby for use
  281. # with things like rbx etc which require a ruby be installed.
  282. __rvm_mri_ruby()
  283. {
  284. __rvm_mri_rubies "${1:-"ruby-1.9|ruby-2"}" |
  285. __rvm_version_sort |
  286. __rvm_awk 'BEGIN{ selected=$0 } /'"$(__rvm_env_string)"'/{ selected=$0 } END {print $0}'
  287. }
  288. __rvm_ensure_has_mri_ruby()
  289. {
  290. \typeset versions
  291. versions="${1:-"ruby-1.9|ruby-2"}"
  292. if
  293. [[ -z "$(__rvm_mri_ruby $versions)" ]]
  294. then
  295. \typeset compat_result
  296. compat_result=0
  297. rvm_warn "
  298. Warning! Requested ruby installation which requires another ruby available - installing ${versions##*|} first.
  299. "
  300. if
  301. (
  302. __rvm_select "${versions##*|}" # prevents endless loop for rbx
  303. __rvm_run_wrapper manage install "${versions##*|}"
  304. )
  305. then
  306. true
  307. else
  308. compat_result=$?
  309. rvm_error "
  310. To proceed rvm requires a ${versions##*|} compatible ruby is installed.
  311. We attempted to install it automatically but it failed with status $compat_result.
  312. Please install it manually (or a compatible alternative) to proceed.
  313. "
  314. fi
  315. return $compat_result
  316. fi
  317. return 0
  318. }
  319. __rvm_is_enough_ram()
  320. {
  321. \typeset __required_ram __existing_ram
  322. __required_ram=$(( $1 * 1024 * 1024 ))
  323. __existing_ram="$(free -b 2>/dev/null | __rvm_awk '{if (NR==3) print $4}')"
  324. : ${__existing_ram:="$(sysctl hw.physmem 2>/dev/null | __rvm_awk -F"[:=]" '{print $2}')"}
  325. : __existing_ram: ${__existing_ram:=0}
  326. rvm_debug "Existing ram $(( __existing_ram /1024 /1024 ))MB."
  327. (( __existing_ram >= __required_ram )) || return $?
  328. }