1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
5 PYTHON_COMPAT=( python{2_7,3_{6,7}} )
6 PYTHON_REQ_USE="threads(+)"
7 inherit bash-completion-r1 flag-o-matic pax-utils python-any-r1 toolchain-funcs xdg-utils
9 DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
10 HOMEPAGE="https://nodejs.org/"
12 https://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz
15 LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT"
17 KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~x86 ~amd64-linux ~x64-macos"
18 IUSE="cpu_flags_x86_sse2 debug doc icu inspector +npm +snapshot +ssl systemtap test"
20 inspector? ( icu ssl )
25 >=dev-libs/libuv-1.33.1:=
26 >=net-dns/c-ares-1.15.0
27 >=net-libs/http-parser-2.9.0:=
28 >=net-libs/nghttp2-1.40.0
30 icu? ( >=dev-libs/icu-64.2:= )
31 ssl? ( >=dev-libs/openssl-1.1.1:0= )
35 systemtap? ( dev-util/systemtap )
36 test? ( net-misc/curl )
42 "${FILESDIR}"/${PN}-10.3.0-global-npm-config.patch
43 "${FILESDIR}"/${PN}-99999999-llhttp.patch
46 S="${WORKDIR}/node-v${PV}"
49 (use x86 && ! use cpu_flags_x86_sse2) && \
50 die "Your CPU doesn't support the required SSE2 instruction."
52 ( [[ ${MERGE_TYPE} != "binary" ]] && ! test-flag-CXX -std=c++11 ) && \
53 die "Your compiler doesn't support C++11. Use GCC 4.8, Clang 3.3 or newer."
57 tc-export CC CXX PKG_CONFIG
59 export BUILDTYPE=Release
61 # fix compilation on Darwin
62 # https://code.google.com/p/gyp/issues/detail?id=260
63 sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
65 # less verbose install output (stating the same as portage, basically)
66 sed -i -e "/print/d" tools/install.py || die
68 # proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504
69 local LIBDIR=$(get_libdir)
70 sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die
71 sed -i -e "s/'lib'/'${LIBDIR}'/" deps/npm/lib/npm.js || die
73 # Avoid writing a depfile, not useful
74 sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die
76 sed -i -e "/'-O3'/d" common.gypi node.gypi || die
78 # Avoid a test that I've only been able to reproduce from emerge. It doesnt
79 # seem sandbox related either (invoking it from a sandbox works fine).
80 # The issue is that no stdin handle is openened when asked for one.
81 # It doesn't really belong upstream , so it'll just be removed until someone
82 # with more gentoo-knowledge than me (jbergstroem) figures it out.
83 rm test/parallel/test-stdout-close-unref.js || die
85 # debug builds. change install path, remove optimisations and override buildtype
87 sed -i -e "s|out/Release/|out/Debug/|g" tools/install.py || die
104 use debug && myconf+=( --debug )
105 use icu && myconf+=( --with-intl=system-icu ) || myconf+=( --with-intl=none )
106 use inspector || myconf+=( --without-inspector )
107 use npm || myconf+=( --without-npm )
108 use snapshot || myconf+=( --without-node-snapshot )
109 use ssl && myconf+=( --shared-openssl --openssl-use-def-ca-store ) || myconf+=( --without-ssl )
113 amd64) myarch="x64";;
115 arm64) myarch="arm64";;
116 ppc64) myarch="ppc64";;
122 GYP_DEFINES="linux_use_gold_flags=0
123 linux_use_bundled_binutils=0
124 linux_use_bundled_gold=0" \
125 "${EPYTHON}" configure.py \
126 --prefix="${EPREFIX}"/usr \
127 --dest-cpu=${myarch} \
128 $(use_with systemtap dtrace) \
129 "${myconf[@]}" || die
133 emake -C out mksnapshot
134 pax-mark m "out/${BUILDTYPE}/mksnapshot"
139 local LIBDIR="${ED}/usr/$(get_libdir)"
142 pax-mark -m "${ED}"/usr/bin/node
144 # set up a symlink structure that node-gyp expects..
145 dodir /usr/include/node/deps/{v8,uv}
146 dosym . /usr/include/node/src
147 for var in deps/{uv,v8}/include; do
148 dosym ../.. /usr/include/node/${var}
153 dodoc -r "${S}"/doc/*
159 # Install bash completion for `npm`
160 # We need to temporarily replace default config path since
161 # npm otherwise tries to write outside of the sandbox
162 local npm_config="usr/$(get_libdir)/node_modules/npm/lib/config/core.js"
163 sed -i -e "s|'/etc'|'${ED}/etc'|g" "${ED}/${npm_config}" || die
164 local tmp_npm_completion_file="$(emktemp)"
165 "${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}"
166 newbashcomp "${tmp_npm_completion_file}" npm
167 sed -i -e "s|'${ED}/etc'|'/etc'|g" "${ED}/${npm_config}" || die
170 doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/*
173 rm "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile} || die
174 rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man} || die
176 local find_exp="-or -name"
178 for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
179 ".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
180 "*.md" "*.markdown" "*.bat" "*.cmd"; do
181 find_name+=( ${find_exp} "${match}" )
184 # Remove various development and/or inappropriate files and
185 # useless docs of dependend packages.
186 find "${LIBDIR}"/node_modules \
187 \( -type d -name examples \) -or \( -type f \( \
190 \) \) -exec rm -rf "{}" \;
193 mv "${ED}"/usr/share/doc/node "${ED}"/usr/share/doc/${PF} || die
197 out/${BUILDTYPE}/cctest || die
198 "${PYTHON}" tools/test.py --mode=${BUILDTYPE,,} -J message parallel sequential || die
202 elog "The global npm config lives in /etc/npm. This deviates slightly"
203 elog "from upstream which otherwise would have it live in /usr/etc/."
205 elog "Protip: When using node-gyp to install native modules, you can"
206 elog "avoid having to download extras by doing the following:"
207 elog "$ node-gyp --nodedir /usr/include/node <command>"