File nodejs.spec of Package nodejs.openSUSE_Leap_42.1_Update

#
# spec file for package nodejs
#
# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


%define npm_version 2.15.11
Name:           nodejs
Version:        4.7.3
Release:        0
Summary:        Evented I/O for V8 JavaScript
License:        MIT
Group:          Development/Languages/NodeJS
Url:            http://www.nodejs.org
Source:         http://nodejs.org/dist/v%{version}/node-v%{version}.tar.xz
Patch6:         nodejs-libpath.patch
# PATCH-FIX-UPSTREAM use custom addon.gypi by default instead of downloading node source
Patch7:         node-gyp-addon-gypi.patch
BuildRequires:	binutils-gold
BuildRequires:  curl
BuildRequires:  fdupes
BuildRequires:  gcc-c++
BuildRequires:  pkg-config
BuildRequires:  procps
BuildRequires:  python
BuildRequires:  xz
BuildRequires:  zlib-devel
Recommends:     npm(npm) = %{npm_version}
#we need ABI virtual provides where SONAMEs aren't enough/not present so deps
#break when binary compatibility is broken
%global nodejs_abi 4.0
Provides:       nodejs(abi) = %{nodejs_abi}
#this corresponds to the "engine" requirement in package.json
Provides:       nodejs(engine) = %{version}
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
#building nodejs makes sense only on v8 archs
ExclusiveArch:  %ix86 x86_64 armv7hl aarch64 ppc ppc64 ppc64le s390x
%if 0%{?suse_version}
BuildRequires:  libopenssl-devel
%else
BuildRequires:  openssl-devel
%endif

%description
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine.
Node.js uses an event-driven, non-blocking I/O model that makes it
lightweight and efficient. Node.js' package ecosystem, npm, is the largest
ecosystem of open source libraries in the world.

%package devel
Summary:        Files needed for development of NodeJS platforms
Group:          Development/Languages/NodeJS
Requires:       %{name} = %{version}

%description devel
This package provides development headers for Node.js.

%package docs
Summary:        Node.js API documentation
Group:          Documentation/NodeJS
%if 0%{?suse_version} >= 1200
# using noarch subpackage seems to break debuginfo on older releases
BuildArch:      noarch
%endif

%description docs
The API documentation for the Node.js JavaScript runtime.

%package -n npm
Summary:        Package manager for Node.js
Group:          Development/Languages/NodeJS
Requires:       %{name}-devel = %{version}
Provides:	npm(npm) = %{npm_version}
Conflicts:      otherproviders(npm(npm))
Provides:       nodejs-npm = %{version}
Obsoletes:      nodejs-npm <= 4.2.1-10.1

%description -n npm
A package manager for Node.js.

%prep
%setup -q -n node-v%{version}
%patch6 -p1
%patch7 -p1
# Make sure nothing gets included from bundled deps:
# We only delete the source and header files, because
# the remaining build scripts are still used.
###for dir in v8 openssl zlib; do
%if 0%{?suse_version} > 1320
for dir in openssl zlib; do
  find deps/$dir -name *.[ch] -delete
done
%else
find deps/zlib -name *.[ch] -delete
%endif

%build
# percent-configure pulls in something that confuses node's configure
# script, so we'll do it thus:
export CFLAGS="%{optflags}"
export CXXFLAGS="%{optflags}"
./configure \
    --prefix=%{_prefix} \
%if 0%{?suse_version} > 1320
    # Node.js 4.x requires OpenSSL 1.0.2, but Leap 42.1 only has 1.0.1.
    --shared-openssl \
%endif
    --shared-zlib \
%ifarch aarch64
    --dest-cpu=arm64 \
%endif
%ifarch s390x
    --dest-cpu=s390x \
%endif
%ifnarch aarch64 ppc ppc64 ppc64le s390x
    --gdb \
%endif
    --without-dtrace
#    --shared-v8 \
#    --shared-cares
%ifarch aarch64
make %{?_smp_mflags} DESTCPU=aarch64
%else
%ifarch s390x
make %{?_smp_mflags} DESTCPU=s390x
%else
make %{?_smp_mflags}
%endif
%endif

