2323
2424from packaging .version import Version
2525import posixpath
26+ import re
27+ from copy import copy as _copy
2628
2729import hpccm .config
2830import hpccm .templates .envvars
3335from hpccm .building_blocks .packages import packages
3436from hpccm .common import linux_distro
3537from hpccm .primitives .comment import comment
38+ from hpccm .toolchain import toolchain
3639
3740class netcdf (bb_base , hpccm .templates .envvars , hpccm .templates .ldconfig ):
3841 """The `netcdf` building block downloads, configures, builds, and
@@ -80,10 +83,10 @@ class netcdf(bb_base, hpccm.templates.envvars, hpccm.templates.ldconfig):
8083
8184 ospackages: List of OS packages to install prior to configuring
8285 and building. For Ubuntu, the default values are
83- `ca-certificates`, `file`, `libcurl4-openssl-dev`, `m4 `, `make `,
84- `wget`, and `zlib1g-dev`. For RHEL-based Linux distributions the
85- default values are `ca-certificates`, `file`, `libcurl-devel`
86- `m4`, `make`, `wget`, and `zlib-devel`.
86+ `ca-certificates`, `file`, `libcurl4-openssl-dev`, `libxml2-dev `, `m4 `,
87+ `make`, ` wget`, and `zlib1g-dev`. For RHEL-based Linux distributions the
88+ default values are `ca-certificates`, `file`, `libcurl-devel`,
89+ `libxml2-devel`, ` m4`, `make`, `wget`, and `zlib-devel`.
8790
8891 prefix: The top level install location. The default location is
8992 `/usr/local/netcdf`.
@@ -134,6 +137,9 @@ def __init__(self, **kwargs):
134137 self .__ospackages = kwargs .pop ('ospackages' , [])
135138 self .__prefix = kwargs .pop ('prefix' , '/usr/local/netcdf' )
136139 self .__runtime_ospackages = [] # Filled in by __distro()
140+ # Create a copy of the toolchain so that it can be modified
141+ # without impacting the original
142+ self .__toolchain = _copy (kwargs .pop ('toolchain' , toolchain ()))
137143 self .__version = kwargs .pop ('version' , '4.7.4' )
138144 self .__version_cxx = kwargs .pop ('version_cxx' , '4.3.1' )
139145 self .__version_fortran = kwargs .pop ('version_fortran' , '4.5.3' )
@@ -165,6 +171,7 @@ def __init__(self, **kwargs):
165171 directory = self .__directory_c ,
166172 prefix = self .__prefix ,
167173 runtime_environment = self .environment_variables ,
174+ toolchain = self .__toolchain ,
168175 url = self .__url_c ,
169176 ** kwargs )]
170177
@@ -180,12 +187,19 @@ def __init__(self, **kwargs):
180187 # Checks fail when using parallel make. Disable it.
181188 parallel = 1 if self .__check else '$(nproc)' ,
182189 prefix = self .__prefix ,
190+ toolchain = self .__toolchain ,
183191 url = '{0}/v{1}.tar.gz' .format (self .__baseurl_cxx ,
184192 self .__version_cxx ),
185193 ** kwargs ))
186194
187195 # Setup optional Fortran build configuration
188196 if self .__fortran :
197+ # PIC workaround when using the NVIDIA compilers
198+ if self .__toolchain .FC and re .match ('.*nvfortran' ,
199+ self .__toolchain .FC ):
200+ if not self .__toolchain .FCFLAGS :
201+ self .__toolchain .FCFLAGS = '-fPIC'
202+
189203 comments .append ('NetCDF Fortran version {}' .format (self .__version_fortran ))
190204 self .__bb .append (generic_autotools (
191205 annotations = {'version' : self .__version_fortran },
@@ -196,6 +210,7 @@ def __init__(self, **kwargs):
196210 # Checks fail when using parallel make. Disable it.
197211 parallel = 1 if self .__check else '$(nproc)' ,
198212 prefix = self .__prefix ,
213+ toolchain = self .__toolchain ,
199214 url = '{0}/v{1}.tar.gz' .format (self .__baseurl_fortran ,
200215 self .__version_fortran ),
201216 ** kwargs ))
@@ -212,14 +227,14 @@ def __distro(self):
212227 if hpccm .config .g_linux_distro == linux_distro .UBUNTU :
213228 if not self .__ospackages :
214229 self .__ospackages = ['ca-certificates' , 'file' ,
215- 'libcurl4-openssl-dev' , 'm4' , 'make ' ,
216- 'wget' , 'zlib1g-dev' ]
230+ 'libcurl4-openssl-dev' , 'libxml2-dev ' ,
231+ 'm4' , 'make' , ' wget' , 'zlib1g-dev' ]
217232 self .__runtime_ospackages = ['zlib1g' ]
218233 elif hpccm .config .g_linux_distro == linux_distro .CENTOS :
219234 if not self .__ospackages :
220235 self .__ospackages = ['ca-certificates' , 'file' ,
221- 'libcurl-devel' , 'm4 ' , 'make ' ,
222- 'wget' , 'zlib-devel' ]
236+ 'libcurl-devel' , 'libxml2-devel ' , 'm4 ' ,
237+ 'make' , ' wget' , 'zlib-devel' ]
223238 if self .__check :
224239 self .__ospackages .append ('diffutils' )
225240 self .__runtime_ospackages = ['zlib' ]
0 commit comments