From 7a5e527cab5980cb4732bb3504fab77d75286a19 Mon Sep 17 00:00:00 2001 From: Sergey Kosukhin Date: Thu, 24 Nov 2022 20:10:18 +0100 Subject: zlib: fix shared libraries when '%nvhpc' (#34039) --- var/spack/repos/builtin/packages/zlib/package.py | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/var/spack/repos/builtin/packages/zlib/package.py b/var/spack/repos/builtin/packages/zlib/package.py index f8af00163b..846675e32f 100644 --- a/var/spack/repos/builtin/packages/zlib/package.py +++ b/var/spack/repos/builtin/packages/zlib/package.py @@ -77,6 +77,43 @@ class MakefileBuilder(spack.build_systems.makefile.MakefileBuilder, SetupEnviron config_args.append("--static") configure("--prefix={0}".format(prefix), *config_args) + if "+shared" in self.spec: + # We need to fix the building of the shared libraries with compilers that are not + # recognized as gcc. Note that a compiler is recognized as gcc if it has "gcc" or + # "clang" substring either in its executable name (including the path) or in the output + # generated with the `-v` flag (i.e '$CC -v 2>&1'). The latter is the reason why, for + # example, %intel and %oneapi are often recognized as gcc: they almost always contain + # "gcc" in the verbose output. Another example is %pgi, which has "gcc" in the name of + # the C compiler (pgcc) and in the verbose output (e.g. "pgcc-Warning-No files to + # process"). Although we should not rely on the false positive results of the configure + # script but patch the makefile for all the aforementioned compilers, given the + # importance of the package, we try to be conservative for now and do the patching only + # for compilers that will not produce a correct shared library otherwise. + if self.spec.compiler.name in ["nvhpc"]: + if "~pic" in self.spec: + # In this case, we should build the static library without PIC, therefore we + # don't append the respective compiler flag to CFLAGS in the build environment. + # However, we need the flag for the objects of the shared library: + filter_file( + r"^(SFLAGS *=.*)$", + r"\1 {0}".format(self.pkg.compiler.cc_pic_flag), + "Makefile", + ) + if any(self.spec.satisfies("platform={0}".format(p)) for p in ["linux", "cray"]): + # Without the following, the shared library will not have a soname entry. + # Currently, we support linux and cray platforms only. + filter_file( + r"^(LDSHARED *= *).*$", + # Note that we should use '-Wl,` and not self.pkg.compiler.linker_arg + # because the former is understood by virtually every C compiler and the + # latter might be meant for the Fortran compiler only (e.g. NAG): + r"\1 {0} -shared " + r"-Wl,-soname,libz.{1}.{2},--version-script,zlib.map".format( + spack_cc, dso_suffix, self.spec.version.up_to(1) + ), + "Makefile", + ) + class GenericBuilder(spack.build_systems.generic.GenericBuilder, SetupEnvironment): def install(self, spec, prefix): -- cgit v1.2.3-70-g09d2