build_config 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. #!/usr/bin/env bash
  2. __rvm_setup_compile_environment()
  3. {
  4. \typeset __type
  5. \typeset -a __types
  6. __types=(
  7. setup movable_early system_early requirements
  8. movable parse_name system architectures gcc47plus bison
  9. flags_docs flags_shared_static flags_threads compatibility_flag
  10. )
  11. for __type in "${__types[@]}"
  12. do
  13. rvm_debug "__rvm_setup_compile_environment_${__type} $1"
  14. __rvm_setup_compile_environment_${__type} "$1" || return $?
  15. done
  16. rvm_debug "found compiler: $( __rvm_found_compiler )"
  17. }
  18. __rvm_setup_compile_environment_setup()
  19. {
  20. __rvm_autolibs_get
  21. rvm_debug "rvm_autolibs_flag=${rvm_autolibs_flag}"
  22. __rvm_autolibs_translate || return $?
  23. [[ -n "${rvm_autolibs_flag_number:-}" ]] || return $?
  24. export initially_selected_compiler="$( __rvm_selected_compiler )"
  25. true
  26. }
  27. __rvm_setup_compile_environment_movable_early()
  28. {
  29. (( ${rvm_movable_flag:-0} > 0 )) || return 0
  30. case "${_system_type}" in
  31. (BSD)
  32. rvm_error "It is not yet supported to build movable rubies on *BSD systems."
  33. return 3
  34. ;;
  35. (Darwin)
  36. case "$1" in
  37. ruby-2*|ruby-head*) true ;;
  38. (*)
  39. if
  40. (( ${rvm_force_flag:-0} > 0 ))
  41. then
  42. true # allow forcing installation of older rubies
  43. else
  44. rvm_error "Only MRI Ruby 2.0+ can be compiled movable with RVM on OSX,
  45. use '--force' if the binary will be moved to the same installation path."
  46. return 2
  47. fi
  48. ;;
  49. esac
  50. [[ "${rvm_autolibs_flag_runner}" == "smf" ]] ||
  51. {
  52. rvm_error "It is not yet supported to build movable rubies with '${rvm_autolibs_flag}',
  53. please install SMF and switch autolibs to it (make sure to follow any displayed instructions):
  54. curl -L https://get.smf.sh | sh
  55. rvm autolibs smf
  56. "
  57. return 3
  58. }
  59. export rvm_static_flag=1
  60. ;;
  61. (*)
  62. case "$1" in
  63. ruby-1.9.3*|ruby-2*|ruby-head*) true ;;
  64. (*)
  65. rvm_error "Only MRI Ruby 1.9.3+ can be compiled movable with RVM"
  66. return 2
  67. ;;
  68. esac
  69. ;;
  70. esac
  71. }
  72. __rvm_setup_compile_environment_system_early()
  73. {
  74. if is_a_function __rvm_setup_compile_environment_system_early_${_system_name}
  75. then __rvm_setup_compile_environment_system_early_${_system_name} "$@" || return $?
  76. fi
  77. }
  78. #
  79. # rvm_autolibs_flag
  80. # - 0 - disabled
  81. # - 1 - use libs, do not install
  82. # - 2 - use libs, fail if missing - default
  83. # - 3 - use libs, install if missing, fallback to 2 if brew not writable
  84. # - 4 - 3 + install package manager if not available
  85. #
  86. __rvm_setup_compile_environment_requirements()
  87. {
  88. (( ${rvm_autolibs_flag_number} > 0 )) || return 0
  89. rvm_log "Checking requirements for ${rvm_autolibs_flag_runner}."
  90. if
  91. __rvm_requirements_run ${rvm_autolibs_flag_runner} "$@"
  92. then
  93. rvm_log "Requirements installation successful."
  94. else
  95. \typeset __status=$?
  96. [[ ${rvm_quiet_flag} == 1 ]] || rvm_error "Requirements installation failed with status: ${__status}."
  97. return ${__status}
  98. fi
  99. }
  100. __rvm_setup_compile_environment_parse_name()
  101. {
  102. case "${rvm_ruby_name:-}" in
  103. (clang) true ${CC:=clang} ;;
  104. esac
  105. }
  106. __rvm_setup_compile_environment_movable()
  107. {
  108. (( ${rvm_movable_flag:-0} > 0 )) || return 0
  109. case "${_system_type}" in
  110. (Darwin)
  111. rvm_configure_flags+=(
  112. --enable-load-relative --with-static-linked-ext
  113. --with-out-ext=dl/win32,fiddle/win32,tk/tkutil,tk,win32ole,-test-/win32/dln,-test-/win32/fd_setsize
  114. )
  115. rvm_patch_names+=( osx_static )
  116. ;;
  117. (*)
  118. rvm_configure_flags+=( --enable-load-relative )
  119. ;;
  120. esac
  121. rvm_configure_flags+=( --sysconfdir=/etc )
  122. }
  123. __rvm_setup_compile_environment_bison()
  124. {
  125. (( ${rvm_autolibs_flag_number} > 1 )) || return 0
  126. case "$1" in
  127. (ruby*|ree*|rbx*)
  128. __rvm_check_for_bison ||
  129. {
  130. result=$?
  131. rvm_error "Bison required but not found. Halting."
  132. return $result
  133. }
  134. ;;
  135. esac
  136. }
  137. __rvm_setup_compile_environment_architectures_osx_map()
  138. {
  139. \typeset _architecture
  140. \typeset _prefix="${1:-}"
  141. \typeset -a _architectures
  142. _architectures=()
  143. for _architecture in "${rvm_architectures[@]}"
  144. do
  145. case "${_architecture}" in
  146. (32) _architecture="i386" ;;
  147. (64) _architecture="x86_64" ;;
  148. esac
  149. _architectures+=( "${_prefix}${_architecture}" )
  150. done
  151. rvm_architectures=( "${_architectures[@]}" )
  152. }
  153. __rvm_setup_compile_environment_architectures_ruby_osx()
  154. {
  155. \typeset -a _flags
  156. _flags=(
  157. MACOSX_DEPLOYMENT_TARGET="$( sw_vers -productVersion | __rvm_awk -F'.' '{print $1"."$2}' )"
  158. CFLAGS="$1 -g -Os -pipe -no-cpp-precomp"
  159. CCFLAGS="$1 -g -Os -pipe"
  160. CXXFLAGS="$1 -g -Os -pipe"
  161. LDFLAGS="$1 -bind_at_load"
  162. LDSHARED="cc $1 -dynamiclib -undefined suppress -flat_namespace"
  163. )
  164. __rvm_update_configure_env "${_flags[@]}"
  165. __rvm_array_contains "*osx-arch-fix*" "${rvm_patch_names[@]}" || rvm_patch_names+=( osx-arch-fix )
  166. }
  167. __rvm_setup_compile_environment_architectures_OSX()
  168. {
  169. case "$1" in
  170. ruby-1.9*|ruby-2*|ruby-head*)
  171. # Ruby 1.9+ supports the easy way
  172. __rvm_setup_compile_environment_architectures_osx_map
  173. rvm_configure_flags+=( --with-arch="${rvm_architectures[*]}" )
  174. ;;
  175. ruby*|ree*)
  176. __rvm_setup_compile_environment_architectures_osx_map "-arch "
  177. __rvm_setup_compile_environment_architectures_ruby_osx "${rvm_architectures[*]}"
  178. ;;
  179. (*)
  180. __rvm_setup_compile_environment_architectures_osx_map "-arch "
  181. __rvm_update_configure_env_arch "${rvm_architectures[*]}"
  182. rvm_configure_flags+=( --disable-dependency-tracking )
  183. ;;
  184. esac
  185. }
  186. __rvm_setup_compile_environment_architectures_Other()
  187. {
  188. (( ${#rvm_architectures[@]} == 1 )) ||
  189. {
  190. rvm_error "Only OSX supports fat binaries, any other system supports only single architecture, please be more specific."
  191. return 1
  192. }
  193. \typeset _architecture
  194. case "${rvm_architectures[*]}" in
  195. (i386) _architecture=( -m32 ) ;;
  196. (x86_64) _architecture=( -m64 ) ;;
  197. (32|64) _architecture=( -m${rvm_architectures[*]} ) ;;
  198. (*) _architecture=( -march=${rvm_architectures[*]} ) ;;
  199. esac
  200. __rvm_update_configure_env_arch ${_architecture}
  201. # Ruby 2+ supports also platform setting needed for different os/kernel architectures, see #2928
  202. case "$1" in
  203. ruby-2*|ruby-head*)
  204. case "${rvm_architectures[*]}" in
  205. (32|i386) rvm_configure_flags+=( --with-arch="i686" ) ;;
  206. (64|x86_64) rvm_configure_flags+=( --with-arch="x86_64" ) ;;
  207. esac
  208. ;;
  209. esac
  210. }
  211. __rvm_setup_compile_environment_architectures()
  212. {
  213. rvm_debug "rvm_architectures(${#rvm_architectures[@]}):${rvm_architectures[*]}."
  214. (( ${#rvm_architectures[@]} > 0 )) || return 0
  215. if is_a_function __rvm_setup_compile_environment_architectures_${_system_name}
  216. then __rvm_setup_compile_environment_architectures_${_system_name} "$@" || return $?
  217. else __rvm_setup_compile_environment_architectures_Other "$@" || return $?
  218. fi
  219. }
  220. __rvm_setup_compile_environment_gcc47plus()
  221. {
  222. __rvm_compiler_version_or_higher "4.7" || return 0
  223. __rvm_string_match "$1" "ruby-1.8.*" "ree*" || return 0
  224. # -g -O2 from 1.8.7-p370 is not enough, need all the flags to fix it
  225. __rvm_update_configure_env CFLAGS="-O2 -fno-tree-dce -fno-optimize-sibling-calls"
  226. }
  227. __rvm_setup_compile_environment_system()
  228. {
  229. if is_a_function __rvm_setup_compile_environment_system_${_system_name}
  230. then __rvm_setup_compile_environment_system_${_system_name} "$@" || return $?
  231. elif is_a_function __rvm_setup_compile_environment_system_${_system_type}
  232. then __rvm_setup_compile_environment_system_${_system_type} "$@" || return $?
  233. fi
  234. }
  235. __rvm_setup_compile_environment_flags_docs()
  236. {
  237. # disable docs, see https://github.com/rvm/rvm/issues/2656
  238. # enable docs on OSX by default (that's development system)
  239. # if [[ "Darwin" == "${_system_type}" ]]
  240. # then : rvm_docs_flag=${rvm_docs_flag:=1}
  241. # fi
  242. # handle docs flag, docs are enabled by default, lets disable this
  243. (( ${rvm_docs_flag:-0} == 1 )) ||
  244. {
  245. case "$1" in
  246. (ruby*|ree*) rvm_configure_flags+=( --disable-install-doc ) ;;
  247. esac
  248. }
  249. true # OSX --trace FIX
  250. }
  251. __rvm_setup_compile_environment_flags_static_darwin()
  252. {
  253. if
  254. [[ "${_system_type}" == "Darwin" ]]
  255. then
  256. __rvm_update_configure_env CFLAGS="-fPIC -mmacosx-version-min=10.7" LDFLAGS="-fPIC" "$@"
  257. rvm_configure_flags+=( --with-arch=x86_64 )
  258. fi
  259. }
  260. __rvm_setup_compile_environment_flags_shared_static()
  261. {
  262. if
  263. (( ${rvm_static_flag:-0} == 1 ))
  264. then
  265. case "$1" in
  266. (openssl*)
  267. rvm_configure_flags+=( no-shared )
  268. __rvm_setup_compile_environment_flags_static_darwin
  269. ;;
  270. (ncurses*)
  271. rvm_configure_flags+=( --without-shared )
  272. __rvm_setup_compile_environment_flags_static_darwin
  273. ;;
  274. (rbx*|rubinius*|jruby*)
  275. true # no flag yet for rbx, does not apply to jruby!
  276. ;;
  277. (*)
  278. rvm_configure_flags+=( --disable-shared )
  279. __rvm_setup_compile_environment_flags_static_darwin LDFLAGS="-Bstatic -lz"
  280. ;;
  281. esac
  282. else
  283. case "$1" in
  284. (openssl*)
  285. rvm_configure_flags+=( shared )
  286. ;;
  287. (readline*)
  288. rvm_configure_flags+=( --disable-static --enable-shared )
  289. ;;
  290. (ncurses*)
  291. rvm_configure_flags+=( --with-shared )
  292. ;;
  293. (rbx*|rubinius*|jruby*)
  294. true # no flag yet for rbx, does not apply to jruby!
  295. ;;
  296. (*)
  297. [[ "${rvm_configure_flags[*]}" == *--disable-shared* ]] ||
  298. rvm_configure_flags+=( --enable-shared )
  299. ;;
  300. esac
  301. fi
  302. true # OSX --trace FIX
  303. }
  304. __rvm_detect_max_threads()
  305. {
  306. case "${_system_name}" in
  307. (OSX|Darwin|FreeBSD|DragonFly)
  308. if
  309. __rvm_which sysctl >/dev/null
  310. then
  311. \command \sysctl -n hw.ncpu
  312. elif
  313. [[ -x /usr/sbin/sysctl ]]
  314. then
  315. /usr/sbin/sysctl -n hw.ncpu
  316. elif
  317. [[ -x /sbin/sysctl ]]
  318. then
  319. /sbin/sysctl -n hw.ncpu
  320. else
  321. echo 1
  322. fi
  323. ;;
  324. (*)
  325. \command \cat /proc/cpuinfo 2>/dev/null | (\command \grep vendor_id || \command \echo 'one';) | \command \wc -l
  326. ;;
  327. esac
  328. }
  329. __rvm_setup_compile_environment_flags_threads()
  330. {
  331. case "$1" in
  332. (openssl*)
  333. # Don't use -j option for make OpenSSL
  334. __rvm_remove_from_array rvm_make_flags "-j*" "${rvm_make_flags[@]}"
  335. rvm_make_flags+=( -j1 )
  336. ;;
  337. (*)
  338. if [[ "${_system_name}" == "FreeBSD" || "${_system_name}" == "DragonFly" ]]
  339. then rvm_make_flags+=( -B )
  340. fi
  341. if [[ " ${rvm_make_flags[*]}" == *" -j"* ]]
  342. then rvm_warn "Found user configured '-j' flag in 'rvm_make_flags', please note that RVM can detect number of CPU threads and set the '-j' flag automatically if you do not set it."
  343. else rvm_make_flags+=( -j$(__rvm_detect_max_threads) )
  344. fi
  345. ;;
  346. esac
  347. }
  348. __rvm_setup_compile_environment_compatibility_flag()
  349. {
  350. case "$1" in
  351. (jruby*)
  352. for mode in 2.1 2.0 1.9 1.8
  353. do
  354. eval "
  355. if
  356. [[ \${rvm_${mode//./}_flag:-0} == 1 ]]
  357. then
  358. rvm_configure_flags+=( -Djruby.default.ruby.version=${mode} )
  359. break
  360. fi
  361. "
  362. done
  363. ;;
  364. esac
  365. }