nodejs-7.7.3.ebuild 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. RESTRICT="test"
  5. PYTHON_COMPAT=( python2_7 )
  6. PYTHON_REQ_USE="threads"
  7. inherit bash-completion-r1 eutils flag-o-matic pax-utils python-single-r1 toolchain-funcs
  8. DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
  9. HOMEPAGE="https://nodejs.org/"
  10. SRC_URI="https://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz"
  11. LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT"
  12. SLOT="0"
  13. KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~x86 ~amd64-linux ~x64-macos"
  14. IUSE="cpu_flags_x86_sse2 debug doc icu +npm +snapshot +ssl systemtap test"
  15. RDEPEND="icu? ( >=dev-libs/icu-56:= )
  16. npm? ( ${PYTHON_DEPS} )
  17. >=net-libs/http-parser-2.6.2:=
  18. >=dev-libs/libuv-1.11.0:=
  19. >=dev-libs/openssl-1.0.2g:0=[-bindist]
  20. sys-libs/zlib"
  21. DEPEND="${RDEPEND}
  22. ${PYTHON_DEPS}
  23. systemtap? ( dev-util/systemtap )
  24. test? ( net-misc/curl )"
  25. S="${WORKDIR}/node-v${PV}"
  26. REQUIRED_USE="${PYTHON_REQUIRED_USE}"
  27. PATCHES=(
  28. "${FILESDIR}"/gentoo-global-npm-config.patch
  29. )
  30. pkg_pretend() {
  31. (use x86 && ! use cpu_flags_x86_sse2) && \
  32. die "Your CPU doesn't support the required SSE2 instruction."
  33. ( [[ ${MERGE_TYPE} != "binary" ]] && ! test-flag-CXX -std=c++11 ) && \
  34. die "Your compiler doesn't support C++11. Use GCC 4.8, Clang 3.3 or newer."
  35. }
  36. src_prepare() {
  37. tc-export CC CXX PKG_CONFIG
  38. export V=1
  39. export BUILDTYPE=Release
  40. # fix compilation on Darwin
  41. # https://code.google.com/p/gyp/issues/detail?id=260
  42. sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
  43. # make sure we use python2.* while using gyp
  44. sed -i -e "s/python/${EPYTHON}/" deps/npm/node_modules/node-gyp/gyp/gyp || die
  45. sed -i -e "s/|| 'python'/|| '${EPYTHON}'/" deps/npm/node_modules/node-gyp/lib/configure.js || die
  46. # less verbose install output (stating the same as portage, basically)
  47. sed -i -e "/print/d" tools/install.py || die
  48. # proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504
  49. local LIBDIR=$(get_libdir)
  50. sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die
  51. sed -i -e "s/'lib'/'${LIBDIR}'/" lib/module.js || die
  52. sed -i -e "s|\"lib\"|\"${LIBDIR}\"|" deps/npm/lib/npm.js || die
  53. # Avoid writing a depfile, not useful
  54. sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die
  55. # Avoid a test that I've only been able to reproduce from emerge. It doesnt
  56. # seem sandbox related either (invoking it from a sandbox works fine).
  57. # The issue is that no stdin handle is openened when asked for one.
  58. # It doesn't really belong upstream , so it'll just be removed until someone
  59. # with more gentoo-knowledge than me (jbergstroem) figures it out.
  60. rm test/parallel/test-stdout-close-unref.js || die
  61. # debug builds. change install path, remove optimisations and override buildtype
  62. if use debug; then
  63. sed -i -e "s|out/Release/|out/Debug/|g" tools/install.py || die
  64. BUILDTYPE=Debug
  65. fi
  66. default
  67. }
  68. src_configure() {
  69. local myarch=""
  70. local myconf=( --shared-openssl --shared-libuv --shared-http-parser --shared-zlib )
  71. use npm || myconf+=( --without-npm )
  72. use icu && myconf+=( --with-intl=system-icu )
  73. use snapshot && myconf+=( --with-snapshot )
  74. use ssl || myconf+=( --without-ssl )
  75. use debug && myconf+=( --debug )
  76. case ${ABI} in
  77. amd64) myarch="x64";;
  78. arm) myarch="arm";;
  79. arm64) myarch="arm64";;
  80. ppc64) myarch="ppc64";;
  81. x32) myarch="x32";;
  82. x86) myarch="ia32";;
  83. *) myarch="${ABI}";;
  84. esac
  85. GYP_DEFINES="linux_use_gold_flags=0
  86. linux_use_bundled_binutils=0
  87. linux_use_bundled_gold=0" \
  88. "${PYTHON}" configure \
  89. --prefix="${EPREFIX}"/usr \
  90. --dest-cpu=${myarch} \
  91. $(use_with systemtap dtrace) \
  92. "${myconf[@]}" || die
  93. }
  94. src_compile() {
  95. emake -C out mksnapshot
  96. pax-mark m "out/${BUILDTYPE}/mksnapshot"
  97. emake -C out
  98. }
  99. src_install() {
  100. local LIBDIR="${ED}/usr/$(get_libdir)"
  101. emake install DESTDIR="${D}"
  102. pax-mark -m "${ED}"usr/bin/node
  103. # set up a symlink structure that node-gyp expects..
  104. dodir /usr/include/node/deps/{v8,uv}
  105. dosym . /usr/include/node/src
  106. for var in deps/{uv,v8}/include; do
  107. dosym ../.. /usr/include/node/${var}
  108. done
  109. if use doc; then
  110. # Patch docs to make them offline readable
  111. for i in `grep -rl 'fonts.googleapis.com' "${S}"/out/doc/api/*`; do
  112. sed -i '/fonts.googleapis.com/ d' $i;
  113. done
  114. # Install docs!
  115. dohtml -r "${S}"/doc/*
  116. fi
  117. if use npm; then
  118. dodir /etc/npm
  119. # Install bash completion for `npm`
  120. # We need to temporarily replace default config path since
  121. # npm otherwise tries to write outside of the sandbox
  122. local npm_config="usr/$(get_libdir)/node_modules/npm/lib/config/core.js"
  123. sed -i -e "s|'/etc'|'${ED}/etc'|g" "${ED}/${npm_config}" || die
  124. local tmp_npm_completion_file="$(emktemp)"
  125. "${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}"
  126. newbashcomp "${tmp_npm_completion_file}" npm
  127. sed -i -e "s|'${ED}/etc'|'/etc'|g" "${ED}/${npm_config}" || die
  128. # Move man pages
  129. doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/*
  130. # Clean up
  131. rm "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile} || die
  132. rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man} || die
  133. local find_exp="-or -name"
  134. local find_name=()
  135. for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
  136. ".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
  137. "*.md" "*.markdown" "*.bat" "*.cmd"; do
  138. find_name+=( ${find_exp} "${match}" )
  139. done
  140. # Remove various development and/or inappropriate files and
  141. # useless docs of dependend packages.
  142. find "${LIBDIR}"/node_modules \
  143. \( -type d -name examples \) -or \( -type f \( \
  144. -iname "LICEN?E*" \
  145. "${find_name[@]}" \
  146. \) \) -exec rm -rf "{}" \;
  147. fi
  148. }
  149. src_test() {
  150. out/${BUILDTYPE}/cctest || die
  151. "${PYTHON}" tools/test.py --mode=${BUILDTYPE,,} -J message parallel sequential || die
  152. }
  153. pkg_postinst() {
  154. einfo "The global npm config lives in /etc/npm. This deviates slightly"
  155. einfo "from upstream which otherwise would have it live in /usr/etc/."
  156. einfo ""
  157. einfo "Protip: When using node-gyp to install native modules, you can"
  158. einfo "avoid having to download extras by doing the following:"
  159. einfo "$ node-gyp --nodedir /usr/include/node <command>"
  160. }