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