pkg 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. #!/usr/bin/env bash
  2. ## common part of requirements_rvm_pkg_* extracted from scripts/functions/requirements/rvm_pkg ->
  3. requirements_rvm_pkg_config()
  4. {
  5. PKG_CONFIG_PATH="${rvm_usr_path:-${rvm_path}/usr}/lib/pkgconfig:${rvm_usr_path:-${rvm_path}/usr}/lib64/pkgconfig:/opt:/usr:/usr/local" pkg-config "$@"
  6. }
  7. requirements_rvm_pkg_lib_installed()
  8. {
  9. if is_a_function ${1}_installed && ${1}_installed
  10. then return 0
  11. fi
  12. requirements_rvm_pkg_config --list-all | __rvm_grep "^$1[- ]" >/dev/null || return $?
  13. true
  14. }
  15. requirements_rvm_pkg_libs_install()
  16. {
  17. while
  18. (( $# ))
  19. do
  20. PKG_CONFIG_LIBDIR="${rvm_usr_path:-${rvm_path}/usr}/lib/pkgconfig" install_$1 || return $?
  21. shift
  22. done
  23. }
  24. requirements_rvm_pkg_after_uniqe_paths()
  25. {
  26. \typeset __lib __lib_full_name
  27. for __lib
  28. do
  29. __lib_full_name=$( requirements_rvm_pkg_config --list-all | __rvm_awk "/^${__lib}[- ]/{print \$1}" )
  30. if
  31. [[ -n "${__lib_full_name}" ]]
  32. then
  33. requirements_rvm_pkg_config ${__lib_full_name} --variable=prefix
  34. elif
  35. [[ "${__lib}" == 'readline' ]]
  36. then
  37. # http://lists.gnu.org/archive/html/bug-readline/2010-09/msg00002.html
  38. echo ${rvm_usr_path:-${rvm_path}/usr}
  39. else
  40. rvm_error "Can not find ${__lib} in 'pkg-config'"
  41. fi
  42. done | sort -u
  43. }
  44. requirements_rvm_pkg_configure()
  45. {
  46. \typeset -a __packages
  47. \typeset __package __target
  48. __target="$1"
  49. shift
  50. __rvm_read_lines __packages <(
  51. requirements_rvm_pkg_after_uniqe_paths "$@"
  52. )
  53. for __package in "${__packages[@]}"
  54. do __rvm_update_configure_opt_dir "$__target" "$__package"
  55. done
  56. }
  57. ## common part of requirements_rvm_pkg_* extracted from scripts/functions/requirements/rvm_pkg <-
  58. ## helper for checking marking missing custom packages
  59. requirements_rvm_pkg_lib_installed_custom()
  60. {
  61. while
  62. (( $# ))
  63. do
  64. requirements_rvm_pkg_lib_installed "$1" || packages_custom+=( "$1" )
  65. shift
  66. done
  67. }
  68. ## Real work for installing packages from source
  69. install_package()
  70. {
  71. __rvm_db "${package}_url" "package_url"
  72. __rvm_db "${package}_rename_dir" "package_rename_dir"
  73. (
  74. __rvm_cd "$rvm_src_path"
  75. __rvm_rm_rf "$rvm_src_path/$package-$version"
  76. local_file="$package-$version.$archive_format"
  77. rvm_log "Fetching $local_file to $rvm_archives_path"
  78. "$rvm_scripts_path/fetch" "$package_url/${remote_file:-$local_file}" "$local_file" || return $?
  79. __rvm_log_command "$package/extract" "Extracting ${package} to $rvm_src_path/$package-$version" \
  80. __rvm_package_extract "$rvm_archives_path/$local_file" "$rvm_src_path" ||
  81. case $? in
  82. 199)
  83. rvm_error "\nUnrecognized archive format '$archive_format'"
  84. return 199
  85. ;;
  86. *)
  87. rvm_error "There has been an error while trying to extract the source. Halting the installation."
  88. return 1
  89. ;;
  90. esac
  91. if [[ -n "${package_rename_dir:-}" ]]
  92. then \command \mv "$rvm_src_path/${package_rename_dir}" "$rvm_src_path/$package-$version"
  93. fi
  94. __rvm_cd "$rvm_src_path/$package-$version"
  95. __rvm_add_to_path append /usr/bin
  96. if
  97. [[ -n "$patches" ]]
  98. then
  99. for patch in $(echo $patches | \command \tr ',' ' ')
  100. do
  101. __rvm_log_command "$package/patch" "Applying patch '$patch'..." __rvm_patch -p0 -f -i "$patch" ||
  102. {
  103. \typeset result=$?
  104. rvm_error "Patch $patch did not apply cleanly... back to the patching board :("
  105. exit $result
  106. }
  107. done
  108. fi
  109. if
  110. [[ "${rvm_skip_autoreconf_flag:-0}" == 0 ]] &&
  111. [[ -f configure.ac || -f configure.in ]]
  112. then
  113. if
  114. (( ${#rvm_autoconf_flags[@]} == 0 ))
  115. then
  116. case "${_system_type}" in
  117. (Windows) rvm_autoconf_flags=( -ivf ) ;; # no symlinks on windows :(
  118. (*) rvm_autoconf_flags=( -is --force ) ;;
  119. esac
  120. fi
  121. __rvm_log_command "$package/autoreconf" "Prepare $package in $rvm_src_path/$package-$version." \
  122. __rvm_autoreconf "${rvm_autoconf_flags[@]}"
  123. fi
  124. [[ -n "${rvm_configure_env[*]}" ]] || rvm_configure_env=() # zsh can assume empty var => ( '' )
  125. (( ${#configure[@]} )) || configure=( ./configure )
  126. configure=(
  127. "${rvm_configure_env[@]}"
  128. "${configure[@]}" --prefix="${prefix_path:-$rvm_usr_path}"
  129. "${rvm_configure_flags[@]}" "${configure_flags[@]}"
  130. )
  131. __rvm_log_command "$package/configure" "Configuring $package in $rvm_src_path/$package-$version." \
  132. "${configure[@]}"
  133. unset configure_flags configure
  134. touch "$rvm_path/config/packages"
  135. if [[ "$action" == "uninstall" ]]
  136. then
  137. __rvm_log_command "$package/make.uninstall" "Uninstalling $package from ${prefix_path:-$rvm_usr_path}" __rvm_make uninstall &&
  138. __rvm_cd "$rvm_src_path" &&
  139. __rvm_log_command "$package/rm_src.uninstall" "Removing ${package}-${version} from $rvm_src_path" \
  140. \command \rm -rf "$rvm_src_path/$package-$version" &&
  141. __rvm_db_ "$rvm_path/config/packages" "${package}" delete
  142. else
  143. __rvm_log_command "$package/make" "Compiling $package in $rvm_src_path/$package-$version." \
  144. __rvm_make "${rvm_make_flags[@]}" &&
  145. __rvm_log_command "$package/make.install" "Installing $package to ${prefix_path:-$rvm_usr_path}" \
  146. __rvm_make install &&
  147. __rvm_db_ "$rvm_path/config/packages" "${package}" "${version}"
  148. fi
  149. )
  150. __function_on_stack __rvm_install_ruby ||
  151. rvm_warn "
  152. Please note that it's required to reinstall all rubies:
  153. rvm reinstall all --force
  154. "
  155. }
  156. package_installed()
  157. {
  158. \typeset __search_path __lib_file __extension
  159. __search_path="${prefix_path:-${rvm_usr_path:-${rvm_path}/usr}}"
  160. [[ -f "${__search_path}/include/$1" ]] || return $?
  161. # __rvm_detect_system() does not support CYGWIN MINGW!
  162. case "${_system_type}" in
  163. (Darwin) __extension="dylib" ;;
  164. (Windows) __extension="dll" ;;
  165. (*) __extension="so" ;;
  166. esac
  167. __lib_file=$( __rvm_find "${__search_path}" -name "$2.${__extension}" | \command \head -n 1 )
  168. [[ -n "${__lib_file}" ]] || return $?
  169. case "${_system_type}" in
  170. (Darwin) lipo -info "${__lib_file}" | __rvm_grep "${_system_arch}" >/dev/null || return $? ;;
  171. esac
  172. }
  173. install_readline()
  174. {
  175. package="readline" ; archive_format="tar.gz"
  176. __rvm_update_configure_opt_dir readline "${rvm_usr_path}"
  177. configure=( ./configure --disable-dependency-tracking )
  178. version="5.2"
  179. patches="$rvm_patches_path/$package-$version/shobj-conf.patch"
  180. install_package
  181. configure=( ./configure --disable-dependency-tracking )
  182. version="6.2"
  183. patches="$rvm_patches_path/$package-$version/patch-shobj-conf.diff"
  184. install_package
  185. }
  186. readline_installed()
  187. {
  188. package_installed "readline/readline.h" "libreadline" || return $?
  189. }
  190. install_iconv()
  191. {
  192. package="libiconv" ; version=1.13.1 ; archive_format="tar.gz"
  193. install_package
  194. }
  195. install_curl()
  196. {
  197. package="curl" ; version=7.19.7 ; archive_format="tar.gz"
  198. install_package
  199. }
  200. install_openssl()
  201. {
  202. \typeset -a openssl_use_asm
  203. package="openssl" ; archive_format="tar.gz"
  204. openssl_use_asm=( "no-asm" )
  205. __rvm_db "${package}_version" "version"
  206. if
  207. [[ "Darwin" == "${_system_type}" ]]
  208. then
  209. configure=( "./Configure" )
  210. if
  211. (( ${#rvm_architectures[@]} > 0 ))
  212. then
  213. if __rvm_string_match "${rvm_architectures[*]}" "64"
  214. then hw_cpu64bit=1
  215. fi
  216. if __rvm_string_match "${rvm_architectures[*]}" "ppc"
  217. then hw_machine="Power Macintosh"
  218. fi
  219. else
  220. hw_machine=$(sysctl hw.machine | __rvm_awk -F: '{print $2}' | __rvm_sed 's/^ //')
  221. hw_cpu64bit=$(sysctl hw.cpu64bit_capable | __rvm_awk '{print $2}')
  222. fi
  223. if
  224. [[ "Power Macintosh" == "$hw_machine" ]]
  225. then
  226. if [[ $hw_cpu64bit == 1 ]]
  227. then configure+=( "darwin64-ppc-cc" )
  228. else configure+=( "darwin-ppc-cc" )
  229. fi
  230. else
  231. if
  232. [[ $hw_cpu64bit == 1 ]]
  233. then
  234. configure+=( "darwin64-x86_64-cc" )
  235. openssl_use_asm=()
  236. else
  237. configure+=( "darwin-i386-cc" )
  238. fi
  239. fi
  240. else
  241. configure=( "./config" )
  242. if __rvm_compiler_version_or_higher "4.6"
  243. then openssl_use_asm=()
  244. fi
  245. fi
  246. configure+=( -I$rvm_usr_path/include -L$rvm_usr_path/lib zlib "${openssl_use_asm[@]}" no-krb5 )
  247. install_package
  248. __rvm_log_command openssl.certs "Updating openssl certificates" update_openssl_certs
  249. }
  250. update_openssl_certs()
  251. (
  252. __rvm_cd "$rvm_usr_path/ssl" &&
  253. __rvm_curl https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt -o cert.pem ||
  254. __rvm_curl https://curl.haxx.se/ca/cacert.pem -o cert.pem
  255. )
  256. openssl_installed()
  257. {
  258. package_installed "openssl/opensslv.h" "libssl" || return $?
  259. }
  260. install_zlib()
  261. {
  262. package="zlib" ; version="1.2.7" ; archive_format="tar.gz"
  263. install_package
  264. }
  265. install_autoconf()
  266. {
  267. package="autoconf" ; version="2.65" ; archive_format="tar.gz"
  268. prefix_path="$rvm_usr_path"
  269. install_package
  270. }
  271. install_ncurses()
  272. {
  273. package="ncurses" ; version="5.7" ; archive_format="tar.gz"
  274. configure_flags=(
  275. --disable-rpath --without-debug --without-ada --enable-safe-sprintf --enable-sigwinch --without-progs
  276. )
  277. install_package
  278. }
  279. install_pkgconfig()
  280. {
  281. package="pkg-config" ; version="0.23" archive_format="tar.gz"
  282. install_package
  283. }
  284. install_gettext()
  285. {
  286. package="gettext" ; version="0.17" ; archive_format="tar.gz"
  287. install_package
  288. }
  289. install_libxml()
  290. {
  291. install_libxml2 "$@"
  292. }
  293. install_libxml2()
  294. {
  295. package="libxml2" ; version="2.7.3" ; archive_format="tar.gz"
  296. if
  297. [[ "Darwin" == "${_system_type}" ]]
  298. then
  299. configure=(
  300. ./configure --build=i686-apple-darwin$(command uname -r) --host=i686-apple-darwin$(command uname -r)
  301. )
  302. fi
  303. install_package
  304. unset prefix_path
  305. }
  306. install_libxslt()
  307. {
  308. package="libxslt" ; version="1.1.26" ; archive_format="tar.gz"
  309. configure_flags=( --with-libxml-prefix="$rvm_usr_path" )
  310. if
  311. [[ "SunOS" == "${_system_type}" ]]
  312. then
  313. patches="$rvm_patches_path/$package-$version/solaris.patch"
  314. fi
  315. install_package
  316. unset prefix_path
  317. }
  318. install_yaml()
  319. {
  320. install_libyaml "$@"
  321. }
  322. install_libyaml()
  323. {
  324. package="yaml" ; archive_format="tar.gz"
  325. __rvm_db "${package}_version" "version"
  326. install_package
  327. }
  328. libyaml_installed()
  329. {
  330. package_installed "yaml.h" "libyaml"
  331. }
  332. install_glib()
  333. {
  334. ( install_pkgconfig; )
  335. ( install_gettext; )
  336. package="glib" ; version="2.23.1" ; archive_format="tar.gz"
  337. __rvm_update_configure_env CC="cc" \
  338. CFLAGS="-I${rvm_usr_path}/include" \
  339. LDFLAGS="-L${rvm_usr_path}/lib" \
  340. PKG_CONFIG="$rvm_usr_path/bin/pkg-config"
  341. install_package
  342. }
  343. install_mono()
  344. {
  345. ( install_glib; )
  346. __rvm_mono_env
  347. package="mono" ; version="2.6.1" ; archive_format="tar.bz2"
  348. install_package
  349. }
  350. install_llvm()
  351. {
  352. package="llvm"
  353. version="89156"
  354. (
  355. __rvm_cd $rvm_src_path
  356. if [[ ! -d "$rvm_src_path/llvm/.svn" ]] ; then
  357. __rvm_db "${package}_url" "package_url"
  358. __rvm_rm_rf "$rvm_src_path/llvm"
  359. svn co -r "$version" "$package_url" llvm
  360. __rvm_cd "$rvm_src_path/llvm"
  361. ./configure --enable-bindings=none
  362. UNIVERSAL=1 UNIVERSAL_ARCH="i386 x86_64" ENABLE_OPTIMIZED=1 __rvm_make -j2
  363. __rvm_try_sudo env UNIVERSAL=1 UNIVERSAL_ARCH="i386 x86_64" ENABLE_OPTIMIZED=1 __rvm_make install
  364. fi
  365. )
  366. }
  367. install_epel()
  368. {
  369. mv="${_system_version%%.*}"
  370. if [[ "${_system_name}" == "CentOS" ]] && [[ -f /etc/yum.repos.d/epel.repo ]] ; then
  371. __rvm_db "epel${mv}_key" "epel_key"
  372. __rvm_db "epel${mv}_rpm" "epel_rpm"
  373. "${rvm_scripts_path}/fetch" "${epel_key}"
  374. "${rvm_scripts_path}/fetch" "${epel_rpm}"
  375. __rvm_try_sudo rpm --import "${rvm_archives_path}/${epel_key##*/}"
  376. __rvm_try_sudo rpm --quiet -i "${rvm_archives_path}/${epel_rpm##*/}"
  377. fi
  378. }