diff --git a/node.c b/node.c index 303c627..cceadb3 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,17 @@ 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) + { + // should not return, and if it does, it probably means + // we should fall back to using node-default fallback. + libalts_exec_default(argv); + fputs("Falling back to using -default symlink.\n", stderr); + } +#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.changes b/nodejs-common.changes index a8122f2..c58ec45 100644 --- a/nodejs-common.changes +++ b/nodejs-common.changes @@ -1,3 +1,13 @@ +------------------------------------------------------------------- +Thu Jun 10 10:27:58 UTC 2021 - Adam Majer + +- Use libalternatives on TW by default + +------------------------------------------------------------------- +Mon May 31 16:32:18 UTC 2021 - Adam Majer + +- Add libalternatives support + ------------------------------------------------------------------- Thu May 6 12:50:02 UTC 2021 - Adam Majer diff --git a/nodejs-common.spec b/nodejs-common.spec index d7ac546..c6ad49f 100644 --- a/nodejs-common.spec +++ b/nodejs-common.spec @@ -28,6 +28,12 @@ %define NODEJS_LTS 16 %define NODEJS_CURRENT 16 +%if 0%{?suse_version} > 1500 +%bcond_without libalternatives +%else +%bcond_with libalternatives +%endif + # SLE-12 variants %if 0%{?suse_version} < 1500 %define default_node_ver %NODEJS_LTS @@ -64,7 +70,7 @@ %endif Name: nodejs-common -Version: 4.1 +Version: 5.0 Release: 0 Summary: Common files for the NodeJS ecosystem License: MIT @@ -78,6 +84,11 @@ 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_cflags -DHAVE_LIBALTERNATIVES_H +%define libalternatives_lflags -lalternatives +%endif %description Common NodeJS files that allow recursive invocation of Node executable @@ -120,7 +131,7 @@ the current architecture and codestream. %prep %build cp %{S:2} . -gcc ${RPM_OPT_FLAGS} -o node %{S:1} +gcc ${RPM_OPT_FLAGS} %?libalternatives_cflags -o node %{S:1} %?libalternatives_lflags echo "Default Node version: " %{default_node_ver}