1PORTNAME=	node
2PORTVERSION=	${NODEJS_PORTVERSION}
3DISTVERSIONPREFIX=	v
4CATEGORIES=	www
5MASTER_SITES=	https://nodejs.org/dist/v${PORTVERSION}/
6PKGNAMESUFFIX=	${PORTVERSION:R:R}
7
8MAINTAINER=	ports@MidnightBSD.org
9COMMENT=	V8 JavaScript for client and server
10WWW=		https://nodejs.org/ \
11		https://github.com/nodejs/node
12
13LICENSE=	mit
14LICENSE_FILE=	${WRKSRC}/LICENSE
15
16BROKEN_SSL=	libressl libressl-devel
17BROKEN_SSL_REASON=	Node.js ${PORTVERSION:R:R}.x requires OpenSSL or the BUNDLED_SSL option enabled
18ONLY_FOR_ARCHS=	aarch64 amd64 armv6 armv7 i386 powerpc64 powerpc64le
19
20BUILD_DEPENDS=	brotli>=1.0.9,1:archivers/brotli \
21		c-ares>=1.17.2:dns/c-ares \
22		libnghttp2>=1.45.1:www/libnghttp2 \
23		libuv>=1.42.0:devel/libuv \
24		objdump:devel/binutils
25LIB_DEPENDS=	libbrotlidec.so:archivers/brotli \
26		libcares.so:dns/c-ares \
27		libnghttp2.so:www/libnghttp2 \
28		libuv.so:devel/libuv
29
30USES=		compiler:c++11-lib gmake localbase pkgconfig python:build shebangfix tar:xz
31
32CONFIGURE_ARGS=	--prefix=${PREFIX:S|^${DESTDIR}||} \
33		--shared-brotli \
34		--shared-cares \
35		--shared-libuv \
36		--shared-nghttp2 \
37		--shared-zlib \
38		--without-npm \
39		--dest-os=freebsd
40HAS_CONFIGURE=	yes
41MAKE_ENV=	CC.host="${CCACHE_BIN} ${CC}" \
42		CFLAGS.host="${CFLAGS}" \
43		CXX.host="${CCACHE_BIN} ${CXX}" \
44		CXXFLAGS.host="${CXXFLAGS}" \
45		LDFLAGS.host="${LDFLAGS}" \
46		LINK.host="${CXX}"
47REINPLACE_ARGS=	-i ''
48
49CONFLICTS_INSTALL=	node[0-9][0-9]
50
51SHEBANG_FILES=	deps/v8/third_party/inspector_protocol/*.py \
52		deps/v8/tools/*.py \
53		tools/*.py \
54		tools/inspector_protocol/*.py
55
56OPTIONS_DEFINE=	BUNDLED_SSL DOCS ICU JIT
57OPTIONS_DEFAULT=ICU JIT
58OPTIONS_SUB=	yes
59BUNDLED_SSL_DESC=	Use bundled OpenSSL implementation from node.js
60JIT_DESC=		Use Just In Time compiler
61
62BUNDLED_SSL_CONFIGURE_OFF=	--openssl-use-def-ca-store --shared-openssl
63BUNDLED_SSL_RUN_DEPENDS_OFF=	ca_root_nss>=0:security/ca_root_nss
64BUNDLED_SSL_USES_OFF=	ssl
65ICU_BUILD_DEPENDS=	icu>=69.1:devel/icu
66ICU_CONFIGURE_ON=	--with-intl=system-icu
67ICU_LIB_DEPENDS=	libicui18n.so:devel/icu
68JIT_CONFIGURE_OFF=	--v8-lite-mode
69
70.include "Makefile.version"
71.include <bsd.mport.options.mk>
72
73.if ${PORT_OPTIONS:MBUNDLED_SSL} && ${ARCH} != amd64
74CONFIGURE_ARGS+=--openssl-no-asm
75.endif
76
77post-patch:
78	@${REINPLACE_CMD} -e 's|/usr/local|${LOCALBASE}|' ${WRKSRC}/tools/v8_gypfiles/v8.gyp
79
80post-configure:
81	# Post-process Makefile and *.mk files created by node-gyp and remove
82	# all occurrences of -I${LOCALBASE}/include. C*FLAGS include this
83	# before all -I../deps/* for bundled code. This can cause build
84	# breakages if the dependency is installed in ${LOCALBASE}. The
85	# USES+=localbase # above will ensure that we pick up includes for real
86	# external dependencies.
87	${FIND} ${WRKSRC}/out -type f -print0 | ${XARGS} -0 ${REINPLACE_CMD} -e "s|-I${LOCALBASE}/include||g"
88
89post-install:
90	${STRIP_CMD} ${PREFIX}/bin/node
91
92.include <bsd.port.mk>
93