We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add ability to turn off LAPACK in ESMF
I have found myself in the situation where I want to build ESMF without LAPACK dependent code paths - the EasyBlock forces the build into the 'user specified LAPACK' mode and doesn't allow this (unless I'm missing something!).

Adding an extra option to disable LAPACK would allow for non-LAPACK builds. PR to follow.

--- 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/e/esmf.py`
Content:
```
1 ##
2 # Copyright 2013-2022 Ghent University
3 #
4 # This file is part of EasyBuild,
5 # originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
6 # with support of Ghent University (http://ugent.be/hpc),
7 # the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
8 # Flemish Research Foundation (FWO) (http://www.fwo.be/en)
9 # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
10 #
11 # https://github.com/easybuilders/easybuild
12 #
13 # EasyBuild is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation v2.
16 #
17 # EasyBuild is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with EasyBuild.  If not, see <http://www.gnu.org/licenses/>.
24 ##
25 """
26 EasyBuild support for building and installing ESMF, implemented as an easyblock
27 
28 @author: Kenneth Hoste (Ghent University)
29 @author: Damian Alvarez (Forschungszentrum Juelich GmbH)
30 @author: Maxime Boissonneault (Digital Research Alliance of Canada)
31 """
32 import os
33 from distutils.version import LooseVersion
34 
35 import easybuild.tools.environment as env
36 import easybuild.tools.toolchain as toolchain
37 from easybuild.easyblocks.generic.configuremake import ConfigureMake
38 from easybuild.tools.build_log import EasyBuildError
39 from easybuild.tools.modules import get_software_root, get_software_version
40 from easybuild.tools.run import run_cmd
41 from easybuild.tools.systemtools import get_shared_lib_ext
42 
43 
44 class EB_ESMF(ConfigureMake):
45     """Support for building/installing ESMF."""
46 
47     def configure_step(self):
48         """Custom configuration procedure for ESMF through environment variables."""
49 
50         env.setvar('ESMF_DIR', self.cfg['start_dir'])
51         env.setvar('ESMF_INSTALL_PREFIX', self.installdir)
52         env.setvar('ESMF_INSTALL_BINDIR', 'bin')
53         env.setvar('ESMF_INSTALL_LIBDIR', 'lib')
54         env.setvar('ESMF_INSTALL_MODDIR', 'mod')
55 
56         # specify compiler
57         comp_family = self.toolchain.comp_family()
58         if comp_family in [toolchain.GCC]:
59             compiler = 'gfortran'
60         else:
61             compiler = comp_family.lower()
62         env.setvar('ESMF_COMPILER', compiler)
63 
64         env.setvar('ESMF_F90COMPILEOPTS', os.getenv('F90FLAGS'))
65         env.setvar('ESMF_CXXCOMPILEOPTS', os.getenv('CXXFLAGS'))
66 
67         # specify MPI communications library
68         comm = None
69         mpi_family = self.toolchain.mpi_family()
70         if mpi_family in [toolchain.MPICH, toolchain.QLOGICMPI]:
71             # MPICH family for MPICH v3.x, which is MPICH2 compatible
72             comm = 'mpich2'
73         else:
74             comm = mpi_family.lower()
75         env.setvar('ESMF_COMM', comm)
76 
77         # specify decent LAPACK lib
78         env.setvar('ESMF_LAPACK', 'user')
79         ldflags = os.getenv('LDFLAGS')
80         liblapack = os.getenv('LIBLAPACK_MT') or os.getenv('LIBLAPACK')
81         if liblapack is None:
82             raise EasyBuildError("$LIBLAPACK(_MT) not defined, no BLAS/LAPACK in %s toolchain?", self.toolchain.name)
83         else:
84             env.setvar('ESMF_LAPACK_LIBS', ldflags + ' ' + liblapack)
85 
86         # specify netCDF
87         netcdf = get_software_root('netCDF')
88         if netcdf:
89             if LooseVersion(self.version) >= LooseVersion('7.1.0'):
90                 env.setvar('ESMF_NETCDF', 'nc-config')
91             else:
92                 env.setvar('ESMF_NETCDF', 'user')
93                 netcdf_libs = ['-L%s/lib' % netcdf, '-lnetcdf']
94 
95                 # Fortran
96                 netcdff = get_software_root('netCDF-Fortran')
97                 if netcdff:
98                     netcdf_libs = ["-L%s/lib" % netcdff] + netcdf_libs + ["-lnetcdff"]
99                 else:
100                     netcdf_libs.append('-lnetcdff')
101 
102                 # C++
103                 netcdfcxx = get_software_root('netCDF-C++')
104                 if netcdfcxx:
105                     netcdf_libs = ["-L%s/lib" % netcdfcxx] + netcdf_libs + ["-lnetcdf_c++"]
106                 else:
107                     netcdfcxx = get_software_root('netCDF-C++4')
108                     if netcdfcxx:
109                         netcdf_libs = ["-L%s/lib" % netcdfcxx] + netcdf_libs + ["-lnetcdf_c++4"]
110                     else:
111                         netcdf_libs.append('-lnetcdf_c++')
112                 env.setvar('ESMF_NETCDF_LIBS', ' '.join(netcdf_libs))
113 
114         # 'make info' provides useful debug info
115         cmd = "make info"
116         run_cmd(cmd, log_all=True, simple=True, log_ok=True)
117 
118     def install_step(self):
119         # first, install the software
120         super(EB_ESMF, self).install_step()
121 
122         python = get_software_version('Python')
123         if python:
124             # then, install the python bindings
125             py_subdir = os.path.join(self.builddir, 'esmf-ESMF_%s' % '_'.join(self.version.split('.')),
126                                      'src', 'addon', 'ESMPy')
127             try:
128                 os.chdir(py_subdir)
129             except OSError as err:
130                 raise EasyBuildError("Failed to move to: %s", err)
131 
132             cmd = "python setup.py build --ESMFMKFILE=%s/lib/esmf.mk " % self.installdir
133             cmd += " && python setup.py install --prefix=%s" % self.installdir
134             run_cmd(cmd, log_all=True, simple=True, log_ok=True)
135 
136     def make_module_extra(self):
137         """Add install path to PYTHONPATH or EBPYTHONPREFIXES"""
138         txt = super(EB_ESMF, self).make_module_extra()
139 
140         if self.cfg['multi_deps'] and 'Python' in self.cfg['multi_deps']:
141             txt += self.module_generator.prepend_paths('EBPYTHONPREFIXES', '')
142         else:
143             python = get_software_version('Python')
144             if python:
145                 pyshortver = '.'.join(get_software_version('Python').split('.')[:2])
146                 pythonpath = os.path.join('lib', 'python%s' % pyshortver, 'site-packages')
147                 txt += self.module_generator.prepend_paths('PYTHONPATH', [pythonpath])
148 
149         return txt
150 
151     def sanity_check_step(self):
152         """Custom sanity check for ESMF."""
153 
154         if LooseVersion(self.version) < LooseVersion('8.1.0'):
155             binaries = ['ESMF_Info', 'ESMF_InfoC', 'ESMF_Regrid', 'ESMF_RegridWeightGen',
156                         'ESMF_Scrip2Unstruct', 'ESMF_WebServController']
157         else:
158             binaries = ['ESMF_PrintInfo', 'ESMF_PrintInfoC', 'ESMF_Regrid', 'ESMF_RegridWeightGen',
159                         'ESMF_Scrip2Unstruct', 'ESMF_WebServController']
160 
161         libs = ['libesmf.a', 'libesmf.%s' % get_shared_lib_ext()]
162         custom_paths = {
163             'files': [os.path.join('bin', x) for x in binaries] + [os.path.join('lib', x) for x in libs],
164             'dirs': ['include', 'mod'],
165         }
166 
167         custom_commands = []
168         if get_software_root('Python'):
169             custom_commands += ["python -c 'import ESMF'"]
170 
171         super(EB_ESMF, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)
172
```
--- 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/e/esmf.py b/easybuild/easyblocks/e/esmf.py
--- a/easybuild/easyblocks/e/esmf.py
+++ b/easybuild/easyblocks/e/esmf.py
@@ -39,11 +39,20 @@
 from easybuild.tools.modules import get_software_root, get_software_version
 from easybuild.tools.run import run_cmd
 from easybuild.tools.systemtools import get_shared_lib_ext
+from easybuild.framework.easyconfig import CUSTOM
 
 
 class EB_ESMF(ConfigureMake):
     """Support for building/installing ESMF."""
 
+    @staticmethod
+    def extra_options():
+        """Custom easyconfig parameters for ESMF"""
+        extra_vars = {
+            'disable_lapack': [False, 'Disable external LAPACK - True or False', CUSTOM]
+        }
+        return ConfigureMake.extra_options(extra_vars)
+
     def configure_step(self):
         """Custom configuration procedure for ESMF through environment variables."""
 
@@ -75,13 +84,19 @@
         env.setvar('ESMF_COMM', comm)
 
         # specify decent LAPACK lib
-        env.setvar('ESMF_LAPACK', 'user')
-        ldflags = os.getenv('LDFLAGS')
-        liblapack = os.getenv('LIBLAPACK_MT') or os.getenv('LIBLAPACK')
-        if liblapack is None:
-            raise EasyBuildError("$LIBLAPACK(_MT) not defined, no BLAS/LAPACK in %s toolchain?", self.toolchain.name)
+        if self.cfg['disable_lapack']:
+            env.setvar('ESMF_LAPACK', 'OFF')
+            # MOAB can't be built without LAPACK
+            env.setvar('ESMF_MOAB', 'OFF')
         else:
-            env.setvar('ESMF_LAPACK_LIBS', ldflags + ' ' + liblapack)
+            env.setvar('ESMF_LAPACK', 'user')
+            ldflags = os.getenv('LDFLAGS')
+            liblapack = os.getenv('LIBLAPACK_MT') or os.getenv('LIBLAPACK')
+            if liblapack is None:
+                msg = "$LIBLAPACK(_MT) not defined, no BLAS/LAPACK in %s toolchain?"
+                raise EasyBuildError(msg, self.toolchain.name)
+            else:
+                env.setvar('ESMF_LAPACK_LIBS', ldflags + ' ' + liblapack)
 
         # specify netCDF
         netcdf = get_software_root('netCDF')

{"golden_diff": "diff --git a/easybuild/easyblocks/e/esmf.py b/easybuild/easyblocks/e/esmf.py\n--- a/easybuild/easyblocks/e/esmf.py\n+++ b/easybuild/easyblocks/e/esmf.py\n@@ -39,11 +39,20 @@\n from easybuild.tools.modules import get_software_root, get_software_version\n from easybuild.tools.run import run_cmd\n from easybuild.tools.systemtools import get_shared_lib_ext\n+from easybuild.framework.easyconfig import CUSTOM\n \n \n class EB_ESMF(ConfigureMake):\n     \"\"\"Support for building/installing ESMF.\"\"\"\n \n+    @staticmethod\n+    def extra_options():\n+        \"\"\"Custom easyconfig parameters for ESMF\"\"\"\n+        extra_vars = {\n+            'disable_lapack': [False, 'Disable external LAPACK - True or False', CUSTOM]\n+        }\n+        return ConfigureMake.extra_options(extra_vars)\n+\n     def configure_step(self):\n         \"\"\"Custom configuration procedure for ESMF through environment variables.\"\"\"\n \n@@ -75,13 +84,19 @@\n         env.setvar('ESMF_COMM', comm)\n \n         # specify decent LAPACK lib\n-        env.setvar('ESMF_LAPACK', 'user')\n-        ldflags = os.getenv('LDFLAGS')\n-        liblapack = os.getenv('LIBLAPACK_MT') or os.getenv('LIBLAPACK')\n-        if liblapack is None:\n-            raise EasyBuildError(\"$LIBLAPACK(_MT) not defined, no BLAS/LAPACK in %s toolchain?\", self.toolchain.name)\n+        if self.cfg['disable_lapack']:\n+            env.setvar('ESMF_LAPACK', 'OFF')\n+            # MOAB can't be built without LAPACK\n+            env.setvar('ESMF_MOAB', 'OFF')\n         else:\n-            env.setvar('ESMF_LAPACK_LIBS', ldflags + ' ' + liblapack)\n+            env.setvar('ESMF_LAPACK', 'user')\n+            ldflags = os.getenv('LDFLAGS')\n+            liblapack = os.getenv('LIBLAPACK_MT') or os.getenv('LIBLAPACK')\n+            if liblapack is None:\n+                msg = \"$LIBLAPACK(_MT) not defined, no BLAS/LAPACK in %s toolchain?\"\n+                raise EasyBuildError(msg, self.toolchain.name)\n+            else:\n+                env.setvar('ESMF_LAPACK_LIBS', ldflags + ' ' + liblapack)\n \n         # specify netCDF\n         netcdf = get_software_root('netCDF')\n", "issue": "Add ability to turn off LAPACK in ESMF\nI have found myself in the situation where I want to build ESMF without LAPACK dependent code paths - the EasyBlock forces the build into the 'user specified LAPACK' mode and doesn't allow this (unless I'm missing something!).\r\n\r\nAdding an extra option to disable LAPACK would allow for non-LAPACK builds. PR to follow.\n", "before_files": [{"content": "##\n# Copyright 2013-2022 Ghent University\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 building and installing ESMF, implemented as an easyblock\n\n@author: Kenneth Hoste (Ghent University)\n@author: Damian Alvarez (Forschungszentrum Juelich GmbH)\n@author: Maxime Boissonneault (Digital Research Alliance of Canada)\n\"\"\"\nimport os\nfrom distutils.version import LooseVersion\n\nimport easybuild.tools.environment as env\nimport easybuild.tools.toolchain as toolchain\nfrom easybuild.easyblocks.generic.configuremake import ConfigureMake\nfrom easybuild.tools.build_log import EasyBuildError\nfrom easybuild.tools.modules import get_software_root, get_software_version\nfrom easybuild.tools.run import run_cmd\nfrom easybuild.tools.systemtools import get_shared_lib_ext\n\n\nclass EB_ESMF(ConfigureMake):\n    \"\"\"Support for building/installing ESMF.\"\"\"\n\n    def configure_step(self):\n        \"\"\"Custom configuration procedure for ESMF through environment variables.\"\"\"\n\n        env.setvar('ESMF_DIR', self.cfg['start_dir'])\n        env.setvar('ESMF_INSTALL_PREFIX', self.installdir)\n        env.setvar('ESMF_INSTALL_BINDIR', 'bin')\n        env.setvar('ESMF_INSTALL_LIBDIR', 'lib')\n        env.setvar('ESMF_INSTALL_MODDIR', 'mod')\n\n        # specify compiler\n        comp_family = self.toolchain.comp_family()\n        if comp_family in [toolchain.GCC]:\n            compiler = 'gfortran'\n        else:\n            compiler = comp_family.lower()\n        env.setvar('ESMF_COMPILER', compiler)\n\n        env.setvar('ESMF_F90COMPILEOPTS', os.getenv('F90FLAGS'))\n        env.setvar('ESMF_CXXCOMPILEOPTS', os.getenv('CXXFLAGS'))\n\n        # specify MPI communications library\n        comm = None\n        mpi_family = self.toolchain.mpi_family()\n        if mpi_family in [toolchain.MPICH, toolchain.QLOGICMPI]:\n            # MPICH family for MPICH v3.x, which is MPICH2 compatible\n            comm = 'mpich2'\n        else:\n            comm = mpi_family.lower()\n        env.setvar('ESMF_COMM', comm)\n\n        # specify decent LAPACK lib\n        env.setvar('ESMF_LAPACK', 'user')\n        ldflags = os.getenv('LDFLAGS')\n        liblapack = os.getenv('LIBLAPACK_MT') or os.getenv('LIBLAPACK')\n        if liblapack is None:\n            raise EasyBuildError(\"$LIBLAPACK(_MT) not defined, no BLAS/LAPACK in %s toolchain?\", self.toolchain.name)\n        else:\n            env.setvar('ESMF_LAPACK_LIBS', ldflags + ' ' + liblapack)\n\n        # specify netCDF\n        netcdf = get_software_root('netCDF')\n        if netcdf:\n            if LooseVersion(self.version) >= LooseVersion('7.1.0'):\n                env.setvar('ESMF_NETCDF', 'nc-config')\n            else:\n                env.setvar('ESMF_NETCDF', 'user')\n                netcdf_libs = ['-L%s/lib' % netcdf, '-lnetcdf']\n\n                # Fortran\n                netcdff = get_software_root('netCDF-Fortran')\n                if netcdff:\n                    netcdf_libs = [\"-L%s/lib\" % netcdff] + netcdf_libs + [\"-lnetcdff\"]\n                else:\n                    netcdf_libs.append('-lnetcdff')\n\n                # C++\n                netcdfcxx = get_software_root('netCDF-C++')\n                if netcdfcxx:\n                    netcdf_libs = [\"-L%s/lib\" % netcdfcxx] + netcdf_libs + [\"-lnetcdf_c++\"]\n                else:\n                    netcdfcxx = get_software_root('netCDF-C++4')\n                    if netcdfcxx:\n                        netcdf_libs = [\"-L%s/lib\" % netcdfcxx] + netcdf_libs + [\"-lnetcdf_c++4\"]\n                    else:\n                        netcdf_libs.append('-lnetcdf_c++')\n                env.setvar('ESMF_NETCDF_LIBS', ' '.join(netcdf_libs))\n\n        # 'make info' provides useful debug info\n        cmd = \"make info\"\n        run_cmd(cmd, log_all=True, simple=True, log_ok=True)\n\n    def install_step(self):\n        # first, install the software\n        super(EB_ESMF, self).install_step()\n\n        python = get_software_version('Python')\n        if python:\n            # then, install the python bindings\n            py_subdir = os.path.join(self.builddir, 'esmf-ESMF_%s' % '_'.join(self.version.split('.')),\n                                     'src', 'addon', 'ESMPy')\n            try:\n                os.chdir(py_subdir)\n            except OSError as err:\n                raise EasyBuildError(\"Failed to move to: %s\", err)\n\n            cmd = \"python setup.py build --ESMFMKFILE=%s/lib/esmf.mk \" % self.installdir\n            cmd += \" && python setup.py install --prefix=%s\" % self.installdir\n            run_cmd(cmd, log_all=True, simple=True, log_ok=True)\n\n    def make_module_extra(self):\n        \"\"\"Add install path to PYTHONPATH or EBPYTHONPREFIXES\"\"\"\n        txt = super(EB_ESMF, self).make_module_extra()\n\n        if self.cfg['multi_deps'] and 'Python' in self.cfg['multi_deps']:\n            txt += self.module_generator.prepend_paths('EBPYTHONPREFIXES', '')\n        else:\n            python = get_software_version('Python')\n            if python:\n                pyshortver = '.'.join(get_software_version('Python').split('.')[:2])\n                pythonpath = os.path.join('lib', 'python%s' % pyshortver, 'site-packages')\n                txt += self.module_generator.prepend_paths('PYTHONPATH', [pythonpath])\n\n        return txt\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for ESMF.\"\"\"\n\n        if LooseVersion(self.version) < LooseVersion('8.1.0'):\n            binaries = ['ESMF_Info', 'ESMF_InfoC', 'ESMF_Regrid', 'ESMF_RegridWeightGen',\n                        'ESMF_Scrip2Unstruct', 'ESMF_WebServController']\n        else:\n            binaries = ['ESMF_PrintInfo', 'ESMF_PrintInfoC', 'ESMF_Regrid', 'ESMF_RegridWeightGen',\n                        'ESMF_Scrip2Unstruct', 'ESMF_WebServController']\n\n        libs = ['libesmf.a', 'libesmf.%s' % get_shared_lib_ext()]\n        custom_paths = {\n            'files': [os.path.join('bin', x) for x in binaries] + [os.path.join('lib', x) for x in libs],\n            'dirs': ['include', 'mod'],\n        }\n\n        custom_commands = []\n        if get_software_root('Python'):\n            custom_commands += [\"python -c 'import ESMF'\"]\n\n        super(EB_ESMF, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)\n", "path": "easybuild/easyblocks/e/esmf.py"}], "after_files": [{"content": "##\n# Copyright 2013-2022 Ghent University\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 building and installing ESMF, implemented as an easyblock\n\n@author: Kenneth Hoste (Ghent University)\n@author: Damian Alvarez (Forschungszentrum Juelich GmbH)\n@author: Maxime Boissonneault (Digital Research Alliance of Canada)\n\"\"\"\nimport os\nfrom distutils.version import LooseVersion\n\nimport easybuild.tools.environment as env\nimport easybuild.tools.toolchain as toolchain\nfrom easybuild.easyblocks.generic.configuremake import ConfigureMake\nfrom easybuild.tools.build_log import EasyBuildError\nfrom easybuild.tools.modules import get_software_root, get_software_version\nfrom easybuild.tools.run import run_cmd\nfrom easybuild.tools.systemtools import get_shared_lib_ext\nfrom easybuild.framework.easyconfig import CUSTOM\n\n\nclass EB_ESMF(ConfigureMake):\n    \"\"\"Support for building/installing ESMF.\"\"\"\n\n    @staticmethod\n    def extra_options():\n        \"\"\"Custom easyconfig parameters for ESMF\"\"\"\n        extra_vars = {\n            'disable_lapack': [False, 'Disable external LAPACK - True or False', CUSTOM]\n        }\n        return ConfigureMake.extra_options(extra_vars)\n\n    def configure_step(self):\n        \"\"\"Custom configuration procedure for ESMF through environment variables.\"\"\"\n\n        env.setvar('ESMF_DIR', self.cfg['start_dir'])\n        env.setvar('ESMF_INSTALL_PREFIX', self.installdir)\n        env.setvar('ESMF_INSTALL_BINDIR', 'bin')\n        env.setvar('ESMF_INSTALL_LIBDIR', 'lib')\n        env.setvar('ESMF_INSTALL_MODDIR', 'mod')\n\n        # specify compiler\n        comp_family = self.toolchain.comp_family()\n        if comp_family in [toolchain.GCC]:\n            compiler = 'gfortran'\n        else:\n            compiler = comp_family.lower()\n        env.setvar('ESMF_COMPILER', compiler)\n\n        env.setvar('ESMF_F90COMPILEOPTS', os.getenv('F90FLAGS'))\n        env.setvar('ESMF_CXXCOMPILEOPTS', os.getenv('CXXFLAGS'))\n\n        # specify MPI communications library\n        comm = None\n        mpi_family = self.toolchain.mpi_family()\n        if mpi_family in [toolchain.MPICH, toolchain.QLOGICMPI]:\n            # MPICH family for MPICH v3.x, which is MPICH2 compatible\n            comm = 'mpich2'\n        else:\n            comm = mpi_family.lower()\n        env.setvar('ESMF_COMM', comm)\n\n        # specify decent LAPACK lib\n        if self.cfg['disable_lapack']:\n            env.setvar('ESMF_LAPACK', 'OFF')\n            # MOAB can't be built without LAPACK\n            env.setvar('ESMF_MOAB', 'OFF')\n        else:\n            env.setvar('ESMF_LAPACK', 'user')\n            ldflags = os.getenv('LDFLAGS')\n            liblapack = os.getenv('LIBLAPACK_MT') or os.getenv('LIBLAPACK')\n            if liblapack is None:\n                msg = \"$LIBLAPACK(_MT) not defined, no BLAS/LAPACK in %s toolchain?\"\n                raise EasyBuildError(msg, self.toolchain.name)\n            else:\n                env.setvar('ESMF_LAPACK_LIBS', ldflags + ' ' + liblapack)\n\n        # specify netCDF\n        netcdf = get_software_root('netCDF')\n        if netcdf:\n            if LooseVersion(self.version) >= LooseVersion('7.1.0'):\n                env.setvar('ESMF_NETCDF', 'nc-config')\n            else:\n                env.setvar('ESMF_NETCDF', 'user')\n                netcdf_libs = ['-L%s/lib' % netcdf, '-lnetcdf']\n\n                # Fortran\n                netcdff = get_software_root('netCDF-Fortran')\n                if netcdff:\n                    netcdf_libs = [\"-L%s/lib\" % netcdff] + netcdf_libs + [\"-lnetcdff\"]\n                else:\n                    netcdf_libs.append('-lnetcdff')\n\n                # C++\n                netcdfcxx = get_software_root('netCDF-C++')\n                if netcdfcxx:\n                    netcdf_libs = [\"-L%s/lib\" % netcdfcxx] + netcdf_libs + [\"-lnetcdf_c++\"]\n                else:\n                    netcdfcxx = get_software_root('netCDF-C++4')\n                    if netcdfcxx:\n                        netcdf_libs = [\"-L%s/lib\" % netcdfcxx] + netcdf_libs + [\"-lnetcdf_c++4\"]\n                    else:\n                        netcdf_libs.append('-lnetcdf_c++')\n                env.setvar('ESMF_NETCDF_LIBS', ' '.join(netcdf_libs))\n\n        # 'make info' provides useful debug info\n        cmd = \"make info\"\n        run_cmd(cmd, log_all=True, simple=True, log_ok=True)\n\n    def install_step(self):\n        # first, install the software\n        super(EB_ESMF, self).install_step()\n\n        python = get_software_version('Python')\n        if python:\n            # then, install the python bindings\n            py_subdir = os.path.join(self.builddir, 'esmf-ESMF_%s' % '_'.join(self.version.split('.')),\n                                     'src', 'addon', 'ESMPy')\n            try:\n                os.chdir(py_subdir)\n            except OSError as err:\n                raise EasyBuildError(\"Failed to move to: %s\", err)\n\n            cmd = \"python setup.py build --ESMFMKFILE=%s/lib/esmf.mk \" % self.installdir\n            cmd += \" && python setup.py install --prefix=%s\" % self.installdir\n            run_cmd(cmd, log_all=True, simple=True, log_ok=True)\n\n    def make_module_extra(self):\n        \"\"\"Add install path to PYTHONPATH or EBPYTHONPREFIXES\"\"\"\n        txt = super(EB_ESMF, self).make_module_extra()\n\n        if self.cfg['multi_deps'] and 'Python' in self.cfg['multi_deps']:\n            txt += self.module_generator.prepend_paths('EBPYTHONPREFIXES', '')\n        else:\n            python = get_software_version('Python')\n            if python:\n                pyshortver = '.'.join(get_software_version('Python').split('.')[:2])\n                pythonpath = os.path.join('lib', 'python%s' % pyshortver, 'site-packages')\n                txt += self.module_generator.prepend_paths('PYTHONPATH', [pythonpath])\n\n        return txt\n\n    def sanity_check_step(self):\n        \"\"\"Custom sanity check for ESMF.\"\"\"\n\n        if LooseVersion(self.version) < LooseVersion('8.1.0'):\n            binaries = ['ESMF_Info', 'ESMF_InfoC', 'ESMF_Regrid', 'ESMF_RegridWeightGen',\n                        'ESMF_Scrip2Unstruct', 'ESMF_WebServController']\n        else:\n            binaries = ['ESMF_PrintInfo', 'ESMF_PrintInfoC', 'ESMF_Regrid', 'ESMF_RegridWeightGen',\n                        'ESMF_Scrip2Unstruct', 'ESMF_WebServController']\n\n        libs = ['libesmf.a', 'libesmf.%s' % get_shared_lib_ext()]\n        custom_paths = {\n            'files': [os.path.join('bin', x) for x in binaries] + [os.path.join('lib', x) for x in libs],\n            'dirs': ['include', 'mod'],\n        }\n\n        custom_commands = []\n        if get_software_root('Python'):\n            custom_commands += [\"python -c 'import ESMF'\"]\n\n        super(EB_ESMF, self).sanity_check_step(custom_commands=custom_commands, custom_paths=custom_paths)\n", "path": "easybuild/easyblocks/e/esmf.py"}]}