diff --git a/node.c b/node.c index 303c627..ef320ee 100644 --- a/node.c +++ b/node.c @@ -5,6 +5,10 @@ #include #include +#ifdef HAVE_LIBALTERNATIVES_H +#include +#endif + const unsigned min_version = 4; const unsigned max_version = 42; const char *default_version = "-default"; @@ -62,6 +66,14 @@ int main(int argc, char *argv[]) printInvalidVersion(version); } +#ifdef HAVE_LIBALTERNATIVES_H + // if we want default version and not using update-alternatives + if (version == default_version) + { + return execDefault(argv); + } +#endif + /* Generate our program path and check that we can execute it */ char *program_path, *program; if (asprintf(&program, "%s%s", *bn, version) == -1 || diff --git a/nodejs-common.spec b/nodejs-common.spec index d7ac546..9b9f571 100644 --- a/nodejs-common.spec +++ b/nodejs-common.spec @@ -28,6 +28,8 @@ %define NODEJS_LTS 16 %define NODEJS_CURRENT 16 +%bcond_with libalternatives + # SLE-12 variants %if 0%{?suse_version} < 1500 %define default_node_ver %NODEJS_LTS @@ -78,6 +80,10 @@ Conflicts: nodejs6 < 6.11.1 Conflicts: nodejs7 < 7.10.1 Conflicts: nodejs8 < 8.1.4 BuildRequires: gcc +%if %{with libalternatives} +BuildRequires: libalternatives-devel +%define libalternatives_flags -DHAVE_LIBALTERNATIVES_H -lalternatives +%endif %description Common NodeJS files that allow recursive invocation of Node executable @@ -120,7 +126,7 @@ the current architecture and codestream. %prep %build cp %{S:2} . -gcc ${RPM_OPT_FLAGS} -o node %{S:1} +gcc ${RPM_OPT_FLAGS} %?libalternatives_flags -o node %{S:1} echo "Default Node version: " %{default_node_ver}