1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
7 PYTHON_COMPAT=( python2_7 )
8 PYTHON_REQ_USE="threads"
10 inherit bash-completion-r1 eutils flag-o-matic pax-utils python-any-r1 toolchain-funcs xdg-utils
12 DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
13 HOMEPAGE="https://nodejs.org/"
14 SRC_URI="https://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz"
16 LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT"
18 KEYWORDS="~amd64 ~arm ~arm64 ~ppc ~ppc64 ~x86 ~amd64-linux ~x64-macos"
19 IUSE="cpu_flags_x86_sse2 debug doc icu inspector +npm +snapshot +ssl systemtap test"
21 inspector? ( icu ssl )
26 >=dev-libs/libuv-1.23.2:=
27 >=net-dns/c-ares-1.10.1
28 >=net-libs/http-parser-2.9.0:=
29 >=net-libs/nghttp2-1.39.2
31 icu? ( >=dev-libs/icu-60.1:= )
32 ssl? ( =dev-libs/openssl-1.0.2*:0=[-bindist] )
37 systemtap? ( dev-util/systemtap )
38 test? ( net-misc/curl )
41 "${FILESDIR}"/nodejs-10.3.0-global-npm-config.patch
43 S="${WORKDIR}/node-v${PV}"
46 (use x86 && ! use cpu_flags_x86_sse2) && \
47 die "Your CPU doesn't support the required SSE2 instruction."
49 ( [[ ${MERGE_TYPE} != "binary" ]] && ! test-flag-CXX -std=c++11 ) && \
50 die "Your compiler doesn't support C++11. Use GCC 4.8, Clang 3.3 or newer."
54 tc-export CC CXX PKG_CONFIG
56 export BUILDTYPE=Release
58 # fix compilation on Darwin
59 # https://code.google.com/p/gyp/issues/detail?id=260
60 sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
62 # make sure we use python2.* while using gyp
63 sed -i -e "s/python/${EPYTHON}/" deps/npm/node_modules/node-gyp/gyp/gyp || die
64 sed -i -e "s/|| 'python2'/|| '${EPYTHON}'/" deps/npm/node_modules/node-gyp/lib/configure.js || die
66 # less verbose install output (stating the same as portage, basically)
67 sed -i -e "/print/d" tools/install.py || die
69 # proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504
70 local LIBDIR=$(get_libdir)
72 -e "s|lib/|${LIBDIR}/|g" \
73 -e 's|share/doc/node/|share/doc/'"${PF}"'/|g' \
74 tools/install.py || die
76 sed -i -e "s/'lib'/'${LIBDIR}'/" lib/module.js deps/npm/lib/npm.js || die
78 # Avoid writing a depfile, not useful
79 sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die
81 sed -i -e "/'-O3'/d" common.gypi deps/v8/gypfiles/toolchain.gypi || die
83 # Avoid a test that I've only been able to reproduce from emerge. It doesnt
84 # seem sandbox related either (invoking it from a sandbox works fine).
85 # The issue is that no stdin handle is openened when asked for one.
86 # It doesn't really belong upstream , so it'll just be removed until someone
87 # with more gentoo-knowledge than me (jbergstroem) figures it out.
88 rm test/parallel/test-stdout-close-unref.js || die
90 # debug builds. change install path, remove optimisations and override buildtype
92 sed -i -e "s|out/Release/|out/Debug/|g" tools/install.py || die
100 xdg_environment_reset
102 local myconf=( --shared-cares --shared-http-parser --shared-libuv --shared-nghttp2 --shared-zlib )
103 use debug && myconf+=( --debug )
104 use icu && myconf+=( --with-intl=system-icu ) || myconf+=( --with-intl=none )
105 use inspector || myconf+=( --without-inspector )
106 use npm || myconf+=( --without-npm )
107 use snapshot && myconf+=( --with-snapshot )
108 use ssl && myconf+=( --shared-openssl ) || myconf+=( --without-ssl )
112 amd64) myarch="x64";;
114 arm64) myarch="arm64";;
115 ppc64) myarch="ppc64";;
121 GYP_DEFINES="linux_use_gold_flags=0
122 linux_use_bundled_binutils=0
123 linux_use_bundled_gold=0" \
124 "${PYTHON}" configure \
125 --prefix="${EPREFIX}"/usr \
126 --dest-cpu=${myarch} \
127 $(use_with systemtap dtrace) \
128 "${myconf[@]}" || die
132 emake -C out mksnapshot
133 pax-mark m "out/${BUILDTYPE}/mksnapshot"
138 out/${BUILDTYPE}/cctest || die
139 "${PYTHON}" tools/test.py --mode=${BUILDTYPE,,} -J message parallel sequential || die
143 local LIBDIR="${ED}/usr/$(get_libdir)"
144 emake install DESTDIR="${D}"
145 pax-mark -m "${ED}"usr/bin/node
147 # set up a symlink structure that node-gyp expects..
148 dodir /usr/include/node/deps/{v8,uv}
149 dosym . /usr/include/node/src
150 for var in deps/{uv,v8}/include; do
151 dosym ../.. /usr/include/node/${var}
155 # Patch docs to make them offline readable
156 for i in `grep -rl 'fonts.googleapis.com' "${S}"/out/doc/api/*`; do
157 sed -i '/fonts.googleapis.com/ d' $i;
160 dodoc -r "${S}"/doc/*
166 # Install bash completion for `npm`
167 # We need to temporarily replace default config path since
168 # npm otherwise tries to write outside of the sandbox
169 local npm_config="usr/$(get_libdir)/node_modules/npm/lib/config/core.js"
170 sed -i -e "s|'/etc'|'${ED}/etc'|g" "${ED}/${npm_config}" || die
171 local tmp_npm_completion_file="$(emktemp)"
172 "${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}"
173 newbashcomp "${tmp_npm_completion_file}" npm
174 sed -i -e "s|'${ED}/etc'|'/etc'|g" "${ED}/${npm_config}" || die
177 doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/*
180 rm "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile} || die
181 rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man} || die
183 local find_exp="-or -name"
185 for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
186 ".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
187 "*.md" "*.markdown" "*.bat" "*.cmd"; do
188 find_name+=( ${find_exp} "${match}" )
191 # Remove various development and/or inappropriate files and
192 # useless docs of dependend packages.
193 find "${LIBDIR}"/node_modules \
194 \( -type d -name examples \) -or \( -type f \( \
197 \) \) -exec rm -rf "{}" \;
202 einfo "The global npm config lives in /etc/npm. This deviates slightly"
203 einfo "from upstream which otherwise would have it live in /usr/etc/."
205 einfo "Protip: When using node-gyp to install native modules, you can"
206 einfo "avoid having to download extras by doing the following:"
207 einfo "$ node-gyp --nodedir /usr/include/node <command>"