From 5bfeffdf4b5de1c60a2ff0d1ddf65db2bb9a1533 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Tue, 19 Mar 2019 23:22:40 -0400
Subject: [PATCH 3/3] Install both binaries and use libdir.

This allows us to build with a shared library for other users while
still providing the normal executable.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>

Stolen from [1]

[1] https://src.fedoraproject.org/rpms/nodejs/raw/master/f/0003-Install-both-binaries-and-use-libdir.patch

Upstream-Status: Pending

Signed-off-by: Andreas Müller <schnitzeltony@gmail.com>
---
 configure.py     |  7 +++++++
 tools/install.py | 31 ++++++++++++++-----------------
 2 files changed, 21 insertions(+), 17 deletions(-)

--- a/configure.py
+++ b/configure.py
@@ -602,6 +602,12 @@ parser.add_option('--shared',
     help='compile shared library for embedding node in another project. ' +
          '(This mode is not officially supported for regular applications)')
 
+parser.add_option('--libdir',
+    action='store',
+    dest='libdir',
+    default='lib',
+    help='a directory to install the shared library into')
+
 parser.add_option('--without-v8-platform',
     action='store_true',
     dest='without_v8_platform',
@@ -1168,6 +1174,7 @@ def configure_node(o):
   o['variables']['node_no_browser_globals'] = b(options.no_browser_globals)
 
   o['variables']['node_shared'] = b(options.shared)
+  o['variables']['libdir'] = options.libdir
   node_module_version = getmoduleversion.get_version()
 
   if options.dest_os == 'android':
--- a/tools/install.py
+++ b/tools/install.py
@@ -121,26 +121,23 @@ def subdir_files(path, dest, action):
 
 def files(action):
   is_windows = sys.platform == 'win32'
-  output_file = 'node'
   output_prefix = 'out/Release/'
+  output_libprefix = output_prefix
 
-  if 'false' == variables.get('node_shared'):
-    if is_windows:
-      output_file += '.exe'
+  if is_windows:
+    output_bin = 'node.exe'
+    output_lib = 'node.dll'
   else:
-    if is_windows:
-      output_file += '.dll'
-    else:
-      output_file = 'lib' + output_file + '.' + variables.get('shlib_suffix')
-      # GYP will output to lib.target except on OS X, this is hardcoded
-      # in its source - see the _InstallableTargetInstallPath function.
-      if sys.platform != 'darwin':
-        output_prefix += 'lib.target/'
+    output_bin = 'node'
+    output_lib = 'libnode.' + variables.get('shlib_suffix')
+    # GYP will output to lib.target except on OS X, this is hardcoded
+    # in its source - see the _InstallableTargetInstallPath function.
+    if sys.platform != 'darwin':
+      output_libprefix += 'lib.target/'
 
-  if 'false' == variables.get('node_shared'):
-    action([output_prefix + output_file], 'bin/' + output_file)
-  else:
-    action([output_prefix + output_file], 'lib/' + output_file)
+  action([output_prefix + output_bin], 'bin/' + output_bin)
+  if 'true' == variables.get('node_shared'):
+    action([output_libprefix + output_lib], variables.get('libdir') + '/' + output_lib)
 
   if 'true' == variables.get('node_use_dtrace'):
     action(['out/Release/node.d'], 'lib/dtrace/node.d')
