We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
PGI doesn't accept "-pthread" switch
I'm trying to compile OpenMPI 2.1.2 with PGI 18.4 and I stumbled upon a pgi error saying that it doen't accept -pthread switch

After few research I saw this thread: https://www.pgroup.com/userforum/viewtopic.php?t=5253&sid=93356f57a47eee097b569b79bc744676
basicaly PGI accept -lpthread instead
and one solution for PGI to accept -pthread would be to modify the siterc in $PGI_INSTALL/bin/siterc

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `easybuild/easyblocks/p/pgi.py`
Content:
```
1 ##
2 # Copyright 2015-2018 Bart Oldeman
3 # Copyright 2016-2018 Forschungszentrum Juelich
4 #
5 # This file is triple-licensed under GPLv2 (see below), MIT, and
6 # BSD three-clause licenses.
7 #
8 # This file is part of EasyBuild,
9 # originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
10 # with support of Ghent University (http://ugent.be/hpc),
11 # the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
12 # Flemish Research Foundation (FWO) (http://www.fwo.be/en)
13 # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
14 #
15 # https://github.com/easybuilders/easybuild
16 #
17 # EasyBuild is free software: you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation v2.
20 #
21 # EasyBuild is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 # GNU General Public License for more details.
25 #
26 # You should have received a copy of the GNU General Public License
27 # along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.
28 ##
29 """
30 EasyBuild support for installing PGI compilers, implemented as an easyblock
31 
32 @author: Bart Oldeman (McGill University, Calcul Quebec, Compute Canada)
33 @author: Damian Alvarez (Forschungszentrum Juelich)
34 """
35 import os
36 import fileinput
37 import re
38 import sys
39 
40 import easybuild.tools.environment as env
41 from easybuild.easyblocks.generic.packedbinary import PackedBinary
42 from easybuild.framework.easyconfig import CUSTOM
43 from easybuild.framework.easyconfig.types import ensure_iterable_license_specs
44 from easybuild.tools.filetools import find_flexlm_license, write_file
45 from easybuild.tools.run import run_cmd
46 from easybuild.tools.modules import get_software_root
47 
48 
49 # contents for siterc file to make PGI pick up $LIBRARY_PATH
50 # cfr. https://www.pgroup.com/support/link.htm#lib_path_ldflags
51 SITERC_LIBRARY_PATH = """
52 # get the value of the environment variable LIBRARY_PATH
53 variable LIBRARY_PATH is environment(LIBRARY_PATH);
54 
55 # split this value at colons, separate by -L, prepend 1st one by -L
56 variable library_path is
57 default($if($LIBRARY_PATH,-L$replace($LIBRARY_PATH,":", -L)));
58 
59 # add the -L arguments to the link line
60 append LDLIBARGS=$library_path;
61 
62 # also include the location where libm & co live on Debian-based systems
63 # cfr. https://github.com/easybuilders/easybuild-easyblocks/pull/919
64 append LDLIBARGS=-L/usr/lib/x86_64-linux-gnu;
65 """
66 
67 
68 class EB_PGI(PackedBinary):
69     """
70     Support for installing the PGI compilers
71     """
72 
73     @staticmethod
74     def extra_options():
75         extra_vars = {
76             'install_amd': [True, "Install AMD software components", CUSTOM],
77             'install_java': [True, "Install Java JRE for graphical debugger",  CUSTOM],
78             'install_managed': [True, "Install OpenACC Unified Memory Evaluation package", CUSTOM],
79             'install_nvidia': [True, "Install CUDA Toolkit Components", CUSTOM],
80         }
81         return PackedBinary.extra_options(extra_vars)
82 
83     def __init__(self, *args, **kwargs):
84         """Easyblock constructor, define custom class variables specific to PGI."""
85         super(EB_PGI, self).__init__(*args, **kwargs)
86 
87         self.license_file = 'UNKNOWN'
88         self.license_env_var = 'UNKNOWN'  # Probably not really necessary for PGI
89 
90         self.pgi_install_subdir = os.path.join('linux86-64', self.version)
91 
92     def configure_step(self):
93         """
94         Handle license file.
95         """
96         default_lic_env_var = 'PGROUPD_LICENSE_FILE'
97         license_specs = ensure_iterable_license_specs(self.cfg['license_file'])
98         lic_specs, self.license_env_var = find_flexlm_license(custom_env_vars=[default_lic_env_var],
99                                                               lic_specs=license_specs)
100 
101         if lic_specs:
102             if self.license_env_var is None:
103                 self.log.info("Using PGI license specifications from 'license_file': %s", lic_specs)
104                 self.license_env_var = default_lic_env_var
105             else:
106                 self.log.info("Using PGI license specifications from %s: %s", self.license_env_var, lic_specs)
107 
108             self.license_file = os.pathsep.join(lic_specs)
109             env.setvar(self.license_env_var, self.license_file)
110 
111         else:
112             self.log.info("No viable license specifications found, assuming PGI Community Edition...")
113 
114     def install_step(self):
115         """Install by running install command."""
116 
117         pgi_env_vars = {
118             'PGI_ACCEPT_EULA': 'accept',
119             'PGI_INSTALL_AMD': str(self.cfg['install_amd']).lower(),
120             'PGI_INSTALL_DIR': self.installdir,
121             'PGI_INSTALL_JAVA': str(self.cfg['install_java']).lower(),
122             'PGI_INSTALL_MANAGED': str(self.cfg['install_managed']).lower(),
123             'PGI_INSTALL_NVIDIA': str(self.cfg['install_nvidia']).lower(),
124             'PGI_SILENT': 'true',
125             }
126         cmd = "%s ./install" % ' '.join(['%s=%s' % x for x in sorted(pgi_env_vars.items())])
127         run_cmd(cmd, log_all=True, simple=True)
128 
129         # make sure localrc uses GCC in PATH, not always the system GCC, and does not use a system g77 but gfortran
130         install_abs_subdir = os.path.join(self.installdir, self.pgi_install_subdir)
131         filename = os.path.join(install_abs_subdir, "bin", "makelocalrc")
132         for line in fileinput.input(filename, inplace='1', backup='.orig'):
133             line = re.sub(r"^PATH=/", r"#PATH=/", line)
134             sys.stdout.write(line)
135 
136         cmd = "%s -x %s -g77 /" % (filename, install_abs_subdir)
137         run_cmd(cmd, log_all=True, simple=True)
138 
139         # If an OS libnuma is NOT found, makelocalrc creates symbolic links to libpgnuma.so
140         # If we use the EB libnuma, delete those symbolic links to ensure they are not used
141         if get_software_root("numactl"):
142             for filename in ["libnuma.so", "libnuma.so.1"]:
143                 path = os.path.join(install_abs_subdir, "lib", filename)
144                 if os.path.islink(path):
145                     os.remove(path)
146 
147         # install (or update) siterc file to make PGI consider $LIBRARY_PATH
148         siterc_path = os.path.join(self.installdir, self.pgi_install_subdir, 'bin', 'siterc')
149         write_file(siterc_path, SITERC_LIBRARY_PATH, append=True)
150         self.log.info("Appended instructions to pick up $LIBRARY_PATH to siterc file at %s: %s",
151                       siterc_path, SITERC_LIBRARY_PATH)
152 
153     def sanity_check_step(self):
154         """Custom sanity check for PGI"""
155         prefix = self.pgi_install_subdir
156         custom_paths = {
157             'files': [os.path.join(prefix, 'bin', x) for x in ['pgcc', 'pgc++', 'pgf77', 'pgfortran', 'siterc']],
158             'dirs': [os.path.join(prefix, 'bin'), os.path.join(prefix, 'lib'),
159                      os.path.join(prefix, 'include'), os.path.join(prefix, 'man')]
160         }
161         super(EB_PGI, self).sanity_check_step(custom_paths=custom_paths)
162 
163     def make_module_req_guess(self):
164         """Prefix subdirectories in PGI install dir considered for environment variables defined in module file."""
165         dirs = super(EB_PGI, self).make_module_req_guess()
166         for key in dirs:
167             dirs[key] = [os.path.join(self.pgi_install_subdir, d) for d in dirs[key]]
168 
169         # $CPATH should not be defined in module for PGI, it causes problems
170         # cfr. https://github.com/easybuilders/easybuild-easyblocks/issues/830
171         if 'CPATH' in dirs:
172             self.log.info("Removing $CPATH entry: %s", dirs['CPATH'])
173             del dirs['CPATH']
174 
175         return dirs
176 
177     def make_module_extra(self):
178         """Add environment variables LM_LICENSE_FILE and PGI for license file and PGI location"""
179         txt = super(EB_PGI, self).make_module_extra()
180         if self.license_env_var:
181             txt += self.module_generator.prepend_paths(self.license_env_var, [self.license_file],
182                                                        allow_abs=True, expand_relpaths=False)
183         txt += self.module_generator.set_environment('PGI', self.installdir)
184         return txt
185
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/easybuild/easyblocks/p/pgi.py b/easybuild/easyblocks/p/pgi.py
--- a/easybuild/easyblocks/p/pgi.py
+++ b/easybuild/easyblocks/p/pgi.py
@@ -64,6 +64,12 @@
 append LDLIBARGS=-L/usr/lib/x86_64-linux-gnu;
 """
 
+# contents for siterc file to make PGI accept the -pthread switch
+SITERC_PTHREAD_SWITCH = """
+# replace unknown switch -pthread with -lpthread
+switch -pthread is replace(-lpthread) positional(linker);
+"""
+
 
 class EB_PGI(PackedBinary):
     """
@@ -144,11 +150,14 @@
                 if os.path.islink(path):
                     os.remove(path)
 
-        # install (or update) siterc file to make PGI consider $LIBRARY_PATH
+        # install (or update) siterc file to make PGI consider $LIBRARY_PATH and accept -pthread
         siterc_path = os.path.join(self.installdir, self.pgi_install_subdir, 'bin', 'siterc')
         write_file(siterc_path, SITERC_LIBRARY_PATH, append=True)
         self.log.info("Appended instructions to pick up $LIBRARY_PATH to siterc file at %s: %s",
                       siterc_path, SITERC_LIBRARY_PATH)
+        write_file(siterc_path, SITERC_PTHREAD_SWITCH, append=True)
+        self.log.info("Append instructions to replace -pthread with -lpthread to siterc file at %s: %s",
+                      siterc_path, SITERC_PTHREAD_SWITCH)
 
     def sanity_check_step(self):
         """Custom sanity check for PGI"""

{"golden_diff": "diff --git a/easybuild/easyblocks/p/pgi.py b/easybuild/easyblocks/p/pgi.py\n--- a/easybuild/easyblocks/p/pgi.py\n+++ b/easybuild/easyblocks/p/pgi.py\n@@ -64,6 +64,12 @@\n append LDLIBARGS=-L/usr/lib/x86_64-linux-gnu;\n \"\"\"\n \n+# contents for siterc file to make PGI accept the -pthread switch\n+SITERC_PTHREAD_SWITCH = \"\"\"\n+# replace unknown switch -pthread with -lpthread\n+switch -pthread is replace(-lpthread) positional(linker);\n+\"\"\"\n+\n \n class EB_PGI(PackedBinary):\n     \"\"\"\n@@ -144,11 +150,14 @@\n                 if os.path.islink(path):\n                     os.remove(path)\n \n-        # install (or update) siterc file to make PGI consider $LIBRARY_PATH\n+        # install (or update) siterc file to make PGI consider $LIBRARY_PATH and accept -pthread\n         siterc_path = os.path.join(self.installdir, self.pgi_install_subdir, 'bin', 'siterc')\n         write_file(siterc_path, SITERC_LIBRARY_PATH, append=True)\n         self.log.info(\"Appended instructions to pick up $LIBRARY_PATH to siterc file at %s: %s\",\n                       siterc_path, SITERC_LIBRARY_PATH)\n+        write_file(siterc_path, SITERC_PTHREAD_SWITCH, append=True)\n+        self.log.info(\"Append instructions to replace -pthread with -lpthread to siterc file at %s: %s\",\n+                      siterc_path, SITERC_PTHREAD_SWITCH)\n \n     def sanity_check_step(self):\n         \"\"\"Custom sanity check for PGI\"\"\"\n", "issue": "PGI doesn't accept \"-pthread\" switch\nI'm trying to compile OpenMPI 2.1.2 with PGI 18.4 and I stumbled upon a pgi error saying that it doen't accept -pthread switch\r\n\r\nAfter few research I saw this thread: https://www.pgroup.com/userforum/viewtopic.php?t=5253&sid=93356f57a47eee097b569b79bc744676\r\nbasicaly PGI accept -lpthread instead\r\nand one solution for PGI to accept -pthread would be to modify the siterc in $PGI_INSTALL/bin/siterc\n", "before_files": [{"content": "##\n# Copyright 2015-2018 Bart Oldeman\n# Copyright 2016-2018 Forschungszentrum Juelich\n#\n# This file is triple-licensed under GPLv2 (see below), MIT, and\n# BSD three-clause licenses.\n#\n# This file is part of EasyBuild,\n# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),\n# with support of Ghent University (http://ugent.be/hpc),\n# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),\n# Flemish Research Foundation (FWO) (http://www.fwo.be/en)\n# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).\n#\n# https://github.com/easybuilders/easybuild\n#\n# EasyBuild is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation v2.\n#\n# EasyBuild is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.\n##\n\"\"\"\nEasyBuild support for installing PGI compilers, implemented as an easyblock\n\n@author: Bart Oldeman (McGill University, Calcul Quebec, Compute Canada)\n@author: Damian Alvarez (Forschungszentrum Juelich)\n\"\"\"\nimport os\nimport fileinput\nimport re\nimport sys\n\nimport easybuild.tools.environment as env\nfrom easybuild.easyblocks.generic.packedbinary import PackedBinary\nfrom easybuild.framework.easyconfig import CUSTOM\nfrom easybuild.framework.easyconfig.types import ensure_iterable_license_specs\nfrom easybuild.tools.filetools import find_flexlm_license, write_file\nfrom easybuild.tools.run import run_cmd\nfrom easybuild.tools.modules import get_software_root\n\n\n# contents for siterc file to make PGI pick up $LIBRARY_PATH\n# cfr. https://www.pgroup.com/support/link.htm#lib_path_ldflags\nSITERC_LIBRARY_PATH = \"\"\"\n# get the value of the environment variable LIBRARY_PATH\nvariable LIBRARY_PATH is environment(LIBRARY_PATH);\n\n# split this value at colons, separate by -L, prepend 1st one by -L\nvariable library_path is\ndefault($if($LIBRARY_PATH,-L$replace($LIBRARY_PATH,\":\", -L)));\n\n# add the -L arguments to the link line\nappend LDLIBARGS=$library_path;\n\n# also include the location where libm & co live on Debian-based systems\n# cfr. https://github.com/easybuilders/easybuild-easyblocks/pull/919\nappend LDLIBARGS=-L/usr/lib/x86_64-linux-gnu;\n\"\"\"\n\n\nclass EB_PGI(PackedBinary):\n    \"\"\"\n    Support for installing the PGI compilers\n    \"\"\"\n\n    @staticmethod\n    def extra_options():\n        extra_vars = {\n            'install_amd': [True, \"Install AMD software components\", CUSTOM],\n            'install_java': [True, \"Install Java JRE for graphical debugger\",  CUSTOM],\n            'install_managed': [True, \"Install OpenACC Unified Memory Evaluation package\", CUSTOM],\n            'install_nvidia': [True, \"Install CUDA Toolkit Components\", CUSTOM],\n        }\n        return PackedBinary.extra_options(extra_vars)\n\n    def __init__(self, *args, **kwargs):\n        \"\"\"Easyblock constructor, define custom class variables specific to PGI.\"\"\"\n        super(EB_PGI, self).__init__(*args, **kwargs)\n\n        self.license_file = 'UNKNOWN'\n        self.license_env_var = 'UNKNOWN'  # Probably not really necessary for PGI\n\n        self.pgi_install_subdir = os.path.join('linux86-64', self.version)\n\n    def configure_step(self):\n        \"\"\"\n        Handle license file.\n        \"\"\"\n        default_lic_env_var = 'PGROUPD_LICENSE_FILE'\n        license_specs = ensure_iterable_license_specs(self.cfg['license_file'])\n        lic_specs, self.license_env_var = find_flexlm_license(custom_env_vars=[default_lic_env_var],\n                                                              lic_specs=license_specs)\n\n        if lic_specs:\n            if self.license_env_var is None:\n                self.log.info(\"Using PGI license specifications from 'license_file': %s\", lic_specs)\n                self.license_env_var = default_lic_env_var\n            else:\n                self.log.info(\"Using PGI license specifications from %s: %s\", self.license_env_var, lic_specs)\n\n            self.license_file = os.pathsep.join(lic_specs)\n            env.setvar(self.license_env_var, self.license_file)\n\n        else:\n            self.log.info(\"No viable license specifications found, assuming PGI Community Edition...\")\n\n    def install_step(self):\n        \"\"\"Install by running install command.\"\"\"\n\n        pgi_env_vars = {\n            'PGI_ACCEPT_EULA': 'accept',\n            'PGI_INSTALL_AMD': str(self.cfg['install_amd']).lower(),\n            'PGI_INSTALL_DIR': self.installdir,\n            'PGI_INSTALL_JAVA': str(self.cfg['install_java']).lower(),\n            'PGI_INSTALL_MANAGED': str(self.cfg['install_managed']).lower(),\n            'PGI_INSTALL_NVIDIA': str(self.cfg['install_nvidia']).lower(),\n            'PGI_SILENT': 'true',\n            }\n        cmd = \"%s ./install\" % ' '.join(['%s=%s' % x for x in sorted(pgi_env_vars.items())])\n        run_cmd(cmd, log_all=True, simple=True)\n\n        # make sure localrc uses GCC in PATH, not always the system GCC, and does not use a system g77 but gfortran\n        install_abs_subdir = os.path.join(self.installdir, self.pgi_install_subdir)\n        filename = os.path.join(install_abs_subdir, \"bin\", \"makelocalrc\")\n        for line in fileinput.input(filename, inplace='1', backup='.orig'):\n            line = re.sub(r\"^PATH=/\", r\"#PATH=/\", line)\n            sys.stdout.write(line)\n\n        cmd = \"%s -x %s -g77 /\" % (filename, install_abs_subdir)\n        run_cmd(cmd, log_all=True, simple=True)\n\n        # If an OS libnuma is NOT found, makelocalrc creates symbolic links to libpgnuma.so\n        # If we use the EB libnuma, delete those symbolic links to ensure they are not used\n        if get_software_root(\"numactl\"):\n            for filename in [\"libnuma.so\", \"libnuma.so.1\"]:\n                path = os.path.join(install_abs_subdir, \"lib\", filename)\n                if os.path.islink(path):\n                    os.remove(path)\n\n        # install (or update) siterc file to make PGI consider $LIBRARY_PATH\n        siterc_path = os.path.join(self.installdir, self.pgi_install_subdir, 'bin', 'siterc')\n        write_file(siterc_path, SITERC_LIBRARY_PATH, append=True)\n        self.log.info(\"Appended instructions to pick up $LIBRARY_PATH to siterc file at %s: %s\",\n                      siterc_path, SITERC_LIBRARY_PATH)\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for PGI\"\"\"\n        prefix = self.pgi_install_subdir\n        custom_paths = {\n            'files': [os.path.join(prefix, 'bin', x) for x in ['pgcc', 'pgc++', 'pgf77', 'pgfortran', 'siterc']],\n            'dirs': [os.path.join(prefix, 'bin'), os.path.join(prefix, 'lib'),\n                     os.path.join(prefix, 'include'), os.path.join(prefix, 'man')]\n        }\n        super(EB_PGI, self).sanity_check_step(custom_paths=custom_paths)\n\n    def make_module_req_guess(self):\n        \"\"\"Prefix subdirectories in PGI install dir considered for environment variables defined in module file.\"\"\"\n        dirs = super(EB_PGI, self).make_module_req_guess()\n        for key in dirs:\n            dirs[key] = [os.path.join(self.pgi_install_subdir, d) for d in dirs[key]]\n\n        # $CPATH should not be defined in module for PGI, it causes problems\n        # cfr. https://github.com/easybuilders/easybuild-easyblocks/issues/830\n        if 'CPATH' in dirs:\n            self.log.info(\"Removing $CPATH entry: %s\", dirs['CPATH'])\n            del dirs['CPATH']\n\n        return dirs\n\n    def make_module_extra(self):\n        \"\"\"Add environment variables LM_LICENSE_FILE and PGI for license file and PGI location\"\"\"\n        txt = super(EB_PGI, self).make_module_extra()\n        if self.license_env_var:\n            txt += self.module_generator.prepend_paths(self.license_env_var, [self.license_file],\n                                                       allow_abs=True, expand_relpaths=False)\n        txt += self.module_generator.set_environment('PGI', self.installdir)\n        return txt\n", "path": "easybuild/easyblocks/p/pgi.py"}], "after_files": [{"content": "##\n# Copyright 2015-2018 Bart Oldeman\n# Copyright 2016-2018 Forschungszentrum Juelich\n#\n# This file is triple-licensed under GPLv2 (see below), MIT, and\n# BSD three-clause licenses.\n#\n# This file is part of EasyBuild,\n# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),\n# with support of Ghent University (http://ugent.be/hpc),\n# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),\n# Flemish Research Foundation (FWO) (http://www.fwo.be/en)\n# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).\n#\n# https://github.com/easybuilders/easybuild\n#\n# EasyBuild is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation v2.\n#\n# EasyBuild is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.\n##\n\"\"\"\nEasyBuild support for installing PGI compilers, implemented as an easyblock\n\n@author: Bart Oldeman (McGill University, Calcul Quebec, Compute Canada)\n@author: Damian Alvarez (Forschungszentrum Juelich)\n\"\"\"\nimport os\nimport fileinput\nimport re\nimport sys\n\nimport easybuild.tools.environment as env\nfrom easybuild.easyblocks.generic.packedbinary import PackedBinary\nfrom easybuild.framework.easyconfig import CUSTOM\nfrom easybuild.framework.easyconfig.types import ensure_iterable_license_specs\nfrom easybuild.tools.filetools import find_flexlm_license, write_file\nfrom easybuild.tools.run import run_cmd\nfrom easybuild.tools.modules import get_software_root\n\n\n# contents for siterc file to make PGI pick up $LIBRARY_PATH\n# cfr. https://www.pgroup.com/support/link.htm#lib_path_ldflags\nSITERC_LIBRARY_PATH = \"\"\"\n# get the value of the environment variable LIBRARY_PATH\nvariable LIBRARY_PATH is environment(LIBRARY_PATH);\n\n# split this value at colons, separate by -L, prepend 1st one by -L\nvariable library_path is\ndefault($if($LIBRARY_PATH,-L$replace($LIBRARY_PATH,\":\", -L)));\n\n# add the -L arguments to the link line\nappend LDLIBARGS=$library_path;\n\n# also include the location where libm & co live on Debian-based systems\n# cfr. https://github.com/easybuilders/easybuild-easyblocks/pull/919\nappend LDLIBARGS=-L/usr/lib/x86_64-linux-gnu;\n\"\"\"\n\n# contents for siterc file to make PGI accept the -pthread switch\nSITERC_PTHREAD_SWITCH = \"\"\"\n# replace unknown switch -pthread with -lpthread\nswitch -pthread is replace(-lpthread) positional(linker);\n\"\"\"\n\n\nclass EB_PGI(PackedBinary):\n    \"\"\"\n    Support for installing the PGI compilers\n    \"\"\"\n\n    @staticmethod\n    def extra_options():\n        extra_vars = {\n            'install_amd': [True, \"Install AMD software components\", CUSTOM],\n            'install_java': [True, \"Install Java JRE for graphical debugger\",  CUSTOM],\n            'install_managed': [True, \"Install OpenACC Unified Memory Evaluation package\", CUSTOM],\n            'install_nvidia': [True, \"Install CUDA Toolkit Components\", CUSTOM],\n        }\n        return PackedBinary.extra_options(extra_vars)\n\n    def __init__(self, *args, **kwargs):\n        \"\"\"Easyblock constructor, define custom class variables specific to PGI.\"\"\"\n        super(EB_PGI, self).__init__(*args, **kwargs)\n\n        self.license_file = 'UNKNOWN'\n        self.license_env_var = 'UNKNOWN'  # Probably not really necessary for PGI\n\n        self.pgi_install_subdir = os.path.join('linux86-64', self.version)\n\n    def configure_step(self):\n        \"\"\"\n        Handle license file.\n        \"\"\"\n        default_lic_env_var = 'PGROUPD_LICENSE_FILE'\n        license_specs = ensure_iterable_license_specs(self.cfg['license_file'])\n        lic_specs, self.license_env_var = find_flexlm_license(custom_env_vars=[default_lic_env_var],\n                                                              lic_specs=license_specs)\n\n        if lic_specs:\n            if self.license_env_var is None:\n                self.log.info(\"Using PGI license specifications from 'license_file': %s\", lic_specs)\n                self.license_env_var = default_lic_env_var\n            else:\n                self.log.info(\"Using PGI license specifications from %s: %s\", self.license_env_var, lic_specs)\n\n            self.license_file = os.pathsep.join(lic_specs)\n            env.setvar(self.license_env_var, self.license_file)\n\n        else:\n            self.log.info(\"No viable license specifications found, assuming PGI Community Edition...\")\n\n    def install_step(self):\n        \"\"\"Install by running install command.\"\"\"\n\n        pgi_env_vars = {\n            'PGI_ACCEPT_EULA': 'accept',\n            'PGI_INSTALL_AMD': str(self.cfg['install_amd']).lower(),\n            'PGI_INSTALL_DIR': self.installdir,\n            'PGI_INSTALL_JAVA': str(self.cfg['install_java']).lower(),\n            'PGI_INSTALL_MANAGED': str(self.cfg['install_managed']).lower(),\n            'PGI_INSTALL_NVIDIA': str(self.cfg['install_nvidia']).lower(),\n            'PGI_SILENT': 'true',\n            }\n        cmd = \"%s ./install\" % ' '.join(['%s=%s' % x for x in sorted(pgi_env_vars.items())])\n        run_cmd(cmd, log_all=True, simple=True)\n\n        # make sure localrc uses GCC in PATH, not always the system GCC, and does not use a system g77 but gfortran\n        install_abs_subdir = os.path.join(self.installdir, self.pgi_install_subdir)\n        filename = os.path.join(install_abs_subdir, \"bin\", \"makelocalrc\")\n        for line in fileinput.input(filename, inplace='1', backup='.orig'):\n            line = re.sub(r\"^PATH=/\", r\"#PATH=/\", line)\n            sys.stdout.write(line)\n\n        cmd = \"%s -x %s -g77 /\" % (filename, install_abs_subdir)\n        run_cmd(cmd, log_all=True, simple=True)\n\n        # If an OS libnuma is NOT found, makelocalrc creates symbolic links to libpgnuma.so\n        # If we use the EB libnuma, delete those symbolic links to ensure they are not used\n        if get_software_root(\"numactl\"):\n            for filename in [\"libnuma.so\", \"libnuma.so.1\"]:\n                path = os.path.join(install_abs_subdir, \"lib\", filename)\n                if os.path.islink(path):\n                    os.remove(path)\n\n        # install (or update) siterc file to make PGI consider $LIBRARY_PATH and accept -pthread\n        siterc_path = os.path.join(self.installdir, self.pgi_install_subdir, 'bin', 'siterc')\n        write_file(siterc_path, SITERC_LIBRARY_PATH, append=True)\n        self.log.info(\"Appended instructions to pick up $LIBRARY_PATH to siterc file at %s: %s\",\n                      siterc_path, SITERC_LIBRARY_PATH)\n        write_file(siterc_path, SITERC_PTHREAD_SWITCH, append=True)\n        self.log.info(\"Append instructions to replace -pthread with -lpthread to siterc file at %s: %s\",\n                      siterc_path, SITERC_PTHREAD_SWITCH)\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for PGI\"\"\"\n        prefix = self.pgi_install_subdir\n        custom_paths = {\n            'files': [os.path.join(prefix, 'bin', x) for x in ['pgcc', 'pgc++', 'pgf77', 'pgfortran', 'siterc']],\n            'dirs': [os.path.join(prefix, 'bin'), os.path.join(prefix, 'lib'),\n                     os.path.join(prefix, 'include'), os.path.join(prefix, 'man')]\n        }\n        super(EB_PGI, self).sanity_check_step(custom_paths=custom_paths)\n\n    def make_module_req_guess(self):\n        \"\"\"Prefix subdirectories in PGI install dir considered for environment variables defined in module file.\"\"\"\n        dirs = super(EB_PGI, self).make_module_req_guess()\n        for key in dirs:\n            dirs[key] = [os.path.join(self.pgi_install_subdir, d) for d in dirs[key]]\n\n        # $CPATH should not be defined in module for PGI, it causes problems\n        # cfr. https://github.com/easybuilders/easybuild-easyblocks/issues/830\n        if 'CPATH' in dirs:\n            self.log.info(\"Removing $CPATH entry: %s\", dirs['CPATH'])\n            del dirs['CPATH']\n\n        return dirs\n\n    def make_module_extra(self):\n        \"\"\"Add environment variables LM_LICENSE_FILE and PGI for license file and PGI location\"\"\"\n        txt = super(EB_PGI, self).make_module_extra()\n        if self.license_env_var:\n            txt += self.module_generator.prepend_paths(self.license_env_var, [self.license_file],\n                                                       allow_abs=True, expand_relpaths=False)\n        txt += self.module_generator.set_environment('PGI', self.installdir)\n        return txt\n", "path": "easybuild/easyblocks/p/pgi.py"}]}