%install
make DESTDIR=%{buildroot} install %{?_smp_mflags}
rm -rf %{buildroot}%{_datadir}/doc/node

# npm man page
rm -rf %{buildroot}%{_libdir}/node_modules/npm/man
mkdir -p %{buildroot}%{_mandir}/{man1,man3,man5,man7}
install -m 644 deps/npm/man/man1/* %{buildroot}%{_mandir}/man1
install -m 644 deps/npm/man/man3/* %{buildroot}%{_mandir}/man3
install -m 644 deps/npm/man/man5/* %{buildroot}%{_mandir}/man5
install -m 644 deps/npm/man/man7/* %{buildroot}%{_mandir}/man7

#node-gyp needs common.gypi too
mkdir -p %{buildroot}%{_datadir}/node
install -m 644 common.gypi \
	%{buildroot}%{_datadir}/node
#install addon-rpm.gypi
mkdir -p %{buildroot}%{_libdir}/node_modules/npm/node_modules/node-gyp/
install -m 644 addon-rpm.gypi \
	%{buildroot}%{_libdir}/node_modules/npm/node_modules/node-gyp/

# Own nodejs_sitelib
mkdir -p %{buildroot}%{_libexecdir}/node_modules

# clean
# file duplicates
%fdupes %{buildroot}%{_libdir}/node_modules/npm/
%fdupes %{buildroot}%{_includedir}/node
# hidden files
find %{buildroot}%{_libdir}/node_modules/npm -name ".nyc_output" -type d -exec rm -rf {} +
find %{buildroot}%{_libdir}/node_modules/npm -name ".*" -delete
# windows stuff
find %{buildroot}%{_libdir}/node_modules/npm -name "*.bat" -delete
find %{buildroot}%{_libdir}/node_modules/npm -name "*.cmd" -delete
# build stuff
find %{buildroot}%{_libdir}/node_modules/npm -name "Makefile" -delete
rm -rf %{buildroot}%{_libdir}/node_modules/npm/{test,scripts}
find %{buildroot}%{_libdir}/node_modules/npm/node_modules -name "*.sh" -delete
find %{buildroot}%{_libdir}/node_modules/npm -name "src" -print0 | xargs -0 rm -rf --
# remove examples/tests/benchmark stuff
find %{buildroot}%{_libdir}/node_modules/npm/node_modules -name "example*" -print0 | xargs -0 rm -rf --
find %{buildroot}%{_libdir}/node_modules/npm/node_modules -name "test*" -print0 | xargs -0 rm -rf --
find %{buildroot}%{_libdir}/node_modules/npm/node_modules -name "*_test.*" -delete
find %{buildroot}%{_libdir}/node_modules/npm/node_modules -type d -name "benchmark" -print0 | xargs -0 rm -rf --
# README.md LICENSE file permission
find %{buildroot}%{_libdir}/node_modules/npm -name "README.md" -exec chmod -x {} +
find %{buildroot}%{_libdir}/node_modules/npm -name "LICENSE" -exec chmod -x {} +
# browser.js is useless for npm cli
find %{buildroot}%{_libdir}/node_modules/npm -name "browser.js" -delete

# Check that Node.js isn't completely broken.
%check
%{buildroot}%{_bindir}/node -e 'require("assert").strictEqual(process.versions.node, "%{version}");'

%files
%defattr(-, root, root)
%doc AUTHORS LICENSE *.md
%{_bindir}/node
%{_libexecdir}/node_modules
%{_mandir}/man1/node.1%{ext_man}
%exclude %{_libdir}/node_modules/npm

%files -n npm
%defattr(-, root, root)
%{_bindir}/npm
%dir %{_libdir}/node_modules
%{_libdir}/node_modules/npm
%{_mandir}/man*/*
%exclude %{_mandir}/man1/node.1%{ext_man}

%files devel
%defattr(-, root, root)
%{_includedir}/node
%{_datadir}/node
%dir %{_datadir}/systemtap
%dir %{_datadir}/systemtap/tapset
%{_datadir}/systemtap/tapset/node.stp

%files docs
%defattr(-,root,root)
%doc doc/api

%changelog
openSUSE Build Service is sponsored by